diff options
author | Robert Grosse <grosse@chromium.org> | 2013-07-25 15:05:16 -0700 |
---|---|---|
committer | Robert Grosse <grosse@chromium.org> | 2013-07-25 15:05:16 -0700 |
commit | 548960c21c590dcd4919a1bba000e989c140c8ef (patch) | |
tree | 240e059006f5d8a323ef426bdbf3b7f2b3d4d3e5 /lib/CodeGen/CodeGenFunction.cpp | |
parent | 7b390888fd9f3886d966ab072c328f4fbd9c64b4 (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/CodeGen/CodeGenFunction.cpp')
-rw-r--r-- | lib/CodeGen/CodeGenFunction.cpp | 70 |
1 files changed, 50 insertions, 20 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() { |