8
8
9
9
#include " llvm/Analysis/TargetLibraryInfo.h"
10
10
#include " llvm/AsmParser/Parser.h"
11
- #include " llvm/IR/IRBuilder.h"
12
11
#include " llvm/IR/LLVMContext.h"
13
12
#include " llvm/IR/Module.h"
14
13
#include " llvm/Support/SourceMgr.h"
@@ -625,59 +624,41 @@ TEST_F(TargetLibraryInfoTest, ValidProto) {
625
624
626
625
namespace {
627
626
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 {
627
+ // / Creates TLI for AArch64 and uses it to get the LibFunc names for the FRem
628
+ // / Instruction .
629
+ class TLITestAarch64 : public ::testing::Test {
631
630
private:
632
- SMDiagnostic Err;
633
631
const Triple TargetTriple;
634
- const TargetLibraryInfoImpl::VectorLibrary VecLib;
635
632
636
633
protected:
637
634
LLVMContext Ctx;
638
- std::unique_ptr<Module> M;
639
635
std::unique_ptr<TargetLibraryInfoImpl> TLII;
640
636
std::unique_ptr<TargetLibraryInfo> TLI;
641
637
642
- // / Create TLI for AArch64 with VecLib ArmPL.
643
- TLITestAarch64ArmPl ()
644
- : TargetTriple(Triple(" aarch64-unknown-linux-gnu" )),
645
- VecLib (TargetLibraryInfoImpl::ArmPL) {
638
+ // / Create TLI for AArch64
639
+ TLITestAarch64 () : TargetTriple(Triple(" aarch64-unknown-linux-gnu" )) {
646
640
TLII = std::make_unique<TargetLibraryInfoImpl>(
647
641
TargetLibraryInfoImpl (TargetTriple));
648
- TLII->addVectorizableFunctionsFromVecLib (VecLib, TargetTriple);
642
+ TLII->addVectorizableFunctionsFromVecLib (TargetLibraryInfoImpl::NoLibrary,
643
+ TargetTriple);
649
644
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
645
}
655
646
656
647
// / Creates an FRem Instruction of Type \p Ty, and uses it to get the TLI
657
648
// / function name.
658
649
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.
650
+ Value *V = Constant::getNullValue (Ty);
651
+ Instruction *FRem = BinaryOperator::Create (Instruction::FRem, V, V);
669
652
LibFunc Func;
670
653
if (!TLI->getLibFunc (*FRem, Func))
671
654
return " " ;
672
- auto FuncName = TLI->getName (Func);
673
- // Erase tmp function to prepare for the next test.
674
- F->eraseFromParent ();
675
- return FuncName;
655
+ FRem->deleteValue ();
656
+ return TLI->getName (Func);
676
657
}
677
658
};
678
659
} // end anonymous namespace
679
660
680
- TEST_F (TLITestAarch64ArmPl , TestFrem) {
661
+ TEST_F (TLITestAarch64 , TestFrem) {
681
662
EXPECT_EQ (getFremScalarName (Type::getDoubleTy (Ctx)), " fmod" );
682
663
EXPECT_EQ (getFremScalarName (Type::getFloatTy (Ctx)), " fmodf" );
683
664
}
0 commit comments