comparison include/llvm/IR/BasicBlock.h @ 95:afa8332a0e37 LLVM3.8

LLVM 3.8
author Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
date Tue, 13 Oct 2015 17:48:58 +0900
parents 60c9769439b8
children 7d135dc70f03
comparison
equal deleted inserted replaced
84:f3e34b893a5f 95:afa8332a0e37
26 class CallInst; 26 class CallInst;
27 class LandingPadInst; 27 class LandingPadInst;
28 class TerminatorInst; 28 class TerminatorInst;
29 class LLVMContext; 29 class LLVMContext;
30 class BlockAddress; 30 class BlockAddress;
31 31 class Function;
32 template<> struct ilist_traits<Instruction> 32
33 : public SymbolTableListTraits<Instruction, BasicBlock> { 33 template <>
34 34 struct SymbolTableListSentinelTraits<BasicBlock>
35 /// \brief Return a node that marks the end of a list. 35 : public ilist_half_embedded_sentinel_traits<BasicBlock> {};
36 ///
37 /// The sentinel is relative to this instance, so we use a non-static
38 /// method.
39 Instruction *createSentinel() const {
40 // Since i(p)lists always publicly derive from their corresponding traits,
41 // placing a data member in this class will augment the i(p)list. But since
42 // the NodeTy is expected to be publicly derive from ilist_node<NodeTy>,
43 // there is a legal viable downcast from it to NodeTy. We use this trick to
44 // superimpose an i(p)list with a "ghostly" NodeTy, which becomes the
45 // sentinel. Dereferencing the sentinel is forbidden (save the
46 // ilist_node<NodeTy>), so no one will ever notice the superposition.
47 return static_cast<Instruction*>(&Sentinel);
48 }
49 static void destroySentinel(Instruction*) {}
50
51 Instruction *provideInitialHead() const { return createSentinel(); }
52 Instruction *ensureHead(Instruction*) const { return createSentinel(); }
53 static void noteHead(Instruction*, Instruction*) {}
54 private:
55 mutable ilist_half_node<Instruction> Sentinel;
56 };
57 36
58 /// \brief LLVM Basic Block Representation 37 /// \brief LLVM Basic Block Representation
59 /// 38 ///
60 /// This represents a single basic block in LLVM. A basic block is simply a 39 /// This represents a single basic block in LLVM. A basic block is simply a
61 /// container of instructions that execute sequentially. Basic blocks are Values 40 /// container of instructions that execute sequentially. Basic blocks are Values
72 /// are "well formed". 51 /// are "well formed".
73 class BasicBlock : public Value, // Basic blocks are data objects also 52 class BasicBlock : public Value, // Basic blocks are data objects also
74 public ilist_node<BasicBlock> { 53 public ilist_node<BasicBlock> {
75 friend class BlockAddress; 54 friend class BlockAddress;
76 public: 55 public:
77 typedef iplist<Instruction> InstListType; 56 typedef SymbolTableList<Instruction> InstListType;
57
78 private: 58 private:
79 InstListType InstList; 59 InstListType InstList;
80 Function *Parent; 60 Function *Parent;
81 61
82 void setParent(Function *parent); 62 void setParent(Function *parent);
83 friend class SymbolTableListTraits<BasicBlock, Function>; 63 friend class SymbolTableListTraits<BasicBlock>;
84 64
85 BasicBlock(const BasicBlock &) = delete; 65 BasicBlock(const BasicBlock &) = delete;
86 void operator=(const BasicBlock &) = delete; 66 void operator=(const BasicBlock &) = delete;
87 67
88 /// \brief Constructor. 68 /// \brief Constructor.
111 static BasicBlock *Create(LLVMContext &Context, const Twine &Name = "", 91 static BasicBlock *Create(LLVMContext &Context, const Twine &Name = "",
112 Function *Parent = nullptr, 92 Function *Parent = nullptr,
113 BasicBlock *InsertBefore = nullptr) { 93 BasicBlock *InsertBefore = nullptr) {
114 return new BasicBlock(Context, Name, Parent, InsertBefore); 94 return new BasicBlock(Context, Name, Parent, InsertBefore);
115 } 95 }
116 ~BasicBlock(); 96 ~BasicBlock() override;
117 97
118 /// \brief Return the enclosing method, or null if none. 98 /// \brief Return the enclosing method, or null if none.
119 const Function *getParent() const { return Parent; } 99 const Function *getParent() const { return Parent; }
120 Function *getParent() { return Parent; } 100 Function *getParent() { return Parent; }
121 101
122 const DataLayout *getDataLayout() const; 102 /// \brief Return the module owning the function this basic block belongs to,
103 /// or nullptr it the function does not have a module.
104 ///
105 /// Note: this is undefined behavior if the block does not have a parent.
106 const Module *getModule() const;
107 Module *getModule();
123 108
124 /// \brief Returns the terminator instruction if the block is well formed or 109 /// \brief Returns the terminator instruction if the block is well formed or
125 /// null if the block is not well formed. 110 /// null if the block is not well formed.
126 TerminatorInst *getTerminator(); 111 TerminatorInst *getTerminator();
127 const TerminatorInst *getTerminator() const; 112 const TerminatorInst *getTerminator() const;
170 155
171 /// \brief Unlink 'this' from the containing function, but do not delete it. 156 /// \brief Unlink 'this' from the containing function, but do not delete it.
172 void removeFromParent(); 157 void removeFromParent();
173 158
174 /// \brief Unlink 'this' from the containing function and delete it. 159 /// \brief Unlink 'this' from the containing function and delete it.
175 void eraseFromParent(); 160 ///
161 // \returns an iterator pointing to the element after the erased one.
162 SymbolTableList<BasicBlock>::iterator eraseFromParent();
176 163
177 /// \brief Unlink this basic block from its current function and insert it 164 /// \brief Unlink this basic block from its current function and insert it
178 /// into the function that \p MovePos lives in, right before \p MovePos. 165 /// into the function that \p MovePos lives in, right before \p MovePos.
179 void moveBefore(BasicBlock *MovePos); 166 void moveBefore(BasicBlock *MovePos);
180 167
206 BasicBlock *getUniquePredecessor(); 193 BasicBlock *getUniquePredecessor();
207 const BasicBlock *getUniquePredecessor() const { 194 const BasicBlock *getUniquePredecessor() const {
208 return const_cast<BasicBlock*>(this)->getUniquePredecessor(); 195 return const_cast<BasicBlock*>(this)->getUniquePredecessor();
209 } 196 }
210 197
211 /// Return the successor of this block if it has a unique successor. 198 /// \brief Return the successor of this block if it has a single successor.
212 /// Otherwise return a null pointer. This method is analogous to 199 /// Otherwise return a null pointer.
213 /// getUniquePredeccessor above. 200 ///
201 /// This method is analogous to getSinglePredecessor above.
202 BasicBlock *getSingleSuccessor();
203 const BasicBlock *getSingleSuccessor() const {
204 return const_cast<BasicBlock*>(this)->getSingleSuccessor();
205 }
206
207 /// \brief Return the successor of this block if it has a unique successor.
208 /// Otherwise return a null pointer.
209 ///
210 /// This method is analogous to getUniquePredecessor above.
214 BasicBlock *getUniqueSuccessor(); 211 BasicBlock *getUniqueSuccessor();
215 const BasicBlock *getUniqueSuccessor() const { 212 const BasicBlock *getUniqueSuccessor() const {
216 return const_cast<BasicBlock*>(this)->getUniqueSuccessor(); 213 return const_cast<BasicBlock*>(this)->getUniqueSuccessor();
217 } 214 }
218 215
242 /// directly if you want to modify it. 239 /// directly if you want to modify it.
243 const InstListType &getInstList() const { return InstList; } 240 const InstListType &getInstList() const { return InstList; }
244 InstListType &getInstList() { return InstList; } 241 InstListType &getInstList() { return InstList; }
245 242
246 /// \brief Returns a pointer to a member of the instruction list. 243 /// \brief Returns a pointer to a member of the instruction list.
247 static iplist<Instruction> BasicBlock::*getSublistAccess(Instruction*) { 244 static InstListType BasicBlock::*getSublistAccess(Instruction*) {
248 return &BasicBlock::InstList; 245 return &BasicBlock::InstList;
249 } 246 }
250 247
251 /// \brief Returns a pointer to the symbol table if one exists. 248 /// \brief Returns a pointer to the symbol table if one exists.
252 ValueSymbolTable *getValueSymbolTable(); 249 ValueSymbolTable *getValueSymbolTable();
272 /// This is actually not used to update the Predecessor list, but is actually 269 /// This is actually not used to update the Predecessor list, but is actually
273 /// used to update the PHI nodes that reside in the block. Note that this 270 /// used to update the PHI nodes that reside in the block. Note that this
274 /// should be called while the predecessor still refers to this block. 271 /// should be called while the predecessor still refers to this block.
275 void removePredecessor(BasicBlock *Pred, bool DontDeleteUselessPHIs = false); 272 void removePredecessor(BasicBlock *Pred, bool DontDeleteUselessPHIs = false);
276 273
274 bool canSplitPredecessors() const;
275
277 /// \brief Split the basic block into two basic blocks at the specified 276 /// \brief Split the basic block into two basic blocks at the specified
278 /// instruction. 277 /// instruction.
279 /// 278 ///
280 /// Note that all instructions BEFORE the specified iterator stay as part of 279 /// Note that all instructions BEFORE the specified iterator stay as part of
281 /// the original basic block, an unconditional branch is added to the original 280 /// the original basic block, an unconditional branch is added to the original
297 bool hasAddressTaken() const { return getSubclassDataFromValue() != 0; } 296 bool hasAddressTaken() const { return getSubclassDataFromValue() != 0; }
298 297
299 /// \brief Update all phi nodes in this basic block's successors to refer to 298 /// \brief Update all phi nodes in this basic block's successors to refer to
300 /// basic block \p New instead of to it. 299 /// basic block \p New instead of to it.
301 void replaceSuccessorsPhiUsesWith(BasicBlock *New); 300 void replaceSuccessorsPhiUsesWith(BasicBlock *New);
301
302 /// \brief Return true if this basic block is an exception handling block.
303 bool isEHPad() const { return getFirstNonPHI()->isEHPad(); }
302 304
303 /// \brief Return true if this basic block is a landing pad. 305 /// \brief Return true if this basic block is a landing pad.
304 /// 306 ///
305 /// Being a ``landing pad'' means that the basic block is the destination of 307 /// Being a ``landing pad'' means that the basic block is the destination of
306 /// the 'unwind' edge of an invoke instruction. 308 /// the 'unwind' edge of an invoke instruction.