Index: include/clang/Basic/CodeGenOptions.def =================================================================== --- include/clang/Basic/CodeGenOptions.def +++ include/clang/Basic/CodeGenOptions.def @@ -109,6 +109,7 @@ CODEGENOPT(InstrumentForProfiling , 1, 0) ///< Set when -pg is enabled. CODEGENOPT(CallFEntry , 1, 0) ///< Set when -mfentry is enabled. +CODEGENOPT(MNopMCount , 1, 0) ///< Set when -mnop-mcount is enabled. CODEGENOPT(LessPreciseFPMAD , 1, 0) ///< Enable less precise MAD instructions to ///< be generated. CODEGENOPT(PrepareForLTO , 1, 0) ///< Set when -flto is enabled on the Index: include/clang/Driver/Options.td =================================================================== --- include/clang/Driver/Options.td +++ include/clang/Driver/Options.td @@ -2383,6 +2383,8 @@ def mno_pie_copy_relocations : Flag<["-"], "mno-pie-copy-relocations">, Group; def mfentry : Flag<["-"], "mfentry">, HelpText<"Insert calls to fentry at function entry (x86 only)">, Flags<[CC1Option]>, Group; +def mnop_mcount : Flag<["-"], "mnop-mcount">, HelpText<"Generate mcount/__fentry__ calls as nops. To activate they need to be patched in.">, + Flags<[CC1Option]>, Group; def mips16 : Flag<["-"], "mips16">, Group; def mno_mips16 : Flag<["-"], "mno-mips16">, Group; def mmicromips : Flag<["-"], "mmicromips">, Group; Index: lib/CodeGen/CodeGenFunction.cpp =================================================================== --- lib/CodeGen/CodeGenFunction.cpp +++ lib/CodeGen/CodeGenFunction.cpp @@ -889,6 +889,8 @@ Fn->addFnAttr("instrument-function-entry-inlined", getTarget().getMCountName()); } + if (CGM.getCodeGenOpts().MNopMCount) + Fn->addFnAttr("mnop-mcount", "true"); } } Index: lib/Driver/ToolChains/Clang.cpp =================================================================== --- lib/Driver/ToolChains/Clang.cpp +++ lib/Driver/ToolChains/Clang.cpp @@ -4688,6 +4688,9 @@ if (TC.SupportsProfiling()) Args.AddLastArg(CmdArgs, options::OPT_mfentry); + if (TC.SupportsProfiling()) + Args.AddLastArg(CmdArgs, options::OPT_mnop_mcount); + if (Args.getLastArg(options::OPT_fapple_kext) || (Args.hasArg(options::OPT_mkernel) && types::isCXX(InputType))) CmdArgs.push_back("-fapple-kext"); Index: lib/Frontend/CompilerInvocation.cpp =================================================================== --- lib/Frontend/CompilerInvocation.cpp +++ lib/Frontend/CompilerInvocation.cpp @@ -1092,6 +1092,7 @@ Opts.InstrumentForProfiling = Args.hasArg(OPT_pg); Opts.CallFEntry = Args.hasArg(OPT_mfentry); + Opts.MNopMCount = Args.hasArg(OPT_mnop_mcount); Opts.EmitOpenCLArgMetadata = Args.hasArg(OPT_cl_kernel_arg_info); if (const Arg *A = Args.getLastArg(OPT_fcf_protection_EQ)) { Index: test/CodeGen/mnop-mcount.c =================================================================== --- /dev/null +++ test/CodeGen/mnop-mcount.c @@ -0,0 +1,18 @@ +// RUN: %clang_cc1 -pg -mfentry -mnop-mcount -triple s390x-ibm-linux -emit-llvm -o - %s | FileCheck %s +// RUN: %clang_cc1 -pg -mnop-mcount -triple s390x-ibm-linux -emit-llvm -o - %s | FileCheck %s +// RUN: %clang_cc1 -mfentry -mnop-mcount -triple s390x-ibm-linux -emit-llvm -o - %s | FileCheck -check-prefix=NOPG %s +// RUN: %clang_cc1 -mnop-mcount -triple s390x-ibm-linux -emit-llvm -o - %s | FileCheck -check-prefix=NOPG %s + +int foo(void) { + return 0; +} + +int __attribute__((no_instrument_function)) no_instrument(void) { + return foo(); +} + +//CHECK: attributes #0 = { {{.*}}"mnop-mcount"="true"{{.*}} } +//CHECK: attributes #1 = { {{.*}} } +//CHECK-NOT: attributes #1 = { {{.*}}"mnop-mcount"="true"{{.*}} } +//NOPG-NOT: attributes #0 = { {{.*}}"mnop-mcount"{{.*}} } +//NOPG-NOT: attributes #1 = { {{.*}}"mnop-mcount"{{.*}} }