[PATCH] D102686: [VP] getDeclarationForParam
Simon Moll via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue May 18 05:48:02 PDT 2021
simoll created this revision.
simoll added reviewers: frasercrmck, rogfer01, craig.topper, vkmr.
simoll added a project: VP.
Herald added subscribers: dexonsmith, hiraditya.
simoll requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
`VPIntrinsic::getDeclarationForParams` creates a vp intrinsic declaration for parameters you want to call it with.
This is in preparation of a new builder class that makes emitting vp intrinsic code nearly as convenient as using a plain ir builder (aka `VectorBuilder`, to be used by D99750 <https://reviews.llvm.org/D99750>).
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D102686
Files:
llvm/include/llvm/IR/IntrinsicInst.h
llvm/lib/IR/IntrinsicInst.cpp
llvm/unittests/IR/VPIntrinsicTest.cpp
Index: llvm/unittests/IR/VPIntrinsicTest.cpp
===================================================================
--- llvm/unittests/IR/VPIntrinsicTest.cpp
+++ llvm/unittests/IR/VPIntrinsicTest.cpp
@@ -221,4 +221,36 @@
ASSERT_NE(FullTripCounts, 0u);
}
+/// Check that VPIntrinsic::getDeclarationForParams works.
+TEST_F(VPIntrinsicTest, VPIntrinsicDeclarationForParams) {
+ std::unique_ptr<Module> M = CreateVPDeclarationModule();
+ assert(M);
+
+ auto OutM = std::make_unique<Module>("", M->getContext());
+
+ for (auto &F : *M) {
+ auto *FuncTy = F.getFunctionType();
+
+ // Declare intrinsic anew with explicit types.
+ std::vector<Value *> Values;
+ for (auto *ParamTy : FuncTy->params())
+ Values.push_back(UndefValue::get(ParamTy));
+
+ ASSERT_NE(F.getIntrinsicID(), Intrinsic::not_intrinsic);
+ auto NewDecl = VPIntrinsic::getDeclarationForParams(
+ OutM.get(), F.getIntrinsicID(), Values);
+ ASSERT_TRUE(NewDecl);
+
+ // Check that 'old decl' == 'new decl'.
+ ASSERT_EQ(F.getIntrinsicID(), NewDecl->getIntrinsicID());
+ auto ItNewParams = NewDecl->getFunctionType()->param_begin();
+ auto EndItNewParams = NewDecl->getFunctionType()->param_end();
+ for (auto *ParamTy : FuncTy->params()) {
+ ASSERT_NE(ItNewParams, EndItNewParams);
+ ASSERT_EQ(*ItNewParams, ParamTy);
+ ++ItNewParams;
+ }
+ }
+}
+
} // end anonymous namespace
Index: llvm/lib/IR/IntrinsicInst.cpp
===================================================================
--- llvm/lib/IR/IntrinsicInst.cpp
+++ llvm/lib/IR/IntrinsicInst.cpp
@@ -384,6 +384,21 @@
return false;
}
+Function *VPIntrinsic::getDeclarationForParams(Module *M, Intrinsic::ID VPID,
+ ArrayRef<Value *> Params) {
+ assert(IsVPIntrinsic(VPID) && "not a VP intrinsic");
+
+ // TODO: Extend this for other VP intrinsics as they are upstreamed. This
+ // works for binary arithmetic VP intrinsics.
+ Value &FirstOp = *Params[0];
+ using ShortTypeVec = SmallVector<Type *, 1>;
+ ShortTypeVec TypeVec(1, FirstOp.getType());
+ auto *VPFunc = Intrinsic::getDeclaration(M, VPID, TypeVec);
+ assert(VPFunc && "Could not declare VP intrinsic");
+
+ return VPFunc;
+}
+
Instruction::BinaryOps BinaryOpIntrinsic::getBinaryOp() const {
switch (getIntrinsicID()) {
case Intrinsic::uadd_with_overflow:
Index: llvm/include/llvm/IR/IntrinsicInst.h
===================================================================
--- llvm/include/llvm/IR/IntrinsicInst.h
+++ llvm/include/llvm/IR/IntrinsicInst.h
@@ -384,6 +384,11 @@
/// This is the common base class for vector predication intrinsics.
class VPIntrinsic : public IntrinsicInst {
public:
+ /// \brief Declares a llvm.vp.* intrinsic in \p M that matches the parameters
+ /// \p Params.
+ static Function *getDeclarationForParams(Module *M, Intrinsic::ID,
+ ArrayRef<Value *> Params);
+
static Optional<int> GetMaskParamPos(Intrinsic::ID IntrinsicID);
static Optional<int> GetVectorLengthParamPos(Intrinsic::ID IntrinsicID);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D102686.346150.patch
Type: text/x-patch
Size: 3098 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210518/789de6db/attachment.bin>
More information about the llvm-commits
mailing list