diff options
author | Vikram S. Adve <vadve@cs.uiuc.edu> | 2001-11-08 04:47:06 +0000 |
---|---|---|
committer | Vikram S. Adve <vadve@cs.uiuc.edu> | 2001-11-08 04:47:06 +0000 |
commit | be49526193c5d8856d0b3c2721dfa6a4c4010d6d (patch) | |
tree | cb28dac5901991e22ffd117debed336b9850888e /include/llvm/CodeGen/MachineInstr.h | |
parent | ebfa232e9dd5dbfedc8a4d2f6c58c0828f329e8c (diff) |
Major overhaul of stack frame management.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1185 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/CodeGen/MachineInstr.h')
-rw-r--r-- | include/llvm/CodeGen/MachineInstr.h | 122 |
1 files changed, 89 insertions, 33 deletions
diff --git a/include/llvm/CodeGen/MachineInstr.h b/include/llvm/CodeGen/MachineInstr.h index dc68904e3c..ca8f1fb1ec 100644 --- a/include/llvm/CodeGen/MachineInstr.h +++ b/include/llvm/CodeGen/MachineInstr.h @@ -20,12 +20,23 @@ #include "llvm/Support/DataTypes.h" #include "llvm/Support/NonCopyable.h" #include "llvm/Target/MachineInstrInfo.h" +#include "llvm/Annotation.h" +#include "llvm/Method.h" #include <hash_map> #include <hash_set> +#include <values.h> template<class _MI, class _V> class ValOpIterator; +//************************** External Constants ****************************/ + +const int INVALID_FRAME_OFFSET = MAXINT; + + +//*************************** External Classes *****************************/ + + //--------------------------------------------------------------------------- // class MachineOperand // @@ -506,64 +517,109 @@ public: //--------------------------------------------------------------------------- -class MachineCodeForMethod: public NonCopyable { + +class MachineCodeForMethod: public NonCopyable, private Annotation { +private: + static AnnotationID AID; private: - Method* method; + const Method* method; bool compiledAsLeaf; unsigned staticStackSize; unsigned automaticVarsSize; unsigned regSpillsSize; - unsigned optionalOutgoingArgsSize; + unsigned currentOptionalArgsSize; + unsigned maxOptionalArgsSize; + unsigned currentTmpValuesSize; hash_set<const ConstPoolVal*> constantsForConstPool; - hash_map<const Value*, int> offsetsFromFP; - hash_map<const Value*, int> offsetsFromSP; - - inline void incrementAutomaticVarsSize(int incr) - { automaticVarsSize+= incr; - staticStackSize += incr; } + hash_map<const Value*, int> offsets; + // hash_map<const Value*, int> offsetsFromSP; public: - /*ctor*/ MachineCodeForMethod(Method* _M) - : method(_M), compiledAsLeaf(false), staticStackSize(0), - automaticVarsSize(0), regSpillsSize(0), optionalOutgoingArgsSize(0) {} - - inline bool isCompiledAsLeafMethod() const { return compiledAsLeaf; } - inline unsigned getStaticStackSize() const { return staticStackSize; } - inline unsigned getAutomaticVarsSize() const { return automaticVarsSize; } - inline unsigned getRegSpillsSize() const { return regSpillsSize; } - inline unsigned getOptionalOutgoingArgsSize() const - { return optionalOutgoingArgsSize; } + /*ctor*/ MachineCodeForMethod(const Method* method, + const TargetMachine& target); + + // The next two methods are used to construct and to retrieve + // the MachineCodeForMethod object for the given method. + // construct() -- Allocates and initializes for a given method and target + // get() -- Returns a handle to the object. + // This should not be called before "construct()" + // for a given Method. + // + inline static MachineCodeForMethod& construct(const Method* method, + const TargetMachine& target) + { + assert(method->getAnnotation(MachineCodeForMethod::AID) == NULL && + "Object already exists for this method!"); + MachineCodeForMethod* mcInfo = new MachineCodeForMethod(method, target); + method->addAnnotation(mcInfo); + return *mcInfo; + } + + inline static MachineCodeForMethod& get(const Method* method) + { + MachineCodeForMethod* mc = (MachineCodeForMethod*) + method->getAnnotation(MachineCodeForMethod::AID); + assert(mc && "Call construct() method first to allocate the object"); + return *mc; + } + + // + // Accessors for global information about generated code for a method. + // + inline bool isCompiledAsLeafMethod() const { return compiledAsLeaf; } + inline unsigned getStaticStackSize() const { return staticStackSize; } + inline unsigned getAutomaticVarsSize() const { return automaticVarsSize; } + inline unsigned getRegSpillsSize() const { return regSpillsSize; } + inline unsigned getMaxOptionalArgsSize() const { return maxOptionalArgsSize;} + inline unsigned getCurrentOptionalArgsSize() const + { return currentOptionalArgsSize;} inline const hash_set<const ConstPoolVal*>& getConstantPoolValues() const {return constantsForConstPool;} + // + // Modifiers used during code generation + // + void initializeFrameLayout (const TargetMachine& target); + void addToConstantPool (const ConstPoolVal* constVal) { constantsForConstPool.insert(constVal); } inline void markAsLeafMethod() { compiledAsLeaf = true; } - inline void incrementStackSize(int incr) { staticStackSize += incr; } + int allocateLocalVar (const TargetMachine& target, + const Value* local); - inline void incrementRegSpillsSize(int incr) - { regSpillsSize+= incr; - staticStackSize += incr; } + int allocateSpilledValue (const TargetMachine& target, + const Type* type); - inline void incrementOptionalOutgoingArgsSize(int incr) - { optionalOutgoingArgsSize+= incr; - staticStackSize += incr; } + int allocateOptionalArg (const TargetMachine& target, + const Type* type); - void putLocalVarAtOffsetFromFP(const Value* local, - int offset, - unsigned int size); + void resetOptionalArgs (const TargetMachine& target); - void putLocalVarAtOffsetFromSP(const Value* local, - int offset, + int pushTempValue (const TargetMachine& target, unsigned int size); - int getOffsetFromFP (const Value* local) const; + void popAllTempValues (const TargetMachine& target); - int getOffsetFromSP (const Value* local) const; + int getOffset (const Value* val) const; + + // int getOffsetFromFP (const Value* val) const; void dump () const; + +private: + inline void incrementAutomaticVarsSize(int incr) { + automaticVarsSize+= incr; + staticStackSize += incr; + } + inline void incrementRegSpillsSize(int incr) { + regSpillsSize+= incr; + staticStackSize += incr; + } + inline void incrementCurrentOptionalArgsSize(int incr) { + currentOptionalArgsSize+= incr; // stack size already includes this! + } }; |