Skip to content

Commit 24f080b

Browse files
elizabethandrewsYang,Yin
authored and
Yang,Yin
committed
[SYCL] Restrict collection of information for optimization record (intel#6170)
Collect information for optimization record only if the optmization record is saved by user (i.e. -fsave-optimization-record or -opt-record-file is passed). This patch prevents unecessary calls to opt-report handlers when not required. I couldn't think of a way to add a test for this since there is no change in output. Information is collected when the flag is passed and emitted into optimization record. Information is no longer collected when there is no optimization record. This is a follow up to intel#3492 and intel#3730 Signed-off-by: Elizabeth Andrews <[email protected]>
1 parent f67c117 commit 24f080b

File tree

5 files changed

+53
-26
lines changed

5 files changed

+53
-26
lines changed

clang/include/clang/Basic/LangOptions.h

+4
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,10 @@ class LangOptions : public LangOptionsBase {
470470
/// The seed used by the randomize structure layout feature.
471471
std::string RandstructSeed;
472472

473+
/// The name of the file to which the backend should save YAML optimization
474+
/// records.
475+
std::string OptRecordFile;
476+
473477
LangOptions();
474478

475479
/// Set language defaults for the given input language and

clang/include/clang/Driver/Options.td

+1-1
Original file line numberDiff line numberDiff line change
@@ -5897,7 +5897,7 @@ def arcmt_action_EQ : Joined<["-"], "arcmt-action=">, Flags<[CC1Option, NoDriver
58975897

58985898
def opt_record_file : Separate<["-"], "opt-record-file">,
58995899
HelpText<"File name to use for YAML optimization record output">,
5900-
MarshallingInfoString<CodeGenOpts<"OptRecordFile">>;
5900+
MarshallingInfoString<LangOpts<"OptRecordFile">>;
59015901
def opt_record_passes : Separate<["-"], "opt-record-passes">,
59025902
HelpText<"Only record remark information for passes whose names match the given regular expression">;
59035903
def opt_record_format : Separate<["-"], "opt-record-format">,

clang/lib/CodeGen/CodeGenFunction.cpp

+21-20
Original file line numberDiff line numberDiff line change
@@ -1602,26 +1602,27 @@ void CodeGenFunction::GenerateCode(GlobalDecl GD, llvm::Function *Fn,
16021602

16031603
// Emit the standard function prologue.
16041604
StartFunction(GD, ResTy, Fn, FnInfo, Args, Loc, BodyRange.getBegin());
1605-
1606-
SyclOptReportHandler &SyclOptReport = CGM.getDiags().getSYCLOptReport();
1607-
if (Fn && SyclOptReport.HasOptReportInfo(FD)) {
1608-
llvm::OptimizationRemarkEmitter ORE(Fn);
1609-
for (auto ORI : llvm::enumerate(SyclOptReport.GetInfo(FD))) {
1610-
llvm::DiagnosticLocation DL =
1611-
SourceLocToDebugLoc(ORI.value().KernelArgLoc);
1612-
StringRef NameInDesc = ORI.value().KernelArgDescName;
1613-
StringRef ArgType = ORI.value().KernelArgType;
1614-
StringRef ArgDesc = ORI.value().KernelArgDesc;
1615-
unsigned ArgSize = ORI.value().KernelArgSize;
1616-
StringRef ArgDecomposedField = ORI.value().KernelArgDecomposedField;
1617-
1618-
llvm::OptimizationRemark Remark("sycl", "Region", DL,
1619-
&Fn->getEntryBlock());
1620-
Remark << "Arg " << llvm::ore::NV("Argument", ORI.index()) << ":"
1621-
<< ArgDesc << NameInDesc << " (" << ArgDecomposedField
1622-
<< "Type:" << ArgType << ", "
1623-
<< "Size: " << llvm::ore::NV("Argument", ArgSize) << ")";
1624-
ORE.emit(Remark);
1605+
if (!getLangOpts().OptRecordFile.empty()) {
1606+
SyclOptReportHandler &SyclOptReport = CGM.getDiags().getSYCLOptReport();
1607+
if (Fn && SyclOptReport.HasOptReportInfo(FD)) {
1608+
llvm::OptimizationRemarkEmitter ORE(Fn);
1609+
for (auto ORI : llvm::enumerate(SyclOptReport.GetInfo(FD))) {
1610+
llvm::DiagnosticLocation DL =
1611+
SourceLocToDebugLoc(ORI.value().KernelArgLoc);
1612+
StringRef NameInDesc = ORI.value().KernelArgDescName;
1613+
StringRef ArgType = ORI.value().KernelArgType;
1614+
StringRef ArgDesc = ORI.value().KernelArgDesc;
1615+
unsigned ArgSize = ORI.value().KernelArgSize;
1616+
StringRef ArgDecomposedField = ORI.value().KernelArgDecomposedField;
1617+
1618+
llvm::OptimizationRemark Remark("sycl", "Region", DL,
1619+
&Fn->getEntryBlock());
1620+
Remark << "Arg " << llvm::ore::NV("Argument", ORI.index()) << ":"
1621+
<< ArgDesc << NameInDesc << " (" << ArgDecomposedField
1622+
<< "Type:" << ArgType << ", "
1623+
<< "Size: " << llvm::ore::NV("Argument", ArgSize) << ")";
1624+
ORE.emit(Remark);
1625+
}
16251626
}
16261627
}
16271628

clang/lib/Frontend/CompilerInvocation.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -1946,6 +1946,8 @@ bool CompilerInvocation::ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args,
19461946

19471947
bool NeedLocTracking = false;
19481948

1949+
Opts.OptRecordFile = LangOpts->OptRecordFile;
1950+
19491951
if (!Opts.OptRecordFile.empty())
19501952
NeedLocTracking = true;
19511953

@@ -3318,6 +3320,8 @@ void CompilerInvocation::GenerateLangArgs(const LangOptions &Opts,
33183320
GenerateArg(Args, OPT_pic_is_pie, SA);
33193321
for (StringRef Sanitizer : serializeSanitizerKinds(Opts.Sanitize))
33203322
GenerateArg(Args, OPT_fsanitize_EQ, Sanitizer, SA);
3323+
if (!Opts.OptRecordFile.empty())
3324+
GenerateArg(Args, OPT_opt_record_file, Opts.OptRecordFile, SA);
33213325

33223326
return;
33233327
}
@@ -3617,6 +3621,12 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args,
36173621
parseSanitizerKinds("-fsanitize=", Args.getAllArgValues(OPT_fsanitize_EQ),
36183622
Diags, Opts.Sanitize);
36193623

3624+
// OptRecordFile is used to generate the optimization record file should
3625+
// be set regardless of the input type.
3626+
if (Args.hasArg(OPT_opt_record_file))
3627+
Opts.OptRecordFile =
3628+
std::string(Args.getLastArgValue(OPT_opt_record_file));
3629+
36203630
return Diags.getNumErrors() == NumErrorsBefore;
36213631
}
36223632

clang/lib/Sema/SemaSYCL.cpp

+17-5
Original file line numberDiff line numberDiff line change
@@ -3669,17 +3669,29 @@ void Sema::ConstructOpenCLKernel(FunctionDecl *KernelCallerFunc,
36693669
SyclOptReportCreator opt_report(*this, kernel_decl, KernelObj->getLocation());
36703670

36713671
KernelObjVisitor Visitor{*this};
3672-
Visitor.VisitRecordBases(KernelObj, kernel_decl, kernel_body, int_header,
3673-
int_footer, opt_report);
3674-
Visitor.VisitRecordFields(KernelObj, kernel_decl, kernel_body, int_header,
3675-
int_footer, opt_report);
3672+
3673+
// Visit handlers to generate information for optimization record only if
3674+
// optimization record is saved.
3675+
if (!getLangOpts().OptRecordFile.empty()) {
3676+
Visitor.VisitRecordBases(KernelObj, kernel_decl, kernel_body, int_header,
3677+
int_footer, opt_report);
3678+
Visitor.VisitRecordFields(KernelObj, kernel_decl, kernel_body, int_header,
3679+
int_footer, opt_report);
3680+
} else {
3681+
Visitor.VisitRecordBases(KernelObj, kernel_decl, kernel_body, int_header,
3682+
int_footer);
3683+
Visitor.VisitRecordFields(KernelObj, kernel_decl, kernel_body, int_header,
3684+
int_footer);
3685+
}
36763686

36773687
if (ParmVarDecl *KernelHandlerArg =
36783688
getSyclKernelHandlerArg(KernelCallerFunc)) {
36793689
kernel_decl.handleSyclKernelHandlerType();
36803690
kernel_body.handleSyclKernelHandlerType(KernelHandlerArg);
36813691
int_header.handleSyclKernelHandlerType(KernelHandlerArg->getType());
3682-
opt_report.handleSyclKernelHandlerType();
3692+
3693+
if (!getLangOpts().OptRecordFile.empty())
3694+
opt_report.handleSyclKernelHandlerType();
36833695
}
36843696
}
36853697

0 commit comments

Comments
 (0)