return *this;
}
+ void reset(pointer NP) { NodePtr = NP; }
+
// Accessors...
operator pointer() const {
return NodePtr;
this->setPrev(CurNode, New);
this->addNodeToList(New); // Notify traits that we added a node...
- return New;
+ return iterator(New);
}
iterator insertAfter(iterator where, NodeTy *New) {
else
Head = NextNode;
this->setPrev(NextNode, PrevNode);
- IT = NextNode;
+ IT.reset(NextNode);
this->removeNodeFromList(Node); // Notify traits that we removed a node...
// Set the next/prev pointers of the current node to null. This isn't
this->setNext(Last, PosNext);
this->setPrev(PosNext, Last);
- this->transferNodesFromList(L2, First, PosNext);
+ this->transferNodesFromList(L2, iterator(First), iterator(PosNext));
// Now that everything is set, restore the pointers to the list sentinels.
L2.setTail(L2Sentinel);
template<typename NodeTy>
struct ilist_nextprev_traits;
+template <typename NodeTy> class ilist_iterator;
+
/// ilist_node - Base class that provides next/prev services for nodes
/// that use ilist_nextprev_traits or ilist_default_traits.
///
ilist_node() : Next(nullptr) {}
public:
+ ilist_iterator<NodeTy> getIterator() {
+ // FIXME: Stop downcasting to create the iterator (potential UB).
+ return ilist_iterator<NodeTy>(static_cast<NodeTy *>(this));
+ }
+ ilist_iterator<const NodeTy> getIterator() const {
+ // FIXME: Stop downcasting to create the iterator (potential UB).
+ return ilist_iterator<const NodeTy>(static_cast<const NodeTy *>(this));
+ }
+
/// @name Adjacent Node Accessors
/// @{
/// inserted into a block.
void ClearInsertionPoint() {
BB = nullptr;
- InsertPt = nullptr;
+ InsertPt.reset(nullptr);
}
BasicBlock *GetInsertBlock() const { return BB; }
/// the specified instruction.
void SetInsertPoint(Instruction *I) {
BB = I->getParent();
- InsertPt = I;
- assert(I != BB->end() && "Can't read debug loc from end()");
+ InsertPt = I->getIterator();
+ assert(InsertPt != BB->end() && "Can't read debug loc from end()");
SetCurrentDebugLocation(I->getDebugLoc());
}
for (typename TraitsTy::nodes_iterator I = TraitsTy::nodes_begin(&F),
E = TraitsTy::nodes_end(&F);
I != E; ++I) {
- if (TraitsTy::child_begin(I) == TraitsTy::child_end(I))
- addRoot(I);
+ if (TraitsTy::child_begin(&*I) == TraitsTy::child_end(&*I))
+ addRoot(&*I);
// Prepopulate maps so that we don't get iterator invalidation issues
// later.
- this->IDoms[I] = nullptr;
- this->DomTreeNodes[I] = nullptr;
+ this->IDoms[&*I] = nullptr;
+ this->DomTreeNodes[&*I] = nullptr;
}
Calculate<FT, Inverse<NodeT *>>(*this, F);
for(Function::const_arg_iterator AI = TheFunction->arg_begin(),
AE = TheFunction->arg_end(); AI != AE; ++AI)
if (!AI->hasName())
- CreateFunctionSlot(AI);
+ CreateFunctionSlot(&*AI);
ST_DEBUG("Inserting Instructions:\n");
Out << " {";
// Output all of the function's basic blocks.
for (Function::const_iterator I = F->begin(), E = F->end(); I != E; ++I)
- printBasicBlock(I);
+ printBasicBlock(&*I);
// Output the function's use-lists.
printUseLists(F);
Function *F = CI->getCalledFunction();
LLVMContext &C = CI->getContext();
IRBuilder<> Builder(C);
- Builder.SetInsertPoint(CI->getParent(), CI);
+ Builder.SetInsertPoint(CI->getParent(), CI->getIterator());
assert(F && "Intrinsic call is not direct?");
Name == "llvm.x86.avx.movnt.ps.256" ||
Name == "llvm.x86.avx.movnt.pd.256") {
IRBuilder<> Builder(C);
- Builder.SetInsertPoint(CI->getParent(), CI);
+ Builder.SetInsertPoint(CI->getParent(), CI->getIterator());
Module *M = F->getParent();
SmallVector<Metadata *, 1> Elts;
assert(!Parent && "Already has a parent");
if (InsertBefore)
- NewParent->getBasicBlockList().insert(InsertBefore, this);
+ NewParent->getBasicBlockList().insert(InsertBefore->getIterator(), this);
else
NewParent->getBasicBlockList().push_back(this);
}
}
void BasicBlock::removeFromParent() {
- getParent()->getBasicBlockList().remove(this);
+ getParent()->getBasicBlockList().remove(getIterator());
}
iplist<BasicBlock>::iterator BasicBlock::eraseFromParent() {
- return getParent()->getBasicBlockList().erase(this);
+ return getParent()->getBasicBlockList().erase(getIterator());
}
/// Unlink this basic block from its current function and
/// insert it into the function that MovePos lives in, right before MovePos.
void BasicBlock::moveBefore(BasicBlock *MovePos) {
- MovePos->getParent()->getBasicBlockList().splice(MovePos,
- getParent()->getBasicBlockList(), this);
+ MovePos->getParent()->getBasicBlockList().splice(
+ MovePos->getIterator(), getParent()->getBasicBlockList(), getIterator());
}
/// Unlink this basic block from its current function and
/// insert it into the function that MovePos lives in, right after MovePos.
void BasicBlock::moveAfter(BasicBlock *MovePos) {
- Function::iterator I = MovePos;
- MovePos->getParent()->getBasicBlockList().splice(++I,
- getParent()->getBasicBlockList(), this);
+ MovePos->getParent()->getBasicBlockList().splice(
+ ++MovePos->getIterator(), getParent()->getBasicBlockList(),
+ getIterator());
}
const Module *BasicBlock::getModule() const {
if (!FirstNonPHI)
return end();
- iterator InsertPt = FirstNonPHI;
+ iterator InsertPt = FirstNonPHI->getIterator();
if (InsertPt->isEHPad()) ++InsertPt;
return InsertPt;
}
Module::global_iterator I = Mod->global_begin();
if (I == Mod->global_end())
return nullptr;
- return wrap(I);
+ return wrap(&*I);
}
LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M) {
Module::global_iterator I = Mod->global_end();
if (I == Mod->global_begin())
return nullptr;
- return wrap(--I);
+ return wrap(&*--I);
}
LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar) {
GlobalVariable *GV = unwrap<GlobalVariable>(GlobalVar);
- Module::global_iterator I = GV;
+ Module::global_iterator I(GV);
if (++I == GV->getParent()->global_end())
return nullptr;
- return wrap(I);
+ return wrap(&*I);
}
LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar) {
GlobalVariable *GV = unwrap<GlobalVariable>(GlobalVar);
- Module::global_iterator I = GV;
+ Module::global_iterator I(GV);
if (I == GV->getParent()->global_begin())
return nullptr;
- return wrap(--I);
+ return wrap(&*--I);
}
void LLVMDeleteGlobal(LLVMValueRef GlobalVar) {
Module::iterator I = Mod->begin();
if (I == Mod->end())
return nullptr;
- return wrap(I);
+ return wrap(&*I);
}
LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M) {
Module::iterator I = Mod->end();
if (I == Mod->begin())
return nullptr;
- return wrap(--I);
+ return wrap(&*--I);
}
LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn) {
Function *Func = unwrap<Function>(Fn);
- Module::iterator I = Func;
+ Module::iterator I(Func);
if (++I == Func->getParent()->end())
return nullptr;
- return wrap(I);
+ return wrap(&*I);
}
LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn) {
Function *Func = unwrap<Function>(Fn);
- Module::iterator I = Func;
+ Module::iterator I(Func);
if (I == Func->getParent()->begin())
return nullptr;
- return wrap(--I);
+ return wrap(&*--I);
}
void LLVMDeleteFunction(LLVMValueRef Fn) {
Function *Fn = unwrap<Function>(FnRef);
for (Function::arg_iterator I = Fn->arg_begin(),
E = Fn->arg_end(); I != E; I++)
- *ParamRefs++ = wrap(I);
+ *ParamRefs++ = wrap(&*I);
}
LLVMValueRef LLVMGetParam(LLVMValueRef FnRef, unsigned index) {
Function::arg_iterator AI = unwrap<Function>(FnRef)->arg_begin();
while (index --> 0)
AI++;
- return wrap(AI);
+ return wrap(&*AI);
}
LLVMValueRef LLVMGetParamParent(LLVMValueRef V) {
Function::arg_iterator I = Func->arg_begin();
if (I == Func->arg_end())
return nullptr;
- return wrap(I);
+ return wrap(&*I);
}
LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn) {
Function::arg_iterator I = Func->arg_end();
if (I == Func->arg_begin())
return nullptr;
- return wrap(--I);
+ return wrap(&*--I);
}
LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg) {
Argument *A = unwrap<Argument>(Arg);
- Function::arg_iterator I = A;
+ Function::arg_iterator I(A);
if (++I == A->getParent()->arg_end())
return nullptr;
- return wrap(I);
+ return wrap(&*I);
}
LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg) {
Argument *A = unwrap<Argument>(Arg);
- Function::arg_iterator I = A;
+ Function::arg_iterator I(A);
if (I == A->getParent()->arg_begin())
return nullptr;
- return wrap(--I);
+ return wrap(&*--I);
}
void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA) {
void LLVMGetBasicBlocks(LLVMValueRef FnRef, LLVMBasicBlockRef *BasicBlocksRefs){
Function *Fn = unwrap<Function>(FnRef);
for (Function::iterator I = Fn->begin(), E = Fn->end(); I != E; I++)
- *BasicBlocksRefs++ = wrap(I);
+ *BasicBlocksRefs++ = wrap(&*I);
}
LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn) {
Function::iterator I = Func->begin();
if (I == Func->end())
return nullptr;
- return wrap(I);
+ return wrap(&*I);
}
LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn) {
Function::iterator I = Func->end();
if (I == Func->begin())
return nullptr;
- return wrap(--I);
+ return wrap(&*--I);
}
LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB) {
BasicBlock *Block = unwrap(BB);
- Function::iterator I = Block;
+ Function::iterator I(Block);
if (++I == Block->getParent()->end())
return nullptr;
- return wrap(I);
+ return wrap(&*I);
}
LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB) {
BasicBlock *Block = unwrap(BB);
- Function::iterator I = Block;
+ Function::iterator I(Block);
if (I == Block->getParent()->begin())
return nullptr;
- return wrap(--I);
+ return wrap(&*--I);
}
LLVMBasicBlockRef LLVMAppendBasicBlockInContext(LLVMContextRef C,
BasicBlock::iterator I = Block->begin();
if (I == Block->end())
return nullptr;
- return wrap(I);
+ return wrap(&*I);
}
LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB) {
BasicBlock::iterator I = Block->end();
if (I == Block->begin())
return nullptr;
- return wrap(--I);
+ return wrap(&*--I);
}
LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst) {
Instruction *Instr = unwrap<Instruction>(Inst);
- BasicBlock::iterator I = Instr;
+ BasicBlock::iterator I(Instr);
if (++I == Instr->getParent()->end())
return nullptr;
- return wrap(I);
+ return wrap(&*I);
}
LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst) {
Instruction *Instr = unwrap<Instruction>(Inst);
- BasicBlock::iterator I = Instr;
+ BasicBlock::iterator I(Instr);
if (I == Instr->getParent()->begin())
return nullptr;
- return wrap(--I);
+ return wrap(&*--I);
}
void LLVMInstructionEraseFromParent(LLVMValueRef Inst) {
LLVMValueRef Instr) {
BasicBlock *BB = unwrap(Block);
Instruction *I = Instr? unwrap<Instruction>(Instr) : (Instruction*) BB->end();
- unwrap(Builder)->SetInsertPoint(BB, I);
+ unwrap(Builder)->SetInsertPoint(BB, I->getIterator());
}
void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr) {
Instruction *I = unwrap<Instruction>(Instr);
- unwrap(Builder)->SetInsertPoint(I->getParent(), I);
+ unwrap(Builder)->SetInsertPoint(I->getParent(), I->getIterator());
}
void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block) {
for (Module::named_metadata_iterator NMI = M.named_metadata_begin(),
NME = M.named_metadata_end(); NMI != NME;) {
- NamedMDNode *NMD = NMI;
+ NamedMDNode *NMD = &*NMI;
++NMI;
if (NMD->getName().startswith("llvm.dbg.")) {
NMD->eraseFromParent();
}
void Function::removeFromParent() {
- getParent()->getFunctionList().remove(this);
+ getParent()->getFunctionList().remove(getIterator());
}
void Function::eraseFromParent() {
- getParent()->getFunctionList().erase(this);
+ getParent()->getFunctionList().erase(getIterator());
}
//===----------------------------------------------------------------------===//
}
if (Before)
- Before->getParent()->getGlobalList().insert(Before, this);
+ Before->getParent()->getGlobalList().insert(Before->getIterator(), this);
else
M.getGlobalList().push_back(this);
}
}
void GlobalVariable::removeFromParent() {
- getParent()->getGlobalList().remove(this);
+ getParent()->getGlobalList().remove(getIterator());
}
void GlobalVariable::eraseFromParent() {
- getParent()->getGlobalList().erase(this);
+ getParent()->getGlobalList().erase(getIterator());
}
void GlobalVariable::setInitializer(Constant *InitVal) {
}
void GlobalAlias::removeFromParent() {
- getParent()->getAliasList().remove(this);
+ getParent()->getAliasList().remove(getIterator());
}
void GlobalAlias::eraseFromParent() {
- getParent()->getAliasList().erase(this);
+ getParent()->getAliasList().erase(getIterator());
}
void GlobalAlias::setAliasee(Constant *Aliasee) {
if (InsertBefore) {
BasicBlock *BB = InsertBefore->getParent();
assert(BB && "Instruction to insert before is not in a basic block!");
- BB->getInstList().insert(InsertBefore, this);
+ BB->getInstList().insert(InsertBefore->getIterator(), this);
}
}
void Instruction::removeFromParent() {
- getParent()->getInstList().remove(this);
+ getParent()->getInstList().remove(getIterator());
}
iplist<Instruction>::iterator Instruction::eraseFromParent() {
- return getParent()->getInstList().erase(this);
+ return getParent()->getInstList().erase(getIterator());
}
/// insertBefore - Insert an unlinked instructions into a basic block
/// immediately before the specified instruction.
void Instruction::insertBefore(Instruction *InsertPos) {
- InsertPos->getParent()->getInstList().insert(InsertPos, this);
+ InsertPos->getParent()->getInstList().insert(InsertPos->getIterator(), this);
}
/// insertAfter - Insert an unlinked instructions into a basic block
/// immediately after the specified instruction.
void Instruction::insertAfter(Instruction *InsertPos) {
- InsertPos->getParent()->getInstList().insertAfter(InsertPos, this);
+ InsertPos->getParent()->getInstList().insertAfter(InsertPos->getIterator(),
+ this);
}
/// moveBefore - Unlink this instruction from its current basic block and
/// insert it into the basic block that MovePos lives in, right before
/// MovePos.
void Instruction::moveBefore(Instruction *MovePos) {
- MovePos->getParent()->getInstList().splice(MovePos,getParent()->getInstList(),
- this);
+ MovePos->getParent()->getInstList().splice(
+ MovePos->getIterator(), getParent()->getInstList(), getIterator());
}
/// Set or clear the unsafe-algebra flag on this instruction, which must be an
/// delete it.
void Module::eraseNamedMetadata(NamedMDNode *NMD) {
static_cast<StringMap<NamedMDNode *> *>(NamedMDSymTab)->erase(NMD->getName());
- NamedMDList.erase(NMD);
+ NamedMDList.erase(NMD->getIterator());
}
bool Module::isValidModFlagBehavior(Metadata *MD, ModFlagBehavior &MFB) {
// Add all of the items to the new symtab.
for (auto I = ItemList.begin(); I != ItemList.end(); ++I)
if (I->hasName())
- NewST->reinsertValue(I);
+ NewST->reinsertValue(&*I);
}
}
// First incorporate the arguments.
for (Function::const_arg_iterator AI = FI->arg_begin(),
AE = FI->arg_end(); AI != AE; ++AI)
- incorporateValue(AI);
+ incorporateValue(&*AI);
for (Function::const_iterator BB = FI->begin(), E = FI->end();
BB != E;++BB)
for (Module::const_named_metadata_iterator I = M.named_metadata_begin(),
E = M.named_metadata_end(); I != E; ++I) {
- const NamedMDNode *NMD = I;
+ const NamedMDNode *NMD = &*I;
for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i)
incorporateMDNode(NMD->getOperand(i));
}
: OS(OS), M(nullptr), Broken(false) {}
private:
+ template <class NodeTy> void Write(const ilist_iterator<NodeTy> &I) {
+ Write(&*I);
+ }
+
void Write(const Value *V) {
if (!V)
return;