Skip to content

Commit d720223

Browse files
aparshin-inteligcbot
authored andcommitted
introduce VC controls for codegen optimization level
Previously there were no facilities to properly define the intended optimization level of VC codegen pipeline. This commit introduces this facilities (though it does not use them yet).
1 parent affc57b commit d720223

File tree

7 files changed

+55
-22
lines changed

7 files changed

+55
-22
lines changed

IGC/Options/include/igc/Options/VCApiOptions.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ def : PlainJoined<"optimize=">, Alias<vc_optimize>,
3131
def : PlainFlag<"no-optimize">, Alias<vc_optimize>,
3232
AliasArgs<["none"]>, HelpText<"Alias for -optimize=none">;
3333

34+
def vc_codegen_optimize : PlainSeparate<"codegen-optimize">,
35+
HelpText<"Set codegen optimization level to either 'none' or 'full'">,
36+
MetaVarName<"<level>">;
37+
def : PlainJoined<"codegen-optimize=">, Alias<vc_codegen_optimize>,
38+
HelpText<"Alias for -codegen-optimize">;
39+
3440
// This option switches off vector splitting in parts to better fit
3541
// into GRF. It may have both positive and negative consequences for
3642
// performance so shall be used with extreme caution.

IGC/VectorCompiler/igcdeps/src/TranslationInterface.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ static void adjustFileType(TC::TB_DATA_FORMAT DataFormat,
164164

165165
static void adjustOptLevel(vc::CompileOptions &Opts) {
166166
if (IGC_IS_FLAG_ENABLED(VCOptimizeNone))
167-
Opts.OptLevel = vc::OptimizerLevel::None;
167+
Opts.IROptLevel = vc::OptimizerLevel::None;
168168
}
169169

170170
static void adjustStackCalls(vc::CompileOptions &Opts, BuildDiag &Diag) {

IGC/VectorCompiler/include/vc/Driver/Driver.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ struct CompileOptions {
8282
// -fno-struct-splitting
8383
bool DisableStructSplitting = false;
8484

85-
OptimizerLevel OptLevel = OptimizerLevel::Full;
85+
OptimizerLevel IROptLevel = OptimizerLevel::Full;
86+
OptimizerLevel CodegenOptLevel = OptimizerLevel::Full;
87+
8688
llvm::Optional<unsigned> StackMemSize;
8789
bool ForceLiveRangesLocalizationForAccUsage = false;
8890
bool ForceDisableNonOverlappingRegionOpt = false;

IGC/VectorCompiler/lib/Driver/Driver.cpp

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ static std::string getSubtargetFeatureString(const vc::CompileOptions &Opts) {
177177
}
178178

179179
static CodeGenOpt::Level getCodeGenOptLevel(const vc::CompileOptions &Opts) {
180-
if (Opts.OptLevel == vc::OptimizerLevel::None)
180+
if (Opts.CodegenOptLevel == vc::OptimizerLevel::None)
181181
return CodeGenOpt::None;
182182
return CodeGenOpt::Default;
183183
}
@@ -236,7 +236,7 @@ static GenXBackendOptions createBackendOptions(const vc::CompileOptions &Opts) {
236236
(Opts.Binary == vc::BinaryKind::ZE);
237237
BackendOpts.DebuggabilityEmitBreakpoints = Opts.EmitExtendedDebug;
238238
bool IsOptLevel_O0 =
239-
Opts.OptLevel == vc::OptimizerLevel::None && Opts.EmitExtendedDebug;
239+
Opts.IROptLevel == vc::OptimizerLevel::None && Opts.EmitExtendedDebug;
240240
BackendOpts.DebuggabilityExtendedDebug =
241241
getDefaultOverridableFlag(Opts.NoOptFinalizerMode, IsOptLevel_O0);
242242

@@ -302,7 +302,7 @@ static void optimizeIR(const vc::CompileOptions &Opts,
302302
createTargetTransformInfoWrapperPass(TM.getTargetIRAnalysis()));
303303

304304
unsigned OptLevel;
305-
if (Opts.OptLevel == vc::OptimizerLevel::None)
305+
if (Opts.IROptLevel == vc::OptimizerLevel::None)
306306
OptLevel = 0;
307307
else
308308
OptLevel = 2;
@@ -596,6 +596,27 @@ static Error makeOptionError(const opt::Arg &A, const opt::ArgList &Opts,
596596
return make_error<vc::OptionError>(BadOpt, IsInternal);
597597
}
598598

599+
static Optional<vc::OptimizerLevel>
600+
parseOptimizationLevelString(StringRef Val) {
601+
return StringSwitch<Optional<vc::OptimizerLevel>>(Val)
602+
.Case("none", vc::OptimizerLevel::None)
603+
.Case("full", vc::OptimizerLevel::Full)
604+
.Default(None);
605+
}
606+
607+
template <typename OptSpecifier>
608+
static Optional<vc::OptimizerLevel>
609+
deriveOptimizationLevel(opt::Arg *A, OptSpecifier PrimaryOpt) {
610+
using namespace IGC::options::api;
611+
if (A->getOption().matches(PrimaryOpt)) {
612+
StringRef Val = A->getValue();
613+
return parseOptimizationLevelString(Val);
614+
} else {
615+
IGC_ASSERT(A->getOption().matches(OPT_opt_disable_ze));
616+
return vc::OptimizerLevel::None;
617+
}
618+
}
619+
599620
static Error fillApiOptions(const opt::ArgList &ApiOptions,
600621
vc::CompileOptions &Opts) {
601622
using namespace IGC::options::api;
@@ -636,19 +657,18 @@ static Error fillApiOptions(const opt::ArgList &ApiOptions,
636657

637658
if (opt::Arg *A =
638659
ApiOptions.getLastArg(OPT_vc_optimize, OPT_opt_disable_ze)) {
639-
if (A->getOption().matches(OPT_vc_optimize)) {
640-
StringRef Val = A->getValue();
641-
auto MaybeLevel = StringSwitch<Optional<vc::OptimizerLevel>>(Val)
642-
.Case("none", vc::OptimizerLevel::None)
643-
.Case("full", vc::OptimizerLevel::Full)
644-
.Default(None);
645-
if (!MaybeLevel)
646-
return makeOptionError(*A, ApiOptions, /*IsInternal=*/false);
647-
Opts.OptLevel = MaybeLevel.getValue();
648-
} else {
649-
IGC_ASSERT(A->getOption().matches(OPT_opt_disable_ze));
650-
Opts.OptLevel = vc::OptimizerLevel::None;
651-
}
660+
auto MaybeLevel = deriveOptimizationLevel(A, OPT_vc_optimize);
661+
if (!MaybeLevel)
662+
return makeOptionError(*A, ApiOptions, /*IsInternal=*/false);
663+
Opts.IROptLevel = MaybeLevel.getValue();
664+
}
665+
666+
if (opt::Arg *A =
667+
ApiOptions.getLastArg(OPT_vc_codegen_optimize, OPT_opt_disable_ze)) {
668+
auto MaybeLevel = deriveOptimizationLevel(A, OPT_vc_codegen_optimize);
669+
if (!MaybeLevel)
670+
return makeOptionError(*A, ApiOptions, /*IsInternal=*/false);
671+
Opts.CodegenOptLevel = MaybeLevel.getValue();
652672
}
653673

654674
if (opt::Arg *A = ApiOptions.getLastArg(OPT_vc_stateless_private_size)) {

IGC/VectorCompiler/lib/GenXCodeGen/GenXCisaBuilder.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6586,8 +6586,9 @@ collectFinalizerArgs(StringSaver &Saver, const GenXSubtarget &ST,
65866586
addArgument("-generateDebugInfo");
65876587
if (Info.EmitCrossThreadOffsetRelocation)
65886588
addArgument("-emitCrossThreadOffR0Reloc");
6589-
if (BC.emitExtendedDebugInfo())
6589+
if (Info.DisableFinalizerOpts)
65906590
addArgument("-debug");
6591+
65916592
if (BC.emitBreakpointAtKernelEntry()) {
65926593
addArgument("-addKernelID");
65936594
addArgument("-setstartbp");

IGC/VectorCompiler/lib/GenXCodeGen/GenXModule.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,15 @@ static bool isImplicitArgsBufferUsed(const Module &M) {
9898
*/
9999
bool GenXModule::runOnModule(Module &M) {
100100
auto FGA = &getAnalysis<FunctionGroupAnalysis>();
101-
ST = &getAnalysis<TargetPassConfig>()
102-
.getTM<GenXTargetMachine>()
103-
.getGenXSubtarget();
101+
const auto &TM = getAnalysis<TargetPassConfig>().getTM<GenXTargetMachine>();
102+
103+
ST = &TM.getGenXSubtarget();
104104
Ctx = &M.getContext();
105105
BC = &getAnalysis<GenXBackendConfig>();
106106

107107
InlineAsm = CheckForInlineAsm(M);
108108

109+
DisableFinalizerOpts = BC->emitExtendedDebugInfo();
109110
EmitDebugInformation =
110111
BC->emitDWARFDebugInfo() && vc::DIBuilder::checkIfModuleHasDebugInfo(M);
111112
ImplicitArgsBufferIsUsed = isImplicitArgsBufferUsed(M);
@@ -286,6 +287,7 @@ GenXModule::getVisaMapping(const Function *F) const {
286287
GenXModule::InfoForFinalizer GenXModule::getInfoForFinalizer() const {
287288
InfoForFinalizer Info;
288289
Info.EmitDebugInformation = EmitDebugInformation;
290+
Info.DisableFinalizerOpts = DisableFinalizerOpts;
289291
IGC_ASSERT_MESSAGE(
290292
ST,
291293
"GenXSubtarget must be defined to call GenXModule::getInfoForFinalizer");

IGC/VectorCompiler/lib/GenXCodeGen/GenXModule.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ namespace llvm {
8585
bool InlineAsm = false;
8686
bool CheckForInlineAsm(Module &M) const;
8787

88+
bool DisableFinalizerOpts = false;
8889
bool EmitDebugInformation = false;
8990
bool ImplicitArgsBufferIsUsed = false;
9091
// represents number of visa instructions in a *kernel*
@@ -106,6 +107,7 @@ namespace llvm {
106107

107108
// Additional info requred to create VISABuilder.
108109
struct InfoForFinalizer final {
110+
bool DisableFinalizerOpts = false;
109111
bool EmitDebugInformation = false;
110112
bool EmitCrossThreadOffsetRelocation = false;
111113
};

0 commit comments

Comments
 (0)