Skip to content

Remove remaining uses of Instruction-constructors that insert before another Instruction #85981

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions clang/lib/CodeGen/CGCUDANV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,9 +484,9 @@ static void replaceManagedVar(llvm::GlobalVariable *Var,
}
if (auto *I = dyn_cast<llvm::Instruction>(U)) {
llvm::Value *OldV = Var;
llvm::Instruction *NewV =
new llvm::LoadInst(Var->getType(), ManagedVar, "ld.managed", false,
llvm::Align(Var->getAlignment()), I);
llvm::Instruction *NewV = new llvm::LoadInst(
Var->getType(), ManagedVar, "ld.managed", false,
llvm::Align(Var->getAlignment()), I->getIterator());
WorkItem.pop_back();
// Replace constant expressions directly or indirectly using the managed
// variable with instructions.
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/CodeGen/CGCall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5062,8 +5062,8 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
llvm::AllocaInst *AI;
if (IP) {
IP = IP->getNextNode();
AI = new llvm::AllocaInst(ArgStruct, DL.getAllocaAddrSpace(),
"argmem", IP);
AI = new llvm::AllocaInst(ArgStruct, DL.getAllocaAddrSpace(), "argmem",
IP->getIterator());
} else {
AI = CreateTempAlloca(ArgStruct, "argmem");
}
Expand Down
8 changes: 5 additions & 3 deletions clang/lib/CodeGen/CGCleanup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,8 @@ void EHScopeStack::Cleanup::anchor() {}
static void createStoreInstBefore(llvm::Value *value, Address addr,
llvm::Instruction *beforeInst,
CodeGenFunction &CGF) {
auto store = new llvm::StoreInst(value, addr.emitRawPointer(CGF), beforeInst);
auto store = new llvm::StoreInst(value, addr.emitRawPointer(CGF),
beforeInst->getIterator());
store->setAlignment(addr.getAlignment().getAsAlign());
}

Expand All @@ -304,7 +305,7 @@ static llvm::LoadInst *createLoadInstBefore(Address addr, const Twine &name,
CodeGenFunction &CGF) {
return new llvm::LoadInst(addr.getElementType(), addr.emitRawPointer(CGF),
name, false, addr.getAlignment().getAsAlign(),
beforeInst);
beforeInst->getIterator());
}

/// All the branch fixups on the EH stack have propagated out past the
Expand Down Expand Up @@ -612,7 +613,8 @@ static void destroyOptimisticNormalEntry(CodeGenFunction &CGF,
llvm::SwitchInst *si = cast<llvm::SwitchInst>(use.getUser());
if (si->getNumCases() == 1 && si->getDefaultDest() == unreachableBB) {
// Replace the switch with a branch.
llvm::BranchInst::Create(si->case_begin()->getCaseSuccessor(), si);
llvm::BranchInst::Create(si->case_begin()->getCaseSuccessor(),
si->getIterator());

// The switch operand is a load from the cleanup-dest alloca.
llvm::LoadInst *condition = cast<llvm::LoadInst>(si->getCondition());
Expand Down
5 changes: 3 additions & 2 deletions clang/lib/CodeGen/CGCoroutine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -867,8 +867,9 @@ void CodeGenFunction::EmitCoroutineBody(const CoroutineBodyStmt &S) {
EmitStmt(S.getPromiseDeclStmt());

Address PromiseAddr = GetAddrOfLocalVar(S.getPromiseDecl());
auto *PromiseAddrVoidPtr = new llvm::BitCastInst(
PromiseAddr.emitRawPointer(*this), VoidPtrTy, "", CoroId);
auto *PromiseAddrVoidPtr =
new llvm::BitCastInst(PromiseAddr.emitRawPointer(*this), VoidPtrTy, "",
CoroId->getIterator());
// Update CoroId to refer to the promise. We could not do it earlier because
// promise local variable was not emitted yet.
CoroId->setArgOperand(1, PromiseAddrVoidPtr);
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/CodeGen/CGExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ llvm::AllocaInst *CodeGenFunction::CreateTempAlloca(llvm::Type *Ty,
if (ArraySize)
return Builder.CreateAlloca(Ty, ArraySize, Name);
return new llvm::AllocaInst(Ty, CGM.getDataLayout().getAllocaAddrSpace(),
ArraySize, Name, AllocaInsertPt);
ArraySize, Name, AllocaInsertPt->getIterator());
}

/// CreateDefaultAlignTempAlloca - This creates an alloca with the
Expand Down
3 changes: 2 additions & 1 deletion clang/lib/CodeGen/CGObjC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2394,7 +2394,8 @@ static llvm::Value *emitOptimizedARCReturnCall(llvm::Value *value,
llvm::OperandBundleDef OB("clang.arc.attachedcall", bundleArgs);
auto *oldCall = cast<llvm::CallBase>(value);
llvm::CallBase *newCall = llvm::CallBase::addOperandBundle(
oldCall, llvm::LLVMContext::OB_clang_arc_attachedcall, OB, oldCall);
oldCall, llvm::LLVMContext::OB_clang_arc_attachedcall, OB,
oldCall->getIterator());
newCall->copyMetadata(*oldCall);
oldCall->replaceAllUsesWith(newCall);
oldCall->eraseFromParent();
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/CodeGen/CodeGenFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -1269,8 +1269,8 @@ class CodeGenFunction : public CodeGenTypeCache {
CodeGenFunction &CGF) {
assert(isInConditionalBranch());
llvm::BasicBlock *block = OutermostConditional->getStartingBlock();
auto store =
new llvm::StoreInst(value, addr.emitRawPointer(CGF), &block->back());
auto store = new llvm::StoreInst(value, addr.emitRawPointer(CGF),
&block->back().getIterator());
store->setAlignment(addr.getAlignment().getAsAlign());
}

Expand Down
10 changes: 5 additions & 5 deletions clang/lib/CodeGen/CodeGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5747,13 +5747,13 @@ static void replaceUsesOfNonProtoConstant(llvm::Constant *old,

llvm::CallBase *newCall;
if (isa<llvm::CallInst>(callSite)) {
newCall =
llvm::CallInst::Create(newFn, newArgs, newBundles, "", callSite);
newCall = llvm::CallInst::Create(newFn, newArgs, newBundles, "",
callSite->getIterator());
} else {
auto *oldInvoke = cast<llvm::InvokeInst>(callSite);
newCall = llvm::InvokeInst::Create(newFn, oldInvoke->getNormalDest(),
oldInvoke->getUnwindDest(), newArgs,
newBundles, "", callSite);
newCall = llvm::InvokeInst::Create(
newFn, oldInvoke->getNormalDest(), oldInvoke->getUnwindDest(),
newArgs, newBundles, "", callSite->getIterator());
}
newArgs.clear(); // for the next iteration

Expand Down
7 changes: 4 additions & 3 deletions llvm/examples/IRTransforms/SimplifyCFG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ static bool eliminateCondBranches_v1(Function &F) {
// Replace the conditional branch with an unconditional one, by creating
// a new unconditional branch to the selected successor and removing the
// conditional one.
BranchInst::Create(BI->getSuccessor(CI->isZero()), BI);
BranchInst::Create(BI->getSuccessor(CI->isZero()), BI->getIterator());
BI->eraseFromParent();
Changed = true;
}
Expand Down Expand Up @@ -195,7 +195,7 @@ static bool eliminateCondBranches_v2(Function &F, DominatorTree &DT) {
// a new unconditional branch to the selected successor and removing the
// conditional one.
BranchInst *NewBranch =
BranchInst::Create(BI->getSuccessor(CI->isZero()), BI);
BranchInst::Create(BI->getSuccessor(CI->isZero()), BI->getIterator());
BI->eraseFromParent();

// Delete the edge between BB and RemovedSucc in the DominatorTree, iff
Expand Down Expand Up @@ -242,7 +242,8 @@ static bool eliminateCondBranches_v3(Function &F, DominatorTree &DT) {
// a new unconditional branch to the selected successor and removing the
// conditional one.

BranchInst *NewBranch = BranchInst::Create(TakenSucc, BB.getTerminator());
BranchInst *NewBranch =
BranchInst::Create(TakenSucc, BB.getTerminator()->getIterator());
BB.getTerminator()->eraseFromParent();

// Delete the edge between BB and RemovedSucc in the DominatorTree, iff
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/FuzzMutate/IRMutator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ void InsertFunctionStrategy::mutate(BasicBlock &BB, RandomIRBuilder &IB) {
auto BuilderFunc = [FTy, F, isRetVoid](ArrayRef<Value *> Srcs,
Instruction *Inst) {
StringRef Name = isRetVoid ? nullptr : "C";
CallInst *Call = CallInst::Create(FTy, F, Srcs, Name, Inst);
CallInst *Call = CallInst::Create(FTy, F, Srcs, Name, Inst->getIterator());
// Don't return this call inst if it return void as it can't be sinked.
return isRetVoid ? nullptr : Call;
};
Expand Down Expand Up @@ -542,7 +542,7 @@ void InsertPHIStrategy::mutate(BasicBlock &BB, RandomIRBuilder &IB) {
if (&BB == &BB.getParent()->getEntryBlock())
return;
Type *Ty = IB.randomType();
PHINode *PHI = PHINode::Create(Ty, llvm::pred_size(&BB), "", &BB.front());
PHINode *PHI = PHINode::Create(Ty, llvm::pred_size(&BB), "", BB.begin());

// Use a map to make sure the same incoming basic block has the same value.
DenseMap<BasicBlock *, Value *> IncomingValues;
Expand Down
32 changes: 21 additions & 11 deletions llvm/lib/FuzzMutate/Operations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ void llvm::describeFuzzerVectorOps(std::vector<fuzzerop::OpDescriptor> &Ops) {

OpDescriptor llvm::fuzzerop::selectDescriptor(unsigned Weight) {
auto buildOp = [](ArrayRef<Value *> Srcs, Instruction *Inst) {
return SelectInst::Create(Srcs[0], Srcs[1], Srcs[2], "S", Inst);
return SelectInst::Create(Srcs[0], Srcs[1], Srcs[2], "S",
Inst->getIterator());
};
return {Weight,
{boolOrVecBoolType(), matchFirstLengthWAnyType(), matchSecondType()},
Expand All @@ -108,15 +109,17 @@ OpDescriptor llvm::fuzzerop::selectDescriptor(unsigned Weight) {

OpDescriptor llvm::fuzzerop::fnegDescriptor(unsigned Weight) {
auto buildOp = [](ArrayRef<Value *> Srcs, Instruction *Inst) {
return UnaryOperator::Create(Instruction::FNeg, Srcs[0], "F", Inst);
return UnaryOperator::Create(Instruction::FNeg, Srcs[0], "F",
Inst->getIterator());
};
return {Weight, {anyFloatOrVecFloatType()}, buildOp};
}

OpDescriptor llvm::fuzzerop::binOpDescriptor(unsigned Weight,
Instruction::BinaryOps Op) {
auto buildOp = [Op](ArrayRef<Value *> Srcs, Instruction *Inst) {
return BinaryOperator::Create(Op, Srcs[0], Srcs[1], "B", Inst);
return BinaryOperator::Create(Op, Srcs[0], Srcs[1], "B",
Inst->getIterator());
};
switch (Op) {
case Instruction::Add:
Expand Down Expand Up @@ -149,7 +152,8 @@ OpDescriptor llvm::fuzzerop::cmpOpDescriptor(unsigned Weight,
Instruction::OtherOps CmpOp,
CmpInst::Predicate Pred) {
auto buildOp = [CmpOp, Pred](ArrayRef<Value *> Srcs, Instruction *Inst) {
return CmpInst::Create(CmpOp, Pred, Srcs[0], Srcs[1], "C", Inst);
return CmpInst::Create(CmpOp, Pred, Srcs[0], Srcs[1], "C",
Inst->getIterator());
};

switch (CmpOp) {
Expand All @@ -174,7 +178,8 @@ OpDescriptor llvm::fuzzerop::splitBlockDescriptor(unsigned Weight) {
// Loop back on this block by replacing the unconditional forward branch
// with a conditional with a backedge.
if (Block != &Block->getParent()->getEntryBlock()) {
BranchInst::Create(Block, Next, Srcs[0], Block->getTerminator());
BranchInst::Create(Block, Next, Srcs[0],
Block->getTerminator()->getIterator());
Block->getTerminator()->eraseFromParent();

// We need values for each phi in the block. Since there isn't a good way
Expand All @@ -198,7 +203,8 @@ OpDescriptor llvm::fuzzerop::gepDescriptor(unsigned Weight) {
// generating a random value and picking its type.
Type *Ty = Srcs[1]->getType();
auto Indices = ArrayRef(Srcs).drop_front(2);
return GetElementPtrInst::Create(Ty, Srcs[0], Indices, "G", Inst);
return GetElementPtrInst::Create(Ty, Srcs[0], Indices, "G",
Inst->getIterator());
};
// TODO: Handle aggregates and vectors
// TODO: Support multiple indices.
Expand Down Expand Up @@ -242,7 +248,7 @@ OpDescriptor llvm::fuzzerop::extractValueDescriptor(unsigned Weight) {
auto buildExtract = [](ArrayRef<Value *> Srcs, Instruction *Inst) {
// TODO: It's pretty inefficient to shuffle this all through constants.
unsigned Idx = cast<ConstantInt>(Srcs[1])->getZExtValue();
return ExtractValueInst::Create(Srcs[0], {Idx}, "E", Inst);
return ExtractValueInst::Create(Srcs[0], {Idx}, "E", Inst->getIterator());
};
// TODO: Should we handle multiple indices?
return {Weight, {anyAggregateType(), validExtractValueIndex()}, buildExtract};
Expand Down Expand Up @@ -301,7 +307,8 @@ OpDescriptor llvm::fuzzerop::insertValueDescriptor(unsigned Weight) {
auto buildInsert = [](ArrayRef<Value *> Srcs, Instruction *Inst) {
// TODO: It's pretty inefficient to shuffle this all through constants.
unsigned Idx = cast<ConstantInt>(Srcs[2])->getZExtValue();
return InsertValueInst::Create(Srcs[0], Srcs[1], {Idx}, "I", Inst);
return InsertValueInst::Create(Srcs[0], Srcs[1], {Idx}, "I",
Inst->getIterator());
};
return {
Weight,
Expand All @@ -311,15 +318,17 @@ OpDescriptor llvm::fuzzerop::insertValueDescriptor(unsigned Weight) {

OpDescriptor llvm::fuzzerop::extractElementDescriptor(unsigned Weight) {
auto buildExtract = [](ArrayRef<Value *> Srcs, Instruction *Inst) {
return ExtractElementInst::Create(Srcs[0], Srcs[1], "E", Inst);
return ExtractElementInst::Create(Srcs[0], Srcs[1], "E",
Inst->getIterator());
};
// TODO: Try to avoid undefined accesses.
return {Weight, {anyVectorType(), anyIntType()}, buildExtract};
}

OpDescriptor llvm::fuzzerop::insertElementDescriptor(unsigned Weight) {
auto buildInsert = [](ArrayRef<Value *> Srcs, Instruction *Inst) {
return InsertElementInst::Create(Srcs[0], Srcs[1], Srcs[2], "I", Inst);
return InsertElementInst::Create(Srcs[0], Srcs[1], Srcs[2], "I",
Inst->getIterator());
};
// TODO: Try to avoid undefined accesses.
return {Weight,
Expand All @@ -344,7 +353,8 @@ static SourcePred validShuffleVectorIndex() {

OpDescriptor llvm::fuzzerop::shuffleVectorDescriptor(unsigned Weight) {
auto buildShuffle = [](ArrayRef<Value *> Srcs, Instruction *Inst) {
return new ShuffleVectorInst(Srcs[0], Srcs[1], Srcs[2], "S", Inst);
return new ShuffleVectorInst(Srcs[0], Srcs[1], Srcs[2], "S",
Inst->getIterator());
};
return {Weight,
{anyVectorType(), matchFirstType(), validShuffleVectorIndex()},
Expand Down
17 changes: 9 additions & 8 deletions llvm/lib/FuzzMutate/RandomIRBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ AllocaInst *RandomIRBuilder::createStackMemory(Function *F, Type *Ty,
BasicBlock *EntryBB = &F->getEntryBlock();
DataLayout DL(F->getParent());
AllocaInst *Alloca = new AllocaInst(Ty, DL.getAllocaAddrSpace(), "A",
&*EntryBB->getFirstInsertionPt());
EntryBB->getFirstInsertionPt());
if (Init)
new StoreInst(Init, Alloca, Alloca->getNextNode());
new StoreInst(Init, Alloca, Alloca->getNextNode()->getIterator());
return Alloca;
}

Expand Down Expand Up @@ -165,7 +165,7 @@ Value *RandomIRBuilder::findOrCreateSource(BasicBlock &BB,
Type *Ty = GV->getValueType();
LoadInst *LoadGV = nullptr;
if (BB.getTerminator()) {
LoadGV = new LoadInst(Ty, GV, "LGV", &*BB.getFirstInsertionPt());
LoadGV = new LoadInst(Ty, GV, "LGV", BB.getFirstInsertionPt());
} else {
LoadGV = new LoadInst(Ty, GV, "LGV", &BB);
}
Expand Down Expand Up @@ -213,7 +213,7 @@ Value *RandomIRBuilder::newSource(BasicBlock &BB, ArrayRef<Instruction *> Insts,
}
// Pick the type independently.
Type *AccessTy = RS.getSelection()->getType();
auto *NewLoad = new LoadInst(AccessTy, Ptr, "L", &*IP);
auto *NewLoad = new LoadInst(AccessTy, Ptr, "L", IP);

// Only sample this load if it really matches the descriptor
if (Pred.matches(Srcs, NewLoad))
Expand All @@ -231,7 +231,8 @@ Value *RandomIRBuilder::newSource(BasicBlock &BB, ArrayRef<Instruction *> Insts,
Function *F = BB.getParent();
AllocaInst *Alloca = createStackMemory(F, Ty, newSrc);
if (BB.getTerminator()) {
newSrc = new LoadInst(Ty, Alloca, /*ArrLen,*/ "L", BB.getTerminator());
newSrc = new LoadInst(Ty, Alloca, /*ArrLen,*/ "L",
BB.getTerminator()->getIterator());
} else {
newSrc = new LoadInst(Ty, Alloca, /*ArrLen,*/ "L", &BB);
}
Expand Down Expand Up @@ -325,7 +326,7 @@ Instruction *RandomIRBuilder::connectToSink(BasicBlock &BB,
for (BasicBlock *Dom : Dominators) {
for (Instruction &I : *Dom) {
if (isa<PointerType>(I.getType()))
return new StoreInst(V, &I, Insts.back());
return new StoreInst(V, &I, Insts.back()->getIterator());
}
}
break;
Expand All @@ -351,7 +352,7 @@ Instruction *RandomIRBuilder::connectToSink(BasicBlock &BB,
Module *M = BB.getParent()->getParent();
auto [GV, DidCreate] =
findOrCreateGlobalVariable(M, {}, fuzzerop::onlyType(V->getType()));
return new StoreInst(V, GV, Insts.back());
return new StoreInst(V, GV, Insts.back()->getIterator());
}
case EndOfValueSink:
default:
Expand All @@ -373,7 +374,7 @@ Instruction *RandomIRBuilder::newSink(BasicBlock &BB,
}
}

return new StoreInst(V, Ptr, Insts.back());
return new StoreInst(V, Ptr, Insts.back()->getIterator());
}

Value *RandomIRBuilder::findPointer(BasicBlock &BB,
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -690,8 +690,8 @@ class RuntimeCallInserter {
if (EHPad && EHPad->isEHPad()) {
// Replace CI with a clone with an added funclet OperandBundle
OperandBundleDef OB("funclet", EHPad);
auto *NewCall =
CallBase::addOperandBundle(CI, LLVMContext::OB_funclet, OB, CI);
auto *NewCall = CallBase::addOperandBundle(CI, LLVMContext::OB_funclet,
OB, CI->getIterator());
NewCall->copyMetadata(*CI);
CI->replaceAllUsesWith(NewCall);
CI->eraseFromParent();
Expand Down
3 changes: 2 additions & 1 deletion llvm/tools/llvm-reduce/deltas/ReduceOperandBundles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ static void maybeRewriteCallWithDifferentBundles(
});

// Finally actually replace the bundles on the call.
CallBase *NewCall = CallBase::Create(OrigCall, NewBundles, OrigCall);
CallBase *NewCall =
CallBase::Create(OrigCall, NewBundles, OrigCall->getIterator());
OrigCall->replaceAllUsesWith(NewCall);
OrigCall->eraseFromParent();
}
Expand Down
Loading