llvm.org GIT mirror llvm / 6815413
Revert "r366069: [PatternMatch] Implement matching code for LibFunc" Reason: the change introduced a layering violation by adding a dependency on IR to Analysis. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@366081 91177308-0d34-0410-b5e6-96231b3b80d8 Ilya Biryukov a month ago
2 changed file(s) with 1 addition(s) and 89 deletion(s). Raw diff Collapse all Expand all
2929
3030 #include "llvm/ADT/APFloat.h"
3131 #include "llvm/ADT/APInt.h"
32 #include "llvm/Analysis/TargetLibraryInfo.h"
3332 #include "llvm/IR/Constant.h"
3433 #include "llvm/IR/Constants.h"
3534 #include "llvm/IR/InstrTypes.h"
18121811 return Signum_match(V);
18131812 }
18141813
1815 /// \brief LibFunc matchers.
1816 struct LibFunc_match {
1817 LibFunc F;
1818 TargetLibraryInfo TLI;
1819
1820 LibFunc_match(LibFunc Func, TargetLibraryInfo TargetLI)
1821 : F(Func), TLI(TargetLI) {}
1822
1823 template bool match(OpTy *V) {
1824 LibFunc LF;
1825 if (const auto *CI = dyn_cast(V))
1826 if (!CI->isNoBuiltin() && CI->getCalledFunction() &&
1827 TLI.getLibFunc(*CI->getCalledFunction(), LF) &&
1828 LF == F && TLI.has(LF))
1829 return true;
1830 return false;
1831 }
1832 };
1833
1834 /// LibFunc matches are combinations of Name matchers, and argument
1835 /// matchers.
1836 template
1837 struct m_LibFunc_Ty;
1838 template struct m_LibFunc_Ty {
1839 using Ty = match_combine_and>;
1840 };
1841 template struct m_LibFunc_Ty {
1842 using Ty =
1843 match_combine_and::Ty,
1844 Argument_match>;
1845 };
1846
1847 /// \brief Match LibFunc calls like this:
1848 /// m_LibFunc(m_Value(X))
1849 template
1850 inline LibFunc_match m_LibFunc(TargetLibraryInfo TLI) {
1851 return LibFunc_match(F, TLI);
1852 }
1853
1854 template
1855 inline typename m_LibFunc_Ty::Ty
1856 m_LibFunc(const TargetLibraryInfo TLI, const T0 &Op0) {
1857 return m_CombineAnd(m_LibFunc(TLI), m_Argument<0>(Op0));
1858 }
1859
1860 template
1861 inline typename m_LibFunc_Ty::Ty
1862 m_LibFunc(const TargetLibraryInfo TLI, const T0 &Op0, const T1 &Op1) {
1863 return m_CombineAnd(m_LibFunc(TLI, Op0), m_Argument<1>(Op1));
1864 }
1865
18661814 } // end namespace PatternMatch
18671815 } // end namespace llvm
18681816
3434 Function *F;
3535 BasicBlock *BB;
3636 IRBuilder IRB;
37 TargetLibraryInfoImpl TLII;
38 TargetLibraryInfo TLI;
3937
4038 PatternMatchTest()
4139 : M(new Module("PatternMatchTestModule", Ctx)),
4240 F(Function::Create(
4341 FunctionType::get(Type::getVoidTy(Ctx), /* IsVarArg */ false),
4442 Function::ExternalLinkage, "f", M.get())),
45 BB(BasicBlock::Create(Ctx, "entry", F)), IRB(BB), TLI(TLII) {}
43 BB(BasicBlock::Create(Ctx, "entry", F)), IRB(BB) {}
4644 };
4745
4846 TEST_F(PatternMatchTest, OneUse) {
10091007 EXPECT_FALSE(match(V3, m_FNeg(m_Value(Match))));
10101008 }
10111009
1012 TEST_F(PatternMatchTest, LibFunc) {
1013 Type *FltTy = IRB.getFloatTy();
1014 Value *One = ConstantFP::get(FltTy, 1.0);
1015 Value *Two = ConstantFP::get(FltTy, 2.0);
1016 Value *MatchOne, *MatchTwo;
1017
1018 StringRef TanName = TLI.getName(LibFunc_tan);
1019 FunctionCallee TanCallee = M->getOrInsertFunction(TanName, FltTy, FltTy);
1020 CallInst *Tan = IRB.CreateCall(TanCallee, One, TanName);
1021
1022 StringRef PowName = TLI.getName(LibFunc_pow);
1023 FunctionCallee PowCallee = M->getOrInsertFunction(PowName, FltTy, FltTy, FltTy);
1024 CallInst *Pow = IRB.CreateCall(PowCallee, {One, Two}, PowName);
1025
1026 EXPECT_TRUE(match(Tan, m_LibFunc(TLI)));
1027 EXPECT_FALSE(match(Tan, m_LibFunc(TLI)));
1028 EXPECT_FALSE(match(Pow, m_LibFunc(TLI)));
1029
1030 EXPECT_TRUE(match(Tan, m_LibFunc(TLI, m_Value(MatchOne))));
1031 EXPECT_EQ(One, MatchOne);
1032 EXPECT_FALSE(match(Tan, m_LibFunc(TLI, m_Value())));
1033
1034 EXPECT_TRUE(match(Pow, m_LibFunc(TLI, m_Value(MatchOne),
1035 m_Value(MatchTwo))));
1036 EXPECT_EQ(One, MatchOne);
1037 EXPECT_EQ(Two, MatchTwo);
1038 EXPECT_FALSE(match(Pow, m_LibFunc(TLI, m_Value(), m_Value())));
1039
1040 TLII.disableAllFunctions();
1041 EXPECT_FALSE(match(Tan, m_LibFunc(TLI)));
1042 EXPECT_FALSE(match(Tan, m_LibFunc(TLI, m_Value())));
1043 EXPECT_FALSE(match(Pow, m_LibFunc(TLI, m_Value(), m_Value())));
1044 }
1045
10461010 template struct MutableConstTest : PatternMatchTest { };
10471011
10481012 typedef ::testing::Types,