Misha Brukman | fce1143 | 2002-10-28 00:28:31 +0000 | [diff] [blame^] | 1 | //===-- llvm/CodeGen/MachineFunction.h ---------------------------*- C++ -*--=// |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 2 | // |
Misha Brukman | fce1143 | 2002-10-28 00:28:31 +0000 | [diff] [blame^] | 3 | // 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 Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 7 | //===----------------------------------------------------------------------===// |
| 8 | |
Misha Brukman | fce1143 | 2002-10-28 00:28:31 +0000 | [diff] [blame^] | 9 | #ifndef LLVM_CODEGEN_MACHINEFUNCTION_H |
| 10 | #define LLVM_CODEGEN_MACHINEFUNCTION_H |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 11 | |
| 12 | #include "llvm/Annotation.h" |
| 13 | #include "Support/NonCopyable.h" |
| 14 | #include "Support/HashExtras.h" |
Chris Lattner | 09ff112 | 2002-07-24 21:21:32 +0000 | [diff] [blame] | 15 | #include <Support/hash_set> |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 16 | class Value; |
Chris Lattner | e7506a3 | 2002-03-23 22:51:58 +0000 | [diff] [blame] | 17 | class Function; |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 18 | class Constant; |
| 19 | class Type; |
| 20 | class TargetMachine; |
| 21 | |
| 22 | |
Misha Brukman | fce1143 | 2002-10-28 00:28:31 +0000 | [diff] [blame^] | 23 | class MachineFunction : private Annotation { |
Chris Lattner | 1089790 | 2002-07-24 21:21:33 +0000 | [diff] [blame] | 24 | hash_set<const Constant*> constantsForConstPool; |
| 25 | hash_map<const Value*, int> offsets; |
Vikram S. Adve | 7b3640b | 2002-04-25 04:47:26 +0000 | [diff] [blame] | 26 | const Function* method; |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 27 | unsigned staticStackSize; |
| 28 | unsigned automaticVarsSize; |
| 29 | unsigned regSpillsSize; |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 30 | unsigned maxOptionalArgsSize; |
Vikram S. Adve | 7b3640b | 2002-04-25 04:47:26 +0000 | [diff] [blame] | 31 | unsigned maxOptionalNumArgs; |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 32 | unsigned currentTmpValuesSize; |
Vikram S. Adve | fa79e6e | 2002-03-31 18:57:49 +0000 | [diff] [blame] | 33 | unsigned maxTmpValuesSize; |
Vikram S. Adve | 7b3640b | 2002-04-25 04:47:26 +0000 | [diff] [blame] | 34 | bool compiledAsLeaf; |
| 35 | bool spillsAreaFrozen; |
| 36 | bool automaticVarsAreaFrozen; |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 37 | |
| 38 | public: |
Misha Brukman | fce1143 | 2002-10-28 00:28:31 +0000 | [diff] [blame^] | 39 | /*ctor*/ MachineFunction(const Function* function, |
| 40 | const TargetMachine& target); |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 41 | |
| 42 | // The next two methods are used to construct and to retrieve |
Misha Brukman | fce1143 | 2002-10-28 00:28:31 +0000 | [diff] [blame^] | 43 | // the MachineFunction object for the given method. |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 44 | // 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 Brukman | fce1143 | 2002-10-28 00:28:31 +0000 | [diff] [blame^] | 49 | static MachineFunction& construct(const Function *method, |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 50 | const TargetMachine &target); |
Chris Lattner | e7506a3 | 2002-03-23 22:51:58 +0000 | [diff] [blame] | 51 | static void destruct(const Function *F); |
Misha Brukman | fce1143 | 2002-10-28 00:28:31 +0000 | [diff] [blame^] | 52 | static MachineFunction& get(const Function* function); |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 53 | |
| 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. Adve | 7b3640b | 2002-04-25 04:47:26 +0000 | [diff] [blame] | 62 | inline unsigned getMaxOptionalNumArgs() const { return maxOptionalNumArgs;} |
Chris Lattner | 1089790 | 2002-07-24 21:21:33 +0000 | [diff] [blame] | 63 | inline const hash_set<const Constant*>& |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 64 | 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. Adve | ce0845a | 2002-03-18 03:23:29 +0000 | [diff] [blame] | 76 | int computeOffsetforLocalVar (const TargetMachine& target, |
Vikram S. Adve | 7b3640b | 2002-04-25 04:47:26 +0000 | [diff] [blame] | 77 | const Value* local, |
Vikram S. Adve | 4cbd550 | 2002-03-24 03:57:38 +0000 | [diff] [blame] | 78 | unsigned int& getPaddedSize, |
| 79 | unsigned int sizeToUse = 0); |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 80 | int allocateLocalVar (const TargetMachine& target, |
| 81 | const Value* local, |
Vikram S. Adve | 4cbd550 | 2002-03-24 03:57:38 +0000 | [diff] [blame] | 82 | unsigned int sizeToUse = 0); |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 83 | |
| 84 | int allocateSpilledValue (const TargetMachine& target, |
| 85 | const Type* type); |
| 86 | |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 87 | int pushTempValue (const TargetMachine& target, |
| 88 | unsigned int size); |
| 89 | |
| 90 | void popAllTempValues (const TargetMachine& target); |
| 91 | |
Vikram S. Adve | 7b3640b | 2002-04-25 04:47:26 +0000 | [diff] [blame] | 92 | void freezeSpillsArea () { spillsAreaFrozen = true; } |
| 93 | void freezeAutomaticVarsArea () { automaticVarsAreaFrozen=true; } |
| 94 | |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 95 | int getOffset (const Value* val) const; |
| 96 | |
| 97 | // int getOffsetFromFP (const Value* val) const; |
| 98 | |
| 99 | void dump () const; |
| 100 | |
| 101 | private: |
| 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. Adve | fa79e6e | 2002-03-31 18:57:49 +0000 | [diff] [blame] | 110 | 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. Adve | 7b3640b | 2002-04-25 04:47:26 +0000 | [diff] [blame] | 121 | int allocateOptionalArg (const TargetMachine& target, |
| 122 | const Type* type); |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 123 | }; |
| 124 | |
| 125 | #endif |