[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
diff --git a/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp b/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp
index a1a65e2..eeaf214 100644
--- a/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp
+++ b/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp
@@ -102,11 +102,11 @@
std::vector<Regex> &Regexes);
// Get pointers to the functions in the runtime library.
- Constant *getStartFileFunc();
- Constant *getEmitFunctionFunc();
- Constant *getEmitArcsFunc();
- Constant *getSummaryInfoFunc();
- Constant *getEndFileFunc();
+ FunctionCallee getStartFileFunc();
+ FunctionCallee getEmitFunctionFunc();
+ FunctionCallee getEmitArcsFunc();
+ FunctionCallee getSummaryInfoFunc();
+ FunctionCallee getEndFileFunc();
// Add the function to write out all our counters to the global destructor
// list.
@@ -647,7 +647,7 @@
for (auto I : ForkAndExecs) {
IRBuilder<> Builder(I);
FunctionType *FTy = FunctionType::get(Builder.getVoidTy(), {}, false);
- Constant *GCOVFlush = M->getOrInsertFunction("__gcov_flush", FTy);
+ FunctionCallee GCOVFlush = M->getOrInsertFunction("__gcov_flush", FTy);
Builder.CreateCall(GCOVFlush);
I->getParent()->splitBasicBlock(I);
}
@@ -863,7 +863,7 @@
// Initialize the environment and register the local writeout and flush
// functions.
- Constant *GCOVInit = M->getOrInsertFunction("llvm_gcov_init", FTy);
+ FunctionCallee GCOVInit = M->getOrInsertFunction("llvm_gcov_init", FTy);
Builder.CreateCall(GCOVInit, {WriteoutF, FlushF});
Builder.CreateRetVoid();
@@ -873,22 +873,21 @@
return Result;
}
-Constant *GCOVProfiler::getStartFileFunc() {
+FunctionCallee GCOVProfiler::getStartFileFunc() {
Type *Args[] = {
Type::getInt8PtrTy(*Ctx), // const char *orig_filename
Type::getInt8PtrTy(*Ctx), // const char version[4]
Type::getInt32Ty(*Ctx), // uint32_t checksum
};
FunctionType *FTy = FunctionType::get(Type::getVoidTy(*Ctx), Args, false);
- auto *Res = M->getOrInsertFunction("llvm_gcda_start_file", FTy);
- if (Function *FunRes = dyn_cast<Function>(Res))
- if (auto AK = TLI->getExtAttrForI32Param(false))
- FunRes->addParamAttr(2, AK);
+ AttributeList AL;
+ if (auto AK = TLI->getExtAttrForI32Param(false))
+ AL = AL.addParamAttribute(*Ctx, 2, AK);
+ FunctionCallee Res = M->getOrInsertFunction("llvm_gcda_start_file", FTy, AL);
return Res;
-
}
-Constant *GCOVProfiler::getEmitFunctionFunc() {
+FunctionCallee GCOVProfiler::getEmitFunctionFunc() {
Type *Args[] = {
Type::getInt32Ty(*Ctx), // uint32_t ident
Type::getInt8PtrTy(*Ctx), // const char *function_name
@@ -897,36 +896,34 @@
Type::getInt32Ty(*Ctx), // uint32_t cfg_checksum
};
FunctionType *FTy = FunctionType::get(Type::getVoidTy(*Ctx), Args, false);
- auto *Res = M->getOrInsertFunction("llvm_gcda_emit_function", FTy);
- if (Function *FunRes = dyn_cast<Function>(Res))
- if (auto AK = TLI->getExtAttrForI32Param(false)) {
- FunRes->addParamAttr(0, AK);
- FunRes->addParamAttr(2, AK);
- FunRes->addParamAttr(3, AK);
- FunRes->addParamAttr(4, AK);
- }
- return Res;
+ AttributeList AL;
+ if (auto AK = TLI->getExtAttrForI32Param(false)) {
+ AL = AL.addParamAttribute(*Ctx, 0, AK);
+ AL = AL.addParamAttribute(*Ctx, 2, AK);
+ AL = AL.addParamAttribute(*Ctx, 3, AK);
+ AL = AL.addParamAttribute(*Ctx, 4, AK);
+ }
+ return M->getOrInsertFunction("llvm_gcda_emit_function", FTy);
}
-Constant *GCOVProfiler::getEmitArcsFunc() {
+FunctionCallee GCOVProfiler::getEmitArcsFunc() {
Type *Args[] = {
Type::getInt32Ty(*Ctx), // uint32_t num_counters
Type::getInt64PtrTy(*Ctx), // uint64_t *counters
};
FunctionType *FTy = FunctionType::get(Type::getVoidTy(*Ctx), Args, false);
- auto *Res = M->getOrInsertFunction("llvm_gcda_emit_arcs", FTy);
- if (Function *FunRes = dyn_cast<Function>(Res))
- if (auto AK = TLI->getExtAttrForI32Param(false))
- FunRes->addParamAttr(0, AK);
- return Res;
+ AttributeList AL;
+ if (auto AK = TLI->getExtAttrForI32Param(false))
+ AL = AL.addParamAttribute(*Ctx, 0, AK);
+ return M->getOrInsertFunction("llvm_gcda_emit_arcs", FTy, AL);
}
-Constant *GCOVProfiler::getSummaryInfoFunc() {
+FunctionCallee GCOVProfiler::getSummaryInfoFunc() {
FunctionType *FTy = FunctionType::get(Type::getVoidTy(*Ctx), false);
return M->getOrInsertFunction("llvm_gcda_summary_info", FTy);
}
-Constant *GCOVProfiler::getEndFileFunc() {
+FunctionCallee GCOVProfiler::getEndFileFunc() {
FunctionType *FTy = FunctionType::get(Type::getVoidTy(*Ctx), false);
return M->getOrInsertFunction("llvm_gcda_end_file", FTy);
}
@@ -946,11 +943,11 @@
BasicBlock *BB = BasicBlock::Create(*Ctx, "entry", WriteoutF);
IRBuilder<> Builder(BB);
- Constant *StartFile = getStartFileFunc();
- Constant *EmitFunction = getEmitFunctionFunc();
- Constant *EmitArcs = getEmitArcsFunc();
- Constant *SummaryInfo = getSummaryInfoFunc();
- Constant *EndFile = getEndFileFunc();
+ FunctionCallee StartFile = getStartFileFunc();
+ FunctionCallee EmitFunction = getEmitFunctionFunc();
+ FunctionCallee EmitArcs = getEmitArcsFunc();
+ FunctionCallee SummaryInfo = getSummaryInfoFunc();
+ FunctionCallee EndFile = getEndFileFunc();
NamedMDNode *CUNodes = M->getNamedMetadata("llvm.dbg.cu");
if (!CUNodes) {