Mercurial > hg > CbC > CbC_llvm
diff 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 |
line wrap: on
line diff
--- a/include/llvm/IR/BasicBlock.h Wed Feb 18 14:56:07 2015 +0900 +++ b/include/llvm/IR/BasicBlock.h Tue Oct 13 17:48:58 2015 +0900 @@ -28,32 +28,11 @@ class TerminatorInst; class LLVMContext; class BlockAddress; - -template<> struct ilist_traits<Instruction> - : public SymbolTableListTraits<Instruction, BasicBlock> { +class Function; - /// \brief Return a node that marks the end of a list. - /// - /// The sentinel is relative to this instance, so we use a non-static - /// method. - Instruction *createSentinel() const { - // Since i(p)lists always publicly derive from their corresponding traits, - // placing a data member in this class will augment the i(p)list. But since - // the NodeTy is expected to be publicly derive from ilist_node<NodeTy>, - // there is a legal viable downcast from it to NodeTy. We use this trick to - // superimpose an i(p)list with a "ghostly" NodeTy, which becomes the - // sentinel. Dereferencing the sentinel is forbidden (save the - // ilist_node<NodeTy>), so no one will ever notice the superposition. - return static_cast<Instruction*>(&Sentinel); - } - static void destroySentinel(Instruction*) {} - - Instruction *provideInitialHead() const { return createSentinel(); } - Instruction *ensureHead(Instruction*) const { return createSentinel(); } - static void noteHead(Instruction*, Instruction*) {} -private: - mutable ilist_half_node<Instruction> Sentinel; -}; +template <> +struct SymbolTableListSentinelTraits<BasicBlock> + : public ilist_half_embedded_sentinel_traits<BasicBlock> {}; /// \brief LLVM Basic Block Representation /// @@ -74,13 +53,14 @@ public ilist_node<BasicBlock> { friend class BlockAddress; public: - typedef iplist<Instruction> InstListType; + typedef SymbolTableList<Instruction> InstListType; + private: InstListType InstList; Function *Parent; void setParent(Function *parent); - friend class SymbolTableListTraits<BasicBlock, Function>; + friend class SymbolTableListTraits<BasicBlock>; BasicBlock(const BasicBlock &) = delete; void operator=(const BasicBlock &) = delete; @@ -113,13 +93,18 @@ BasicBlock *InsertBefore = nullptr) { return new BasicBlock(Context, Name, Parent, InsertBefore); } - ~BasicBlock(); + ~BasicBlock() override; /// \brief Return the enclosing method, or null if none. const Function *getParent() const { return Parent; } Function *getParent() { return Parent; } - const DataLayout *getDataLayout() const; + /// \brief Return the module owning the function this basic block belongs to, + /// or nullptr it the function does not have a module. + /// + /// Note: this is undefined behavior if the block does not have a parent. + const Module *getModule() const; + Module *getModule(); /// \brief Returns the terminator instruction if the block is well formed or /// null if the block is not well formed. @@ -172,7 +157,9 @@ void removeFromParent(); /// \brief Unlink 'this' from the containing function and delete it. - void eraseFromParent(); + /// + // \returns an iterator pointing to the element after the erased one. + SymbolTableList<BasicBlock>::iterator eraseFromParent(); /// \brief Unlink this basic block from its current function and insert it /// into the function that \p MovePos lives in, right before \p MovePos. @@ -208,9 +195,19 @@ return const_cast<BasicBlock*>(this)->getUniquePredecessor(); } - /// Return the successor of this block if it has a unique successor. - /// Otherwise return a null pointer. This method is analogous to - /// getUniquePredeccessor above. + /// \brief Return the successor of this block if it has a single successor. + /// Otherwise return a null pointer. + /// + /// This method is analogous to getSinglePredecessor above. + BasicBlock *getSingleSuccessor(); + const BasicBlock *getSingleSuccessor() const { + return const_cast<BasicBlock*>(this)->getSingleSuccessor(); + } + + /// \brief Return the successor of this block if it has a unique successor. + /// Otherwise return a null pointer. + /// + /// This method is analogous to getUniquePredecessor above. BasicBlock *getUniqueSuccessor(); const BasicBlock *getUniqueSuccessor() const { return const_cast<BasicBlock*>(this)->getUniqueSuccessor(); @@ -244,7 +241,7 @@ InstListType &getInstList() { return InstList; } /// \brief Returns a pointer to a member of the instruction list. - static iplist<Instruction> BasicBlock::*getSublistAccess(Instruction*) { + static InstListType BasicBlock::*getSublistAccess(Instruction*) { return &BasicBlock::InstList; } @@ -274,6 +271,8 @@ /// should be called while the predecessor still refers to this block. void removePredecessor(BasicBlock *Pred, bool DontDeleteUselessPHIs = false); + bool canSplitPredecessors() const; + /// \brief Split the basic block into two basic blocks at the specified /// instruction. /// @@ -300,6 +299,9 @@ /// basic block \p New instead of to it. void replaceSuccessorsPhiUsesWith(BasicBlock *New); + /// \brief Return true if this basic block is an exception handling block. + bool isEHPad() const { return getFirstNonPHI()->isEHPad(); } + /// \brief Return true if this basic block is a landing pad. /// /// Being a ``landing pad'' means that the basic block is the destination of