From 178e0160b7fc5b14c664c339d7f9b18fad8bdca8 Mon Sep 17 00:00:00 2001 From: Roman Divacky Date: Thu, 10 Feb 2011 16:52:03 +0000 Subject: Implement mcount profiling, enabled via -pg. llvm-svn: 125282 --- clang/lib/CodeGen/CodeGenFunction.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'clang/lib/CodeGen/CodeGenFunction.cpp') diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index 66114c8..364f269 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -210,6 +210,15 @@ void CodeGenFunction::EmitFunctionInstrumentation(const char *Fn) { CallSite); } +void CodeGenFunction::EmitMCountInstrumentation() { + llvm::FunctionType *FTy = + llvm::FunctionType::get(llvm::Type::getVoidTy(getLLVMContext()), false); + + llvm::Constant *MCountFn = CGM.CreateRuntimeFunction(FTy, + Target.getMCountName()); + Builder.CreateCall(MCountFn); +} + void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy, llvm::Function *Fn, const FunctionArgList &Args, @@ -260,6 +269,9 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy, EmitFunctionInstrumentation("__cyg_profile_func_enter"); + if (CGM.getCodeGenOpts().InstrumentForProfiling) + EmitMCountInstrumentation(); + // FIXME: Leaked. // CC info is ignored, hopefully? CurFnInfo = &CGM.getTypes().getFunctionInfo(FnRetTy, Args, -- cgit v1.1