diff options
author | James Y Knight <jyknight@google.com> | 2019-01-31 20:35:56 +0000 |
---|---|---|
committer | James Y Knight <jyknight@google.com> | 2019-01-31 20:35:56 +0000 |
commit | f47d6b38c7a61d50db4566b02719de05492dcef1 (patch) | |
tree | f5c99869bcceba2f8b973cdbcadf7d3db52660b9 /llvm/unittests/Analysis | |
parent | e1b332efba12ce1d5a482084a5182e0527e9c88d (diff) | |
download | bcm5719-llvm-f47d6b38c7a61d50db4566b02719de05492dcef1.tar.gz bcm5719-llvm-f47d6b38c7a61d50db4566b02719de05492dcef1.zip |
[opaque pointer types] Add a FunctionCallee wrapper type, and use it.
The FunctionCallee type is effectively a {FunctionType*,Value*} pair,
and is a useful convenience to enable code to continue passing the
result of getOrInsertFunction() through to EmitCall, even once pointer
types lose their pointee-type.
Then:
- update the CallInst/InvokeInst instruction creation functions to
take a Callee,
- modify getOrInsertFunction to return FunctionCallee, and
- update all callers appropriately.
One area of particular note is the change to the sanitizer
code. Previously, they had been casting the result of
`getOrInsertFunction` to a `Function*` via
`checkSanitizerInterfaceFunction`, and storing that. That would report
an error if someone had already inserted a function declaraction with
a mismatching signature.
However, in general, LLVM allows for such mismatches, as
`getOrInsertFunction` will automatically insert a bitcast if
needed. As part of this cleanup, cause the sanitizer code to do the
same. (It will call its functions using the expected signature,
however they may have been declared.)
Finally, in a small number of locations, callers of
`getOrInsertFunction` actually were expecting/requiring that a brand
new function was being created. In such cases, I've switched them to
Function::Create instead.
Differential Revision: https://reviews.llvm.org/D57315
llvm-svn: 352791
Diffstat (limited to 'llvm/unittests/Analysis')
-rw-r--r-- | llvm/unittests/Analysis/AliasAnalysisTest.cpp | 2 | ||||
-rw-r--r-- | llvm/unittests/Analysis/DivergenceAnalysisTest.cpp | 2 | ||||
-rw-r--r-- | llvm/unittests/Analysis/OrderedInstructionsTest.cpp | 2 | ||||
-rw-r--r-- | llvm/unittests/Analysis/PhiValuesTest.cpp | 6 | ||||
-rw-r--r-- | llvm/unittests/Analysis/ScalarEvolutionTest.cpp | 40 | ||||
-rw-r--r-- | llvm/unittests/Analysis/TBAATest.cpp | 2 | ||||
-rw-r--r-- | llvm/unittests/Analysis/TargetLibraryInfoTest.cpp | 2 |
7 files changed, 30 insertions, 26 deletions
diff --git a/llvm/unittests/Analysis/AliasAnalysisTest.cpp b/llvm/unittests/Analysis/AliasAnalysisTest.cpp index 7a842575df4..a1a020f000b 100644 --- a/llvm/unittests/Analysis/AliasAnalysisTest.cpp +++ b/llvm/unittests/Analysis/AliasAnalysisTest.cpp @@ -166,7 +166,7 @@ TEST_F(AliasAnalysisTest, getModRefInfo) { // Setup function. FunctionType *FTy = FunctionType::get(Type::getVoidTy(C), std::vector<Type *>(), false); - auto *F = cast<Function>(M.getOrInsertFunction("f", FTy)); + auto *F = Function::Create(FTy, Function::ExternalLinkage, "f", M); auto *BB = BasicBlock::Create(C, "entry", F); auto IntType = Type::getInt32Ty(C); auto PtrType = Type::getInt32PtrTy(C); diff --git a/llvm/unittests/Analysis/DivergenceAnalysisTest.cpp b/llvm/unittests/Analysis/DivergenceAnalysisTest.cpp index deaa800f7be..9416e592012 100644 --- a/llvm/unittests/Analysis/DivergenceAnalysisTest.cpp +++ b/llvm/unittests/Analysis/DivergenceAnalysisTest.cpp @@ -78,7 +78,7 @@ TEST_F(DivergenceAnalysisTest, DAInitialState) { IntegerType *IntTy = IntegerType::getInt32Ty(Context); FunctionType *FTy = FunctionType::get(Type::getVoidTy(Context), {IntTy}, false); - Function *F = cast<Function>(M.getOrInsertFunction("f", FTy)); + Function *F = Function::Create(FTy, Function::ExternalLinkage, "f", M); BasicBlock *BB = BasicBlock::Create(Context, "entry", F); ReturnInst::Create(Context, nullptr, BB); diff --git a/llvm/unittests/Analysis/OrderedInstructionsTest.cpp b/llvm/unittests/Analysis/OrderedInstructionsTest.cpp index 1f4002fb766..58eb0e56e06 100644 --- a/llvm/unittests/Analysis/OrderedInstructionsTest.cpp +++ b/llvm/unittests/Analysis/OrderedInstructionsTest.cpp @@ -25,7 +25,7 @@ TEST(OrderedInstructionsTest, DominanceTest) { IRBuilder<> B(Ctx); FunctionType *FTy = FunctionType::get(Type::getVoidTy(Ctx), {B.getInt8PtrTy()}, false); - Function *F = cast<Function>(M.getOrInsertFunction("f", FTy)); + Function *F = Function::Create(FTy, Function::ExternalLinkage, "f", M); // Create the function as follow and check for dominance relation. // diff --git a/llvm/unittests/Analysis/PhiValuesTest.cpp b/llvm/unittests/Analysis/PhiValuesTest.cpp index ec60255cf12..6fd3f6d6654 100644 --- a/llvm/unittests/Analysis/PhiValuesTest.cpp +++ b/llvm/unittests/Analysis/PhiValuesTest.cpp @@ -26,7 +26,8 @@ TEST(PhiValuesTest, SimplePhi) { Type *I32PtrTy = Type::getInt32PtrTy(C); // Create a function with phis that do not have other phis as incoming values - Function *F = cast<Function>(M.getOrInsertFunction("f", FunctionType::get(VoidTy, false))); + Function *F = Function::Create(FunctionType::get(VoidTy, false), + Function::ExternalLinkage, "f", M); BasicBlock *Entry = BasicBlock::Create(C, "entry", F); BasicBlock *If = BasicBlock::Create(C, "if", F); @@ -92,7 +93,8 @@ TEST(PhiValuesTest, DependentPhi) { Type *I32PtrTy = Type::getInt32PtrTy(C); // Create a function with a phi that has another phi as an incoming value - Function *F = cast<Function>(M.getOrInsertFunction("f", FunctionType::get(VoidTy, false))); + Function *F = Function::Create(FunctionType::get(VoidTy, false), + Function::ExternalLinkage, "f", M); BasicBlock *Entry = BasicBlock::Create(C, "entry", F); BasicBlock *If1 = BasicBlock::Create(C, "if1", F); diff --git a/llvm/unittests/Analysis/ScalarEvolutionTest.cpp b/llvm/unittests/Analysis/ScalarEvolutionTest.cpp index 9d293e0b2a2..d39df897ea6 100644 --- a/llvm/unittests/Analysis/ScalarEvolutionTest.cpp +++ b/llvm/unittests/Analysis/ScalarEvolutionTest.cpp @@ -63,7 +63,7 @@ protected: TEST_F(ScalarEvolutionsTest, SCEVUnknownRAUW) { FunctionType *FTy = FunctionType::get(Type::getVoidTy(Context), std::vector<Type *>(), false); - Function *F = cast<Function>(M.getOrInsertFunction("f", FTy)); + Function *F = Function::Create(FTy, Function::ExternalLinkage, "f", M); BasicBlock *BB = BasicBlock::Create(Context, "entry", F); ReturnInst::Create(Context, nullptr, BB); @@ -112,7 +112,7 @@ TEST_F(ScalarEvolutionsTest, SCEVUnknownRAUW) { TEST_F(ScalarEvolutionsTest, SimplifiedPHI) { FunctionType *FTy = FunctionType::get(Type::getVoidTy(Context), std::vector<Type *>(), false); - Function *F = cast<Function>(M.getOrInsertFunction("f", FTy)); + Function *F = Function::Create(FTy, Function::ExternalLinkage, "f", M); BasicBlock *EntryBB = BasicBlock::Create(Context, "entry", F); BasicBlock *LoopBB = BasicBlock::Create(Context, "loop", F); BasicBlock *ExitBB = BasicBlock::Create(Context, "exit", F); @@ -146,7 +146,7 @@ TEST_F(ScalarEvolutionsTest, ExpandPtrTypeSCEV) { auto *I32PtrTy = Type::getInt32PtrTy(Context); FunctionType *FTy = FunctionType::get(Type::getVoidTy(Context), std::vector<Type *>(), false); - Function *F = cast<Function>(M.getOrInsertFunction("f", FTy)); + Function *F = Function::Create(FTy, Function::ExternalLinkage, "f", M); BasicBlock *EntryBB = BasicBlock::Create(Context, "entry", F); BasicBlock *LoopBB = BasicBlock::Create(Context, "loop", F); BasicBlock *ExitBB = BasicBlock::Create(Context, "exit", F); @@ -329,7 +329,7 @@ TEST_F(ScalarEvolutionsTest, CommutativeExprOperandOrder) { TEST_F(ScalarEvolutionsTest, CompareSCEVComplexity) { FunctionType *FTy = FunctionType::get(Type::getVoidTy(Context), std::vector<Type *>(), false); - Function *F = cast<Function>(M.getOrInsertFunction("f", FTy)); + Function *F = Function::Create(FTy, Function::ExternalLinkage, "f", M); BasicBlock *EntryBB = BasicBlock::Create(Context, "entry", F); BasicBlock *LoopBB = BasicBlock::Create(Context, "bb1", F); BranchInst::Create(LoopBB, EntryBB); @@ -399,7 +399,7 @@ TEST_F(ScalarEvolutionsTest, CompareValueComplexity) { FunctionType *FTy = FunctionType::get(Type::getVoidTy(Context), {IntPtrTy, IntPtrTy}, false); - Function *F = cast<Function>(M.getOrInsertFunction("f", FTy)); + Function *F = Function::Create(FTy, Function::ExternalLinkage, "f", M); BasicBlock *EntryBB = BasicBlock::Create(Context, "entry", F); Value *X = &*F->arg_begin(); @@ -435,7 +435,7 @@ TEST_F(ScalarEvolutionsTest, SCEVAddExpr) { FunctionType *FTy = FunctionType::get(Type::getVoidTy(Context), ArgTys, false); - Function *F = cast<Function>(M.getOrInsertFunction("f", FTy)); + Function *F = Function::Create(FTy, Function::ExternalLinkage, "f", M); Argument *A1 = &*F->arg_begin(); Argument *A2 = &*(std::next(F->arg_begin())); @@ -669,7 +669,7 @@ TEST_F(ScalarEvolutionsTest, SCEVZeroExtendExpr) { // ret void // } FunctionType *FTy = FunctionType::get(Type::getVoidTy(Context), {}, false); - Function *F = cast<Function>(M.getOrInsertFunction("foo", FTy)); + Function *F = Function::Create(FTy, Function::ExternalLinkage, "foo", M); BasicBlock *EntryBB = BasicBlock::Create(Context, "entry", F); BasicBlock *CondBB = BasicBlock::Create(Context, "for.cond", F); @@ -748,7 +748,7 @@ TEST_F(ScalarEvolutionsTest, SCEVZeroExtendExprNonIntegral) { FunctionType *FTy = FunctionType::get(Type::getVoidTy(Context), {T_pint64}, false); - Function *F = cast<Function>(NIM.getOrInsertFunction("foo", FTy)); + Function *F = Function::Create(FTy, Function::ExternalLinkage, "foo", NIM); Argument *Arg = &*F->arg_begin(); @@ -821,7 +821,7 @@ TEST_F(ScalarEvolutionsTest, SCEVExitLimitForgetLoop) { FunctionType *FTy = FunctionType::get(Type::getVoidTy(Context), {T_pint64}, false); - Function *F = cast<Function>(NIM.getOrInsertFunction("foo", FTy)); + Function *F = Function::Create(FTy, Function::ExternalLinkage, "foo", NIM); BasicBlock *Top = BasicBlock::Create(Context, "top", F); BasicBlock *LPh = BasicBlock::Create(Context, "L.ph", F); @@ -919,7 +919,7 @@ TEST_F(ScalarEvolutionsTest, SCEVExitLimitForgetValue) { FunctionType *FTy = FunctionType::get(Type::getVoidTy(Context), {T_pint64}, false); - Function *F = cast<Function>(NIM.getOrInsertFunction("foo", FTy)); + Function *F = Function::Create(FTy, Function::ExternalLinkage, "foo", NIM); Argument *Arg = &*F->arg_begin(); @@ -979,7 +979,8 @@ TEST_F(ScalarEvolutionsTest, SCEVAddRecFromPHIwithLargeConstants) { // ix. FunctionType *FTy = FunctionType::get(Type::getVoidTy(Context), std::vector<Type *>(), false); - Function *F = cast<Function>(M.getOrInsertFunction("addrecphitest", FTy)); + Function *F = + Function::Create(FTy, Function::ExternalLinkage, "addrecphitest", M); /* Create IR: @@ -1035,7 +1036,8 @@ TEST_F(ScalarEvolutionsTest, SCEVAddRecFromPHIwithLargeConstantAccum) { SmallVector<Type *, 1> Types; Types.push_back(Int32Ty); FunctionType *FTy = FunctionType::get(Type::getVoidTy(Context), Types, false); - Function *F = cast<Function>(M.getOrInsertFunction("addrecphitest", FTy)); + Function *F = + Function::Create(FTy, Function::ExternalLinkage, "addrecphitest", M); /* Create IR: @@ -1089,7 +1091,7 @@ TEST_F(ScalarEvolutionsTest, SCEVFoldSumOfTruncs) { SmallVector<Type *, 1> Types; Types.push_back(ArgTy); FunctionType *FTy = FunctionType::get(Type::getVoidTy(Context), Types, false); - Function *F = cast<Function>(M.getOrInsertFunction("f", FTy)); + Function *F = Function::Create(FTy, Function::ExternalLinkage, "f", M); BasicBlock *BB = BasicBlock::Create(Context, "entry", F); ReturnInst::Create(Context, nullptr, BB); @@ -1145,7 +1147,7 @@ TEST_F(ScalarEvolutionsTest, SCEVExpanderIsSafeToExpandAt) { FunctionType *FTy = FunctionType::get(Type::getVoidTy(Context), {T_pint64}, false); - Function *F = cast<Function>(NIM.getOrInsertFunction("foo", FTy)); + Function *F = Function::Create(FTy, Function::ExternalLinkage, "foo", NIM); BasicBlock *Top = BasicBlock::Create(Context, "top", F); BasicBlock *LPh = BasicBlock::Create(Context, "L.ph", F); @@ -1206,7 +1208,7 @@ TEST_F(ScalarEvolutionsTest, SCEVExpanderNUW) { FunctionType *FTy = FunctionType::get(Type::getVoidTy(Context), { T_int64 }, false); - Function *F = cast<Function>(M.getOrInsertFunction("func", FTy)); + Function *F = Function::Create(FTy, Function::ExternalLinkage, "func", M); Argument *Arg = &*F->arg_begin(); ConstantInt *C = ConstantInt::get(Context, APInt(64, -1)); @@ -1258,7 +1260,7 @@ TEST_F(ScalarEvolutionsTest, SCEVExpanderNSW) { FunctionType *FTy = FunctionType::get(Type::getVoidTy(Context), { T_int64 }, false); - Function *F = cast<Function>(M.getOrInsertFunction("func", FTy)); + Function *F = Function::Create(FTy, Function::ExternalLinkage, "func", M); Argument *Arg = &*F->arg_begin(); ConstantInt *C = ConstantInt::get(Context, APInt(64, -1)); @@ -1308,7 +1310,7 @@ TEST_F(ScalarEvolutionsTest, SCEVCacheNUW) { FunctionType *FTy = FunctionType::get(Type::getVoidTy(Context), { T_int64 }, false); - Function *F = cast<Function>(M.getOrInsertFunction("func", FTy)); + Function *F = Function::Create(FTy, Function::ExternalLinkage, "func", M); Argument *Arg = &*F->arg_begin(); ConstantInt *C = ConstantInt::get(Context, APInt(64, -1)); @@ -1359,7 +1361,7 @@ TEST_F(ScalarEvolutionsTest, SCEVCacheNSW) { FunctionType *FTy = FunctionType::get(Type::getVoidTy(Context), { T_int64 }, false); - Function *F = cast<Function>(M.getOrInsertFunction("func", FTy)); + Function *F = Function::Create(FTy, Function::ExternalLinkage, "func", M); Argument *Arg = &*F->arg_begin(); ConstantInt *C = ConstantInt::get(Context, APInt(64, -1)); @@ -1409,7 +1411,7 @@ TEST_F(ScalarEvolutionsTest, SCEVComputeExpressionSize) { FunctionType *FTy = FunctionType::get(Type::getVoidTy(Context), { T_int64, T_int64 }, false); - Function *F = cast<Function>(M.getOrInsertFunction("func", FTy)); + Function *F = Function::Create(FTy, Function::ExternalLinkage, "func", M); Argument *A = &*F->arg_begin(); Argument *B = &*std::next(F->arg_begin()); ConstantInt *C = ConstantInt::get(Context, APInt(64, 1)); diff --git a/llvm/unittests/Analysis/TBAATest.cpp b/llvm/unittests/Analysis/TBAATest.cpp index a626018c838..5a71c74a80b 100644 --- a/llvm/unittests/Analysis/TBAATest.cpp +++ b/llvm/unittests/Analysis/TBAATest.cpp @@ -33,7 +33,7 @@ protected: static StoreInst *getFunctionWithSingleStore(Module *M, StringRef Name) { auto &C = M->getContext(); FunctionType *FTy = FunctionType::get(Type::getVoidTy(C), {}); - auto *F = cast<Function>(M->getOrInsertFunction(Name, FTy)); + auto *F = Function::Create(FTy, Function::ExternalLinkage, Name, M); auto *BB = BasicBlock::Create(C, "entry", F); auto *IntType = Type::getInt32Ty(C); auto *PtrType = Type::getInt32PtrTy(C); diff --git a/llvm/unittests/Analysis/TargetLibraryInfoTest.cpp b/llvm/unittests/Analysis/TargetLibraryInfoTest.cpp index 7830ca4ef7c..f3b72b624fc 100644 --- a/llvm/unittests/Analysis/TargetLibraryInfoTest.cpp +++ b/llvm/unittests/Analysis/TargetLibraryInfoTest.cpp @@ -67,7 +67,7 @@ TEST_F(TargetLibraryInfoTest, InvalidProto) { for (unsigned FI = 0; FI != LibFunc::NumLibFuncs; ++FI) { LibFunc LF = (LibFunc)FI; auto *F = cast<Function>( - M->getOrInsertFunction(TLI.getName(LF), InvalidFTy)); + M->getOrInsertFunction(TLI.getName(LF), InvalidFTy).getCallee()); EXPECT_FALSE(isLibFunc(F, LF)); } } |