Skip to content

Commit

Permalink
Return iterator from BasicBlock::eraseFromParent
Browse files Browse the repository at this point in the history
Summary:
Same as the last patch, but for BasicBlock
(Requires same code movement)

Reviewers: chandlerc

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D8801

llvm-svn: 233992
  • Loading branch information
dberlin committed Apr 3, 2015
1 parent 56cbe4f commit 0bf7ff5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 23 deletions.
27 changes: 26 additions & 1 deletion llvm/include/llvm/IR/BasicBlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,23 @@ class LandingPadInst;
class TerminatorInst;
class LLVMContext;
class BlockAddress;
class Function;

// Traits for intrusive list of basic blocks...
template<> struct ilist_traits<BasicBlock>
: public SymbolTableListTraits<BasicBlock, Function> {

BasicBlock *createSentinel() const;
static void destroySentinel(BasicBlock*) {}

BasicBlock *provideInitialHead() const { return createSentinel(); }
BasicBlock *ensureHead(BasicBlock*) const { return createSentinel(); }
static void noteHead(BasicBlock*, BasicBlock*) {}

static ValueSymbolTable *getSymTab(Function *ItemParent);
private:
mutable ilist_half_node<BasicBlock> Sentinel;
};


/// \brief LLVM Basic Block Representation
Expand Down Expand Up @@ -151,7 +168,9 @@ class BasicBlock : public Value, // Basic blocks are data objects also
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.
iplist<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.
Expand Down Expand Up @@ -307,6 +326,12 @@ class BasicBlock : public Value, // Basic blocks are data objects also
}
};

// createSentinel is used to get hold of the node that marks the end of the
// list... (same trick used here as in ilist_traits<Instruction>)
inline BasicBlock *ilist_traits<BasicBlock>::createSentinel() const {
return static_cast<BasicBlock*>(&Sentinel);
}

// Create wrappers for C Binding types (see CBindingWrapping.h).
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BasicBlock, LLVMBasicBlockRef)

Expand Down
20 changes: 0 additions & 20 deletions llvm/include/llvm/IR/Function.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,6 @@ namespace llvm {
class FunctionType;
class LLVMContext;

// Traits for intrusive list of basic blocks...
template<> struct ilist_traits<BasicBlock>
: public SymbolTableListTraits<BasicBlock, Function> {

// createSentinel is used to get hold of the node that marks the end of the
// list... (same trick used here as in ilist_traits<Instruction>)
BasicBlock *createSentinel() const {
return static_cast<BasicBlock*>(&Sentinel);
}
static void destroySentinel(BasicBlock*) {}

BasicBlock *provideInitialHead() const { return createSentinel(); }
BasicBlock *ensureHead(BasicBlock*) const { return createSentinel(); }
static void noteHead(BasicBlock*, BasicBlock*) {}

static ValueSymbolTable *getSymTab(Function *ItemParent);
private:
mutable ilist_half_node<BasicBlock> Sentinel;
};

template<> struct ilist_traits<Argument>
: public SymbolTableListTraits<Argument, Function> {

Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/IR/BasicBlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ void BasicBlock::removeFromParent() {
getParent()->getBasicBlockList().remove(this);
}

void BasicBlock::eraseFromParent() {
getParent()->getBasicBlockList().erase(this);
iplist<BasicBlock>::iterator BasicBlock::eraseFromParent() {
return getParent()->getBasicBlockList().erase(this);
}

/// Unlink this basic block from its current function and
Expand Down

0 comments on commit 0bf7ff5

Please sign in to comment.