aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/CodeGenFunction.cpp
diff options
context:
space:
mode:
authorRobert Grosse <grosse@chromium.org>2013-07-25 14:34:41 -0700
committerRobert Grosse <grosse@chromium.org>2013-07-25 14:34:41 -0700
commit7b390888fd9f3886d966ab072c328f4fbd9c64b4 (patch)
tree61d7d80f47627e5736931a1ae488377c92594f4c /lib/CodeGen/CodeGenFunction.cpp
parent0adde5bbb53bfb2aadcb566c514efd3e218bf0bc (diff)
Add a -finstrument-functions-size=n option to control basic block
filtering. If omitted entirely, the original behavior is restored. This also undos the string and __pnacl_profile stuff from the previous CL. Finally, it fixes and updates the -finstrument-function tests. BUG=none R=bradnelson@google.com, dschuff@chromium.org Review URL: https://codereview.chromium.org/19793007
Diffstat (limited to 'lib/CodeGen/CodeGenFunction.cpp')
-rw-r--r--lib/CodeGen/CodeGenFunction.cpp22
1 files changed, 16 insertions, 6 deletions
diff --git a/lib/CodeGen/CodeGenFunction.cpp b/lib/CodeGen/CodeGenFunction.cpp
index 75c60edbba..a3c39649b7 100644
--- a/lib/CodeGen/CodeGenFunction.cpp
+++ b/lib/CodeGen/CodeGenFunction.cpp
@@ -222,8 +222,18 @@ void CodeGenFunction::FinishFunction(SourceLocation EndLoc) {
// Emit function epilog (to return).
EmitReturnBlock();
- if (ShouldInstrumentFunction())
- EmitFunctionInstrumentation("__cyg_profile_func_exit");
+ if (ShouldInstrumentFunction()) {
+ // The size of the function isn't known during StartFunction, so in order
+ // to instrument selectively based on function size, we need to wait
+ // until the end and insert both the entry and exit instrumentation
+ 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");
+ }
// Emit debug descriptor for function end.
if (CGDebugInfo *DI = getDebugInfo()) {
@@ -274,7 +284,10 @@ bool CodeGenFunction::ShouldInstrumentFunction() {
return false;
if (!CurFuncDecl || CurFuncDecl->hasAttr<NoInstrumentFunctionAttr>())
return false;
- return true;
+
+ // If not specified, defaults to 0.
+ int Size = CGM.getCodeGenOpts().InstrumentFunctionsSize;
+ return CurFn->getBasicBlockList().size() >= Size;
}
/// EmitFunctionInstrumentation - Emit LLVM code to call the specified
@@ -541,9 +554,6 @@ void CodeGenFunction::StartFunction(GlobalDecl GD,
DI->EmitFunctionStart(GD, FnType, CurFn, Builder);
}
- if (ShouldInstrumentFunction())
- EmitFunctionInstrumentation("__cyg_profile_func_enter");
-
if (CGM.getCodeGenOpts().InstrumentForProfiling)
EmitMCountInstrumentation();