/// 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<unsigned> getMaskParamPos(Intrinsic::ID IntrinsicID);
static Optional<unsigned> getVectorLengthParamPos(Intrinsic::ID IntrinsicID);
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.
+ auto *VPFunc = Intrinsic::getDeclaration(M, VPID, Params[0]->getType());
+ assert(VPFunc && "Could not declare VP intrinsic");
+ return VPFunc;
+}
+
Instruction::BinaryOps BinaryOpIntrinsic::getBinaryOp() const {
switch (getIntrinsicID()) {
case Intrinsic::uadd_with_overflow:
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