Skip to content

[DebugInfo][RemoveDIs] Use iterator-inserters in clang #102006

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

Merged
merged 3 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -505,9 +505,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 @@ -5081,8 +5081,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
20 changes: 14 additions & 6 deletions clang/lib/CodeGen/CGCleanup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,18 +295,25 @@ 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());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth updating the beforeInst parameter to a iterator instead of ->getIterator()-ing here? That would match the createLoadInstBefore overload you've added in this patch too.

store->setAlignment(addr.getAlignment().getAsAlign());
}

static llvm::LoadInst *createLoadInstBefore(Address addr, const Twine &name,
llvm::Instruction *beforeInst,
llvm::BasicBlock::iterator beforeInst,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please capitalize variable names and apply clang-format, this line exceeds 80 column limit.

CodeGenFunction &CGF) {
return new llvm::LoadInst(addr.getElementType(), addr.emitRawPointer(CGF),
name, false, addr.getAlignment().getAsAlign(),
beforeInst);
}

static llvm::LoadInst *createLoadInstBefore(Address addr, const Twine &name,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Insert before what?

CodeGenFunction &CGF) {
return new llvm::LoadInst(addr.getElementType(), addr.emitRawPointer(CGF),
name, false, addr.getAlignment().getAsAlign());
}

/// All the branch fixups on the EH stack have propagated out past the
/// outermost normal cleanup; resolve them all by adding cases to the
/// given switch instruction.
Expand Down Expand Up @@ -358,7 +365,7 @@ static llvm::SwitchInst *TransitionToCleanupSwitch(CodeGenFunction &CGF,
if (llvm::BranchInst *Br = dyn_cast<llvm::BranchInst>(Term)) {
assert(Br->isUnconditional());
auto Load = createLoadInstBefore(CGF.getNormalCleanupDestSlot(),
"cleanup.dest", Term, CGF);
"cleanup.dest", Term->getIterator(), CGF);
llvm::SwitchInst *Switch =
llvm::SwitchInst::Create(Load, Br->getSuccessor(0), 4, Block);
Br->eraseFromParent();
Expand Down Expand Up @@ -612,7 +619,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 Expand Up @@ -908,8 +916,8 @@ void CodeGenFunction::PopCleanupBlock(bool FallthroughIsBranchThrough,
// pass the abnormal exit flag to Fn (SEH cleanup)
cleanupFlags.setHasExitSwitch();

llvm::LoadInst *Load = createLoadInstBefore(
getNormalCleanupDestSlot(), "cleanup.dest", nullptr, *this);
llvm::LoadInst *Load = createLoadInstBefore(getNormalCleanupDestSlot(),
"cleanup.dest", *this);
llvm::SwitchInst *Switch =
llvm::SwitchInst::Create(Load, Default, SwitchCapacity);

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 @@ -866,8 +866,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 @@ -121,7 +121,7 @@ llvm::AllocaInst *CodeGenFunction::CreateTempAlloca(llvm::Type *Ty,
Alloca = Builder.CreateAlloca(Ty, ArraySize, Name);
else
Alloca = new llvm::AllocaInst(Ty, CGM.getDataLayout().getAllocaAddrSpace(),
ArraySize, Name, &*AllocaInsertPt);
ArraySize, Name, AllocaInsertPt);
if (Allocas) {
Allocas->Add(Alloca);
}
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 @@ -2393,7 +2393,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
2 changes: 1 addition & 1 deletion clang/lib/CodeGen/CGStmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3226,7 +3226,7 @@ CodeGenFunction::addConvergenceControlToken(llvm::CallBase *Input,
llvm::Value *bundleArgs[] = {ParentToken};
llvm::OperandBundleDef OB("convergencectrl", bundleArgs);
auto Output = llvm::CallBase::addOperandBundle(
Input, llvm::LLVMContext::OB_convergencectrl, OB, Input);
Input, llvm::LLVMContext::OB_convergencectrl, OB, Input->getIterator());
Input->replaceAllUsesWith(Output);
Input->eraseFromParent();
return Output;
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 @@ -1310,8 +1310,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 @@ -5893,13 +5893,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
Loading