aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRobert Grosse <grosse@chromium.org>2013-07-25 15:05:16 -0700
committerRobert Grosse <grosse@chromium.org>2013-07-25 15:05:16 -0700
commit548960c21c590dcd4919a1bba000e989c140c8ef (patch)
tree240e059006f5d8a323ef426bdbf3b7f2b3d4d3e5 /lib
parent7b390888fd9f3886d966ab072c328f4fbd9c64b4 (diff)
Change __cyg_profile_func_enter/exit to __pnacl_profile... and change the signature.
__pnacl_profile_function_x takes a single argument - the name of the current function as a constant string, rather than a pair of function addresses like __cyg takes. This makes it work even in PNaCl and removes the need to track symbol information separately. BUG=none R=dschuff@chromium.org Review URL: https://codereview.chromium.org/20000003
Diffstat (limited to 'lib')
-rw-r--r--lib/CodeGen/CodeGenFunction.cpp70
-rw-r--r--lib/Driver/Tools.cpp4
-rw-r--r--lib/Frontend/CompilerInvocation.cpp3
3 files changed, 56 insertions, 21 deletions
diff --git a/lib/CodeGen/CodeGenFunction.cpp b/lib/CodeGen/CodeGenFunction.cpp
index a3c39649b7..1c846185eb 100644
--- a/lib/CodeGen/CodeGenFunction.cpp
+++ b/lib/CodeGen/CodeGenFunction.cpp
@@ -229,10 +229,19 @@ void CodeGenFunction::FinishFunction(SourceLocation EndLoc) {
llvm::BasicBlock *CurBlock = Builder.GetInsertBlock();
llvm::BasicBlock *BeginBlock = &CurFn->getEntryBlock();
- Builder.SetInsertPoint(BeginBlock, BeginBlock->begin());
- EmitFunctionInstrumentation("__cyg_profile_func_enter");
- Builder.SetInsertPoint(CurBlock);
- EmitFunctionInstrumentation("__cyg_profile_func_exit");
+// @LOCALMOD-BEGIN
+ if (CGM.getCodeGenOpts().InstrumentFunctionsPNaCl) {
+ Builder.SetInsertPoint(BeginBlock, BeginBlock->begin());
+ EmitFunctionInstrumentation("__pnacl_profile_func_enter");
+ Builder.SetInsertPoint(CurBlock);
+ EmitFunctionInstrumentation("__pnacl_profile_func_exit");
+ } else {
+ Builder.SetInsertPoint(BeginBlock, BeginBlock->begin());
+ EmitFunctionInstrumentation("__cyg_profile_func_enter");
+ Builder.SetInsertPoint(CurBlock);
+ EmitFunctionInstrumentation("__cyg_profile_func_exit");
+ }
+// @LOCALMOD-END
}
// Emit debug descriptor for function end.
@@ -294,24 +303,45 @@ bool CodeGenFunction::ShouldInstrumentFunction() {
/// instrumentation function with the current function and the call site, if
/// function instrumentation is enabled.
void CodeGenFunction::EmitFunctionInstrumentation(const char *Fn) {
- // void __cyg_profile_func_{enter,exit} (void *this_fn, void *call_site);
llvm::PointerType *PointerTy = Int8PtrTy;
- llvm::Type *ProfileFuncArgs[] = { PointerTy, PointerTy };
- llvm::FunctionType *FunctionTy =
- llvm::FunctionType::get(VoidTy, ProfileFuncArgs, false);
-
- llvm::Constant *F = CGM.CreateRuntimeFunction(FunctionTy, Fn);
- llvm::CallInst *CallSite = Builder.CreateCall(
- CGM.getIntrinsic(llvm::Intrinsic::returnaddress),
- llvm::ConstantInt::get(Int32Ty, 0),
- "callsite");
-
- llvm::Value *args[] = {
- llvm::ConstantExpr::getBitCast(CurFn, PointerTy),
- CallSite
- };
- EmitNounwindRuntimeCall(F, args);
+// @LOCALMOD-BEGIN
+ if (CGM.getCodeGenOpts().InstrumentFunctionsPNaCl) {
+ const FunctionDecl *CFD = dyn_cast<FunctionDecl>(CurFuncDecl);
+ if (!CFD)
+ return;
+
+ llvm::Type *ProfileFuncArgs[] = { PointerTy };
+ llvm::FunctionType *FunctionTy =
+ llvm::FunctionType::get(VoidTy, ProfileFuncArgs, false);
+
+ std::string NameStr = CFD->getQualifiedNameAsString();
+ llvm::Constant *F = CGM.CreateRuntimeFunction(FunctionTy, Fn);
+ llvm::Constant *FName = CGM.GetAddrOfConstantCString(NameStr, NULL, 16u);
+ llvm::Value *args[] = {
+ llvm::ConstantExpr::getBitCast(FName, PointerTy)
+ };
+
+ EmitNounwindRuntimeCall(F, args);
+ } else {
+ llvm::Type *ProfileFuncArgs[] = { PointerTy, PointerTy };
+ llvm::FunctionType *FunctionTy =
+ llvm::FunctionType::get(VoidTy, ProfileFuncArgs, false);
+
+ llvm::Constant *F = CGM.CreateRuntimeFunction(FunctionTy, Fn);
+ llvm::CallInst *CallSite = Builder.CreateCall(
+ CGM.getIntrinsic(llvm::Intrinsic::returnaddress),
+ llvm::ConstantInt::get(Int32Ty, 0),
+ "callsite");
+
+ llvm::Value *args[] = {
+ llvm::ConstantExpr::getBitCast(CurFn, PointerTy),
+ CallSite
+ };
+
+ EmitNounwindRuntimeCall(F, args);
+ }
+// @LOCALMOD-END
}
void CodeGenFunction::EmitMCountInstrumentation() {
diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp
index c04fc13b23..78e7775bff 100644
--- a/lib/Driver/Tools.cpp
+++ b/lib/Driver/Tools.cpp
@@ -2461,7 +2461,9 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
Args.AddAllArgs(CmdArgs, options::OPT_fdata_sections);
Args.AddAllArgs(CmdArgs, options::OPT_finstrument_functions);
-
+// @LOCALMOD-BEGIN
+ Args.AddAllArgs(CmdArgs, options::OPT_finstrument_functions_pnacl);
+// @LOCALMOD-END
if (Arg *A = Args.getLastArg(options::OPT_finstrument_functions_size_EQ)) {
CmdArgs.push_back("-finstrument-functions-size");
CmdArgs.push_back(A->getValue());
diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp
index 06d8b12e6c..2a156e6c37 100644
--- a/lib/Frontend/CompilerInvocation.cpp
+++ b/lib/Frontend/CompilerInvocation.cpp
@@ -409,6 +409,9 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK,
Opts.InstrumentFunctions = Args.hasArg(OPT_finstrument_functions);
Opts.InstrumentFunctionsSize =
Args.getLastArgIntValue(OPT_finstrument_functions_size, 0);
+// @LOCALMOD-BEGIN
+ Opts.InstrumentFunctionsPNaCl = Args.hasArg(OPT_finstrument_functions_pnacl);
+// @LOCALMOD-END
Opts.InstrumentForProfiling = Args.hasArg(OPT_pg);
Opts.EmitOpenCLArgMetadata = Args.hasArg(OPT_cl_kernel_arg_info);
Opts.DebugCompilationDir = Args.getLastArgValue(OPT_fdebug_compilation_dir);