[llvm] 168e23c - [VPlan] Remove reference to Instr when setting debug loc. (NFCI)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 5 02:59:20 PDT 2023
Author: Florian Hahn
Date: 2023-09-05T10:59:13+01:00
New Revision: 168e23c741ca648771a842cb85938a99943902dc
URL: https://github.com/llvm/llvm-project/commit/168e23c741ca648771a842cb85938a99943902dc
DIFF: https://github.com/llvm/llvm-project/commit/168e23c741ca648771a842cb85938a99943902dc.diff
LOG: [VPlan] Remove reference to Instr when setting debug loc. (NFCI)
This allows untangling references to underlying IR for various recipes.
Added:
Modified:
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
llvm/lib/Transforms/Vectorize/VPlan.cpp
llvm/lib/Transforms/Vectorize/VPlan.h
llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index f4671ec20530c6..a36c5fb95d38f0 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -2444,7 +2444,8 @@ void InnerLoopVectorizer::vectorizeInterleaveGroup(
for (unsigned Part = 0; Part < UF; Part++) {
Value *AddrPart = State.get(Addr, VPIteration(Part, 0));
- State.setDebugLocFromInst(AddrPart);
+ if (auto *I = dyn_cast<Instruction>(AddrPart))
+ State.setDebugLocFrom(I->getDebugLoc());
// Notice current instruction could be any index. Need to adjust the address
// to the member of index 0.
@@ -2465,7 +2466,7 @@ void InnerLoopVectorizer::vectorizeInterleaveGroup(
AddrParts.push_back(AddrPart);
}
- State.setDebugLocFromInst(Instr);
+ State.setDebugLocFrom(Instr->getDebugLoc());
Value *PoisonVec = PoisonValue::get(VecTy);
auto CreateGroupMask = [this, &BlockInMask, &State, &InterleaveFactor](
@@ -2668,8 +2669,8 @@ void InnerLoopVectorizer::scalarizeInstruction(const Instruction *Instr,
RepRecipe->setFlags(Cloned);
- if (Instr->getDebugLoc())
- State.setDebugLocFromInst(Instr);
+ if (auto DL = Instr->getDebugLoc())
+ State.setDebugLocFrom(DL);
// Replace the operands of the cloned instructions with their scalar
// equivalents in the new loop.
@@ -3789,7 +3790,8 @@ void InnerLoopVectorizer::fixReduction(VPReductionPHIRecipe *PhiR,
RecurKind RK = RdxDesc.getRecurrenceKind();
TrackingVH<Value> ReductionStartValue = RdxDesc.getRecurrenceStartValue();
Instruction *LoopExitInst = RdxDesc.getLoopExitInstr();
- State.setDebugLocFromInst(ReductionStartValue);
+ if (auto *I = dyn_cast<Instruction>(&*ReductionStartValue))
+ State.setDebugLocFrom(I->getDebugLoc());
VPValue *LoopExitInstDef = PhiR->getBackedgeValue();
// This is the vector-clone of the value that leaves the loop.
@@ -3801,7 +3803,7 @@ void InnerLoopVectorizer::fixReduction(VPReductionPHIRecipe *PhiR,
// instructions.
Builder.SetInsertPoint(&*LoopMiddleBlock->getFirstInsertionPt());
- State.setDebugLocFromInst(LoopExitInst);
+ State.setDebugLocFrom(LoopExitInst->getDebugLoc());
Type *PhiTy = OrigPhi->getType();
@@ -3882,7 +3884,7 @@ void InnerLoopVectorizer::fixReduction(VPReductionPHIRecipe *PhiR,
// conditional branch, and (c) other passes may add new predecessors which
// terminate on this line. This is the easiest way to ensure we don't
// accidentally cause an extra step back into the loop while debugging.
- State.setDebugLocFromInst(LoopMiddleBlock->getTerminator());
+ State.setDebugLocFrom(LoopMiddleBlock->getTerminator()->getDebugLoc());
if (PhiR->isOrdered())
ReducedPartRdx = State.get(LoopExitInstDef, UF - 1);
else {
@@ -9500,7 +9502,7 @@ void VPWidenMemoryInstructionRecipe::execute(VPTransformState &State) {
// Handle Stores:
if (SI) {
- State.setDebugLocFromInst(SI);
+ State.setDebugLocFrom(SI->getDebugLoc());
for (unsigned Part = 0; Part < State.UF; ++Part) {
Instruction *NewSI = nullptr;
@@ -9533,7 +9535,7 @@ void VPWidenMemoryInstructionRecipe::execute(VPTransformState &State) {
// Handle loads.
assert(LI && "Must have a load instruction");
- State.setDebugLocFromInst(LI);
+ State.setDebugLocFrom(LI->getDebugLoc());
for (unsigned Part = 0; Part < State.UF; ++Part) {
Value *NewLI;
if (CreateGatherScatter) {
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.cpp b/llvm/lib/Transforms/Vectorize/VPlan.cpp
index 5273f0da4be590..cf100cd000bb86 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlan.cpp
@@ -360,20 +360,15 @@ void VPTransformState::addMetadata(ArrayRef<Value *> To, Instruction *From) {
}
}
-void VPTransformState::setDebugLocFromInst(const Value *V) {
- const Instruction *Inst = dyn_cast<Instruction>(V);
- if (!Inst) {
- Builder.SetCurrentDebugLocation(DebugLoc());
- return;
- }
-
- const DILocation *DIL = Inst->getDebugLoc();
+void VPTransformState::setDebugLocFrom(DebugLoc DL) {
+ const DILocation *DIL = DL;
// When a FSDiscriminator is enabled, we don't need to add the multiply
// factors to the discriminators.
- if (DIL && Inst->getFunction()->shouldEmitDebugInfoForProfiling() &&
+ if (DIL &&
+ Builder.GetInsertBlock()
+ ->getParent()
+ ->shouldEmitDebugInfoForProfiling() &&
!EnableFSDiscriminator) {
- assert(!Inst->isDebugOrPseudoInst() &&
- "debug and pseudo instruction aren't part of VPlan");
// FIXME: For scalable vectors, assume vscale=1.
auto NewDIL =
DIL->cloneByMultiplyingDuplicationFactor(UF * VF.getKnownMinValue());
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h
index 8556c1d1a8d83b..afc379beb01277 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.h
+++ b/llvm/lib/Transforms/Vectorize/VPlan.h
@@ -349,8 +349,8 @@ struct VPTransformState {
/// vector of instructions.
void addMetadata(ArrayRef<Value *> To, Instruction *From);
- /// Set the debug location in the builder using the debug location in \p V.
- void setDebugLocFromInst(const Value *V);
+ /// Set the debug location in the builder using the debug location \p DL.
+ void setDebugLocFrom(DebugLoc DL);
/// Construct the vector value of a scalarized value \p V one lane at a time.
void packScalarIntoVectorValue(VPValue *Def, const VPIteration &Instance);
diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
index 5a60df5aa17c6b..65acabbd1fc984 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
@@ -500,7 +500,7 @@ void VPWidenCallRecipe::execute(VPTransformState &State) {
auto &CI = *cast<CallInst>(getUnderlyingInstr());
assert(!isa<DbgInfoIntrinsic>(CI) &&
"DbgInfoIntrinsic should have been dropped during VPlan construction");
- State.setDebugLocFromInst(&CI);
+ State.setDebugLocFrom(CI.getDebugLoc());
for (unsigned Part = 0; Part < State.UF; ++Part) {
SmallVector<Type *, 2> TysForDecl;
@@ -592,7 +592,7 @@ void VPWidenSelectRecipe::print(raw_ostream &O, const Twine &Indent,
void VPWidenSelectRecipe::execute(VPTransformState &State) {
auto &I = *cast<SelectInst>(getUnderlyingInstr());
- State.setDebugLocFromInst(&I);
+ State.setDebugLocFrom(I.getDebugLoc());
// The condition can be loop invariant but still defined inside the
// loop. This means that we can't just use the original 'cond' value.
@@ -683,7 +683,7 @@ void VPWidenRecipe::execute(VPTransformState &State) {
case Instruction::Or:
case Instruction::Xor: {
// Just widen unops and binops.
- State.setDebugLocFromInst(&I);
+ State.setDebugLocFrom(I.getDebugLoc());
for (unsigned Part = 0; Part < State.UF; ++Part) {
SmallVector<Value *, 2> Ops;
@@ -703,7 +703,7 @@ void VPWidenRecipe::execute(VPTransformState &State) {
break;
}
case Instruction::Freeze: {
- State.setDebugLocFromInst(&I);
+ State.setDebugLocFrom(I.getDebugLoc());
for (unsigned Part = 0; Part < State.UF; ++Part) {
Value *Op = State.get(getOperand(0), Part);
@@ -718,7 +718,7 @@ void VPWidenRecipe::execute(VPTransformState &State) {
// Widen compares. Generate vector compares.
bool FCmp = (I.getOpcode() == Instruction::FCmp);
auto *Cmp = cast<CmpInst>(&I);
- State.setDebugLocFromInst(Cmp);
+ State.setDebugLocFrom(Cmp->getDebugLoc());
for (unsigned Part = 0; Part < State.UF; ++Part) {
Value *A = State.get(getOperand(0), Part);
Value *B = State.get(getOperand(1), Part);
@@ -758,7 +758,7 @@ void VPWidenRecipe::print(raw_ostream &O, const Twine &Indent,
void VPWidenCastRecipe::execute(VPTransformState &State) {
auto *I = cast_or_null<Instruction>(getUnderlyingValue());
if (I)
- State.setDebugLocFromInst(I);
+ State.setDebugLocFrom(I->getDebugLoc());
auto &Builder = State.Builder;
/// Vectorize casts.
assert(State.VF.isVector() && "Not vectorizing?");
@@ -1193,7 +1193,7 @@ void VPWidenGEPRecipe::print(raw_ostream &O, const Twine &Indent,
#endif
void VPBlendRecipe::execute(VPTransformState &State) {
- State.setDebugLocFromInst(Phi);
+ State.setDebugLocFrom(Phi->getDebugLoc());
// We know that all PHIs in non-header blocks are converted into
// selects, so we don't have to worry about the insertion order and we
// can just use the builder.
More information about the llvm-commits
mailing list