Skip to content

Commit ebe1bd0

Browse files
authored
Merge pull request #126 from sx-aurora-dev/merge/vp-opaque-ptr
Merge/vp opaque ptr
2 parents 3b23f5f + 80e0db6 commit ebe1bd0

File tree

8 files changed

+36
-46
lines changed

8 files changed

+36
-46
lines changed

llvm/include/llvm/IR/IRBuilder.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -783,9 +783,10 @@ class IRBuilderBase {
783783

784784

785785
/// Call an arithmetic VP intrinsic.
786-
Instruction *CreateVectorPredicatedInst(unsigned OC, ArrayRef<Value *>,
787-
Instruction *FMFSource = nullptr,
788-
const Twine &Name = "");
786+
Instruction *CreateVectorPredicatedInst(unsigned OC, Type *ReturnTy,
787+
ArrayRef<Value *>,
788+
Instruction *FMFSource = nullptr,
789+
const Twine &Name = "");
789790

790791
/// Call an comparison VP intrinsic.
791792
Instruction *CreateVectorPredicatedCmp(CmpInst::Predicate Pred,

llvm/include/llvm/IR/IntrinsicInst.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -399,10 +399,11 @@ class VPIntrinsic : public IntrinsicInst {
399399
static bool HasExceptionMode(Intrinsic::ID VPID);
400400

401401
/// \brief Declares a llvm.vp.* intrinsic in \p M that matches the parameters
402-
/// \p Params.
402+
/// \p Params. Additionally, the load and gather intrinsics require
403+
/// \p ReturnType to be specified.
403404
static Function *getDeclarationForParams(Module *M, Intrinsic::ID,
404-
ArrayRef<Value *> Params,
405-
Type *VecRetTy = nullptr);
405+
Type *ReturnType,
406+
ArrayRef<Value *> Params);
406407

407408
static Optional<unsigned> getMaskParamPos(Intrinsic::ID IntrinsicID);
408409
static Optional<unsigned> getVectorLengthParamPos(Intrinsic::ID IntrinsicID);

llvm/include/llvm/IR/VPBuilder.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ class VPBuilder {
6767

6868
// Memory
6969
Value& CreateContiguousStore(Value & Val, Value & Pointer, MaybeAlign Alignment);
70-
Value& CreateContiguousLoad(Value & Pointer, MaybeAlign Alignment);
70+
Value& CreateContiguousLoad(Type *ReturnTy, Value & Pointer, MaybeAlign Alignment);
7171
Value& CreateScatter(Value & Val, Value & PointerVec, MaybeAlign Alignment);
72-
Value& CreateGather(Value & PointerVec, MaybeAlign Alignment);
72+
Value& CreateGather(Type *ReturnTy, Value & PointerVec, MaybeAlign Alignment);
7373
};
7474

7575

llvm/lib/IR/IRBuilder.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -563,14 +563,15 @@ CallInst *IRBuilderBase::CreateMaskedIntrinsic(Intrinsic::ID Id,
563563
/// \p FMFSource - Copy source for Fast Math Flags
564564
/// \p Name - name of the result variable
565565
Instruction *IRBuilderBase::CreateVectorPredicatedInst(unsigned OC,
566+
Type *ReturnTy,
566567
ArrayRef<Value *> Params,
567568
Instruction *FMFSource,
568569
const Twine &Name) {
569570

570571
Module *M = BB->getParent()->getParent();
571572

572573
Intrinsic::ID VPID = VPIntrinsic::getForOpcode(OC);
573-
auto VPFunc = VPIntrinsic::getDeclarationForParams(M, VPID, Params);
574+
auto VPFunc = VPIntrinsic::getDeclarationForParams(M, VPID, ReturnTy, Params);
574575
auto *VPCall = createCallHelper(VPFunc, Params, this, Name);
575576

576577
// transfer fast math flags
@@ -594,7 +595,9 @@ Instruction *IRBuilderBase::CreateVectorPredicatedCmp(
594595

595596
Module *M = BB->getParent()->getParent();
596597

597-
// encode comparison predicate as MD
598+
auto *ReturnTy = MaskParam->getType();
599+
600+
// Encode comparison predicate as MD
598601
uint8_t RawPred = static_cast<uint8_t>(Pred);
599602
auto Int8Ty = Type::getInt8Ty(getContext());
600603
auto PredParam = ConstantInt::get(Int8Ty, RawPred, false);
@@ -604,7 +607,8 @@ Instruction *IRBuilderBase::CreateVectorPredicatedCmp(
604607
: Intrinsic::vp_fcmp;
605608

606609
auto VPFunc = VPIntrinsic::getDeclarationForParams(
607-
M, VPID, {FirstParam, SndParam, PredParam, MaskParam, VectorLengthParam});
610+
M, VPID, ReturnTy,
611+
{FirstParam, SndParam, PredParam, MaskParam, VectorLengthParam});
608612

609613
return createCallHelper(
610614
VPFunc, {FirstParam, SndParam, PredParam, MaskParam, VectorLengthParam},

llvm/lib/IR/IntrinsicInst.cpp

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,9 @@ using VPTypeTokenVec = SmallVector<VPTypeToken, 4>;
541541
static VPIntrinsic::ShortTypeVec getVPIntrinsicTypes(Intrinsic::ID ID,
542542
Type *VecRetTy, Type *VecPtrTy,
543543
Type *VectorTy) {
544+
if (VPReductionIntrinsic::isVPReduction(ID))
545+
return VPIntrinsic::ShortTypeVec{VectorTy};
546+
544547
switch (ID) {
545548
default:
546549
llvm_unreachable("not implemented!");
@@ -616,9 +619,7 @@ static VPIntrinsic::ShortTypeVec getVPIntrinsicTypes(Intrinsic::ID ID,
616619

617620
case Intrinsic::vp_gather:
618621
case Intrinsic::vp_load:
619-
assert(VecRetTy);
620622
return VPIntrinsic::ShortTypeVec{VecRetTy, VecPtrTy};
621-
622623
case Intrinsic::vp_scatter:
623624
case Intrinsic::vp_store:
624625
return VPIntrinsic::ShortTypeVec{VectorTy, VecPtrTy};
@@ -639,8 +640,8 @@ static VPIntrinsic::ShortTypeVec getVPIntrinsicTypes(Intrinsic::ID ID,
639640
}
640641

641642
Function *VPIntrinsic::getDeclarationForParams(Module *M, Intrinsic::ID VPID,
642-
ArrayRef<Value *> Params,
643-
Type *VecRetTy) {
643+
Type *VecRetTy,
644+
ArrayRef<Value *> Params) {
644645
assert(VPID != Intrinsic::not_intrinsic && "todo dispatch to default insts");
645646

646647
bool IsArithOp = VPIntrinsic::IsBinaryVPOp(VPID) ||
@@ -683,15 +684,6 @@ Function *VPIntrinsic::getDeclarationForParams(Module *M, Intrinsic::ID VPID,
683684
if (DataPosOpt.hasValue()) {
684685
// store-kind operation
685686
VecTy = Params[DataPosOpt.getValue()]->getType();
686-
} else if (VPID == Intrinsic::vp_gather) {
687-
// Construct data vector from vector of pointer to element.
688-
auto *ElemTy =
689-
cast<VectorType>(VecPtrTy)->getElementType()->getPointerElementType();
690-
VecTy = VectorType::get(ElemTy,
691-
cast<VectorType>(VecPtrTy)->getElementCount());
692-
} else {
693-
// load-kind operation
694-
VecTy = VecPtrTy->getPointerElementType();
695687
}
696688

697689
} else if (IsShuffleOp) {

llvm/lib/IR/PredicatedInst.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ Instruction *PredicatedUnaryOperator::Create(
7979
// Fetch the VP intrinsic
8080
auto &VecTy = cast<VectorType>(*V->getType());
8181
auto *VPFunc =
82-
VPIntrinsic::getDeclarationForParams(Mod, VPID, {V}, &VecTy);
82+
VPIntrinsic::getDeclarationForParams(Mod, VPID, &VecTy, {V});
8383

8484
// Encode default environment fp behavior
8585

@@ -139,7 +139,7 @@ Instruction *PredicatedBinaryOperator::Create(
139139
// Fetch the VP intrinsic
140140
auto &VecTy = cast<VectorType>(*V1->getType());
141141
auto *VPFunc =
142-
VPIntrinsic::getDeclarationForParams(Mod, VPID, {V1, V2}, &VecTy);
142+
VPIntrinsic::getDeclarationForParams(Mod, VPID, &VecTy, {V1, V2});
143143

144144
// Encode default environment fp behavior
145145

llvm/lib/IR/VPBuilder.cpp

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ Value *VPBuilder::CreateVectorCopy(Instruction &Inst, ValArray VecOpArray) {
8989
Type *VecRetTy = ScaRetTy->isVoidTy() ? ScaRetTy : &getVectorType(*ScaRetTy);
9090
auto &M = *Builder.GetInsertBlock()->getParent()->getParent();
9191
auto VPDecl =
92-
VPIntrinsic::getDeclarationForParams(&M, VPID, VecParams, VecRetTy);
92+
VPIntrinsic::getDeclarationForParams(&M, VPID, VecRetTy, VecParams);
9393

9494
// Prepare constraint fp params
9595
// FIXME: \p Inst could also be just another VP intrinsic.
@@ -150,16 +150,12 @@ Value &VPBuilder::CreateContiguousStore(Value &Val, Value &ElemPointer,
150150
return StoreCall;
151151
}
152152

153-
Value &VPBuilder::CreateContiguousLoad(Value &ElemPointer,
153+
Value &VPBuilder::CreateContiguousLoad(Type *ReturnTy,
154+
Value &ElemPointer,
154155
MaybeAlign AlignOpt) {
155-
auto &PointerTy = cast<PointerType>(*ElemPointer.getType());
156-
auto &VecTy = getVectorType(*PointerTy.getPointerElementType());
157-
auto *VecPtrTy = VecTy.getPointerTo(PointerTy.getAddressSpace());
158-
auto *VecPtr = Builder.CreatePointerCast(&ElemPointer, VecPtrTy);
159-
160-
auto *LoadFunc = Intrinsic::getDeclaration(&getModule(), Intrinsic::vp_load,
161-
{&VecTy, VecPtrTy});
162-
ShortValueVec Args{VecPtr, &RequestPred(), &RequestEVL()};
156+
auto *LoadFunc = VPIntrinsic::getDeclarationForParams(
157+
&getModule(), Intrinsic::vp_load, ReturnTy, {&ElemPointer});
158+
ShortValueVec Args{&ElemPointer, &RequestPred(), &RequestEVL()};
163159
CallInst &LoadCall = *Builder.CreateCall(LoadFunc, Args);
164160
if (AlignOpt.hasValue()) {
165161
unsigned PtrPos =
@@ -173,7 +169,7 @@ Value &VPBuilder::CreateContiguousLoad(Value &ElemPointer,
173169
Value &VPBuilder::CreateScatter(Value &Val, Value &PointerVec,
174170
MaybeAlign AlignOpt) {
175171
auto *ScatterFunc =
176-
Intrinsic::getDeclaration(&getModule(), Intrinsic::vp_scatter,
172+
Intrinsic::getDeclaration(&getModule(), Intrinsic::vp_scatter,
177173
{Val.getType(), PointerVec.getType()});
178174
ShortValueVec Args{&Val, &PointerVec, &RequestPred(), &RequestEVL()};
179175
CallInst &ScatterCall = *Builder.CreateCall(ScatterFunc, Args);
@@ -189,13 +185,9 @@ Value &VPBuilder::CreateScatter(Value &Val, Value &PointerVec,
189185
return ScatterCall;
190186
}
191187

192-
Value &VPBuilder::CreateGather(Value &PointerVec, MaybeAlign AlignOpt) {
193-
auto &PointerVecTy = cast<VectorType>(*PointerVec.getType());
194-
auto &ElemTy = *cast<PointerType>(*PointerVecTy.getElementType())
195-
.getPointerElementType();
196-
auto &VecTy = *VectorType::get(&ElemTy, PointerVecTy.getElementCount());
197-
auto *GatherFunc = Intrinsic::getDeclaration(
198-
&getModule(), Intrinsic::vp_gather, {&VecTy, &PointerVecTy});
188+
Value &VPBuilder::CreateGather(Type *RetTy, Value &PointerVec, MaybeAlign AlignOpt) {
189+
auto *GatherFunc = VPIntrinsic::getDeclarationForParams(
190+
&getModule(), Intrinsic::vp_gather, RetTy, {&PointerVec});
199191

200192
ShortValueVec Args{&PointerVec, &RequestPred(), &RequestEVL()};
201193
CallInst &GatherCall = *Builder.CreateCall(GatherFunc, Args);
@@ -213,7 +205,7 @@ Value &VPBuilder::CreateGather(Value &PointerVec, MaybeAlign AlignOpt) {
213205

214206
Value *VPBuilder::CreateVectorShift(Value *SrcVal, Value *Amount, Twine Name) {
215207
auto D = VPIntrinsic::getDeclarationForParams(
216-
&getModule(), Intrinsic::vp_vshift, {SrcVal, Amount});
208+
&getModule(), Intrinsic::vp_vshift, SrcVal->getType(), {SrcVal, Amount});
217209
return Builder.CreateCall(D, {SrcVal, Amount, &RequestPred(), &RequestEVL()},
218210
Name);
219211
}

llvm/unittests/IR/VPIntrinsicTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ TEST_F(VPIntrinsicTest, VPIntrinsicDeclarationForParams) {
336336

337337
ASSERT_NE(F.getIntrinsicID(), Intrinsic::not_intrinsic);
338338
auto *NewDecl = VPIntrinsic::getDeclarationForParams(
339-
OutM.get(), F.getIntrinsicID(), Values, VecRetTy);
339+
OutM.get(), F.getIntrinsicID(), FuncTy->getReturnType(), Values);
340340
ASSERT_TRUE(NewDecl);
341341

342342
// Check that 'old decl' == 'new decl'.

0 commit comments

Comments
 (0)