Index: clang/lib/Driver/ToolChains/Clang.cpp =================================================================== --- clang/lib/Driver/ToolChains/Clang.cpp +++ clang/lib/Driver/ToolChains/Clang.cpp @@ -3995,8 +3995,13 @@ Args.hasArg(options::OPT_dA)) CmdArgs.push_back("-masm-verbose"); - if (!TC.useIntegratedAs()) + if (!TC.useIntegratedAs()) { CmdArgs.push_back("-no-integrated-as"); + // .cgprofile can only be parsed by llvm-as, do not run CGProfilePass if + // integrated-as is not used. + CmdArgs.push_back("-mllvm"); + CmdArgs.push_back("-enable-call-graph-profile-sort=false"); + } if (Args.hasArg(options::OPT_fdebug_pass_structure)) { CmdArgs.push_back("-mdebug-pass"); Index: llvm/lib/Passes/PassBuilder.cpp =================================================================== --- llvm/lib/Passes/PassBuilder.cpp +++ llvm/lib/Passes/PassBuilder.cpp @@ -212,6 +212,10 @@ EnableCHR("enable-chr-npm", cl::init(true), cl::Hidden, cl::desc("Enable control height reduction optimization (CHR)")); +static cl::opt EnableCallGraphProfileSort( + "enable-call-graph-profile-sort", cl::init(true), cl::Hidden, + cl::desc("Enable call graph profile pass for the new PM (default = on)")); + extern cl::opt EnableHotColdSplit; extern cl::opt EnableOrderFileInstrumentation; @@ -939,7 +943,8 @@ // Add the core optimizing pipeline. MPM.addPass(createModuleToFunctionPassAdaptor(std::move(OptimizePM))); - MPM.addPass(CGProfilePass()); + if (EnableCallGraphProfileSort) + MPM.addPass(CGProfilePass()); // Now we need to do some global optimization transforms. // FIXME: It would seem like these should come first in the optimization