llvm.org GIT mirror llvm / 0a0e68a
Introduce a new technique for merging BasicBlock with Instruction sentinel by superposition. This looks dangerous, but isn't because the sentinel is accessed in special way only, namely the Next and Prev fields of it, and these are guaranteed to exist. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@65626 91177308-0d34-0410-b5e6-96231b3b80d8 Gabor Greif 11 years ago
3 changed file(s) with 12 addition(s) and 37 deletion(s). Raw diff Collapse all Expand all
1919 template
2020 struct ilist_nextprev_traits;
2121
22 template
23 struct ilist_traits;
24
2225 /// ilist_node - Base class that provides next/prev services for nodes
2326 /// that use ilist_nextprev_traits or ilist_default_traits.
2427 ///
3538 void setNext(NodeTy *N) { Next = N; }
3639 protected:
3740 ilist_node() : Prev(0), Next(0) {}
41 friend struct ilist_traits;
3842 };
3943
4044 } // End llvm namespace
2525 template<> struct ilist_traits
2626 : public SymbolTableListTraits {
2727 // createSentinel is used to create a node that marks the end of the list...
28 static Instruction *createSentinel();
29 static void destroySentinel(Instruction *I) { delete I; }
28 Instruction *createSentinel() const {
29 return const_cast(static_cast(&Sentinel));
30 }
31 static void destroySentinel(Instruction *I) { }
3032 static iplist &getList(BasicBlock *BB);
3133 static ValueSymbolTable *getSymTab(BasicBlock *ItemParent);
3234 static int getListOffset();
35 private:
36 ilist_node Sentinel;
3337 };
3438
3539 /// This represents a single basic block in LLVM. A basic block is simply a
4852 /// @brief LLVM Basic Block Representation
4953 class BasicBlock : public Value, // Basic blocks are data objects also
5054 public ilist_node {
55
5156 public:
5257 typedef iplist InstListType;
53 private :
58 private:
5459 InstListType InstList;
5560 Function *Parent;
5661
3030 return 0;
3131 }
3232
33
34 namespace {
35 /// DummyInst - An instance of this class is used to mark the end of the
36 /// instruction list. This is not a real instruction.
37 struct VISIBILITY_HIDDEN DummyInst : public Instruction {
38 // allocate space for exactly zero operands
39 void *operator new(size_t s) {
40 return User::operator new(s, 0);
41 }
42 DummyInst() : Instruction(Type::VoidTy, OtherOpsEnd, 0, 0) {
43 // This should not be garbage monitored.
44 LeakDetector::removeGarbageObject(this);
45 }
46
47 Instruction *clone() const {
48 assert(0 && "Cannot clone EOL");abort();
49 return 0;
50 }
51 const char *getOpcodeName() const { return "*end-of-list-inst*"; }
52
53 // Methods for support type inquiry through isa, cast, and dyn_cast...
54 static inline bool classof(const DummyInst *) { return true; }
55 static inline bool classof(const Instruction *I) {
56 return I->getOpcode() == OtherOpsEnd;
57 }
58 static inline bool classof(const Value *V) {
59 return isa(V) && classof(cast(V));
60 }
61 };
62 }
63
64 Instruction *ilist_traits::createSentinel() {
65 return new DummyInst();
66 }
6733 iplist &ilist_traits::getList(BasicBlock *BB) {
6834 return BB->getInstList();
6935 }