@@ -77,12 +77,23 @@ static cl::opt<bool> EmitLgc("emit-lgc", cl::desc("Emit LLVM assembly suitable f
7777static cl::opt<bool > ShowEncoding (" show-encoding" , cl::desc(" Show instruction encodings" ), cl::init(false ));
7878
7979// -opt: Override the optimization level passed in to LGC with the given one.
80+ #if LLVM_MAIN_REVISION && LLVM_MAIN_REVISION < 474768
81+ // Old version of the code
8082static cl::opt<CodeGenOpt::Level> OptLevel (" opt" , cl::desc(" Set the optimization level for LGC:" ),
8183 cl::init(CodeGenOpt::Default),
8284 values(clEnumValN(CodeGenOpt::None, " none" , " no optimizations" ),
8385 clEnumValN(CodeGenOpt::Less, " quick" , " quick compilation time" ),
8486 clEnumValN(CodeGenOpt::Default, " default" , " default optimizations" ),
8587 clEnumValN(CodeGenOpt::Aggressive, " fast" , " fast execution time" )));
88+ #else
89+ // New version of the code (also handles unknown version, which we treat as latest)
90+ static cl::opt<CodeGenOptLevel>
91+ OptLevel (" opt" , cl::desc(" Set the optimization level for LGC:" ), cl::init(CodeGenOptLevel::Default),
92+ values(clEnumValN(CodeGenOptLevel::None, " none" , " no optimizations" ),
93+ clEnumValN(CodeGenOptLevel::Less, " quick" , " quick compilation time" ),
94+ clEnumValN(CodeGenOptLevel::Default, " default" , " default optimizations" ),
95+ clEnumValN(CodeGenOptLevel::Aggressive, " fast" , " fast execution time" )));
96+ #endif
8697
8798// =====================================================================================================================
8899// Set default for a command-line option, but only if command-line processing has not happened yet, or did not see
@@ -216,7 +227,14 @@ bool LgcContext::isGpuNameValid(llvm::StringRef gpuName) {
216227//
217228// @param gpuName : LLVM GPU name (e.g. "gfx900"); empty to use -mcpu option setting
218229// @param optLevel : LLVM optimization level used to initialize target machine
219- std::unique_ptr<TargetMachine> LgcContext::createTargetMachine (StringRef gpuName, CodeGenOpt::Level optLevel) {
230+ #if LLVM_MAIN_REVISION && LLVM_MAIN_REVISION < 474768
231+ // Old version of the code
232+ std::unique_ptr<TargetMachine> LgcContext::createTargetMachine (StringRef gpuName, CodeGenOpt::Level optLevel)
233+ #else
234+ // New version of the code (also handles unknown version, which we treat as latest)
235+ std::unique_ptr<TargetMachine> LgcContext::createTargetMachine (StringRef gpuName, CodeGenOptLevel optLevel)
236+ #endif
237+ {
220238 assert (Initialized && " Must call LgcContext::initialize before LgcContext::createTargetMachine" );
221239
222240 std::string mcpuName = codegen::getMCPU (); // -mcpu setting from llvm/CodeGen/CommandFlags.h
@@ -245,7 +263,7 @@ std::unique_ptr<TargetMachine> LgcContext::createTargetMachine(StringRef gpuName
245263 if (OptLevel.getPosition () != 0 )
246264 optLevel = OptLevel;
247265
248- LLPC_OUTS (" TargetMachine optimization level = " << optLevel << " \n " );
266+ LLPC_OUTS (" TargetMachine optimization level = " << static_cast < uint32_t >( optLevel) << " \n " );
249267
250268 return std::unique_ptr<TargetMachine>(target->createTargetMachine (triple, gpuName, " " , targetOpts, {}, {}, optLevel));
251269}
@@ -358,7 +376,14 @@ void LgcContext::addTargetPasses(lgc::LegacyPassManager &passMgr, Timer *codeGen
358376 passMgr.add (createStartStopTimer (codeGenTimer, false ));
359377}
360378
379+ #if LLVM_MAIN_REVISION && LLVM_MAIN_REVISION < 474768
380+ // Old version of the code
361381llvm::CodeGenOpt::Level LgcContext::getOptimizationLevel () const {
382+ #else
383+ // New version of the code (also handles unknown version, which we treat as latest)
384+ llvm::CodeGenOptLevel LgcContext::getOptimizationLevel () const {
385+ #endif
386+
362387 return m_targetMachine->getOptLevel ();
363388}
364389
0 commit comments