diff --git a/projects/clr/rocclr/compiler/lib/backends/common/codegen.cpp b/projects/clr/rocclr/compiler/lib/backends/common/codegen.cpp index 2ab55dc629..0309a95272 100644 --- a/projects/clr/rocclr/compiler/lib/backends/common/codegen.cpp +++ b/projects/clr/rocclr/compiler/lib/backends/common/codegen.cpp @@ -392,7 +392,7 @@ llvmCodeGen( aclBinary* binary) { const FamilyMapping &familyMap = familySet[binary->target.arch_id]; - const bool optimize = (OptionsObj ? (OptionsObj->oVariables->OptLevel > 0) : true); + const bool optimize = (OptionsObj ? (OptionsObj->oVariables->OptLevel > amd::option::OPT_O0) : true); const TargetMapping* targetMap = familyMap.target; unsigned famID = binary->target.chip_id; if (!targetMap || !targetMap[famID].supported) { @@ -475,20 +475,22 @@ llvmCodeGen( CodeGenOpt::Level OLvl = CodeGenOpt::None; switch (OptionsObj->oVariables->OptLevel) { - case 0: // -O0 + case amd::option::OPT_O0: // -O0 OLvl = CodeGenOpt::None; break; - case 1: // -O1 + case amd::option::OPT_O1: // -O1 OLvl = CodeGenOpt::Less; break; default: assert(!"Error with optimization level"); - case 2: // -O2 - case 5: // -O5(-Os) + case amd::option::OPT_O2: // -O2 + case amd::option::OPT_O5: // -O5 + case amd::option::OPT_OS: // -Os OLvl = CodeGenOpt::Default; break; - case 3: // -O3 - case 4: // -O4 + case amd::option::OPT_OG: // -Og + case amd::option::OPT_O3: // -O3 + case amd::option::OPT_O4: // -O4 OLvl = CodeGenOpt::Aggressive; break; }; diff --git a/projects/clr/rocclr/compiler/lib/backends/common/linker.cpp b/projects/clr/rocclr/compiler/lib/backends/common/linker.cpp index adb5493500..1988f0fc3c 100644 --- a/projects/clr/rocclr/compiler/lib/backends/common/linker.cpp +++ b/projects/clr/rocclr/compiler/lib/backends/common/linker.cpp @@ -572,7 +572,7 @@ amdcl::OCLLinker::link(llvm::Module* input, std::vectoroVariables->OptSimplifyLibCall); setUnsafeMathOpt(Options()->oVariables->UnsafeMathOpt); - setIsPreLinkOpt(Options()->oVariables->OptLevel); + setIsPreLinkOpt(Options()->oVariables->OptLevel != amd::option::OPT_O0); setFP32RoundDivideSqrt(Options()->oVariables->FP32RoundDivideSqrt); setUseNative(Options()->oVariables->OptUseNative); setDenormsAreZero(Options()->oVariables->DenormsAreZero); diff --git a/projects/clr/rocclr/compiler/lib/backends/common/opt_level.cpp b/projects/clr/rocclr/compiler/lib/backends/common/opt_level.cpp index bd5810f98b..397587d8db 100644 --- a/projects/clr/rocclr/compiler/lib/backends/common/opt_level.cpp +++ b/projects/clr/rocclr/compiler/lib/backends/common/opt_level.cpp @@ -63,18 +63,20 @@ OptLevel::setup(aclBinary *elf, bool isGPU, uint32_t OptLevel) llvm::CodeGenOpt::Level OLvl = CodeGenOpt::None; switch (Options()->oVariables->OptLevel) { - case 0: // -O0 + case amd::option::OPT_O0: // -O0 OLvl = CodeGenOpt::None; break; - case 1: // -O1 + case amd::option::OPT_O1: // -O1 OLvl = CodeGenOpt::Less; break; - case 2: // -O2 - case 5: // -O5(-Os) + case amd::option::OPT_O2: // -O2 + case amd::option::OPT_O5: // -O5 + case amd::option::OPT_OS: // -Os OLvl = CodeGenOpt::Default; break; - case 3: // -O3 - case 4: // -O4 + case amd::option::OPT_OG: // -Og + case amd::option::OPT_O3: // -O3 + case amd::option::OPT_O4: // -O4 OLvl = CodeGenOpt::Aggressive; break; default: @@ -271,3 +273,12 @@ OsOptLevel::optimize(aclBinary *elf, Module *input, bool isGPU) run(elf); return 0; } + +int +OgOptLevel::optimize(aclBinary *elf, Module *input, bool isGPU) +{ + module_ = input; + setup(elf, isGPU, 3); + run(elf); + return 0; +} diff --git a/projects/clr/rocclr/compiler/lib/backends/common/opt_level.hpp b/projects/clr/rocclr/compiler/lib/backends/common/opt_level.hpp index 397d8d0f7a..207b70c75e 100644 --- a/projects/clr/rocclr/compiler/lib/backends/common/opt_level.hpp +++ b/projects/clr/rocclr/compiler/lib/backends/common/opt_level.hpp @@ -200,5 +200,19 @@ namespace amdcl }; // class OsOptLevel /*@}*/ + class OgOptLevel : public OptLevel { + OgOptLevel(OgOptLevel&); // DO NOT IMPLEMENT. + OgOptLevel(); // DO NOT IMPLEMENT. + + public: + OgOptLevel(amd::option::Options *opts) + : OptLevel(opts) {} + + virtual ~OgOptLevel() {} + + virtual int optimize(aclBinary *elf, llvm::Module *input, bool isGPU); + }; // class OgOptLevel + /*@}*/ + }; // amdcl namespace #endif // _BE_OPT_LEVEL_HPP_ diff --git a/projects/clr/rocclr/compiler/lib/backends/common/optimizer.cpp b/projects/clr/rocclr/compiler/lib/backends/common/optimizer.cpp index 3d5f4bd18d..b162d69992 100644 --- a/projects/clr/rocclr/compiler/lib/backends/common/optimizer.cpp +++ b/projects/clr/rocclr/compiler/lib/backends/common/optimizer.cpp @@ -25,25 +25,29 @@ using namespace amdcl; using namespace llvm; static OptLevel* getOptLevel(amd::option::Options* Options, bool isGPU) { - switch(Options->oVariables->OptLevel) { + switch(Options->oVariables->OptLevel) { case amd::option::OPT_O0: - return (isGPU) ? new GPUO0OptLevel(Options) : new O0OptLevel(Options); + return (isGPU) ? new GPUO0OptLevel(Options) : new O0OptLevel(Options); case amd::option::OPT_O1: - return new O1OptLevel(Options); + return new O1OptLevel(Options); default: - assert(!"Found an invalid optimization level!"); + assert(!"Found an invalid optimization level!"); case amd::option::OPT_O2: - return new O2OptLevel(Options); + return new O2OptLevel(Options); + case amd::option::OPT_OG: + return new OgOptLevel(Options); case amd::option::OPT_O3: - return new O3OptLevel(Options); + return new O3OptLevel(Options); case amd::option::OPT_O4: - return new O4OptLevel(Options); + return new O4OptLevel(Options); + case amd::option::OPT_O5: case amd::option::OPT_OS: - return new OsOptLevel(Options); - } - assert(!"Unreachable!"); - return NULL; + return new OsOptLevel(Options); + } + assert(!"Unreachable!"); + return NULL; } + int CPUOptimizer::preOptimizer(llvm::Module* M) { diff --git a/projects/clr/rocclr/compiler/lib/utils/OPTIONS.def b/projects/clr/rocclr/compiler/lib/utils/OPTIONS.def index 407de272ac..b30fbb6657 100644 --- a/projects/clr/rocclr/compiler/lib/utils/OPTIONS.def +++ b/projects/clr/rocclr/compiler/lib/utils/OPTIONS.def @@ -48,6 +48,7 @@ * OT_INT32 : int32 * OT_UINT32 : uint32 * OT_CSTRING : char* + * OT_uCHAR : unsigned char * * attr: option attributes, divided in several groups: * OptionValue : value attribute. Use exactly one. @@ -118,17 +119,17 @@ * NOPTION, no varialbe in option object for this. But we still need PP_D (as option ID) * All unused parameters are set to 0. * - * -O[0|1|2|3|4|5] - * OPTION(OT_UINT32, \ + * -O[0|1|2|3|4|5|s|g] + * OPTION(OT_UCHAR, \ * OA_RUNTIME|OVIS_INTERNAL|OVA_OPTIONAL|OA_SEPARATOR_NONE, \ * "O", NULL, \ * OptLevel, \ - * 3, 0, 3, NULL, \ - * "Set optimization level to (0-4, 5(-Os equivalent)") + * '3', 0, 's', NULL, \ + * "Set optimization level to (0-4, 5(-Os equivalent), g") * * where sn = "O", var = "OptLevel", ideft is 3 (Which means -O will mean -O3). And code * can use the following for checking the option level: - * if (localOptions.oVariables->OptLevel == 0) { + * if (localOptions.oVariables->OptLevel == amd::option::OPT_O0) { * ... * } * @@ -549,13 +550,13 @@ OPTION(OT_CSTRING, \ 0, 0, 0, NULL, \ "Pass comma-separated to the finalizer (sc)") -// -O[0|1|2|3|4|5] -OPTION(OT_UINT32, \ +// -O[0|1|2|3|4|5|s|g] +OPTION(OT_UCHAR, \ OA_RUNTIME|OVA_OPTIONAL|OA_SEPARATOR_NONE, \ "O", NULL, \ OptLevel, \ - 3, 0, 5, NULL, \ - "Set optimization level to (0|1|2|3|4|5(-Os equivalent))") + '3', 0, 's', NULL, \ + "Set optimization level to (0|1|2|3|4|5(-Os equivalent)|g)") // -srt/--sr-threshold= : Scalar Replacement threshold OPTION(OT_UINT32, \ diff --git a/projects/clr/rocclr/compiler/lib/utils/options.cpp b/projects/clr/rocclr/compiler/lib/utils/options.cpp index 490b29f1c8..bb263e4d4a 100644 --- a/projects/clr/rocclr/compiler/lib/utils/options.cpp +++ b/projects/clr/rocclr/compiler/lib/utils/options.cpp @@ -128,10 +128,10 @@ getDefault2(int OptDescTableIx, int64_t& idefault2, const char*& sdefault2) break; case OID_OptLevel: - idefault2 = 3; + idefault2 = amd::option::OPT_O3; break; - case OID_OptUseNative: + case OID_OptUseNative: sdefault2 = "all"; break; @@ -285,6 +285,8 @@ ShowOptionsHelp(const char* helpValue, Options& Opts) case OT_UINT32: pntVal = ""; break; + case OT_UCHAR: + pntVal = "<0-9 | a-z>"; default: break; } @@ -425,6 +427,10 @@ setOptionVariable (OptionDescriptor* oDesc, OptionVariables* oVars, OT_CSTRING_t* o = reinterpret_cast(addr); *o = static_cast(SValue); } + else if (OPTION_type(oDesc) == OT_UCHAR) { + OT_UCHAR_t* o = reinterpret_cast(addr); + *o = static_cast(IValue); + } else { return false; } @@ -452,6 +458,11 @@ setOptionVariable (OptionDescriptor* oDesc, OptionVariables* srcOVars, OT_UINT32_t* dst = reinterpret_cast(dstAddr); *dst = *src; } + else if (OPTION_type(oDesc) == OT_UCHAR) { + OT_UCHAR_t* src = reinterpret_cast(srcAddr); + OT_UCHAR_t* dst = reinterpret_cast(dstAddr); + *dst = *src; + } else if (OPTION_type(oDesc) == OT_CSTRING) { OT_CSTRING_t* src = reinterpret_cast(srcAddr); OT_CSTRING_t* dst = reinterpret_cast(dstAddr); @@ -670,6 +681,12 @@ processOption(int OptDescTableIx, Options& Opts, const std::string& Value, } break; + case OT_UCHAR: + { + ival = Value.at(0); + } + break; + case OT_INT32: ival = ::strtol(Value.c_str(), &p, 0); if (*p != '\0') { @@ -741,6 +758,14 @@ processOption(int OptDescTableIx, Options& Opts, const std::string& Value, } break; + case OID_OptLevel: + if (ival == 'g') { +#if defined(WITH_LIGHTNING_COMPILER) + Opts.clangOptions.push_back("-Og"); +#endif + } + break; + case OID_FiniteMathOnly: Opts.setFlag(OID_FiniteMathOnly, 1); tod = &OptDescTable[OID_FiniteMathOnly]; @@ -833,7 +858,6 @@ processOption(int OptDescTableIx, Options& Opts, const std::string& Value, } break; - case OID_DisableAllWarnings: if (ival != 0) { Opts.clcOptions.append(" --no_warnings"); @@ -1597,6 +1621,11 @@ bool Options::equals(const Options& other, bool ignoreClcOptions) const OT_CSTRING_t* o2 = reinterpret_cast(addr2); if (!isCStrOptionsEqual(*o,*o2)) return false; } + else if (OPTION_type(od) == OT_UCHAR) { + OT_UCHAR_t* o = reinterpret_cast(addr); + OT_UCHAR_t* o2 = reinterpret_cast(addr2); + if (*o != *o2) return false; + } else { return false; } diff --git a/projects/clr/rocclr/compiler/lib/utils/options.hpp b/projects/clr/rocclr/compiler/lib/utils/options.hpp index ceb4a9b34d..9f2f7635f1 100644 --- a/projects/clr/rocclr/compiler/lib/utils/options.hpp +++ b/projects/clr/rocclr/compiler/lib/utils/options.hpp @@ -31,6 +31,7 @@ enum OptionType { OT_INT32, OT_UINT32, OT_CSTRING, + OT_UCHAR, OT_MASK = 0x3f }; @@ -91,6 +92,7 @@ typedef bool OT_BOOL_t; typedef int32_t OT_INT32_t; typedef uint32_t OT_UINT32_t; typedef const char* OT_CSTRING_t; +typedef unsigned char OT_UCHAR_t; // This must be a POD struct OptionDescriptor { @@ -180,18 +182,20 @@ enum DumpFlags { }; enum OptLevelFlags { - OPT_O0 = 0, // No optimization setting. - OPT_O1 = 1, - OPT_O2 = 2, - OPT_O3 = 3, - OPT_O4 = 4, - OPT_OS = 5, - OPT_Error = 6, // Invalid optimization set + OPT_O0 = 48, // No optimization setting. + OPT_O1 = 49, + OPT_O2 = 50, + OPT_O3 = 51, + OPT_O4 = 52, + OPT_O5 = 53, + OPT_OG = 103, // g ASCII + OPT_OS = 115, // s ASCII + OPT_Error = 116, // Invalid optimization set /** Canary Value that guards against enum changes * @warning This value cannot be changed without updating the appropriate * tests and should NEVER be decreased. */ - optLast = 7 + optLast = 117 }; class Options {