diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/llvm/CodeGen/BreakCriticalMachineEdge.h | 8 | ||||
-rw-r--r-- | include/llvm/CodeGen/MachineBasicBlock.h | 69 | ||||
-rw-r--r-- | include/llvm/CodeGen/MachineFunction.h | 133 | ||||
-rw-r--r-- | include/llvm/CodeGen/MachineInstr.h | 59 | ||||
-rw-r--r-- | include/llvm/CodeGen/MachineInstrBuilder.h | 20 |
5 files changed, 155 insertions, 134 deletions
diff --git a/include/llvm/CodeGen/BreakCriticalMachineEdge.h b/include/llvm/CodeGen/BreakCriticalMachineEdge.h index a803427598..fd5df521f2 100644 --- a/include/llvm/CodeGen/BreakCriticalMachineEdge.h +++ b/include/llvm/CodeGen/BreakCriticalMachineEdge.h @@ -22,9 +22,10 @@ namespace llvm { MachineBasicBlock* SplitCriticalMachineEdge(MachineBasicBlock* src, MachineBasicBlock* dst) { + MachineFunction &MF = *src->getParent(); const BasicBlock* srcBB = src->getBasicBlock(); - MachineBasicBlock* crit_mbb = new MachineBasicBlock(srcBB); + MachineBasicBlock* crit_mbb = MF.CreateMachineBasicBlock(srcBB); // modify the llvm control flow graph src->removeSuccessor(dst); @@ -32,11 +33,10 @@ MachineBasicBlock* SplitCriticalMachineEdge(MachineBasicBlock* src, crit_mbb->addSuccessor(dst); // insert the new block into the machine function. - src->getParent()->getBasicBlockList().insert(src->getParent()->end(), - crit_mbb); + MF.push_back(crit_mbb); // insert a unconditional branch linking the new block to dst - const TargetMachine& TM = src->getParent()->getTarget(); + const TargetMachine& TM = MF.getTarget(); const TargetInstrInfo* TII = TM.getInstrInfo(); std::vector<MachineOperand> emptyConditions; TII->InsertBranch(*crit_mbb, dst, (MachineBasicBlock*)0, diff --git a/include/llvm/CodeGen/MachineBasicBlock.h b/include/llvm/CodeGen/MachineBasicBlock.h index cd7c8d5992..6958dba271 100644 --- a/include/llvm/CodeGen/MachineBasicBlock.h +++ b/include/llvm/CodeGen/MachineBasicBlock.h @@ -16,57 +16,38 @@ #include "llvm/CodeGen/MachineInstr.h" #include "llvm/ADT/GraphTraits.h" -#include "llvm/ADT/ilist.h" #include "llvm/Support/Streams.h" namespace llvm { class MachineFunction; -// ilist_traits template <> -struct ilist_traits<MachineInstr> { +struct alist_traits<MachineInstr, MachineInstr> { protected: - // this is only set by the MachineBasicBlock owning the ilist + // this is only set by the MachineBasicBlock owning the LiveList friend class MachineBasicBlock; - MachineBasicBlock* parent; + MachineBasicBlock* Parent; -public: - ilist_traits<MachineInstr>() : parent(0) { } - - static MachineInstr* getPrev(MachineInstr* N) { return N->Prev; } - static MachineInstr* getNext(MachineInstr* N) { return N->Next; } - - static const MachineInstr* - getPrev(const MachineInstr* N) { return N->Prev; } - - static const MachineInstr* - getNext(const MachineInstr* N) { return N->Next; } + typedef alist_iterator<MachineInstr> iterator; - static void setPrev(MachineInstr* N, MachineInstr* prev) { N->Prev = prev; } - static void setNext(MachineInstr* N, MachineInstr* next) { N->Next = next; } +public: + alist_traits<MachineInstr, MachineInstr>() : Parent(0) { } - static MachineInstr* createSentinel(); - static void destroySentinel(MachineInstr *MI) { delete MI; } void addNodeToList(MachineInstr* N); void removeNodeFromList(MachineInstr* N); - void transferNodesFromList( - iplist<MachineInstr, ilist_traits<MachineInstr> >& toList, - ilist_iterator<MachineInstr> first, - ilist_iterator<MachineInstr> last); + void transferNodesFromList(alist_traits &, iterator, iterator); + void deleteNode(MachineInstr *N); }; class BasicBlock; class MachineBasicBlock { - typedef ilist<MachineInstr> Instructions; + typedef alist<MachineInstr> Instructions; Instructions Insts; - MachineBasicBlock *Prev, *Next; const BasicBlock *BB; int Number; MachineFunction *xParent; - void setParent(MachineFunction *P) { xParent = P; } - /// Predecessors/Successors - Keep track of the predecessor / successor /// basicblocks. std::vector<MachineBasicBlock *> Predecessors; @@ -84,15 +65,14 @@ class MachineBasicBlock { /// exception handler. bool IsLandingPad; -public: - explicit MachineBasicBlock(const BasicBlock *bb = 0) - : Prev(0), Next(0), BB(bb), Number(-1), xParent(0), - Alignment(0), IsLandingPad(false) { - Insts.parent = this; - } + explicit MachineBasicBlock(MachineFunction &mf, const BasicBlock *bb); + + ~MachineBasicBlock() {} - ~MachineBasicBlock(); + // MachineBasicBlocks are allocated and owned by MachineFunction. + friend class MachineFunction; +public: /// getBasicBlock - Return the LLVM basic block that this instance /// corresponded to originally. /// @@ -103,8 +83,8 @@ public: const MachineFunction *getParent() const { return xParent; } MachineFunction *getParent() { return xParent; } - typedef ilist<MachineInstr>::iterator iterator; - typedef ilist<MachineInstr>::const_iterator const_iterator; + typedef Instructions::iterator iterator; + typedef Instructions::const_iterator const_iterator; typedef std::reverse_iterator<const_iterator> const_reverse_iterator; typedef std::reverse_iterator<iterator> reverse_iterator; @@ -272,6 +252,14 @@ public: Insts.splice(where, Other->Insts, From, To); } + /// removeFromParent - This method unlinks 'this' from the containing + /// function, and returns it, but does not delete it. + MachineBasicBlock *removeFromParent(); + + /// eraseFromParent - This method unlinks 'this' from the containing + /// function and deletes it. + void eraseFromParent(); + /// ReplaceUsesOfBlockWith - Given a machine basic block that branched to /// 'Old', change the code and CFG so that it branches to 'New' instead. void ReplaceUsesOfBlockWith(MachineBasicBlock *Old, MachineBasicBlock *New); @@ -299,12 +287,7 @@ public: void setNumber(int N) { Number = N; } private: // Methods used to maintain doubly linked list of blocks... - friend struct ilist_traits<MachineBasicBlock>; - - MachineBasicBlock *getPrev() const { return Prev; } - MachineBasicBlock *getNext() const { return Next; } - void setPrev(MachineBasicBlock *P) { Prev = P; } - void setNext(MachineBasicBlock *N) { Next = N; } + friend struct alist_traits<MachineBasicBlock>; // Machine-CFG mutators diff --git a/include/llvm/CodeGen/MachineFunction.h b/include/llvm/CodeGen/MachineFunction.h index ad4f1d120c..2fbe9b803e 100644 --- a/include/llvm/CodeGen/MachineFunction.h +++ b/include/llvm/CodeGen/MachineFunction.h @@ -18,8 +18,11 @@ #ifndef LLVM_CODEGEN_MACHINEFUNCTION_H #define LLVM_CODEGEN_MACHINEFUNCTION_H +#include "llvm/ADT/alist.h" #include "llvm/CodeGen/MachineBasicBlock.h" #include "llvm/Support/Annotation.h" +#include "llvm/Support/Allocator.h" +#include "llvm/Support/Recycler.h" namespace llvm { @@ -30,40 +33,16 @@ class MachineFrameInfo; class MachineConstantPool; class MachineJumpTableInfo; -// ilist_traits template <> -class ilist_traits<MachineBasicBlock> { - // this is only set by the MachineFunction owning the ilist - friend class MachineFunction; - MachineFunction* Parent; - +class alist_traits<MachineBasicBlock, MachineBasicBlock> { + typedef alist_iterator<MachineBasicBlock> iterator; public: - ilist_traits<MachineBasicBlock>() : Parent(0) { } - - static MachineBasicBlock* getPrev(MachineBasicBlock* N) { return N->Prev; } - static MachineBasicBlock* getNext(MachineBasicBlock* N) { return N->Next; } - - static const MachineBasicBlock* - getPrev(const MachineBasicBlock* N) { return N->Prev; } - - static const MachineBasicBlock* - getNext(const MachineBasicBlock* N) { return N->Next; } - - static void setPrev(MachineBasicBlock* N, MachineBasicBlock* prev) { - N->Prev = prev; - } - static void setNext(MachineBasicBlock* N, MachineBasicBlock* next) { - N->Next = next; - } - - static MachineBasicBlock* createSentinel(); - static void destroySentinel(MachineBasicBlock *MBB) { delete MBB; } - void addNodeToList(MachineBasicBlock* N); - void removeNodeFromList(MachineBasicBlock* N); - void transferNodesFromList(iplist<MachineBasicBlock, - ilist_traits<MachineBasicBlock> > &toList, - ilist_iterator<MachineBasicBlock> first, - ilist_iterator<MachineBasicBlock> last); + void addNodeToList(MachineBasicBlock* MBB); + void removeNodeFromList(MachineBasicBlock* MBB); + void transferNodesFromList(alist_traits<MachineBasicBlock> &, + iterator, + iterator) {} + void deleteNode(MachineBasicBlock *MBB); }; /// MachineFunctionInfo - This class can be derived from and used by targets to @@ -78,9 +57,6 @@ class MachineFunction : private Annotation { const Function *Fn; const TargetMachine &Target; - // List of machine basic blocks in function - ilist<MachineBasicBlock> BasicBlocks; - // RegInfo - Information about each register in use in the function. MachineRegisterInfo *RegInfo; @@ -102,6 +78,22 @@ class MachineFunction : private Annotation { // numbered and this vector keeps track of the mapping from ID's to MBB's. std::vector<MachineBasicBlock*> MBBNumbering; + // Pool-allocate MachineFunction-lifetime and IR objects. + BumpPtrAllocator Allocator; + + // Allocation management for instructions in function. + Recycler<MachineInstr> InstructionRecycler; + + // Allocation management for basic blocks in function. + Recycler<MachineBasicBlock> BasicBlockRecycler; + + // Allocation management for memoperands in function. + Recycler<MachineMemOperand> MemOperandRecycler; + + // List of machine basic blocks in function + typedef alist<MachineBasicBlock> BasicBlockListType; + BasicBlockListType BasicBlocks; + public: MachineFunction(const Function *Fn, const TargetMachine &TM); ~MachineFunction(); @@ -116,31 +108,35 @@ public: /// getRegInfo - Return information about the registers currently in use. /// - MachineRegisterInfo &getRegInfo() const { return *RegInfo; } + MachineRegisterInfo &getRegInfo() { return *RegInfo; } + const MachineRegisterInfo &getRegInfo() const { return *RegInfo; } /// getFrameInfo - Return the frame info object for the current function. /// This object contains information about objects allocated on the stack /// frame of the current function in an abstract way. /// - MachineFrameInfo *getFrameInfo() const { return FrameInfo; } + MachineFrameInfo *getFrameInfo() { return FrameInfo; } + const MachineFrameInfo *getFrameInfo() const { return FrameInfo; } /// getJumpTableInfo - Return the jump table info object for the current /// function. This object contains information about jump tables for switch /// instructions in the current function. /// - MachineJumpTableInfo *getJumpTableInfo() const { return JumpTableInfo; } + MachineJumpTableInfo *getJumpTableInfo() { return JumpTableInfo; } + const MachineJumpTableInfo *getJumpTableInfo() const { return JumpTableInfo; } /// getConstantPool - Return the constant pool object for the current /// function. /// - MachineConstantPool *getConstantPool() const { return ConstantPool; } + MachineConstantPool *getConstantPool() { return ConstantPool; } + const MachineConstantPool *getConstantPool() const { return ConstantPool; } /// MachineFunctionInfo - Keep track of various per-function pieces of /// information for backends that would like to do so. /// template<typename Ty> Ty *getInfo() { - if (!MFInfo) MFInfo = new Ty(*this); + if (!MFInfo) MFInfo = new (Allocator.Allocate<Ty>()) Ty(*this); assert((void*)dynamic_cast<Ty*>(MFInfo) == (void*)MFInfo && "Invalid concrete type or multiple inheritence for getInfo"); @@ -215,18 +211,13 @@ public: static MachineFunction& get(const Function *F); // Provide accessors for the MachineBasicBlock list... - typedef ilist<MachineBasicBlock> BasicBlockListType; typedef BasicBlockListType::iterator iterator; typedef BasicBlockListType::const_iterator const_iterator; typedef std::reverse_iterator<const_iterator> const_reverse_iterator; typedef std::reverse_iterator<iterator> reverse_iterator; - // Provide accessors for basic blocks... - const BasicBlockListType &getBasicBlockList() const { return BasicBlocks; } - BasicBlockListType &getBasicBlockList() { return BasicBlocks; } - //===--------------------------------------------------------------------===// - // BasicBlock iterator forwarding functions + // BasicBlock accessor functions. // iterator begin() { return BasicBlocks.begin(); } const_iterator begin() const { return BasicBlocks.begin(); } @@ -245,6 +236,22 @@ public: const MachineBasicBlock & back() const { return BasicBlocks.back(); } MachineBasicBlock & back() { return BasicBlocks.back(); } + void push_back (MachineBasicBlock *MBB) { BasicBlocks.push_back (MBB); } + void push_front(MachineBasicBlock *MBB) { BasicBlocks.push_front(MBB); } + void insert(iterator MBBI, MachineBasicBlock *MBB) { + BasicBlocks.insert(MBBI, MBB); + } + void splice(iterator InsertPt, iterator MBBI) { + BasicBlocks.splice(InsertPt, BasicBlocks, MBBI); + } + + void remove(iterator MBBI) { + BasicBlocks.remove(MBBI); + } + void erase(iterator MBBI) { + BasicBlocks.erase(MBBI); + } + //===--------------------------------------------------------------------===// // Internal functions used to automatically number MachineBasicBlocks // @@ -264,6 +271,40 @@ public: assert(N < MBBNumbering.size() && "Illegal basic block #"); MBBNumbering[N] = 0; } + + /// CreateMachineInstr - Allocate a new MachineInstr. Use this instead + /// of `new MachineInstr'. + /// + MachineInstr *CreateMachineInstr(const TargetInstrDesc &TID, + bool NoImp = false); + + /// CloneMachineInstr - Create a new MachineInstr which is a copy of the + /// 'Orig' instruction, identical in all ways except the the instruction + /// has no parent, prev, or next. + /// + MachineInstr *CloneMachineInstr(const MachineInstr *Orig); + + /// DeleteMachineInstr - Delete the given MachineInstr. + /// + void DeleteMachineInstr(MachineInstr *MI); + + /// CreateMachineBasicBlock - Allocate a new MachineBasicBlock. Use this + /// instead of `new MachineBasicBlock'. + /// + MachineBasicBlock *CreateMachineBasicBlock(const BasicBlock *bb = 0); + + /// DeleteMachineBasicBlock - Delete the given MachineBasicBlock. + /// + void DeleteMachineBasicBlock(MachineBasicBlock *MBB); + + /// CreateMachineMemOperand - Allocate a new MachineMemOperand. Use this + /// instead of `new MachineMemOperand'. + /// + MachineMemOperand *CreateMachineMemOperand(const MachineMemOperand &MMO); + + /// DeleteMachineMemOperand - Delete the given MachineMemOperand. + /// + void DeleteMachineMemOperand(MachineMemOperand *MMO); }; //===--------------------------------------------------------------------===// diff --git a/include/llvm/CodeGen/MachineInstr.h b/include/llvm/CodeGen/MachineInstr.h index 06d15ab3a3..77e5e76521 100644 --- a/include/llvm/CodeGen/MachineInstr.h +++ b/include/llvm/CodeGen/MachineInstr.h @@ -16,6 +16,7 @@ #ifndef LLVM_CODEGEN_MACHINEINSTR_H #define LLVM_CODEGEN_MACHINEINSTR_H +#include "llvm/ADT/alist.h" #include "llvm/CodeGen/MachineOperand.h" #include "llvm/CodeGen/MachineMemOperand.h" #include <vector> @@ -25,9 +26,7 @@ namespace llvm { class TargetInstrDesc; class TargetInstrInfo; class TargetRegisterInfo; - -template <typename T> struct ilist_traits; -template <typename T> struct ilist; +class MachineFunction; //===----------------------------------------------------------------------===// /// MachineInstr - Representation of each machine instruction. @@ -38,21 +37,24 @@ class MachineInstr { // are determined at construction time). std::vector<MachineOperand> Operands; // the operands - std::vector<MachineMemOperand> MemOperands;// information on memory references - MachineInstr *Prev, *Next; // Links for MBB's intrusive list. + alist<MachineMemOperand> MemOperands; // information on memory references MachineBasicBlock *Parent; // Pointer to the owning basic block. // OperandComplete - Return true if it's illegal to add a new operand bool OperandsComplete() const; - MachineInstr(const MachineInstr&); + MachineInstr(const MachineInstr&); // DO NOT IMPLEMENT void operator=(const MachineInstr&); // DO NOT IMPLEMENT // Intrusive list support - friend struct ilist_traits<MachineInstr>; - friend struct ilist_traits<MachineBasicBlock>; + friend struct alist_traits<MachineInstr>; + friend struct alist_traits<MachineBasicBlock>; void setParent(MachineBasicBlock *P) { Parent = P; } -public: + + /// MachineInstr ctor - This constructor creates a copy of the given + /// MachineInstr in the given MachineFunction. + MachineInstr(MachineFunction &, const MachineInstr &); + /// MachineInstr ctor - This constructor creates a dummy MachineInstr with /// TID NULL and no operands. MachineInstr(); @@ -70,6 +72,10 @@ public: ~MachineInstr(); + // MachineInstrs are pool-allocated and owned by MachineFunction. + friend class MachineFunction; + +public: const MachineBasicBlock* getParent() const { return Parent; } MachineBasicBlock* getParent() { return Parent; } @@ -99,16 +105,15 @@ public: unsigned getNumExplicitOperands() const; /// Access to memory operands of the instruction - unsigned getNumMemOperands() const { return (unsigned)MemOperands.size(); } - - const MachineMemOperand& getMemOperand(unsigned i) const { - assert(i < getNumMemOperands() && "getMemOperand() out of range!"); - return MemOperands[i]; - } - MachineMemOperand& getMemOperand(unsigned i) { - assert(i < getNumMemOperands() && "getMemOperand() out of range!"); - return MemOperands[i]; - } + alist<MachineMemOperand>::iterator memoperands_begin() + { return MemOperands.begin(); } + alist<MachineMemOperand>::iterator memoperands_end() + { return MemOperands.end(); } + alist<MachineMemOperand>::const_iterator memoperands_begin() const + { return MemOperands.begin(); } + alist<MachineMemOperand>::const_iterator memoperands_end() const + { return MemOperands.end(); } + bool memoperands_empty() const { return MemOperands.empty(); } /// isIdenticalTo - Return true if this instruction is identical to (same /// opcode and same operands as) the specified instruction. @@ -122,19 +127,13 @@ public: return true; } - /// clone - Create a copy of 'this' instruction that is identical in - /// all ways except the the instruction has no parent, prev, or next. - MachineInstr* clone() const { return new MachineInstr(*this); } - /// removeFromParent - This method unlinks 'this' from the containing basic /// block, and returns it, but does not delete it. MachineInstr *removeFromParent(); /// eraseFromParent - This method unlinks 'this' from the containing basic /// block and deletes it. - void eraseFromParent() { - delete removeFromParent(); - } + void eraseFromParent(); /// isLabel - Returns true if the MachineInstr represents a label. /// @@ -270,9 +269,11 @@ public: /// addMemOperand - Add a MachineMemOperand to the machine instruction, /// referencing arbitrary storage. - void addMemOperand(const MachineMemOperand &MO) { - MemOperands.push_back(MO); - } + void addMemOperand(MachineFunction &MF, + const MachineMemOperand &MO); + + /// clearMemOperands - Erase all of this MachineInstr's MachineMemOperands. + void clearMemOperands(MachineFunction &MF); private: /// getRegInfo - If this instruction is embedded into a MachineFunction, diff --git a/include/llvm/CodeGen/MachineInstrBuilder.h b/include/llvm/CodeGen/MachineInstrBuilder.h index 748a9b4006..0b1f2f71b2 100644 --- a/include/llvm/CodeGen/MachineInstrBuilder.h +++ b/include/llvm/CodeGen/MachineInstrBuilder.h @@ -83,27 +83,23 @@ public: MI->addOperand(MachineOperand::CreateES(FnName, 0)); return *this; } - - /// addMemOperand - Add a memory operand to the machine instruction. - const MachineInstrBuilder &addMemOperand(const MachineMemOperand &MO) const { - MI->addMemOperand(MO); - return *this; - } }; /// BuildMI - Builder interface. Specify how to create the initial instruction /// itself. /// -inline MachineInstrBuilder BuildMI(const TargetInstrDesc &TID) { - return MachineInstrBuilder(new MachineInstr(TID)); +inline MachineInstrBuilder BuildMI(MachineFunction &MF, + const TargetInstrDesc &TID) { + return MachineInstrBuilder(MF.CreateMachineInstr(TID)); } /// BuildMI - This version of the builder sets up the first operand as a /// destination virtual register. /// -inline MachineInstrBuilder BuildMI(const TargetInstrDesc &TID, +inline MachineInstrBuilder BuildMI(MachineFunction &MF, + const TargetInstrDesc &TID, unsigned DestReg) { - return MachineInstrBuilder(new MachineInstr(TID)).addReg(DestReg, true); + return MachineInstrBuilder(MF.CreateMachineInstr(TID)).addReg(DestReg, true); } /// BuildMI - This version of the builder inserts the newly-built @@ -114,7 +110,7 @@ inline MachineInstrBuilder BuildMI(MachineBasicBlock &BB, MachineBasicBlock::iterator I, const TargetInstrDesc &TID, unsigned DestReg) { - MachineInstr *MI = new MachineInstr(TID); + MachineInstr *MI = BB.getParent()->CreateMachineInstr(TID); BB.insert(I, MI); return MachineInstrBuilder(MI).addReg(DestReg, true); } @@ -126,7 +122,7 @@ inline MachineInstrBuilder BuildMI(MachineBasicBlock &BB, inline MachineInstrBuilder BuildMI(MachineBasicBlock &BB, MachineBasicBlock::iterator I, const TargetInstrDesc &TID) { - MachineInstr *MI = new MachineInstr(TID); + MachineInstr *MI = BB.getParent()->CreateMachineInstr(TID); BB.insert(I, MI); return MachineInstrBuilder(MI); } |