[PATCH] [Profile] Instrumenter support for setting profile output from command line
Teresa Johnson
tejohnson at google.com
Thu Apr 30 11:27:29 PDT 2015
FYI I went ahead and uploaded the third patch (the cfe part):
http://reviews.llvm.org/D9407
On Tue, Apr 28, 2015 at 9:44 PM, Teresa Johnson <tejohnson at google.com> wrote:
> This change is the second of 3 patches to add support for specifying
> the profile output from the command line via -fprofile-instr-generate=<path>,
> where the specified output path/file will be overridden by the
> LLVM_PROFILE_FILE environment variable.
>
> This patch adds the necessary support to the llvm instrumenter, specifically
> a new member of GCOVOptions for clang to save the specified filename, and
> support for calling the new compiler-rt interface from __llvm_profile_init.
>
> http://reviews.llvm.org/D9334
>
> Files:
> include/llvm/Transforms/Instrumentation.h
> lib/Transforms/Instrumentation/InstrProfiling.cpp
>
> Index: include/llvm/Transforms/Instrumentation.h
> ===================================================================
> --- include/llvm/Transforms/Instrumentation.h
> +++ include/llvm/Transforms/Instrumentation.h
> @@ -74,6 +74,9 @@
>
> // Add the 'noredzone' attribute to added runtime library calls.
> bool NoRedZone;
> +
> + // Name of the profile file to use as output
> + std::string InstrProfileOutput;
> };
>
> /// Insert frontend instrumentation based profiling.
> Index: lib/Transforms/Instrumentation/InstrProfiling.cpp
> ===================================================================
> --- lib/Transforms/Instrumentation/InstrProfiling.cpp
> +++ lib/Transforms/Instrumentation/InstrProfiling.cpp
> @@ -97,7 +97,8 @@
> /// Add uses of our data variables and runtime hook.
> void emitUses();
>
> - /// Create a static initializer for our data, on platforms that need it.
> + /// Create a static initializer for our data, on platforms that need it,
> + /// and for any profile output file that was specified.
> void emitInitialization();
> };
>
> @@ -328,8 +329,10 @@
> }
>
> void InstrProfiling::emitInitialization() {
> + std::string InstrProfileOutput = Options.InstrProfileOutput;
> +
> Constant *RegisterF = M->getFunction("__llvm_profile_register_functions");
> - if (!RegisterF)
> + if (!RegisterF && InstrProfileOutput.empty())
> return;
>
> // Create the initialization function.
> @@ -344,7 +347,24 @@
>
> // Add the basic block and the necessary calls.
> IRBuilder<> IRB(BasicBlock::Create(M->getContext(), "", F));
> - IRB.CreateCall(RegisterF);
> + if (RegisterF)
> + IRB.CreateCall(RegisterF);
> + if (!InstrProfileOutput.empty()) {
> + auto *VoidTy = Type::getVoidTy(M->getContext());
> + auto *Int8PtrTy = Type::getInt8PtrTy(M->getContext());
> + auto *SetFnameFTy = FunctionType::get(VoidTy, Int8PtrTy, false);
> + auto *SetFnameF = Function::Create(SetFnameFTy, GlobalValue::ExternalLinkage,
> + "__llvm_profile_set_filename_env_override", M);
> +
> + // Create variable for profile name
> + Constant *ProfileNameStrConst =
> + ConstantDataArray::getString(M->getContext(), InstrProfileOutput, true);
> + GlobalVariable *ProfileName =
> + new GlobalVariable(*M, ProfileNameStrConst->getType(), true,
> + GlobalValue::PrivateLinkage, ProfileNameStrConst);
> +
> + IRB.CreateCall(SetFnameF, IRB.CreatePointerCast(ProfileName, Int8PtrTy));
> + }
> IRB.CreateRetVoid();
>
> appendToGlobalCtors(*M, F, 0);
>
> EMAIL PREFERENCES
> http://reviews.llvm.org/settings/panel/emailpreferences/
--
Teresa Johnson | Software Engineer | tejohnson at google.com | 408-460-2413
More information about the llvm-commits
mailing list