From 365c2a82172e4e27d5a04bb01a30e98687a6ec8d Mon Sep 17 00:00:00 2001 From: Jameson Nash Date: Tue, 28 Sep 2021 13:01:09 -0400 Subject: [PATCH] llvm: cleanup options parsing --- src/codegen.cpp | 48 +++++++++++++-------------------------------- test/cmdlineargs.jl | 20 +++++++++++++++++++ 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/src/codegen.cpp b/src/codegen.cpp index a675ebd71cfc5..854079efee863 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -8209,42 +8209,20 @@ extern "C" void jl_init_llvm(void) #endif // Parse command line flags after initialization - const char *const argv_tailmerge[] = {"", "-enable-tail-merge=0"}; // NOO TOUCHIE; NO TOUCH! See #922 - cl::ParseCommandLineOptions(sizeof(argv_tailmerge)/sizeof(argv_tailmerge[0]), argv_tailmerge, "disable-tail-merge\n"); -#if defined(_OS_WINDOWS_) && defined(_CPU_X86_64_) - const char *const argv_copyprop[] = {"", "-disable-copyprop"}; // llvm bug 21743 - cl::ParseCommandLineOptions(sizeof(argv_copyprop)/sizeof(argv_copyprop[0]), argv_copyprop, "disable-copyprop\n"); -#endif -#if defined(_CPU_X86_) || defined(_CPU_X86_64_) - const char *const argv_avoidsfb[] = {"", "-x86-disable-avoid-SFB"}; // llvm bug 41629, see https://gist.github.com/vtjnash/192cab72a6cfc00256ff118238163b55 - cl::ParseCommandLineOptions(sizeof(argv_avoidsfb)/sizeof(argv_avoidsfb[0]), argv_avoidsfb, "disable-avoidsfb\n"); -#endif -#if JL_LLVM_VERSION >= 120000 - // https://reviews.llvm.org/rGc068e9c8c123e7f8c8f3feb57245a012ccd09ccf - Optional envValue = sys::Process::GetEnv("JULIA_LLVM_ARGS"); - if (envValue) { - SmallVector newArgv; - BumpPtrAllocator A; - StringSaver Saver(A); - newArgv.push_back(Saver.save("Julia").data()); - - // Parse the value of the environment variable into a "command line" - // and hand it off to ParseCommandLineOptions(). - cl::TokenizeGNUCommandLine(*envValue, Saver, newArgv); - int newArgc = static_cast(newArgv.size()); - cl::ParseCommandLineOptions(newArgc, &newArgv[0]); - } -#else - cl::ParseEnvironmentOptions("Julia", "JULIA_LLVM_ARGS"); -#endif - + StringMap &llvmopts = cl::getRegisteredOptions(); + const char *const argv[1] = {"julia"}; + cl::ParseCommandLineOptions(1, argv, "", nullptr, "JULIA_LLVM_ARGS"); + + // Set preferred non-default options + cl::Option *clopt; + clopt = llvmopts.lookup("enable-tail-merge"); // NOO TOUCHIE; NO TOUCH! See #922 + if (clopt->getNumOccurrences() == 0) + cl::ProvidePositionalOption(clopt, "0", 1); // if the patch adding this option has been applied, lower its limit to provide // better DAGCombiner performance. - auto &clOptions = cl::getRegisteredOptions(); - if (clOptions.find("combiner-store-merge-dependence-limit") != clOptions.end()) { - const char *const argv_smdl[] = {"", "-combiner-store-merge-dependence-limit=4"}; - cl::ParseCommandLineOptions(sizeof(argv_smdl)/sizeof(argv_smdl[0]), argv_smdl); - } + clopt = llvmopts.lookup("combiner-store-merge-dependence-limit"); + if (clopt && clopt->getNumOccurrences() == 0) + cl::ProvidePositionalOption(clopt, "4", 1); TargetOptions options = TargetOptions(); //options.PrintMachineCode = true; //Print machine code produced during JIT compiling @@ -8346,6 +8324,8 @@ extern "C" void jl_init_llvm(void) if (jl_using_perf_jitevents) jl_ExecutionEngine->RegisterJITEventListener(JITEventListener::createPerfJITEventListener()); #endif + + cl::PrintOptionValues(); } extern "C" void jl_init_codegen(void) diff --git a/test/cmdlineargs.jl b/test/cmdlineargs.jl index 8d85b1a1cc5c8..6e06f12ef4fe0 100644 --- a/test/cmdlineargs.jl +++ b/test/cmdlineargs.jl @@ -93,6 +93,26 @@ let exename = `$(Base.julia_cmd()) --startup-file=no --color=no` @test v[2] == "1" @test isempty(v[3]) end + + let v = readchomperrors(setenv(`$exename -e 0`, "JULIA_LLVM_ARGS" => "-print-options", "HOME" => homedir())) + @test v[1] + @test contains(v[2], r"print-options + = 1") + @test contains(v[2], r"combiner-store-merge-dependence-limit + = 4") + @test contains(v[2], r"enable-tail-merge + = 2") + @test isempty(v[3]) + end + let v = readchomperrors(setenv(`$exename -e 0`, "JULIA_LLVM_ARGS" => "-print-options -enable-tail-merge=1 -combiner-store-merge-dependence-limit=6", "HOME" => homedir())) + @test v[1] + @test contains(v[2], r"print-options + = 1") + @test contains(v[2], r"combiner-store-merge-dependence-limit + = 6") + @test contains(v[2], r"enable-tail-merge + = 1") + @test isempty(v[3]) + end + let v = readchomperrors(setenv(`$exename -e 0`, "JULIA_LLVM_ARGS" => "-print-options -enable-tail-merge=1 -enable-tail-merge=1", "HOME" => homedir())) + @test !v[1] + @test isempty(v[2]) + @test v[3] == "julia: for the --enable-tail-merge option: may only occur zero or one times!" + end end let exename = `$(Base.julia_cmd()) --startup-file=no --color=no`