diff options
author | Paschalis Mpeis <paschalis.mpeis@arm.com> | 2023-12-21 11:02:54 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-21 11:02:54 +0000 |
commit | c4ff0a67d146030636e96eab4992233a7b5858d8 (patch) | |
tree | 84fa5f76e3f18d4d95c80c96ee651620a6788939 /llvm/unittests/Analysis/TargetLibraryInfoTest.cpp | |
parent | f5687636415969e6d945659a0b78734abdfb0f06 (diff) | |
download | llvm-c4ff0a67d146030636e96eab4992233a7b5858d8.zip llvm-c4ff0a67d146030636e96eab4992233a7b5858d8.tar.gz llvm-c4ff0a67d146030636e96eab4992233a7b5858d8.tar.bz2 |
[TLI] Add getLibFunc that accepts an Opcode and scalar Type. (#75919)
It sets a LibFunc similarly with the other two getLibFunc methods.
Currently, it supports only the FRem Instruction.
Add tests for FRem.
Diffstat (limited to 'llvm/unittests/Analysis/TargetLibraryInfoTest.cpp')
-rw-r--r-- | llvm/unittests/Analysis/TargetLibraryInfoTest.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/llvm/unittests/Analysis/TargetLibraryInfoTest.cpp b/llvm/unittests/Analysis/TargetLibraryInfoTest.cpp index 292b5ca..34b06fe 100644 --- a/llvm/unittests/Analysis/TargetLibraryInfoTest.cpp +++ b/llvm/unittests/Analysis/TargetLibraryInfoTest.cpp @@ -621,3 +621,38 @@ TEST_F(TargetLibraryInfoTest, ValidProto) { EXPECT_TRUE(isLibFunc(F, LF)); } } + +namespace { + +/// Creates TLI for AArch64 and uses it to get the LibFunc names for the given +/// Instruction opcode and Type. +class TLITestAarch64 : public ::testing::Test { +private: + const Triple TargetTriple; + +protected: + LLVMContext Ctx; + std::unique_ptr<TargetLibraryInfoImpl> TLII; + std::unique_ptr<TargetLibraryInfo> TLI; + + /// Create TLI for AArch64 + TLITestAarch64() : TargetTriple(Triple("aarch64-unknown-linux-gnu")) { + TLII = std::make_unique<TargetLibraryInfoImpl>( + TargetLibraryInfoImpl(TargetTriple)); + TLI = std::make_unique<TargetLibraryInfo>(TargetLibraryInfo(*TLII)); + } + + /// Returns the TLI function name for the given \p Opcode and type \p Ty. + StringRef getScalarName(unsigned int Opcode, Type *Ty) { + LibFunc Func; + if (!TLI->getLibFunc(Opcode, Ty, Func)) + return ""; + return TLI->getName(Func); + } +}; +} // end anonymous namespace + +TEST_F(TLITestAarch64, TestFrem) { + EXPECT_EQ(getScalarName(Instruction::FRem, Type::getDoubleTy(Ctx)), "fmod"); + EXPECT_EQ(getScalarName(Instruction::FRem, Type::getFloatTy(Ctx)), "fmodf"); +}
\ No newline at end of file |