[llvm] [TLI] Add getLibFunc in TLI API that accepts an Instruction. (PR #75919)
Paul Walker via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 19 06:53:08 PST 2023
================
@@ -621,3 +622,62 @@ TEST_F(TargetLibraryInfoTest, ValidProto) {
EXPECT_TRUE(isLibFunc(F, LF));
}
}
+
+namespace {
+
+// Creates TLI for AArch64 and VecLibrary ARmPL, and uses it to get the TLI
+// names for different FRem Instructions.
+class TLITestAarch64ArmPl : public ::testing::Test {
+private:
+ SMDiagnostic Err;
+ const Triple TargetTriple;
+ const TargetLibraryInfoImpl::VectorLibrary VecLib;
+
+protected:
+ LLVMContext Ctx;
+ std::unique_ptr<Module> M;
+ std::unique_ptr<TargetLibraryInfoImpl> TLII;
+ std::unique_ptr<TargetLibraryInfo> TLI;
+
+ /// Create TLI for AArch64 with VecLib ArmPL.
+ TLITestAarch64ArmPl()
+ : TargetTriple(Triple("aarch64-unknown-linux-gnu")),
+ VecLib(TargetLibraryInfoImpl::ArmPL) {
+ TLII = std::make_unique<TargetLibraryInfoImpl>(
+ TargetLibraryInfoImpl(TargetTriple));
+ TLII->addVectorizableFunctionsFromVecLib(VecLib, TargetTriple);
+ TLI = std::make_unique<TargetLibraryInfo>(TargetLibraryInfo(*TLII));
+ // Create a dummy module needed for tests.
+ M = parseAssemblyString("declare void @dummy()", Err, Ctx);
+ EXPECT_NE(M.get(), nullptr)
+ << "Loading an invalid module.\n " << Err.getMessage() << "\n";
+ }
+
+ /// Creates an FRem Instruction of Type \p Ty, and uses it to get the TLI
+ /// function name.
+ StringRef getFremScalarName(Type *Ty) {
+ // Use a dummy function and a BB to create an FRem Instruction.
+ FunctionType *FTy = FunctionType::get(Ty, {Ty, Ty}, false);
+ Function *F = Function::Create(FTy, Function::ExternalLinkage, "foo", *M);
+ BasicBlock *BB = BasicBlock::Create(Ctx, "entry", F);
+ IRBuilder<> Builder(BB);
+ Builder.SetInsertPoint(BB);
+ auto *FRem =
+ dyn_cast<Instruction>(Builder.CreateFRem(F->getArg(0), F->getArg(1)));
+
----------------
paulwalker-arm wrote:
Is this necessary. Does creating the instruction directly (e.g. `BinaryOperator::Create()`) not work?
https://github.com/llvm/llvm-project/pull/75919
More information about the llvm-commits
mailing list