Skip to content

[SYCL] Restrict collection of information for optimization record #6170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions clang/include/clang/Basic/LangOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,10 @@ class LangOptions : public LangOptionsBase {
/// The seed used by the randomize structure layout feature.
std::string RandstructSeed;

/// The name of the file to which the backend should save YAML optimization
/// records.
std::string OptRecordFile;

LangOptions();

/// Set language defaults for the given input language and
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -5897,7 +5897,7 @@ def arcmt_action_EQ : Joined<["-"], "arcmt-action=">, Flags<[CC1Option, NoDriver

def opt_record_file : Separate<["-"], "opt-record-file">,
HelpText<"File name to use for YAML optimization record output">,
MarshallingInfoString<CodeGenOpts<"OptRecordFile">>;
MarshallingInfoString<LangOpts<"OptRecordFile">>;
def opt_record_passes : Separate<["-"], "opt-record-passes">,
HelpText<"Only record remark information for passes whose names match the given regular expression">;
def opt_record_format : Separate<["-"], "opt-record-format">,
Expand Down
41 changes: 21 additions & 20 deletions clang/lib/CodeGen/CodeGenFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1602,26 +1602,27 @@ void CodeGenFunction::GenerateCode(GlobalDecl GD, llvm::Function *Fn,

// Emit the standard function prologue.
StartFunction(GD, ResTy, Fn, FnInfo, Args, Loc, BodyRange.getBegin());

SyclOptReportHandler &SyclOptReport = CGM.getDiags().getSYCLOptReport();
if (Fn && SyclOptReport.HasOptReportInfo(FD)) {
llvm::OptimizationRemarkEmitter ORE(Fn);
for (auto ORI : llvm::enumerate(SyclOptReport.GetInfo(FD))) {
llvm::DiagnosticLocation DL =
SourceLocToDebugLoc(ORI.value().KernelArgLoc);
StringRef NameInDesc = ORI.value().KernelArgDescName;
StringRef ArgType = ORI.value().KernelArgType;
StringRef ArgDesc = ORI.value().KernelArgDesc;
unsigned ArgSize = ORI.value().KernelArgSize;
StringRef ArgDecomposedField = ORI.value().KernelArgDecomposedField;

llvm::OptimizationRemark Remark("sycl", "Region", DL,
&Fn->getEntryBlock());
Remark << "Arg " << llvm::ore::NV("Argument", ORI.index()) << ":"
<< ArgDesc << NameInDesc << " (" << ArgDecomposedField
<< "Type:" << ArgType << ", "
<< "Size: " << llvm::ore::NV("Argument", ArgSize) << ")";
ORE.emit(Remark);
if (!getLangOpts().OptRecordFile.empty()) {
SyclOptReportHandler &SyclOptReport = CGM.getDiags().getSYCLOptReport();
if (Fn && SyclOptReport.HasOptReportInfo(FD)) {
llvm::OptimizationRemarkEmitter ORE(Fn);
for (auto ORI : llvm::enumerate(SyclOptReport.GetInfo(FD))) {
llvm::DiagnosticLocation DL =
SourceLocToDebugLoc(ORI.value().KernelArgLoc);
StringRef NameInDesc = ORI.value().KernelArgDescName;
StringRef ArgType = ORI.value().KernelArgType;
StringRef ArgDesc = ORI.value().KernelArgDesc;
unsigned ArgSize = ORI.value().KernelArgSize;
StringRef ArgDecomposedField = ORI.value().KernelArgDecomposedField;

llvm::OptimizationRemark Remark("sycl", "Region", DL,
&Fn->getEntryBlock());
Remark << "Arg " << llvm::ore::NV("Argument", ORI.index()) << ":"
<< ArgDesc << NameInDesc << " (" << ArgDecomposedField
<< "Type:" << ArgType << ", "
<< "Size: " << llvm::ore::NV("Argument", ArgSize) << ")";
ORE.emit(Remark);
}
}
}

Expand Down
10 changes: 10 additions & 0 deletions clang/lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1946,6 +1946,8 @@ bool CompilerInvocation::ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args,

bool NeedLocTracking = false;

Opts.OptRecordFile = LangOpts->OptRecordFile;

if (!Opts.OptRecordFile.empty())
NeedLocTracking = true;

Expand Down Expand Up @@ -3318,6 +3320,8 @@ void CompilerInvocation::GenerateLangArgs(const LangOptions &Opts,
GenerateArg(Args, OPT_pic_is_pie, SA);
for (StringRef Sanitizer : serializeSanitizerKinds(Opts.Sanitize))
GenerateArg(Args, OPT_fsanitize_EQ, Sanitizer, SA);
if (!Opts.OptRecordFile.empty())
GenerateArg(Args, OPT_opt_record_file, Opts.OptRecordFile, SA);

return;
}
Expand Down Expand Up @@ -3617,6 +3621,12 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args,
parseSanitizerKinds("-fsanitize=", Args.getAllArgValues(OPT_fsanitize_EQ),
Diags, Opts.Sanitize);

// OptRecordFile is used to generate the optimization record file should
// be set regardless of the input type.
if (Args.hasArg(OPT_opt_record_file))
Opts.OptRecordFile =
std::string(Args.getLastArgValue(OPT_opt_record_file));

return Diags.getNumErrors() == NumErrorsBefore;
}

Expand Down
22 changes: 17 additions & 5 deletions clang/lib/Sema/SemaSYCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3669,17 +3669,29 @@ void Sema::ConstructOpenCLKernel(FunctionDecl *KernelCallerFunc,
SyclOptReportCreator opt_report(*this, kernel_decl, KernelObj->getLocation());

KernelObjVisitor Visitor{*this};
Visitor.VisitRecordBases(KernelObj, kernel_decl, kernel_body, int_header,
int_footer, opt_report);
Visitor.VisitRecordFields(KernelObj, kernel_decl, kernel_body, int_header,
int_footer, opt_report);

// Visit handlers to generate information for optimization record only if
// optimization record is saved.
if (!getLangOpts().OptRecordFile.empty()) {
Visitor.VisitRecordBases(KernelObj, kernel_decl, kernel_body, int_header,
int_footer, opt_report);
Visitor.VisitRecordFields(KernelObj, kernel_decl, kernel_body, int_header,
int_footer, opt_report);
} else {
Visitor.VisitRecordBases(KernelObj, kernel_decl, kernel_body, int_header,
int_footer);
Visitor.VisitRecordFields(KernelObj, kernel_decl, kernel_body, int_header,
int_footer);
}

if (ParmVarDecl *KernelHandlerArg =
getSyclKernelHandlerArg(KernelCallerFunc)) {
kernel_decl.handleSyclKernelHandlerType();
kernel_body.handleSyclKernelHandlerType(KernelHandlerArg);
int_header.handleSyclKernelHandlerType(KernelHandlerArg->getType());
opt_report.handleSyclKernelHandlerType();

if (!getLangOpts().OptRecordFile.empty())
opt_report.handleSyclKernelHandlerType();
}
}

Expand Down