blob: 141838f6003fd144e2b564bdfc3317bb9c140bc6 [file] [log] [blame]
Misha Brukmanfce11432002-10-28 00:28:31 +00001//===-- llvm/CodeGen/MachineFunction.h ---------------------------*- C++ -*--=//
Chris Lattnerf2868ce2002-02-03 07:54:50 +00002//
Misha Brukmanfce11432002-10-28 00:28:31 +00003// Collect native machine code information for a method. This allows
4// target-specific information about the generated code to be stored with each
5// method.
6//
Chris Lattnerf2868ce2002-02-03 07:54:50 +00007//===----------------------------------------------------------------------===//
8
Misha Brukmanfce11432002-10-28 00:28:31 +00009#ifndef LLVM_CODEGEN_MACHINEFUNCTION_H
10#define LLVM_CODEGEN_MACHINEFUNCTION_H
Chris Lattnerf2868ce2002-02-03 07:54:50 +000011
12#include "llvm/Annotation.h"
13#include "Support/NonCopyable.h"
14#include "Support/HashExtras.h"
Chris Lattner09ff1122002-07-24 21:21:32 +000015#include <Support/hash_set>
Chris Lattnerf2868ce2002-02-03 07:54:50 +000016class Value;
Chris Lattnere7506a32002-03-23 22:51:58 +000017class Function;
Chris Lattnerf2868ce2002-02-03 07:54:50 +000018class Constant;
19class Type;
20class TargetMachine;
21
22
Misha Brukmanfce11432002-10-28 00:28:31 +000023class MachineFunction : private Annotation {
Chris Lattner10897902002-07-24 21:21:33 +000024 hash_set<const Constant*> constantsForConstPool;
25 hash_map<const Value*, int> offsets;
Vikram S. Adve7b3640b2002-04-25 04:47:26 +000026 const Function* method;
Chris Lattnerf2868ce2002-02-03 07:54:50 +000027 unsigned staticStackSize;
28 unsigned automaticVarsSize;
29 unsigned regSpillsSize;
Chris Lattnerf2868ce2002-02-03 07:54:50 +000030 unsigned maxOptionalArgsSize;
Vikram S. Adve7b3640b2002-04-25 04:47:26 +000031 unsigned maxOptionalNumArgs;
Chris Lattnerf2868ce2002-02-03 07:54:50 +000032 unsigned currentTmpValuesSize;
Vikram S. Advefa79e6e2002-03-31 18:57:49 +000033 unsigned maxTmpValuesSize;
Vikram S. Adve7b3640b2002-04-25 04:47:26 +000034 bool compiledAsLeaf;
35 bool spillsAreaFrozen;
36 bool automaticVarsAreaFrozen;
Chris Lattnerf2868ce2002-02-03 07:54:50 +000037
38public:
Misha Brukmanfce11432002-10-28 00:28:31 +000039 /*ctor*/ MachineFunction(const Function* function,
40 const TargetMachine& target);
Chris Lattnerf2868ce2002-02-03 07:54:50 +000041
42 // The next two methods are used to construct and to retrieve
Misha Brukmanfce11432002-10-28 00:28:31 +000043 // the MachineFunction object for the given method.
Chris Lattnerf2868ce2002-02-03 07:54:50 +000044 // construct() -- Allocates and initializes for a given method and target
45 // get() -- Returns a handle to the object.
46 // This should not be called before "construct()"
47 // for a given Method.
48 //
Misha Brukmanfce11432002-10-28 00:28:31 +000049 static MachineFunction& construct(const Function *method,
Chris Lattnerf2868ce2002-02-03 07:54:50 +000050 const TargetMachine &target);
Chris Lattnere7506a32002-03-23 22:51:58 +000051 static void destruct(const Function *F);
Misha Brukmanfce11432002-10-28 00:28:31 +000052 static MachineFunction& get(const Function* function);
Chris Lattnerf2868ce2002-02-03 07:54:50 +000053
54 //
55 // Accessors for global information about generated code for a method.
56 //
57 inline bool isCompiledAsLeafMethod() const { return compiledAsLeaf; }
58 inline unsigned getStaticStackSize() const { return staticStackSize; }
59 inline unsigned getAutomaticVarsSize() const { return automaticVarsSize; }
60 inline unsigned getRegSpillsSize() const { return regSpillsSize; }
61 inline unsigned getMaxOptionalArgsSize() const { return maxOptionalArgsSize;}
Vikram S. Adve7b3640b2002-04-25 04:47:26 +000062 inline unsigned getMaxOptionalNumArgs() const { return maxOptionalNumArgs;}
Chris Lattner10897902002-07-24 21:21:33 +000063 inline const hash_set<const Constant*>&
Chris Lattnerf2868ce2002-02-03 07:54:50 +000064 getConstantPoolValues() const {return constantsForConstPool;}
65
66 //
67 // Modifiers used during code generation
68 //
69 void initializeFrameLayout (const TargetMachine& target);
70
71 void addToConstantPool (const Constant* constVal)
72 { constantsForConstPool.insert(constVal); }
73
74 inline void markAsLeafMethod() { compiledAsLeaf = true; }
75
Vikram S. Advece0845a2002-03-18 03:23:29 +000076 int computeOffsetforLocalVar (const TargetMachine& target,
Vikram S. Adve7b3640b2002-04-25 04:47:26 +000077 const Value* local,
Vikram S. Adve4cbd5502002-03-24 03:57:38 +000078 unsigned int& getPaddedSize,
79 unsigned int sizeToUse = 0);
Chris Lattnerf2868ce2002-02-03 07:54:50 +000080 int allocateLocalVar (const TargetMachine& target,
81 const Value* local,
Vikram S. Adve4cbd5502002-03-24 03:57:38 +000082 unsigned int sizeToUse = 0);
Chris Lattnerf2868ce2002-02-03 07:54:50 +000083
84 int allocateSpilledValue (const TargetMachine& target,
85 const Type* type);
86
Chris Lattnerf2868ce2002-02-03 07:54:50 +000087 int pushTempValue (const TargetMachine& target,
88 unsigned int size);
89
90 void popAllTempValues (const TargetMachine& target);
91
Vikram S. Adve7b3640b2002-04-25 04:47:26 +000092 void freezeSpillsArea () { spillsAreaFrozen = true; }
93 void freezeAutomaticVarsArea () { automaticVarsAreaFrozen=true; }
94
Chris Lattnerf2868ce2002-02-03 07:54:50 +000095 int getOffset (const Value* val) const;
96
97 // int getOffsetFromFP (const Value* val) const;
98
99 void dump () const;
100
101private:
102 inline void incrementAutomaticVarsSize(int incr) {
103 automaticVarsSize+= incr;
104 staticStackSize += incr;
105 }
106 inline void incrementRegSpillsSize(int incr) {
107 regSpillsSize+= incr;
108 staticStackSize += incr;
109 }
Vikram S. Advefa79e6e2002-03-31 18:57:49 +0000110 inline void incrementTmpAreaSize(int incr) {
111 currentTmpValuesSize += incr;
112 if (maxTmpValuesSize < currentTmpValuesSize)
113 {
114 staticStackSize += currentTmpValuesSize - maxTmpValuesSize;
115 maxTmpValuesSize = currentTmpValuesSize;
116 }
117 }
118 inline void resetTmpAreaSize() {
119 currentTmpValuesSize = 0;
120 }
Vikram S. Adve7b3640b2002-04-25 04:47:26 +0000121 int allocateOptionalArg (const TargetMachine& target,
122 const Type* type);
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000123};
124
125#endif