Skip to content

Commit 07966ba

Browse files
committed
Update to realign with incubator changes
1 parent 290ee42 commit 07966ba

File tree

9 files changed

+39
-61
lines changed

9 files changed

+39
-61
lines changed

clang/include/clang/CIR/FrontendAction/CIRGenAction.h

+1-9
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,9 @@ class CIRGenAction : public clang::ASTFrontendAction {
2626
public:
2727
enum class OutputType {
2828
EmitAssembly,
29-
EmitCIR,
29+
EmitMLIR,
3030
EmitLLVM,
3131
EmitBC,
32-
EmitMLIR,
3332
EmitObj,
3433
};
3534

@@ -53,13 +52,6 @@ class CIRGenAction : public clang::ASTFrontendAction {
5352
OutputType Action;
5453
};
5554

56-
class EmitCIRAction : public CIRGenAction {
57-
virtual void anchor();
58-
59-
public:
60-
EmitCIRAction(mlir::MLIRContext *MLIRCtx = nullptr);
61-
};
62-
6355
class EmitMLIRAction : public CIRGenAction {
6456
virtual void anchor();
6557

clang/include/clang/Driver/Options.td

+7-6
Original file line numberDiff line numberDiff line change
@@ -2985,15 +2985,16 @@ defm clangir : BoolFOption<"clangir",
29852985
PosFlag<SetTrue, [], [ClangOption, CC1Option], "Use the ClangIR pipeline to compile">,
29862986
NegFlag<SetFalse, [], [ClangOption, CC1Option], "Use the AST -> LLVM pipeline to compile">,
29872987
BothFlags<[], [ClangOption, CC1Option], "">>;
2988-
def emit_cir : Flag<["-"], "emit-cir">, Visibility<[ClangOption, CC1Option]>,
2989-
Group<Action_Group>, HelpText<"Build ASTs and then lower to ClangIR">;
2990-
def emit_mlir_EQ : Joined<["-"], "emit-mlir=">, Visibility<[CC1Option]>, Group<Action_Group>,
2991-
HelpText<"Build ASTs and then generate/lower to the selected MLIR dialect, emit the .mlir or .cir file. "
2988+
def emit_mlir_EQ : Joined<["-"], "emit-mlir=">, Visibility<[ClangOption, CC1Option]>, Group<Action_Group>,
2989+
HelpText<"Build ASTs and then generate/lower to the selected MLIR dialect, emit the .mlir file. "
29922990
"Allowed values are `core` for MLIR core dialects and `cir` for ClangIR">,
29932991
Values<"core,cir">,
29942992
NormalizedValuesScope<"clang::frontend">,
2995-
NormalizedValues<["MLIR_Core", "MLIR_CIR"]>,
2996-
MarshallingInfoEnum<FrontendOpts<"MLIRTargetDialect">, "MLIR_CIR">;
2993+
NormalizedValues<["MLIR_CORE", "MLIR_CIR"]>,
2994+
MarshallingInfoEnum<FrontendOpts<"MLIRTargetDialect">, "MLIR_CORE">;
2995+
def emit_cir : Flag<["-"], "emit-cir">, Visibility<[ClangOption, CC1Option]>,
2996+
Group<Action_Group>, Alias<emit_mlir_EQ>, AliasArgs<["cir"]>,
2997+
HelpText<"Build ASTs and then lower to ClangIR">;
29972998
/// ClangIR-specific options - END
29982999

29993000
def flto_EQ : Joined<["-"], "flto=">,

clang/include/clang/Driver/Types.def

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ TYPE("ir", LLVM_BC, INVALID, "bc", phases
9999
TYPE("lto-ir", LTO_IR, INVALID, "s", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
100100
TYPE("lto-bc", LTO_BC, INVALID, "o", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
101101

102-
TYPE("cir", CIR, INVALID, "cir", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
102+
TYPE("mlir", MLIR, INVALID, "mlir", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
103103
// Misc.
104104
TYPE("ast", AST, INVALID, "ast", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
105105
TYPE("ifs", IFS, INVALID, "ifs", phases::IfsMerge)

clang/include/clang/Frontend/FrontendOptions.h

+2-5
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,6 @@ enum ActionKind {
6565
/// Translate input source into HTML.
6666
EmitHTML,
6767

68-
/// Emit a .cir file
69-
EmitCIR,
70-
7168
/// Emit a .mlir file
7269
EmitMLIR,
7370

@@ -151,7 +148,7 @@ enum ActionKind {
151148
PrintDependencyDirectivesSourceMinimizerOutput
152149
};
153150

154-
enum MLIRDialectKind { MLIR_CIR, MLIR_Core };
151+
enum MLIRDialectKind { MLIR_CORE, MLIR_CIR };
155152

156153
} // namespace frontend
157154

@@ -422,7 +419,7 @@ class FrontendOptions {
422419
/// Specifies the output format of the AST.
423420
ASTDumpOutputFormat ASTDumpFormat = ADOF_Default;
424421

425-
frontend::MLIRDialectKind MLIRTargetDialect = frontend::MLIR_CIR;
422+
frontend::MLIRDialectKind MLIRTargetDialect;
426423

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

clang/lib/CIR/FrontendAction/CIRGenAction.cpp

+16-23
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ namespace cir {
2424
static BackendAction
2525
getBackendActionFromOutputType(CIRGenAction::OutputType Action) {
2626
switch (Action) {
27-
case CIRGenAction::OutputType::EmitCIR:
2827
case CIRGenAction::OutputType::EmitMLIR:
2928
assert(false &&
3029
"Unsupported output type for getBackendActionFromOutputType!");
@@ -85,28 +84,28 @@ class CIRGenConsumer : public clang::ASTConsumer {
8584
Gen->HandleTranslationUnit(C);
8685
mlir::ModuleOp MlirModule = Gen->getModule();
8786
mlir::MLIRContext &MlirCtx = Gen->getMLIRContext();
87+
88+
auto emitMLIR = [&](mlir::Operation *MlirMod) {
89+
assert(MlirMod &&
90+
"MLIR module does not exist, but lowering did not fail?");
91+
assert(OutputStream && "Missing output stream when emitting MLIR!");
92+
// FIXME: we cannot roundtrip prettyForm=true right now.
93+
mlir::OpPrintingFlags Flags;
94+
Flags.enableDebugInfo(/*enable=*/true, /*prettyForm=*/false);
95+
MlirMod->print(*OutputStream, Flags);
96+
};
97+
8898
switch (Action) {
89-
case CIRGenAction::OutputType::EmitCIR:
90-
assert(CI.getFrontendOpts().MLIRTargetDialect == frontend::MLIR_CIR);
9199
case CIRGenAction::OutputType::EmitMLIR: {
92100
switch (CI.getFrontendOpts().MLIRTargetDialect) {
93-
case frontend::MLIR_CIR:
94-
if (OutputStream && MlirModule) {
95-
mlir::OpPrintingFlags Flags;
96-
Flags.enableDebugInfo(/*enable=*/true, /*prettyForm=*/false);
97-
MlirModule->print(*OutputStream, Flags);
98-
}
101+
case frontend::MLIR_CORE:
102+
emitMLIR(lowerFromCIRToMLIR(MlirModule, MlirCtx));
99103
break;
100-
case frontend::MLIR_Core:
101-
mlir::ModuleOp LoweredMlirModule =
102-
lowerFromCIRToMLIR(MlirModule, MlirCtx);
103-
assert(OutputStream && "No output stream when lowering to MLIR!");
104-
// FIXME: we cannot roundtrip prettyForm=true right now.
105-
mlir::OpPrintingFlags Flags;
106-
Flags.enableDebugInfo(/*enable=*/true, /*prettyForm=*/false);
107-
LoweredMlirModule->print(*OutputStream, Flags);
104+
case frontend::MLIR_CIR:
105+
emitMLIR(MlirModule);
108106
break;
109107
}
108+
break;
110109
}
111110
case CIRGenAction::OutputType::EmitLLVM:
112111
case CIRGenAction::OutputType::EmitBC:
@@ -140,8 +139,6 @@ getOutputStream(CompilerInstance &CI, StringRef InFile,
140139
switch (Action) {
141140
case CIRGenAction::OutputType::EmitAssembly:
142141
return CI.createDefaultOutputFile(false, InFile, "s");
143-
case CIRGenAction::OutputType::EmitCIR:
144-
return CI.createDefaultOutputFile(false, InFile, "cir");
145142
case CIRGenAction::OutputType::EmitMLIR:
146143
return CI.createDefaultOutputFile(false, InFile, "mlir");
147144
case CIRGenAction::OutputType::EmitLLVM:
@@ -171,10 +168,6 @@ void EmitAssemblyAction::anchor() {}
171168
EmitAssemblyAction::EmitAssemblyAction(mlir::MLIRContext *MLIRCtx)
172169
: CIRGenAction(OutputType::EmitAssembly, MLIRCtx) {}
173170

174-
void EmitCIRAction::anchor() {}
175-
EmitCIRAction::EmitCIRAction(mlir::MLIRContext *MLIRCtx)
176-
: CIRGenAction(OutputType::EmitCIR, MLIRCtx) {}
177-
178171
void EmitMLIRAction::anchor() {}
179172
EmitMLIRAction::EmitMLIRAction(mlir::MLIRContext *MLIRCtx)
180173
: CIRGenAction(OutputType::EmitMLIR, MLIRCtx) {}

clang/lib/Driver/Driver.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -5127,8 +5127,8 @@ Action *Driver::ConstructPhaseAction(
51275127
return C.MakeAction<AnalyzeJobAction>(Input, types::TY_Plist);
51285128
if (Args.hasArg(options::OPT_emit_ast))
51295129
return C.MakeAction<CompileJobAction>(Input, types::TY_AST);
5130-
if (Args.hasArg(options::OPT_emit_cir))
5131-
return C.MakeAction<CompileJobAction>(Input, types::TY_CIR);
5130+
if (Args.hasArg(options::OPT_emit_mlir_EQ))
5131+
return C.MakeAction<CompileJobAction>(Input, types::TY_MLIR);
51325132
if (Args.hasArg(options::OPT_module_file_info))
51335133
return C.MakeAction<CompileJobAction>(Input, types::TY_ModuleFile);
51345134
if (Args.hasArg(options::OPT_verify_pch))

clang/lib/Driver/ToolChains/Clang.cpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -5215,7 +5215,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
52155215
}
52165216
}
52175217

5218-
if (Args.hasArg(options::OPT_fclangir))
5218+
if (Args.hasArg(options::OPT_fclangir) ||
5219+
Args.hasArg(options::OPT_emit_mlir_EQ))
52195220
CmdArgs.push_back("-fclangir");
52205221

52215222
if (IsOpenMPDevice) {
@@ -5384,8 +5385,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
53845385
} else if (JA.getType() == types::TY_RewrittenLegacyObjC) {
53855386
CmdArgs.push_back("-rewrite-objc");
53865387
rewriteKind = RK_Fragile;
5387-
} else if (JA.getType() == types::TY_CIR) {
5388-
CmdArgs.push_back("-emit-cir");
5388+
} else if (JA.getType() == types::TY_MLIR) {
5389+
CmdArgs.push_back(Args.MakeArgString(
5390+
Twine("-emit-mlir=") +
5391+
Args.getLastArgValue(options::OPT_emit_mlir_EQ)));
53895392
} else {
53905393
assert(JA.getType() == types::TY_PP_Asm && "Unexpected output type!");
53915394
}

clang/lib/Frontend/CompilerInvocation.cpp

+3-5
Original file line numberDiff line numberDiff line change
@@ -2739,7 +2739,6 @@ static const auto &getFrontendActionTable() {
27392739
{frontend::DumpTokens, OPT_dump_tokens},
27402740
{frontend::EmitAssembly, OPT_S},
27412741
{frontend::EmitBC, OPT_emit_llvm_bc},
2742-
{frontend::EmitCIR, OPT_emit_cir},
27432742
{frontend::EmitMLIR, OPT_emit_mlir_EQ},
27442743
{frontend::EmitHTML, OPT_emit_html},
27452744
{frontend::EmitLLVM, OPT_emit_llvm},
@@ -2859,8 +2858,8 @@ static void GenerateFrontendArgs(const FrontendOptions &Opts,
28592858

28602859
if (Opts.ProgramAction == frontend::EmitMLIR) {
28612860
GenerateProgramAction = [&]() {
2862-
if (Opts.MLIRTargetDialect == frontend::MLIR_CIR)
2863-
GenerateArg(Consumer, OPT_emit_cir);
2861+
if (Opts.MLIRTargetDialect == frontend::MLIR_CORE)
2862+
GenerateArg(Consumer, OPT_emit_mlir_EQ, "core");
28642863
};
28652864
}
28662865

@@ -3110,7 +3109,7 @@ static bool ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args,
31103109
if (Opts.ProgramAction != frontend::GenerateModule && Opts.IsSystemModule)
31113110
Diags.Report(diag::err_drv_argument_only_allowed_with) << "-fsystem-module"
31123111
<< "-emit-module";
3113-
if (Args.hasArg(OPT_fclangir) || Args.hasArg(OPT_emit_cir))
3112+
if (Args.hasArg(OPT_fclangir) || Args.hasArg(OPT_emit_mlir_EQ))
31143113
Opts.UseClangIRPipeline = true;
31153114

31163115
if (Args.hasArg(OPT_aux_target_cpu))
@@ -4638,7 +4637,6 @@ static bool isStrictlyPreprocessorAction(frontend::ActionKind Action) {
46384637
case frontend::ASTView:
46394638
case frontend::EmitAssembly:
46404639
case frontend::EmitBC:
4641-
case frontend::EmitCIR:
46424640
case frontend::EmitMLIR:
46434641
case frontend::EmitHTML:
46444642
case frontend::EmitLLVM:

clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp

+1-7
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ CreateFrontendBaseAction(CompilerInstance &CI) {
4848

4949
unsigned UseCIR = CI.getFrontendOpts().UseClangIRPipeline;
5050
frontend::ActionKind Act = CI.getFrontendOpts().ProgramAction;
51-
bool EmitsCIR = Act == EmitCIR;
51+
bool EmitsCIR = Act == EmitMLIR;
5252

5353
if (!UseCIR && EmitsCIR)
5454
llvm::report_fatal_error("-emit-cir and only valid when using -fclangir");
@@ -74,12 +74,6 @@ CreateFrontendBaseAction(CompilerInstance &CI) {
7474
return std::make_unique<cir::EmitBCAction>();
7575
#endif
7676
return std::make_unique<EmitBCAction>();
77-
case EmitCIR:
78-
#if CLANG_ENABLE_CIR
79-
return std::make_unique<cir::EmitCIRAction>();
80-
#else
81-
llvm_unreachable("CIR suppport not built into clang");
82-
#endif
8377
case EmitMLIR:
8478
#if CLANG_ENABLE_CIR
8579
return std::make_unique<cir::EmitMLIRAction>();

0 commit comments

Comments
 (0)