aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/clang/Driver/Options.td4
-rw-r--r--include/clang/Frontend/CodeGenOptions.def3
-rw-r--r--lib/CodeGen/CodeGenFunction.cpp70
-rw-r--r--lib/Driver/Tools.cpp4
-rw-r--r--lib/Frontend/CompilerInvocation.cpp3
5 files changed, 63 insertions, 21 deletions
diff --git a/include/clang/Driver/Options.td b/include/clang/Driver/Options.td
index fea7ba3c00..2582ccebac 100644
--- a/include/clang/Driver/Options.td
+++ b/include/clang/Driver/Options.td
@@ -486,6 +486,10 @@ def finstrument_functions : Flag<["-"], "finstrument-functions">, Group<f_Group>
HelpText<"Generate calls to instrument function entry and exit">;
def finstrument_functions_size_EQ : Joined<["-"], "finstrument-functions-size=">, Group<f_Group>, Flags<[CC1Option]>,
HelpText<"Set a minimum number of basic blocks for function instrumentation">;
+// @LOCALMOD-BEGIN
+def finstrument_functions_pnacl : Flag<["-"], "finstrument-functions-pnacl">, Group<f_Group>, Flags<[CC1Option]>,
+ HelpText<"If finstrument-functions is also specified, change __cyg_profile_func_x to __pnacl_profile_func_x">;
+// @LOCALMOD-END
def fkeep_inline_functions : Flag<["-"], "fkeep-inline-functions">, Group<clang_ignored_f_Group>;
def flat__namespace : Flag<["-"], "flat_namespace">;
def flax_vector_conversions : Flag<["-"], "flax-vector-conversions">, Group<f_Group>;
diff --git a/include/clang/Frontend/CodeGenOptions.def b/include/clang/Frontend/CodeGenOptions.def
index 63516e8684..c25415af20 100644
--- a/include/clang/Frontend/CodeGenOptions.def
+++ b/include/clang/Frontend/CodeGenOptions.def
@@ -65,6 +65,9 @@ CODEGENOPT(InstrumentFunctions , 1, 0) ///< Set when -finstrument-functions is
VALUE_CODEGENOPT(InstrumentFunctionsSize, 32, 0) ///< If set, only functions with
///< at least this many basic
///< blocks are instrumented.
+// @LOCALMOD-BEGIN
+CODEGENOPT(InstrumentFunctionsPNaCl , 1, 0)
+// @LOCALMOD-END
CODEGENOPT(InstrumentForProfiling , 1, 0) ///< Set when -pg is enabled.
CODEGENOPT(LessPreciseFPMAD , 1, 0) ///< Enable less precise MAD instructions to
///< be generated.
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);