8
8
9
9
#include " llvm/Analysis/TargetLibraryInfo.h"
10
10
#include " llvm/AsmParser/Parser.h"
11
+ #include " llvm/IR/IRBuilder.h"
11
12
#include " llvm/IR/LLVMContext.h"
12
13
#include " llvm/IR/Module.h"
13
14
#include " llvm/Support/SourceMgr.h"
@@ -621,3 +622,63 @@ TEST_F(TargetLibraryInfoTest, ValidProto) {
621
622
EXPECT_TRUE (isLibFunc (F, LF));
622
623
}
623
624
}
625
+
626
+ namespace {
627
+
628
+ // Creates TLI for AArch64 and VecLibrary ARmPL, and uses it to get the TLI
629
+ // names for different FRem Instructions.
630
+ class TLITestAarch64ArmPl : public ::testing::Test {
631
+ private:
632
+ SMDiagnostic Err;
633
+ const Triple TargetTriple;
634
+ const TargetLibraryInfoImpl::VectorLibrary VecLib;
635
+
636
+ protected:
637
+ LLVMContext Ctx;
638
+ std::unique_ptr<Module> M;
639
+ std::unique_ptr<TargetLibraryInfoImpl> TLII;
640
+ std::unique_ptr<TargetLibraryInfo> TLI;
641
+
642
+ // / Create TLI for AArch64 with VecLib ArmPL.
643
+ TLITestAarch64ArmPl ()
644
+ : TargetTriple(Triple(" aarch64-unknown-linux-gnu" )),
645
+ VecLib (TargetLibraryInfoImpl::ArmPL) {
646
+ TLII = std::make_unique<TargetLibraryInfoImpl>(
647
+ TargetLibraryInfoImpl (TargetTriple));
648
+ TLII->addVectorizableFunctionsFromVecLib (VecLib, TargetTriple);
649
+ TLI = std::make_unique<TargetLibraryInfo>(TargetLibraryInfo (*TLII));
650
+ // Create a dummy module needed for tests.
651
+ M = parseAssemblyString (" declare void @dummy()" , Err, Ctx);
652
+ EXPECT_NE (M.get (), nullptr )
653
+ << " Loading an invalid module.\n " << Err.getMessage () << " \n " ;
654
+ }
655
+
656
+ // / Creates an FRem Instruction of Type \p Ty, and uses it to get the TLI
657
+ // / function name.
658
+ StringRef getFremScalarName (Type *Ty) {
659
+ // Use a dummy function and a BB to create an FRem Instruction.
660
+ FunctionType *FTy = FunctionType::get (Ty, {Ty, Ty}, false );
661
+ Function *F = Function::Create (FTy, Function::ExternalLinkage, " foo" , *M);
662
+ BasicBlock *BB = BasicBlock::Create (Ctx, " entry" , F);
663
+ IRBuilder<> Builder (BB);
664
+ Builder.SetInsertPoint (BB);
665
+ auto *FRem =
666
+ dyn_cast<Instruction>(Builder.CreateFRem (F->getArg (0 ), F->getArg (1 )));
667
+
668
+ // Use TLI to get LibFunc and then the TLI name.
669
+ LibFunc Func;
670
+ if (!TLI->getLibFunc (*FRem, Func))
671
+ return " " ;
672
+ auto FuncName = TLI->getName (Func);
673
+ // Erase tmp function to prepare for the next test.
674
+ F->eraseFromParent ();
675
+ return FuncName;
676
+ }
677
+ };
678
+ } // end anonymous namespace
679
+
680
+ TEST_F (TLITestAarch64ArmPl, TestFrem) {
681
+ EXPECT_EQ (getFremScalarName (Type::getDoubleTy (Ctx)), " fmod" );
682
+ EXPECT_EQ (getFremScalarName (Type::getFloatTy (Ctx)), " fmodf" );
683
+ EXPECT_EQ (getFremScalarName (Type::getFP128Ty (Ctx)), " fmodl" );
684
+ }
0 commit comments