llvm.org GIT mirror llvm / d0aa0cd
Change MachineBasicBlock's to not be Annotations, instead they are kept as part of a linked list tracked by MachineFunction. MachineBasicBlock::get is now linear time instead of constant time, and thus is deprecated! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@4337 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 18 years ago
6 changed file(s) with 83 addition(s) and 52 deletion(s). Raw diff Collapse all Expand all
66 #ifndef LLVM_CODEGEN_MACHINEBASICBLOCK_H
77 #define LLVM_CODEGEN_MACHINEBASICBLOCK_H
88
9 #include "llvm/Annotation.h"
109 #include
1110 class BasicBlock;
1211 class MachineInstr;
1312 template struct ilist_traits;
1413
15 extern AnnotationID MCFBB_AID;
16
17 class MachineBasicBlock : public Annotation {
14 class MachineBasicBlock {
1815 std::vector Insts;
1916 MachineBasicBlock *Prev, *Next;
17 BasicBlock *BB;
2018 public:
21 MachineBasicBlock() : Annotation(MCFBB_AID) {}
19 MachineBasicBlock(BasicBlock *bb = 0) : Prev(0), Next(0), BB(bb) {}
2220 ~MachineBasicBlock() {}
2321
24 // Static methods to retrieve or destroy the MachineBasicBlock
25 // object for a given basic block.
26 static MachineBasicBlock& get(const BasicBlock *BB) {
27 return *(MachineBasicBlock*)
28 ((Annotable*)BB)->getOrCreateAnnotation(MCFBB_AID);
29 }
30
31 static void destroy(const BasicBlock *BB) {
32 ((Annotable*)BB)->deleteAnnotation(MCFBB_AID);
33 }
22 // get - This deprecated static method returns the MachineBasicBlock object
23 // for the specified BasicBlock.
24 //
25 static MachineBasicBlock& get(const BasicBlock *BB);
26
27 /// getBasicBlock - Return the LLVM basic block that this instance
28 /// corresponded to originally.
29 ///
30 BasicBlock *getBasicBlock() const { return BB; }
3431
3532 typedef std::vector::iterator iterator;
3633 typedef std::vector::const_iterator const_iterator;
99 #define LLVM_CODEGEN_MACHINEFUNCTION_H
1010
1111 #include "llvm/CodeGen/MachineBasicBlock.h"
12 #include "llvm/Annotation.h"
1213 #include "Support/NonCopyable.h"
1314 #include "Support/HashExtras.h"
1415 #include "Support/hash_set"
5859 static MachineFunction& construct(const Function *method,
5960 const TargetMachine &target);
6061 static void destruct(const Function *F);
61 static MachineFunction& get(const Function* function);
62
62 static MachineFunction& get(const Function *F);
6363
64 // Provide accessors for the MachineBasicBlock list...
65 typedef iplist BasicBlockListType;
66 typedef BasicBlockListType::iterator iterator;
67 typedef BasicBlockListType::const_iterator const_iterator;
68 typedef std::reverse_iterator const_reverse_iterator;
69 typedef std::reverse_iterator reverse_iterator;
70
71 // Provide accessors for basic blocks...
72 const BasicBlockListType &getBasicBlockList() const { return BasicBlocks; }
73 BasicBlockListType &getBasicBlockList() { return BasicBlocks; }
74
75 //===--------------------------------------------------------------------===//
76 // BasicBlock iterator forwarding functions
77 //
78 iterator begin() { return BasicBlocks.begin(); }
79 const_iterator begin() const { return BasicBlocks.begin(); }
80 iterator end () { return BasicBlocks.end(); }
81 const_iterator end () const { return BasicBlocks.end(); }
82
83 reverse_iterator rbegin() { return BasicBlocks.rbegin(); }
84 const_reverse_iterator rbegin() const { return BasicBlocks.rbegin(); }
85 reverse_iterator rend () { return BasicBlocks.rend(); }
86 const_reverse_iterator rend () const { return BasicBlocks.rend(); }
87
88 unsigned size() const { return BasicBlocks.size(); }
89 bool empty() const { return BasicBlocks.empty(); }
90 const MachineBasicBlock &front() const { return BasicBlocks.front(); }
91 MachineBasicBlock &front() { return BasicBlocks.front(); }
92 const MachineBasicBlock &back() const { return BasicBlocks.back(); }
93 MachineBasicBlock &back() { return BasicBlocks.back(); }
6494
6595 //===--------------------------------------------------------------------===//
6696 //
138138 }
139139
140140 //
141 // Record instructions in the vector for each basic block
142 //
143 for (Function::iterator BI = F.begin(), BE = F.end(); BI != BE; ++BI)
141 // Create the MachineBasicBlock records and add all of the MachineInstrs
142 // defined in the MachineCodeForInstruction objects to also live in the
143 // MachineBasicBlock objects.
144 //
145 MachineFunction &MF = MachineFunction::get(&F);
146 for (Function::iterator BI = F.begin(), BE = F.end(); BI != BE; ++BI) {
147 MachineBasicBlock *MCBB = new MachineBasicBlock(BI);
148 MF.getBasicBlockList().push_back(MCBB);
149
144150 for (BasicBlock::iterator II = BI->begin(); II != BI->end(); ++II) {
145151 MachineCodeForInstruction &mvec = MachineCodeForInstruction::get(II);
146 MachineBasicBlock &MCBB = MachineBasicBlock::get(BI);
147 MCBB.insert(MCBB.end(), mvec.begin(), mvec.end());
148 }
152 MCBB->insert(MCBB->end(), mvec.begin(), mvec.end());
153 }
154 }
149155
150156 // Insert phi elimination code
151157 InsertCodeForPhis(F);
+0
-23
lib/CodeGen/MachineBasicBlock.cpp less more
None //===-- MachineBasicBlock.cpp ---------------------------------------------===//
1 //
2 // Collect the sequence of machine instructions for a basic block.
3 //
4 //===----------------------------------------------------------------------===//
5
6 #include "llvm/CodeGen/MachineBasicBlock.h"
7
8 AnnotationID MCFBB_AID(
9 AnnotationManager::getID("CodeGen::MachineBasicBlock"));
10
11 static Annotation *CreateMCFBB(AnnotationID AID, const Annotable *, void *) {
12 assert(AID == MCFBB_AID);
13 return new MachineBasicBlock(); // Invoke constructor!
14 }
15
16 // Register the annotation with the annotation factory
17 static struct MCFBBInitializer {
18 MCFBBInitializer() {
19 AnnotationManager::registerAnnotationFactory(MCFBB_AID, &CreateMCFBB);
20 }
21 } RegisterCreateMCFBB;
22
6868
6969 Pass *createMachineCodeDestructionPass() {
7070 return new DestroyMachineFunction();
71 }
72
73
74 // get - This deprecated static method returns the MachineBasicBlock object
75 // for the specified BasicBlock.
76 //
77 MachineBasicBlock& MachineBasicBlock::get(const BasicBlock *BB) {
78 const Function *F = BB->getParent();
79 MachineFunction &MF = MachineFunction::get(F);
80
81 for (MachineFunction::iterator I = MF.begin(), E = MF.end(); I != E; ++I)
82 if (I->getBasicBlock() == BB)
83 return *I;
84 assert(0 && "MachineBasicBlock object not found for specified block!");
85 return get(BB);
7186 }
7287
7388
138138 }
139139
140140 //
141 // Record instructions in the vector for each basic block
142 //
143 for (Function::iterator BI = F.begin(), BE = F.end(); BI != BE; ++BI)
141 // Create the MachineBasicBlock records and add all of the MachineInstrs
142 // defined in the MachineCodeForInstruction objects to also live in the
143 // MachineBasicBlock objects.
144 //
145 MachineFunction &MF = MachineFunction::get(&F);
146 for (Function::iterator BI = F.begin(), BE = F.end(); BI != BE; ++BI) {
147 MachineBasicBlock *MCBB = new MachineBasicBlock(BI);
148 MF.getBasicBlockList().push_back(MCBB);
149
144150 for (BasicBlock::iterator II = BI->begin(); II != BI->end(); ++II) {
145151 MachineCodeForInstruction &mvec = MachineCodeForInstruction::get(II);
146 MachineBasicBlock &MCBB = MachineBasicBlock::get(BI);
147 MCBB.insert(MCBB.end(), mvec.begin(), mvec.end());
148 }
152 MCBB->insert(MCBB->end(), mvec.begin(), mvec.end());
153 }
154 }
149155
150156 // Insert phi elimination code
151157 InsertCodeForPhis(F);