Commit 93767143 authored by Jonas Paulsson's avatar Jonas Paulsson
Browse files

[Clang FE] Recognize -mnop-mcount CL option (SystemZ only).

Recognize -mnop-mcount from the command line and add a function attribute
"mnop-mcount"="true" when passed.

When this option is used, a nop is added instead of a call to fentry. This
is used when building the Linux Kernel.

If this option is passed for any other target than SystemZ, an error is
generated.

Review: Ulrich Weigand
https://reviews.llvm.org/D67763
parent 646896a4
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -112,6 +112,7 @@ VALUE_CODEGENOPT(XRayInstructionThreshold , 32, 200)

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
+2 −0
Original line number Diff line number Diff line
@@ -271,6 +271,8 @@ def err_target_unsupported_mcmse : Error<
  "-mcmse is not supported for %0">;
def err_opt_not_valid_with_opt : Error<
  "option '%0' cannot be specified with '%1'">;
def err_opt_not_valid_without_opt : Error<
  "option '%0' cannot be specified without '%1'">;
def err_opt_not_valid_on_target : Error<
  "option '%0' cannot be specified on this target">;

+2 −0
Original line number Diff line number Diff line
@@ -2448,6 +2448,8 @@ def mpie_copy_relocations : Flag<["-"], "mpie-copy-relocations">, Group<m_Group>
def mno_pie_copy_relocations : Flag<["-"], "mno-pie-copy-relocations">, Group<m_Group>;
def mfentry : Flag<["-"], "mfentry">, HelpText<"Insert calls to fentry at function entry (x86/SystemZ only)">,
  Flags<[CC1Option]>, Group<m_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<m_Group>;
def mips16 : Flag<["-"], "mips16">, Group<m_mips_Features_Group>;
def mno_mips16 : Flag<["-"], "mno-mips16">, Group<m_mips_Features_Group>;
def mmicromips : Flag<["-"], "mmicromips">, Group<m_mips_Features_Group>;
+10 −0
Original line number Diff line number Diff line
@@ -893,6 +893,16 @@ void CodeGenFunction::StartFunction(GlobalDecl GD,
        Fn->addFnAttr("instrument-function-entry-inlined",
                      getTarget().getMCountName());
      }
      if (CGM.getCodeGenOpts().MNopMCount) {
        if (getContext().getTargetInfo().getTriple().getArch() !=
            llvm::Triple::systemz)
          CGM.getDiags().Report(diag::err_opt_not_valid_on_target)
            << "-mnop-mcount";
        if (!CGM.getCodeGenOpts().CallFEntry)
          CGM.getDiags().Report(diag::err_opt_not_valid_without_opt)
            << "-mnop-mcount" << "-mfentry";
        Fn->addFnAttr("mnop-mcount", "true");
      }
    }
  }

+3 −0
Original line number Diff line number Diff line
@@ -4616,6 +4616,9 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
  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");
Loading