From 544a1f307fe9a756660820448b6dfd5a94d9679c Mon Sep 17 00:00:00 2001 From: Ryan Houdek Date: Thu, 14 Jan 2021 11:50:25 -0800 Subject: [PATCH] Adds an option to disable optimization passes Instead of forcing someone to test by modifying code, allow a -O0 option to be passed in. Also added to FEXConfig GUI for easily touching. Fixes #652 --- .../Source/Interface/IR/PassManager.cpp | 37 ++++++++++++------- .../FEXCore/include/FEXCore/Config/Config.h | 1 + Source/Common/ArgumentLoader.cpp | 8 ++++ Source/Common/Config.cpp | 2 + Source/Tools/FEXConfig/Main.cpp | 9 +++++ 5 files changed, 44 insertions(+), 13 deletions(-) diff --git a/External/FEXCore/Source/Interface/IR/PassManager.cpp b/External/FEXCore/Source/Interface/IR/PassManager.cpp index 1136a64a0..22a9de0da 100644 --- a/External/FEXCore/Source/Interface/IR/PassManager.cpp +++ b/External/FEXCore/Source/Interface/IR/PassManager.cpp @@ -2,28 +2,39 @@ #include "Interface/IR/Passes/RegisterAllocationPass.h" #include "Interface/IR/PassManager.h" +#include + namespace FEXCore::IR { void PassManager::AddDefaultPasses(bool InlineConstants, bool StaticRegisterAllocation) { - InsertPass(CreateContextLoadStoreElimination()); - InsertPass(CreateDeadFlagStoreElimination()); - InsertPass(CreateDeadGPRStoreElimination()); - InsertPass(CreateDeadFPRStoreElimination()); - InsertPass(CreatePassDeadCodeElimination()); - InsertPass(CreateConstProp(InlineConstants)); + FEXCore::Config::Value DisablePasses{FEXCore::Config::CONFIG_DEBUG_DISABLE_OPTIMIZATION_PASSES, false}; - ////// InsertPass(CreateDeadFlagCalculationEliminination()); + if (!DisablePasses()) { + InsertPass(CreateContextLoadStoreElimination()); + InsertPass(CreateDeadFlagStoreElimination()); + InsertPass(CreateDeadGPRStoreElimination()); + InsertPass(CreateDeadFPRStoreElimination()); + InsertPass(CreatePassDeadCodeElimination()); + InsertPass(CreateConstProp(InlineConstants)); - InsertPass(CreateSyscallOptimization()); - InsertPass(CreatePassDeadCodeElimination()); + ////// InsertPass(CreateDeadFlagCalculationEliminination()); - // only do SRA if enabled and JIT - if (InlineConstants && StaticRegisterAllocation) - InsertPass(CreateStaticRegisterAllocationPass()); + InsertPass(CreateSyscallOptimization()); + InsertPass(CreatePassDeadCodeElimination()); + // only do SRA if enabled and JIT + if (InlineConstants && StaticRegisterAllocation) + InsertPass(CreateStaticRegisterAllocationPass()); + } + else { + // only do SRA if enabled and JIT + if (InlineConstants && StaticRegisterAllocation) + InsertPass(CreateStaticRegisterAllocationPass()); + } + + CompactionPass = CreateIRCompaction(); // If the IR is compacted post-RA then the node indexing gets messed up and the backend isn't able to find the register assigned to a node // Compact before IR, don't worry about RA generating spills/fills - CompactionPass = CreateIRCompaction(); InsertPass(CompactionPass); } diff --git a/External/FEXCore/include/FEXCore/Config/Config.h b/External/FEXCore/include/FEXCore/Config/Config.h index f8e33ec52..3b1b5fb84 100644 --- a/External/FEXCore/include/FEXCore/Config/Config.h +++ b/External/FEXCore/include/FEXCore/Config/Config.h @@ -30,6 +30,7 @@ namespace FEXCore::Config { CONFIG_IS_INTERPRETER, CONFIG_INTERPRETER_INSTALLED, CONFIG_APP_FILENAME, + CONFIG_DEBUG_DISABLE_OPTIMIZATION_PASSES, }; enum ConfigCore { diff --git a/Source/Common/ArgumentLoader.cpp b/Source/Common/ArgumentLoader.cpp index 7f92c39d4..e276ec9a1 100644 --- a/Source/Common/ArgumentLoader.cpp +++ b/Source/Common/ArgumentLoader.cpp @@ -109,6 +109,11 @@ namespace FEX::ArgLoader { .help("Adds an environment variable") .action("append"); + EmulationGroup.add_option("-O") + .dest("O0") + .help("Disables optimization passes for debugging") + .choices({"0"}); + Parser.add_option_group(EmulationGroup); } { @@ -241,6 +246,9 @@ namespace FEX::ArgLoader { Set(FEXCore::Config::ConfigOption::CONFIG_ENVIRONMENT, *iter); } } + if (Options.is_set_by_user("O0")) { + Set(FEXCore::Config::ConfigOption::CONFIG_DEBUG_DISABLE_OPTIMIZATION_PASSES, std::to_string(true)); + } } { diff --git a/Source/Common/Config.cpp b/Source/Common/Config.cpp index 870fa2092..ea7f0ec85 100644 --- a/Source/Common/Config.cpp +++ b/Source/Common/Config.cpp @@ -186,6 +186,7 @@ namespace FEX::Config { {FEXCore::Config::ConfigOption::CONFIG_SMC_CHECKS, "SMCChecks"}, {FEXCore::Config::ConfigOption::CONFIG_ABI_LOCAL_FLAGS, "ABILocalFlags"}, {FEXCore::Config::ConfigOption::CONFIG_ABI_NO_PF, "ABINoPF"}, + {FEXCore::Config::ConfigOption::CONFIG_DEBUG_DISABLE_OPTIMIZATION_PASSES, "O0"}, }}; @@ -232,6 +233,7 @@ namespace FEX::Config { {"SMCChecks", FEXCore::Config::ConfigOption::CONFIG_SMC_CHECKS}, {"ABILocalFlags", FEXCore::Config::ConfigOption::CONFIG_ABI_LOCAL_FLAGS}, {"AbiNoPF", FEXCore::Config::ConfigOption::CONFIG_ABI_NO_PF}, + {"O0", FEXCore::Config::ConfigOption::CONFIG_DEBUG_DISABLE_OPTIMIZATION_PASSES}, }}; void OptionMapper::MapNameToOption(const char *ConfigName, const char *ConfigString) { diff --git a/Source/Tools/FEXConfig/Main.cpp b/Source/Tools/FEXConfig/Main.cpp index 8813fdca4..639873cf5 100644 --- a/Source/Tools/FEXConfig/Main.cpp +++ b/Source/Tools/FEXConfig/Main.cpp @@ -74,6 +74,7 @@ namespace { LoadedConfig->Set(FEXCore::Config::ConfigOption::CONFIG_SMC_CHECKS, "0"); LoadedConfig->Set(FEXCore::Config::ConfigOption::CONFIG_ABI_LOCAL_FLAGS, "0"); LoadedConfig->Set(FEXCore::Config::ConfigOption::CONFIG_ABI_NO_PF, "0"); + LoadedConfig->Set(FEXCore::Config::ConfigOption::CONFIG_DEBUG_DISABLE_OPTIMIZATION_PASSES, "0"); } void SaveFile(std::string Filename) { @@ -245,6 +246,14 @@ namespace { } } + ImGui::Text("Debugging:"); + Value = LoadedConfig->Get(FEXCore::Config::ConfigOption::CONFIG_DEBUG_DISABLE_OPTIMIZATION_PASSES); + bool DisablePasses = Value.has_value() && **Value == "1"; + if (ImGui::Checkbox("Disable Optimization Passes", &DisablePasses)) { + LoadedConfig->EraseSet(FEXCore::Config::ConfigOption::CONFIG_DEBUG_DISABLE_OPTIMIZATION_PASSES, DisablePasses ? "1" : "0"); + ConfigChanged = true; + } + ImGui::EndTabItem(); } }