Skip to content

Commit a5796b3

Browse files
bcardosolopesxlauko
authored andcommitted
[CIR] Add initial support for idiom recognizing std::find
- Identify such calls and produce a remark. Next step is to map this to a CIR operation representing std::find, which should come next. - Add new `-fclangir-idiom-recognizer=` option, used to control remark options for now.
1 parent 7b473fe commit a5796b3

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

clang/include/clang/Frontend/FrontendOptions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,7 @@ class FrontendOptions {
462462
frontend::MLIRDialectKind MLIRTargetDialect;
463463

464464
std::string ClangIRLifetimeCheckOpts;
465+
std::string ClangIRIdiomRecognizerOpts;
465466

466467
/// The input kind, either specified via -x argument or deduced from the input
467468
/// file name.

clang/lib/CIR/FrontendAction/CIRGenAction.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ using namespace cir;
6060
using namespace clang;
6161

6262
static std::string sanitizePassOptions(llvm::StringRef o) {
63+
if (o.empty())
64+
return "";
6365
std::string opts{o};
6466
// MLIR pass options are space separated, but we use ';' in clang since
6567
// space aren't well supported, switch it back.
@@ -172,15 +174,18 @@ class CIRGenConsumer : public clang::ASTConsumer {
172174
// Sanitize passes options. MLIR uses spaces between pass options
173175
// and since that's hard to fly in clang, we currently use ';'.
174176
std::string lifetimeOpts;
177+
std::string idiomRecognizerOpts;
175178
if (feOptions.ClangIRLifetimeCheck)
176179
lifetimeOpts = sanitizePassOptions(feOptions.ClangIRLifetimeCheckOpts);
180+
idiomRecognizerOpts =
181+
sanitizePassOptions(feOptions.ClangIRIdiomRecognizerOpts);
177182

178183
// Setup and run CIR pipeline.
179184
bool passOptParsingFailure = false;
180185
if (runCIRToCIRPasses(mlirMod, mlirCtx.get(), C,
181186
!feOptions.ClangIRDisableCIRVerifier,
182187
feOptions.ClangIRLifetimeCheck, lifetimeOpts,
183-
passOptParsingFailure)
188+
idiomRecognizerOpts, passOptParsingFailure)
184189
.failed()) {
185190
if (passOptParsingFailure)
186191
diagnosticsEngine.Report(diag::err_drv_cir_pass_opt_parsing)

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3187,6 +3187,10 @@ static bool ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args,
31873187
Opts.ClangIRLifetimeCheckOpts = A->getValue();
31883188
}
31893189

3190+
if (Args.hasArg(OPT_fclangir_idiom_recognizer_EQ))
3191+
Opts.AuxTargetCPU =
3192+
std::string(Args.getLastArgValue(OPT_fclangir_idiom_recognizer_EQ));
3193+
31903194
if (Args.hasArg(OPT_aux_target_cpu))
31913195
Opts.AuxTargetCPU = std::string(Args.getLastArgValue(OPT_aux_target_cpu));
31923196
if (Args.hasArg(OPT_aux_target_feature))

0 commit comments

Comments
 (0)