Skip to content

Commit 359ab3a

Browse files
authored
[CIR] Add options to emit ClangIR and enable the ClangIR pipeline
Introduce just the option definitions and support for their existance at a few different points in the frontend. This will be followed soon by functionality that uses it. Reviewers: bcardosolopes, jansvoboda11, AaronBallman, erichkeane, MaskRay Reviewed By: erichkeane Pull Request: #89030
1 parent 99ce84c commit 359ab3a

File tree

5 files changed

+28
-1
lines changed

5 files changed

+28
-1
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2886,6 +2886,17 @@ def flax_vector_conversions : Flag<["-"], "flax-vector-conversions">, Group<f_Gr
28862886
def flimited_precision_EQ : Joined<["-"], "flimited-precision=">, Group<f_Group>;
28872887
def fapple_link_rtlib : Flag<["-"], "fapple-link-rtlib">, Group<f_Group>,
28882888
HelpText<"Force linking the clang builtins runtime library">;
2889+
2890+
/// ClangIR-specific options - BEGIN
2891+
defm clangir : BoolFOption<"clangir",
2892+
FrontendOpts<"UseClangIRPipeline">, DefaultFalse,
2893+
PosFlag<SetTrue, [], [ClangOption, CC1Option], "Use the ClangIR pipeline to compile">,
2894+
NegFlag<SetFalse, [], [ClangOption, CC1Option], "Use the AST -> LLVM pipeline to compile">,
2895+
BothFlags<[], [ClangOption, CC1Option], "">>;
2896+
def emit_cir : Flag<["-"], "emit-cir">, Visibility<[CC1Option]>,
2897+
Group<Action_Group>, HelpText<"Build ASTs and then lower to ClangIR">;
2898+
/// ClangIR-specific options - END
2899+
28892900
def flto_EQ : Joined<["-"], "flto=">,
28902901
Visibility<[ClangOption, CLOption, CC1Option, FC1Option, FlangOption]>,
28912902
Group<f_Group>,

clang/include/clang/Frontend/FrontendOptions.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ enum ActionKind {
6565
/// Translate input source into HTML.
6666
EmitHTML,
6767

68+
/// Emit a .cir file
69+
EmitCIR,
70+
6871
/// Emit a .ll file.
6972
EmitLLVM,
7073

@@ -408,6 +411,10 @@ class FrontendOptions {
408411
LLVM_PREFERRED_TYPE(bool)
409412
unsigned GenReducedBMI : 1;
410413

414+
/// Use Clang IR pipeline to emit code
415+
LLVM_PREFERRED_TYPE(bool)
416+
unsigned UseClangIRPipeline : 1;
417+
411418
CodeCompleteOptions CodeCompleteOpts;
412419

413420
/// Specifies the output format of the AST.
@@ -590,7 +597,7 @@ class FrontendOptions {
590597
EmitSymbolGraph(false), EmitExtensionSymbolGraphs(false),
591598
EmitSymbolGraphSymbolLabelsForTesting(false),
592599
EmitPrettySymbolGraphs(false), GenReducedBMI(false),
593-
TimeTraceGranularity(500) {}
600+
UseClangIRPipeline(false), TimeTraceGranularity(500) {}
594601

595602
/// getInputKindForExtension - Return the appropriate input kind for a file
596603
/// extension. For example, "c" would return Language::C.

clang/lib/Driver/Driver.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@ phases::ID Driver::getFinalPhase(const DerivedArgList &DAL,
361361
(PhaseArg = DAL.getLastArg(options::OPT_rewrite_legacy_objc)) ||
362362
(PhaseArg = DAL.getLastArg(options::OPT__migrate)) ||
363363
(PhaseArg = DAL.getLastArg(options::OPT__analyze)) ||
364+
(PhaseArg = DAL.getLastArg(options::OPT_emit_cir)) ||
364365
(PhaseArg = DAL.getLastArg(options::OPT_emit_ast))) {
365366
FinalPhase = phases::Compile;
366367

@@ -4799,6 +4800,8 @@ Action *Driver::ConstructPhaseAction(
47994800
return C.MakeAction<MigrateJobAction>(Input, types::TY_Remap);
48004801
if (Args.hasArg(options::OPT_emit_ast))
48014802
return C.MakeAction<CompileJobAction>(Input, types::TY_AST);
4803+
if (Args.hasArg(options::OPT_emit_cir))
4804+
return C.MakeAction<CompileJobAction>(Input, types::TY_CIR);
48024805
if (Args.hasArg(options::OPT_module_file_info))
48034806
return C.MakeAction<CompileJobAction>(Input, types::TY_ModuleFile);
48044807
if (Args.hasArg(options::OPT_verify_pch))

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2549,6 +2549,7 @@ static const auto &getFrontendActionTable() {
25492549
{frontend::DumpTokens, OPT_dump_tokens},
25502550
{frontend::EmitAssembly, OPT_S},
25512551
{frontend::EmitBC, OPT_emit_llvm_bc},
2552+
{frontend::EmitCIR, OPT_emit_cir},
25522553
{frontend::EmitHTML, OPT_emit_html},
25532554
{frontend::EmitLLVM, OPT_emit_llvm},
25542555
{frontend::EmitLLVMOnly, OPT_emit_llvm_only},
@@ -2891,6 +2892,8 @@ static bool ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args,
28912892
if (Opts.ProgramAction != frontend::GenerateModule && Opts.IsSystemModule)
28922893
Diags.Report(diag::err_drv_argument_only_allowed_with) << "-fsystem-module"
28932894
<< "-emit-module";
2895+
if (Args.hasArg(OPT_fclangir) || Args.hasArg(OPT_emit_cir))
2896+
Opts.UseClangIRPipeline = true;
28942897

28952898
if (Args.hasArg(OPT_aux_target_cpu))
28962899
Opts.AuxTargetCPU = std::string(Args.getLastArgValue(OPT_aux_target_cpu));
@@ -4337,6 +4340,7 @@ static bool isStrictlyPreprocessorAction(frontend::ActionKind Action) {
43374340
case frontend::ASTView:
43384341
case frontend::EmitAssembly:
43394342
case frontend::EmitBC:
4343+
case frontend::EmitCIR:
43404344
case frontend::EmitHTML:
43414345
case frontend::EmitLLVM:
43424346
case frontend::EmitLLVMOnly:

clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ CreateFrontendBaseAction(CompilerInstance &CI) {
5353
case DumpTokens: return std::make_unique<DumpTokensAction>();
5454
case EmitAssembly: return std::make_unique<EmitAssemblyAction>();
5555
case EmitBC: return std::make_unique<EmitBCAction>();
56+
case EmitCIR:
57+
llvm_unreachable("CIR suppport not built into clang");
5658
case EmitHTML: return std::make_unique<HTMLPrintAction>();
5759
case EmitLLVM: return std::make_unique<EmitLLVMAction>();
5860
case EmitLLVMOnly: return std::make_unique<EmitLLVMOnlyAction>();

0 commit comments

Comments
 (0)