Skip to content

Commit

Permalink
[VPlan] Remove reference to Instr when setting debug loc. (NFCI)
Browse files Browse the repository at this point in the history
This allows untangling references to underlying IR for various recipes.
  • Loading branch information
fhahn committed Sep 5, 2023
1 parent e8144c7 commit 168e23c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 29 deletions.
20 changes: 11 additions & 9 deletions llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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](
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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();

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
17 changes: 6 additions & 11 deletions llvm/lib/Transforms/Vectorize/VPlan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Transforms/Vectorize/VPlan.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 7 additions & 7 deletions llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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?");
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 168e23c

Please sign in to comment.