[LoopVectorize][NFC] Add optional Name parameter to VPInstruction
This patch is a simple piece of refactoring that now permits users to create VPInstructions and specify the name of the value being generated. This is useful for creating more readable/meaningful names in IR. Differential Revision: https://reviews.llvm.org/D128982
This commit is contained in:
parent
79942d32a6
commit
02d6950d84
|
@ -45,8 +45,9 @@ class VPBuilder {
|
|||
VPBasicBlock::iterator InsertPt = VPBasicBlock::iterator();
|
||||
|
||||
VPInstruction *createInstruction(unsigned Opcode,
|
||||
ArrayRef<VPValue *> Operands, DebugLoc DL) {
|
||||
VPInstruction *Instr = new VPInstruction(Opcode, Operands, DL);
|
||||
ArrayRef<VPValue *> Operands, DebugLoc DL,
|
||||
const Twine &Name = "") {
|
||||
VPInstruction *Instr = new VPInstruction(Opcode, Operands, DL, Name);
|
||||
if (BB)
|
||||
BB->insert(Instr, InsertPt);
|
||||
return Instr;
|
||||
|
@ -54,8 +55,8 @@ class VPBuilder {
|
|||
|
||||
VPInstruction *createInstruction(unsigned Opcode,
|
||||
std::initializer_list<VPValue *> Operands,
|
||||
DebugLoc DL) {
|
||||
return createInstruction(Opcode, ArrayRef<VPValue *>(Operands), DL);
|
||||
DebugLoc DL, const Twine &Name = "") {
|
||||
return createInstruction(Opcode, ArrayRef<VPValue *>(Operands), DL, Name);
|
||||
}
|
||||
|
||||
public:
|
||||
|
@ -123,34 +124,37 @@ public:
|
|||
/// Create an N-ary operation with \p Opcode, \p Operands and set \p Inst as
|
||||
/// its underlying Instruction.
|
||||
VPValue *createNaryOp(unsigned Opcode, ArrayRef<VPValue *> Operands,
|
||||
Instruction *Inst = nullptr) {
|
||||
Instruction *Inst = nullptr, const Twine &Name = "") {
|
||||
DebugLoc DL;
|
||||
if (Inst)
|
||||
DL = Inst->getDebugLoc();
|
||||
VPInstruction *NewVPInst = createInstruction(Opcode, Operands, DL);
|
||||
VPInstruction *NewVPInst = createInstruction(Opcode, Operands, DL, Name);
|
||||
NewVPInst->setUnderlyingValue(Inst);
|
||||
return NewVPInst;
|
||||
}
|
||||
VPValue *createNaryOp(unsigned Opcode, ArrayRef<VPValue *> Operands,
|
||||
DebugLoc DL) {
|
||||
return createInstruction(Opcode, Operands, DL);
|
||||
DebugLoc DL, const Twine &Name = "") {
|
||||
return createInstruction(Opcode, Operands, DL, Name);
|
||||
}
|
||||
|
||||
VPValue *createNot(VPValue *Operand, DebugLoc DL) {
|
||||
return createInstruction(VPInstruction::Not, {Operand}, DL);
|
||||
VPValue *createNot(VPValue *Operand, DebugLoc DL, const Twine &Name = "") {
|
||||
return createInstruction(VPInstruction::Not, {Operand}, DL, Name);
|
||||
}
|
||||
|
||||
VPValue *createAnd(VPValue *LHS, VPValue *RHS, DebugLoc DL) {
|
||||
return createInstruction(Instruction::BinaryOps::And, {LHS, RHS}, DL);
|
||||
VPValue *createAnd(VPValue *LHS, VPValue *RHS, DebugLoc DL,
|
||||
const Twine &Name = "") {
|
||||
return createInstruction(Instruction::BinaryOps::And, {LHS, RHS}, DL, Name);
|
||||
}
|
||||
|
||||
VPValue *createOr(VPValue *LHS, VPValue *RHS, DebugLoc DL) {
|
||||
return createInstruction(Instruction::BinaryOps::Or, {LHS, RHS}, DL);
|
||||
VPValue *createOr(VPValue *LHS, VPValue *RHS, DebugLoc DL,
|
||||
const Twine &Name = "") {
|
||||
return createInstruction(Instruction::BinaryOps::Or, {LHS, RHS}, DL, Name);
|
||||
}
|
||||
|
||||
VPValue *createSelect(VPValue *Cond, VPValue *TrueVal, VPValue *FalseVal,
|
||||
DebugLoc DL) {
|
||||
return createNaryOp(Instruction::Select, {Cond, TrueVal, FalseVal}, DL);
|
||||
DebugLoc DL, const Twine &Name = "") {
|
||||
return createNaryOp(Instruction::Select, {Cond, TrueVal, FalseVal}, DL,
|
||||
Name);
|
||||
}
|
||||
|
||||
//===--------------------------------------------------------------------===//
|
||||
|
|
|
@ -8031,7 +8031,8 @@ VPValue *VPRecipeBuilder::createBlockInMask(BasicBlock *BB, VPlanPtr &Plan) {
|
|||
Builder.setInsertPoint(HeaderVPBB, NewInsertionPoint);
|
||||
if (CM.TTI.emitGetActiveLaneMask()) {
|
||||
VPValue *TC = Plan->getOrCreateTripCount();
|
||||
BlockMask = Builder.createNaryOp(VPInstruction::ActiveLaneMask, {IV, TC});
|
||||
BlockMask = Builder.createNaryOp(VPInstruction::ActiveLaneMask, {IV, TC},
|
||||
nullptr, "active.lane.mask");
|
||||
} else {
|
||||
VPValue *BTC = Plan->getOrCreateBackedgeTakenCount();
|
||||
BlockMask = Builder.createNaryOp(VPInstruction::ICmpULE, {IV, BTC});
|
||||
|
@ -8588,7 +8589,7 @@ static void addCanonicalIVRecipes(VPlan &Plan, Type *IdxTy, DebugLoc DL,
|
|||
auto *CanonicalIVIncrement =
|
||||
new VPInstruction(HasNUW ? VPInstruction::CanonicalIVIncrementNUW
|
||||
: VPInstruction::CanonicalIVIncrement,
|
||||
{CanonicalIVPHI}, DL);
|
||||
{CanonicalIVPHI}, DL, "index.next");
|
||||
CanonicalIVPHI->addOperand(CanonicalIVIncrement);
|
||||
|
||||
VPBasicBlock *EB = TopRegion->getExitingBasicBlock();
|
||||
|
|
|
@ -794,6 +794,9 @@ private:
|
|||
FastMathFlags FMF;
|
||||
DebugLoc DL;
|
||||
|
||||
/// An optional name that can be used for the generated IR instruction.
|
||||
const std::string Name;
|
||||
|
||||
/// Utility method serving execute(): generates a single instance of the
|
||||
/// modeled instruction.
|
||||
void generateInstruction(VPTransformState &State, unsigned Part);
|
||||
|
@ -802,14 +805,15 @@ protected:
|
|||
void setUnderlyingInstr(Instruction *I) { setUnderlyingValue(I); }
|
||||
|
||||
public:
|
||||
VPInstruction(unsigned Opcode, ArrayRef<VPValue *> Operands, DebugLoc DL)
|
||||
VPInstruction(unsigned Opcode, ArrayRef<VPValue *> Operands, DebugLoc DL,
|
||||
const Twine &Name = "")
|
||||
: VPRecipeBase(VPRecipeBase::VPInstructionSC, Operands),
|
||||
VPValue(VPValue::VPVInstructionSC, nullptr, this), Opcode(Opcode),
|
||||
DL(DL) {}
|
||||
DL(DL), Name(Name.str()) {}
|
||||
|
||||
VPInstruction(unsigned Opcode, std::initializer_list<VPValue *> Operands,
|
||||
DebugLoc DL = {})
|
||||
: VPInstruction(Opcode, ArrayRef<VPValue *>(Operands), DL) {}
|
||||
DebugLoc DL = {}, const Twine &Name = "")
|
||||
: VPInstruction(Opcode, ArrayRef<VPValue *>(Operands), DL, Name) {}
|
||||
|
||||
/// Method to support type inquiry through isa, cast, and dyn_cast.
|
||||
static inline bool classof(const VPValue *V) {
|
||||
|
@ -818,7 +822,7 @@ public:
|
|||
|
||||
VPInstruction *clone() const {
|
||||
SmallVector<VPValue *, 2> Operands(operands());
|
||||
return new VPInstruction(Opcode, Operands, DL);
|
||||
return new VPInstruction(Opcode, Operands, DL, Name);
|
||||
}
|
||||
|
||||
/// Method to support type inquiry through isa, cast, and dyn_cast.
|
||||
|
|
|
@ -189,7 +189,8 @@ void VPInstruction::generateInstruction(VPTransformState &State,
|
|||
if (Instruction::isBinaryOp(getOpcode())) {
|
||||
Value *A = State.get(getOperand(0), Part);
|
||||
Value *B = State.get(getOperand(1), Part);
|
||||
Value *V = Builder.CreateBinOp((Instruction::BinaryOps)getOpcode(), A, B);
|
||||
Value *V =
|
||||
Builder.CreateBinOp((Instruction::BinaryOps)getOpcode(), A, B, Name);
|
||||
State.set(this, V, Part);
|
||||
return;
|
||||
}
|
||||
|
@ -197,14 +198,14 @@ void VPInstruction::generateInstruction(VPTransformState &State,
|
|||
switch (getOpcode()) {
|
||||
case VPInstruction::Not: {
|
||||
Value *A = State.get(getOperand(0), Part);
|
||||
Value *V = Builder.CreateNot(A);
|
||||
Value *V = Builder.CreateNot(A, Name);
|
||||
State.set(this, V, Part);
|
||||
break;
|
||||
}
|
||||
case VPInstruction::ICmpULE: {
|
||||
Value *IV = State.get(getOperand(0), Part);
|
||||
Value *TC = State.get(getOperand(1), Part);
|
||||
Value *V = Builder.CreateICmpULE(IV, TC);
|
||||
Value *V = Builder.CreateICmpULE(IV, TC, Name);
|
||||
State.set(this, V, Part);
|
||||
break;
|
||||
}
|
||||
|
@ -212,7 +213,7 @@ void VPInstruction::generateInstruction(VPTransformState &State,
|
|||
Value *Cond = State.get(getOperand(0), Part);
|
||||
Value *Op1 = State.get(getOperand(1), Part);
|
||||
Value *Op2 = State.get(getOperand(2), Part);
|
||||
Value *V = Builder.CreateSelect(Cond, Op1, Op2);
|
||||
Value *V = Builder.CreateSelect(Cond, Op1, Op2, Name);
|
||||
State.set(this, V, Part);
|
||||
break;
|
||||
}
|
||||
|
@ -226,7 +227,7 @@ void VPInstruction::generateInstruction(VPTransformState &State,
|
|||
auto *PredTy = VectorType::get(Int1Ty, State.VF);
|
||||
Instruction *Call = Builder.CreateIntrinsic(
|
||||
Intrinsic::get_active_lane_mask, {PredTy, ScalarTC->getType()},
|
||||
{VIVElem0, ScalarTC}, nullptr, "active.lane.mask");
|
||||
{VIVElem0, ScalarTC}, nullptr, Name);
|
||||
State.set(this, Call, Part);
|
||||
break;
|
||||
}
|
||||
|
@ -250,7 +251,8 @@ void VPInstruction::generateInstruction(VPTransformState &State,
|
|||
State.set(this, PartMinus1, Part);
|
||||
} else {
|
||||
Value *V2 = State.get(getOperand(1), Part);
|
||||
State.set(this, Builder.CreateVectorSplice(PartMinus1, V2, -1), Part);
|
||||
State.set(this, Builder.CreateVectorSplice(PartMinus1, V2, -1, Name),
|
||||
Part);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -264,7 +266,7 @@ void VPInstruction::generateInstruction(VPTransformState &State,
|
|||
// elements) times the unroll factor (num of SIMD instructions).
|
||||
Value *Step =
|
||||
createStepForVF(Builder, Phi->getType(), State.VF, State.UF);
|
||||
Next = Builder.CreateAdd(Phi, Step, "index.next", IsNUW, false);
|
||||
Next = Builder.CreateAdd(Phi, Step, Name, IsNUW, false);
|
||||
} else {
|
||||
Next = State.get(this, 0);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue