clang 24.0.0git
CIRGenAction.cpp
Go to the documentation of this file.
1//===--- CIRGenAction.cpp - LLVM Code generation Frontend Action ---------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
11#include "mlir/Bytecode/BytecodeWriter.h"
12#include "mlir/IR/BuiltinOps.h"
13#include "mlir/IR/MLIRContext.h"
14#include "mlir/IR/OwningOpRef.h"
15#include "mlir/Parser/Parser.h"
28#include "llvm/ADT/STLFunctionalExtras.h"
29#include "llvm/ADT/ScopeExit.h"
30#include "llvm/ADT/SmallString.h"
31#include "llvm/Frontend/Offloading/OffloadWrapper.h"
32#include "llvm/IR/DiagnosticHandler.h"
33#include "llvm/IR/Function.h"
34#include "llvm/IR/GlobalValue.h"
35#include "llvm/IR/LLVMContext.h"
36#include "llvm/IR/Module.h"
37#include "llvm/Support/LibraryOptionsContext.h"
38#include "llvm/Support/MemoryBuffer.h"
39#include "llvm/Support/Path.h"
40#include "llvm/Support/raw_ostream.h"
41
42using namespace cir;
43using namespace clang;
44
45namespace cir {
46
47static BackendAction
49 switch (Action) {
52 assert(false &&
53 "Unsupported output type for getBackendActionFromOutputType!");
54 break; // Unreachable, but fall through to report that
63 }
64 // We should only get here if a non-enum value is passed in or we went through
65 // the assert(false) case above
66 llvm_unreachable("Unsupported output type!");
67}
68
69static std::unique_ptr<llvm::Module> lowerFromCIRToLLVMIR(
70 mlir::ModuleOp MLIRModule, llvm::LLVMContext &LLVMCtx, bool EnableOpenMP,
71 llvm::StringRef mlirSaveTempsOutFile = {},
72 llvm::vfs::FileSystem *fs = nullptr, bool enableOptimizations = false) {
73 return direct::lowerDirectlyFromCIRToLLVMIR(MLIRModule, LLVMCtx, EnableOpenMP,
74 mlirSaveTempsOutFile, fs,
75 enableOptimizations);
76}
77
78// Print \p MLIRModule the way -emit-cir does, so that CIR emitted from source
79// and CIR printed back from ClangIR input use the same form.
80static void printCIRModule(mlir::ModuleOp MLIRModule, raw_ostream &OS) {
81 mlir::OpPrintingFlags Flags;
82 Flags.enableDebugInfo(/*enable=*/true, /*prettyForm=*/false);
83 MLIRModule->print(OS, Flags);
84}
85
86// Reads the device binary named by -foffload-include-binary and embeds it
87// into the host module. wrapSYCLBinaries also appends the registration ctor
88// at priority 101 when no registration-function out-param is supplied.
89static void embedSYCLDeviceBinary(CompilerInstance &CI, llvm::Module &M) {
90 StringRef fileName = CI.getCodeGenOpts().OffloadBinaryToEmbedFile;
91 auto bufferOrErr = CI.getVirtualFileSystem().getBufferForFile(fileName);
92 if (std::error_code ec = bufferOrErr.getError()) {
93 CI.getDiagnostics().Report(diag::err_cannot_open_file)
94 << fileName << ec.message();
95 return;
96 }
97 std::unique_ptr<llvm::MemoryBuffer> buffer = std::move(bufferOrErr.get());
98 if (llvm::Error err = llvm::offloading::wrapSYCLBinaries(
99 M, ArrayRef<char>(buffer->getBufferStart(), buffer->getBufferSize()),
100 llvm::offloading::SYCLJITOptions(), /*IsFinalizedImage=*/true)) {
101 CI.getDiagnostics().Report(diag::err_fe_error_backend)
102 << llvm::toString(std::move(err));
103 return;
104 }
105}
106
107// Runs the CIR-to-CIR pipeline on \p MlirModule unless -clangir-disable-passes
108// is given.
109static mlir::LogicalResult runCIRPipeline(const FrontendOptions &FEOpts,
110 const CodeGenOptions &CGO,
111 mlir::ModuleOp MlirModule,
112 mlir::MLIRContext &MlirCtx) {
113 if (FEOpts.ClangIRDisablePasses)
114 return mlir::success();
115 const bool EnableLibOpt =
116 FEOpts.ClangIRLibOptEnabled && (CGO.OptimizationLevel > 0);
117 return runCIRToCIRPasses(
118 MlirModule, MlirCtx, !FEOpts.ClangIRDisableCIRVerifier,
119 FEOpts.ClangIREnableIdiomRecognizer, CGO.OptimizationLevel > 0,
120 EnableLibOpt, FEOpts.ClangIRLibOptOptions,
122}
123
124// Emits the output requested by \p Action for \p MlirModule, a CIR module that
125// has been through the CIR-to-CIR pipeline. Language facts are read from the
126// module's #cir.lowering_options and target facts from \p CI, so this
127// does not need an ASTContext and can also run on CIR loaded from a file.
128// \p AddFunctionSourceLocations, if set, runs on the lowered LLVM module
129// before linking.
132 mlir::ModuleOp MlirModule, llvm::LLVMContext &LLVMCtx,
134 BackendDiagnosticConsumer &DiagConsumer,
135 std::unique_ptr<raw_pwrite_stream> OutputStream,
136 llvm::function_ref<void(llvm::Module &)> AddFunctionSourceLocations = {}) {
137 CodeGenOptions &CGO = CI.getCodeGenOpts();
138 switch (Action) {
140 if (OutputStream && MlirModule)
141 printCIRModule(MlirModule, *OutputStream);
142 break;
144 if (OutputStream && MlirModule &&
145 failed(mlir::writeBytecodeToFile(MlirModule, *OutputStream)) &&
147 CI.getDiagnostics().Report(diag::err_cir_bc_write_failed);
148 break;
153 StringRef saveTempsPrefix = CGO.SaveTempsFilePrefix;
154 std::string cirSaveTempsOutFile, mlirSaveTempsOutFile;
155 if (!saveTempsPrefix.empty()) {
156 SmallString<128> stem(saveTempsPrefix);
157 llvm::sys::path::replace_extension(stem, "cir");
158 cirSaveTempsOutFile = std::string(stem);
159 llvm::sys::path::replace_extension(stem, "mlir");
160 mlirSaveTempsOutFile = std::string(stem);
161 }
162
163 if (!cirSaveTempsOutFile.empty()) {
164 std::error_code ec;
165 llvm::raw_fd_ostream out(cirSaveTempsOutFile, ec);
166 if (!ec)
167 MlirModule->print(out);
168 }
169
170 // If errors occurred during codegen, stop before running the backend.
172 return;
173
174 // Read the lowering facts before lowering rewrites the module. Without the
175 // attribute (e.g. hand-written CIR) every fact defaults to off.
176 auto LangOptsAttr = MlirModule->getAttrOfType<cir::LoweringOptionsAttr>(
177 cir::CIRDialect::getLoweringOptionsAttrName());
178 const bool EnableOpenMP = LangOptsAttr && LangOptsAttr.getOpenmp();
179
180 // Route LLVM backend diagnostics (optimization remarks, unsupported
181 // features, inline-asm errors, etc.) through clang diagnostics for
182 // the remainder of the LLVM-emitting pipeline.
183 std::unique_ptr<llvm::DiagnosticHandler> OldDiagnosticHandler =
184 LLVMCtx.getDiagnosticHandler();
185 llvm::scope_exit RestoreDiagnosticHandler([&]() {
186 LLVMCtx.setDiagnosticHandler(std::move(OldDiagnosticHandler));
187 });
188 LLVMCtx.setDiagnosticHandler(DiagConsumer.createDiagnosticHandler());
189
190 // Backend components (e.g. the inline-asm parser) reach the filesystem
191 // through the context's VFS, which must be set to stay within the IO
192 // sandbox.
193 LLVMCtx.setVirtualFileSystem(CI.getVirtualFileSystemPtr());
194
195 // Enable the llvm-simplify-cfg pass when optimizations are on
196 // (-O1 and up); at -O0 the lowered IR keeps its raw shape.
197 std::unique_ptr<llvm::Module> LLVMModule =
198 lowerFromCIRToLLVMIR(MlirModule, LLVMCtx, EnableOpenMP,
199 mlirSaveTempsOutFile, &CI.getVirtualFileSystem(),
200 /*enableOptimizations=*/CGO.OptimizationLevel > 0);
201 if (!LLVMModule) {
202 // Lowering errors are already routed through the MLIR diagnostic
203 // handler. Only emit the generic error if nothing was reported.
205 CI.getDiagnostics().Report(diag::err_cir_to_llvm_lowering_failed);
206 return;
207 }
208
209 LLVMModule->setDataLayout(CI.getTarget().getDataLayoutString());
210
211 if (AddFunctionSourceLocations)
212 AddFunctionSourceLocations(*LLVMModule);
213
214 if (linkInModules(*LLVMModule, LinkModules, CGO, CI.getLangOpts(),
215 CI.getTargetOpts(), DiagConsumer))
216 return;
217
218 const LangOptions &LangOpts = CI.getLangOpts();
219
220 // Embed the offloaded SYCL device binary into the host module.
221 if (LangOpts.SYCLIsHost && !CGO.OffloadBinaryToEmbedFile.empty())
222 embedSYCLDeviceBinary(CI, *LLVMModule);
223
224 // CUDA, HIP and OpenMP offloading rely on host-side offload entries that
225 // are not emitted on the ClangIR path yet, so embedding their device
226 // objects would produce a host object that cannot be registered.
227 // LangOptions::CUDA is also set for HIP.
228 if (!CGO.OffloadObjects.empty() &&
229 (LangOpts.CUDA || !LangOpts.OMPTargetTriples.empty())) {
230 DiagnosticsEngine &Diags = CI.getDiagnostics();
231 Diags.Report(Diags.getCustomDiagID(
233 "ClangIR code gen Not Yet Implemented: embedding offload objects "
234 "for CUDA, HIP or OpenMP offloading"));
235 return;
236 }
237
238 // If there is device offloading code embed it in the host now.
239 EmbedObject(LLVMModule.get(), CGO, CI.getVirtualFileSystem(),
240 CI.getDiagnostics());
241
242 EmbedBitcode(LLVMModule.get(), CGO, llvm::MemoryBufferRef());
243
245 emitBackendOutput(CI, CGO, LLVMModule.get(), BEAction,
246 CI.getVirtualFileSystemPtr(), std::move(OutputStream));
247 break;
248 }
249 }
250}
251
253
254 virtual void anchor();
255
257
259
260 std::unique_ptr<raw_pwrite_stream> OutputStream;
261
262 ASTContext *Context{nullptr};
264 std::unique_ptr<CIRGenerator> Gen;
265 const FrontendOptions &FEOptions;
266 CodeGenOptions &CGO;
267
268 llvm::LLVMContext &LLVMCtx;
270
271 std::optional<CIRDiagnosticHandler> MLIRDiagHandler;
272
273 // Translates LLVM backend diagnostics (raised while lowering CIR to LLVM
274 // IR and while running emitBackendOutput) into clang diagnostics; shared
275 // with classic CodeGen's BackendConsumer.
276 BackendDiagnosticConsumer DiagConsumer;
277
278public:
280 CodeGenOptions &CGO, std::unique_ptr<raw_pwrite_stream> OS,
281 llvm::LLVMContext &LLVMCtx,
283 : Action(Action), CI(CI), OutputStream(std::move(OS)),
284 FS(&CI.getVirtualFileSystem()),
285 Gen(std::make_unique<CIRGenerator>(CI.getDiagnostics(), std::move(FS),
286 CI.getCodeGenOpts())),
287 FEOptions(CI.getFrontendOpts()), CGO(CGO), LLVMCtx(LLVMCtx),
288 LinkModules(LinkModules),
289 DiagConsumer(CI.getDiagnostics(), CI.getCodeGenOpts()) {}
290
291 void Initialize(ASTContext &Ctx) override {
292 assert(!Context && "initialized multiple times");
293 Context = &Ctx;
294 DiagConsumer.setSourceManager(&Ctx.getSourceManager());
295 Gen->Initialize(Ctx);
296 // Install the MLIR diagnostic handler now that CIRGenerator owns its
297 // MLIRContext. Lifetime is tied to this consumer, which spans CIRGen,
298 // CIR-to-CIR passes, and CIR-to-LLVM lowering.
299 MLIRDiagHandler.emplace(&Gen->getMLIRContext(), CI.getDiagnostics(),
300 CI.getSourceManager(), CI.getFileManager());
301 }
302
304 Gen->HandleTopLevelDecl(D);
305 return true;
306 }
307
309 Gen->HandleCXXStaticMemberVarInstantiation(VD);
310 }
311
313 const OpenACCRoutineDecl *RD) override {
314 Gen->HandleOpenACCRoutineReference(FD, RD);
315 }
316
318 Gen->HandleInlineFunctionDefinition(D);
319 }
320
322 Gen->HandleTranslationUnit(C);
323
324 if (!FEOptions.ClangIRDisableCIRVerifier) {
325 if (!Gen->verifyModule()) {
326 // Verifier output already routed through ClangIRDiagnosticHandler.
327 // Only emit the generic fatal if nothing more specific was reported.
328 if (!CI.getDiagnostics().hasErrorOccurred())
329 CI.getDiagnostics().Report(
330 diag::err_cir_verification_failed_pre_passes);
331 llvm::report_fatal_error(
332 "CIR codegen: module verification error before running CIR passes");
333 return;
334 }
335 }
336
337 mlir::ModuleOp MlirModule = Gen->getModule();
338 mlir::MLIRContext &MlirCtx = Gen->getMLIRContext();
339
340 if (runCIRPipeline(FEOptions, CGO, MlirModule, MlirCtx).failed()) {
341 // Pass-side errors already routed through ClangIRDiagnosticHandler.
342 // Skip the generic catch-all if a specific diagnostic was emitted.
343 if (!CI.getDiagnostics().hasErrorOccurred())
344 CI.getDiagnostics().Report(diag::err_cir_to_cir_transform_failed);
345 return;
346 }
347
348 // CIRGen-only step: map the emitted LLVM functions back to their source
349 // declarations so backend diagnostics point at the original source.
350 auto AddFunctionSourceLocations = [&](llvm::Module &LLVMModule) {
351 for (llvm::Function &F : LLVMModule.functions())
352 if (const Decl *FD = Gen->getDeclForMangledName(F.getName()))
353 DiagConsumer.addFunctionSourceLocation(
354 F.getName(), FD->getASTContext().getFullLoc(FD->getLocation()));
355 };
356 emitCIRModuleOutput(Action, CI, MlirModule, LLVMCtx, LinkModules,
357 DiagConsumer, std::move(OutputStream),
358 AddFunctionSourceLocations);
359 }
360
363 Context->getSourceManager(),
364 "CIR generation of declaration");
365 Gen->HandleTagDeclDefinition(D);
366 }
367
368 void HandleTagDeclRequiredDefinition(const TagDecl *D) override {
369 Gen->HandleTagDeclRequiredDefinition(D);
370 }
371
373 Gen->CompleteTentativeDefinition(D);
374 }
375
376 void HandleVTable(CXXRecordDecl *RD) override { Gen->HandleVTable(RD); }
377};
378} // namespace cir
379
380void CIRGenConsumer::anchor() {}
381
383 : Ctx(std::make_unique<llvm::LLVMContext>()), Action(Act) {}
384
385CIRGenAction::~CIRGenAction() { MLIRMod.release(); }
386
388 Ctx->getLibraryOptions().assign(CI.getLibraryOptions());
389 Ctx->setVirtualFileSystem(CI.getVirtualFileSystemPtr());
390 if (clang::loadLinkModules(CI, *Ctx, LinkModules,
391 /*OnlyInternalized=*/false))
392 return false;
394}
395
396static std::unique_ptr<raw_pwrite_stream>
397getOutputStream(CompilerInstance &CI, StringRef InFile,
399
401 if (getCurrentFileKind().getLanguage() != Language::CIR) {
403 return;
404 }
405
407 DiagnosticsEngine &Diags = CI.getDiagnostics();
409
410 std::unique_ptr<raw_pwrite_stream> OS = CI.takeOutputStream();
411 if (!OS)
413 if (!OS)
414 return;
415
416 std::optional<llvm::MemoryBufferRef> MainFile =
418 if (!MainFile)
419 return;
420
421 mlir::MLIRContext MLIRContext;
422 cir::registerAllDialects(MLIRContext);
423
424 // Route parser and verifier errors through clang's diagnostics. Parse
425 // errors point into the .cir input. Verifier errors use the location of
426 // the failing op, which for CIR emitted by CIRGen is a location in the
427 // original source file; that file is not loaded in the SourceManager, so
428 // the handler reports such errors with the original location as text.
429 // TODO: Decide where errors in CIRGen-produced input should point: at the
430 // .cir text, or at the original source.
431 CIRDiagnosticHandler DiagHandler(&MLIRContext, Diags, SM,
432 CI.getFileManager());
433
434 mlir::OwningOpRef<mlir::ModuleOp> Module =
435 mlir::parseSourceString<mlir::ModuleOp>(MainFile->getBuffer(),
436 mlir::ParserConfig(&MLIRContext),
437 MainFile->getBufferIdentifier());
438 if (!Module) {
439 if (!Diags.hasErrorOccurred())
440 Diags.Report(diag::err_invalid_cir);
441 return;
442 }
443
444 // CIR is lowered for the target ABI of its own triple, so a module emitted
445 // for a different target cannot be retargeted by overriding its triple.
446 auto ModuleTriple = mlir::dyn_cast_if_present<mlir::StringAttr>(
447 (*Module)->getAttr(cir::CIRDialect::getTripleAttrName()));
448 if (!ModuleTriple) {
449 Diags.Report(diag::err_cir_input_missing_triple);
450 return;
451 }
452 const std::string &TargetTriple = CI.getTarget().getTriple().str();
453 if (ModuleTriple.getValue() != TargetTriple) {
454 Diags.Report(diag::err_cir_input_triple_mismatch)
455 << ModuleTriple.getValue() << TargetTriple;
456 return;
457 }
458
459 // ClangIR input may already have been through the pipeline in an earlier
460 // invocation (e.g. -emit-cir). Its passes are safe to rerun, so run it whole.
462 MLIRContext)
463 .failed()) {
464 if (!Diags.hasErrorOccurred())
465 Diags.Report(diag::err_cir_to_cir_transform_failed);
466 return;
467 }
468 BackendDiagnosticConsumer DiagConsumer(Diags, CI.getCodeGenOpts());
469 DiagConsumer.setSourceManager(&SM);
470 emitCIRModuleOutput(Action, CI, *Module, *Ctx, LinkModules, DiagConsumer,
471 std::move(OS));
472}
473
474static std::unique_ptr<raw_pwrite_stream>
475getOutputStream(CompilerInstance &CI, StringRef InFile,
477 switch (Action) {
479 return CI.createDefaultOutputFile(false, InFile, "s");
481 return CI.createDefaultOutputFile(false, InFile, "cir");
483 return CI.createDefaultOutputFile(true, InFile, "cirbc");
485 return CI.createDefaultOutputFile(false, InFile, "ll");
487 return CI.createDefaultOutputFile(true, InFile, "bc");
489 return CI.createDefaultOutputFile(true, InFile, "o");
490 }
491 llvm_unreachable("Invalid CIRGenAction::OutputType");
492}
493
494std::unique_ptr<ASTConsumer>
496 std::unique_ptr<llvm::raw_pwrite_stream> Out = CI.takeOutputStream();
497
498 if (!Out)
499 Out = getOutputStream(CI, InFile, Action);
500
501 auto Result = std::make_unique<cir::CIRGenConsumer>(
502 Action, CI, CI.getCodeGenOpts(), std::move(Out), *Ctx, LinkModules);
503
504 return Result;
505}
506
507void EmitAssemblyAction::anchor() {}
510
511void EmitCIRAction::anchor() {}
513
514void EmitCIRBCAction::anchor() {}
516
517void EmitLLVMAction::anchor() {}
519
520void EmitBCAction::anchor() {}
522
523void EmitObjAction::anchor() {}
Defines the clang::ASTContext interface.
static std::unique_ptr< raw_pwrite_stream > getOutputStream(CompilerInstance &CI, StringRef InFile, CIRGenAction::OutputType Action)
Routes MLIR-side diagnostics emitted during CIR passes, the verifier, and CIR-to-LLVM lowering throug...
OutputType Action
void ExecuteAction() override
Implement the ExecuteAction interface by running Sema on the already-initialized AST consumer.
bool BeginSourceFileAction(clang::CompilerInstance &CI) override
Callback at the start of processing a single input.
~CIRGenAction() override
std::unique_ptr< clang::ASTConsumer > CreateASTConsumer(clang::CompilerInstance &CI, llvm::StringRef InFile) override
CIRGenAction(OutputType Action)
void Initialize(ASTContext &Ctx) override
Initialize - This is called to initialize the consumer, providing the ASTContext.
bool HandleTopLevelDecl(DeclGroupRef D) override
HandleTopLevelDecl - Handle the specified top-level declaration.
void HandleTranslationUnit(ASTContext &C) override
HandleTranslationUnit - This method is called when the ASTs for entire translation unit have been par...
void HandleInlineFunctionDefinition(FunctionDecl *D) override
This callback is invoked each time an inline (method or friend) function definition in a class is com...
void CompleteTentativeDefinition(VarDecl *D) override
CompleteTentativeDefinition - Callback invoked at the end of a translation unit to notify the consume...
void HandleTagDeclRequiredDefinition(const TagDecl *D) override
This callback is invoked the first time each TagDecl is required to be complete.
CIRGenConsumer(CIRGenAction::OutputType Action, CompilerInstance &CI, CodeGenOptions &CGO, std::unique_ptr< raw_pwrite_stream > OS, llvm::LLVMContext &LLVMCtx, SmallVectorImpl<::clang::LinkModule > &LinkModules)
void HandleVTable(CXXRecordDecl *RD) override
Callback involved at the end of a translation unit to notify the consumer that a vtable for the given...
void HandleCXXStaticMemberVarInstantiation(clang::VarDecl *VD) override
HandleCXXStaticMemberVarInstantiation - Tell the consumer that this.
void HandleOpenACCRoutineReference(const FunctionDecl *FD, const OpenACCRoutineDecl *RD) override
Callback to handle the end-of-translation unit attachment of OpenACC routine declaration information.
void HandleTagDeclDefinition(TagDecl *D) override
HandleTagDeclDefinition - This callback is invoked each time a TagDecl (e.g.
ASTConsumer - This is an abstract interface that should be implemented by clients that read ASTs.
Definition ASTConsumer.h:35
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:245
SourceManager & getSourceManager()
Definition ASTContext.h:916
void ExecuteAction() override
Implement the ExecuteAction interface by running Sema on the already-initialized AST consumer.
Owns the state needed to translate LLVM backend diagnostics into clang diagnostics,...
std::unique_ptr< llvm::DiagnosticHandler > createDiagnosticHandler()
Create an llvm::DiagnosticHandler that forwards diagnostics to this consumer.
void setSourceManager(SourceManager *SM)
The SourceManager used to translate backend-reported file:line:col locations back into clang SourceLo...
Represents a C++ struct/union/class.
Definition DeclCXX.h:258
CodeGenOptions - Track various options which control how the code is optimized and passed to the back...
std::string OffloadBinaryToEmbedFile
Name of file passed with -foffload-include-binary option to forward to offloading runtime back-end fo...
std::string SaveTempsFilePrefix
Prefix to use for -save-temps output.
std::vector< std::string > OffloadObjects
List of filenames passed in using the -fembed-offload-object option.
CompilerInstance - Helper class for managing a single instance of the Clang compiler.
std::unique_ptr< raw_pwrite_stream > createDefaultOutputFile(bool Binary=true, StringRef BaseInput="", StringRef Extension="", bool RemoveFileOnSignal=true, bool CreateMissingDirectories=false, bool ForceUseTemporary=false, bool SetOnlyIfDifferent=false)
Create the default output file (from the invocation's options) and add it to the list of tracked outp...
DiagnosticsEngine & getDiagnostics() const
Get the current diagnostics engine.
FileManager & getFileManager() const
Return the current file manager to the caller.
const llvm::cl::LibraryOptionsContext & getLibraryOptions() const
IntrusiveRefCntPtr< llvm::vfs::FileSystem > getVirtualFileSystemPtr() const
TargetOptions & getTargetOpts()
std::unique_ptr< llvm::raw_pwrite_stream > takeOutputStream()
FrontendOptions & getFrontendOpts()
TargetInfo & getTarget() const
llvm::vfs::FileSystem & getVirtualFileSystem() const
CodeGenOptions & getCodeGenOpts()
SourceManager & getSourceManager() const
Return the current source manager.
Decl - This represents one declaration (or definition), e.g.
Definition DeclBase.h:86
Concrete class used by the front-end to report problems and issues.
Definition Diagnostic.h:240
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
unsigned getCustomDiagID(Level L, const char(&FormatString)[N])
Return an ID for a diagnostic with the specified format string and level.
Definition Diagnostic.h:952
bool hasErrorOccurred() const
Definition Diagnostic.h:919
InputKind getCurrentFileKind() const
virtual bool BeginSourceFileAction(CompilerInstance &CI)
Callback at the start of processing a single input.
CompilerInstance & getCompilerInstance() const
StringRef getCurrentFileOrBufferName() const
FrontendOptions - Options for controlling the behavior of the frontend.
unsigned ClangIRDisablePasses
Disable Clang IR specific (CIR) passes.
unsigned ClangIRDisableCIRVerifier
Disable Clang IR (CIR) verifier.
unsigned ClangIRLibOptEnabled
Enable ClangIR library optimization.
std::string ClangIRLibOptOptions
Options to control ClangIR library optimization.
unsigned ClangIREnableIdiomRecognizer
Enable Clang IR (CIR) idiom recognizer.
unsigned ClangIRCallConvLowering
Run the Clang IR (CIR) calling-convention lowering pass.
Represents a function declaration or definition.
Definition Decl.h:2082
std::vector< llvm::Triple > OMPTargetTriples
Triples of the OpenMP targets that the host code codegen should take into account in order to generat...
Describes a module or submodule.
Definition Module.h:340
PrettyStackTraceDecl - If a crash occurs, indicate that it happened when doing something to a specifi...
Definition DeclBase.h:1318
Encodes a location in the source.
This class handles loading and caching of source files into memory.
FileID getMainFileID() const
Returns the FileID of the main source file.
std::optional< llvm::MemoryBufferRef > getBufferOrNone(FileID FID, SourceLocation Loc=SourceLocation()) const
Return the buffer for the specified FileID.
Represents the declaration of a struct/union/class/enum.
Definition Decl.h:3898
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
const char * getDataLayoutString() const
Represents a variable declaration or definition.
Definition Decl.h:934
std::unique_ptr< llvm::Module > lowerDirectlyFromCIRToLLVMIR(mlir::ModuleOp mlirModule, llvm::LLVMContext &llvmCtx, bool enableOpenMP, llvm::StringRef mlirSaveTempsOutFile={}, llvm::vfs::FileSystem *fs=nullptr, bool enableOptimizations=false)
Lowers mlirModule, a CIR module, to an LLVM module in llvmCtx.
static BackendAction getBackendActionFromOutputType(CIRGenAction::OutputType Action)
static void emitCIRModuleOutput(CIRGenAction::OutputType Action, CompilerInstance &CI, mlir::ModuleOp MlirModule, llvm::LLVMContext &LLVMCtx, SmallVectorImpl<::clang::LinkModule > &LinkModules, BackendDiagnosticConsumer &DiagConsumer, std::unique_ptr< raw_pwrite_stream > OutputStream, llvm::function_ref< void(llvm::Module &)> AddFunctionSourceLocations={})
mlir::LogicalResult runCIRToCIRPasses(mlir::ModuleOp theModule, mlir::MLIRContext &mlirCtx, bool enableVerifier, bool enableIdiomRecognizer, bool enableCIRSimplify, bool enableLibOpt, llvm::StringRef libOptOptions, bool enableCallConvLowering)
Definition CIRPasses.cpp:85
static void printCIRModule(mlir::ModuleOp MLIRModule, raw_ostream &OS)
static std::unique_ptr< llvm::Module > lowerFromCIRToLLVMIR(mlir::ModuleOp MLIRModule, llvm::LLVMContext &LLVMCtx, bool EnableOpenMP, llvm::StringRef mlirSaveTempsOutFile={}, llvm::vfs::FileSystem *fs=nullptr, bool enableOptimizations=false)
void registerAllDialects(mlir::DialectRegistry &registry)
static void embedSYCLDeviceBinary(CompilerInstance &CI, llvm::Module &M)
static mlir::LogicalResult runCIRPipeline(const FrontendOptions &FEOpts, const CodeGenOptions &CGO, mlir::ModuleOp MlirModule, mlir::MLIRContext &MlirCtx)
Top level wrappers for InstallAPI frontend operations.
bool loadLinkModules(CompilerInstance &CI, llvm::LLVMContext &Ctx, llvm::SmallVectorImpl< LinkModule > &LinkModules, bool OnlyInternalized)
Load every bitcode file listed in CodeGenOpts.LinkBitcodeFiles into LinkModules.
@ CIR
LLVM IR & CIR: we accept these so that we can run the optimizer on them, and compile them to assembly...
bool linkInModules(llvm::Module &M, llvm::SmallVectorImpl< LinkModule > &LinkModules, const CodeGenOptions &CodeGenOpts, const LangOptions &LangOpts, const TargetOptions &TargetOpts, BackendDiagnosticConsumer &DiagConsumer)
Link every module in LinkModules into M, propagating default function attributes and internalizing as...
void EmbedObject(llvm::Module *M, const CodeGenOptions &CGOpts, llvm::vfs::FileSystem &VFS, DiagnosticsEngine &Diags)
void emitBackendOutput(CompilerInstance &CI, CodeGenOptions &CGOpts, llvm::Module *M, BackendAction Action, llvm::IntrusiveRefCntPtr< llvm::vfs::FileSystem > VFS, std::unique_ptr< raw_pwrite_stream > OS, BackendConsumer *BC=nullptr)
void EmbedBitcode(llvm::Module *M, const CodeGenOptions &CGOpts, llvm::MemoryBufferRef Buf)
BackendAction
Definition BackendUtil.h:31
@ Backend_EmitAssembly
Emit native assembly files.
Definition BackendUtil.h:32
@ Backend_EmitLL
Emit human-readable LLVM assembly.
Definition BackendUtil.h:34
@ Backend_EmitBC
Emit LLVM bitcode files.
Definition BackendUtil.h:33
@ Backend_EmitObj
Emit native object files.
Definition BackendUtil.h:37
Diagnostic wrappers for TextAPI types for error reporting.
Definition Dominators.h:30