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>
70lowerFromCIRToLLVMIR(mlir::ModuleOp MLIRModule, llvm::LLVMContext &LLVMCtx,
71 bool EnableOpenMP,
72 llvm::StringRef mlirSaveTempsOutFile = {},
73 llvm::vfs::FileSystem *fs = nullptr) {
74 return direct::lowerDirectlyFromCIRToLLVMIR(MLIRModule, LLVMCtx, EnableOpenMP,
75 mlirSaveTempsOutFile, fs);
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// Emits the output requested by \p Action for \p MlirModule, a CIR module that
108// has been through the CIR-to-CIR pipeline. Language facts are read from the
109// module's #cir.lowering_lang_options and target facts from \p CI, so this
110// does not need an ASTContext and can also run on CIR loaded from a file.
111// \p AddFunctionSourceLocations, if set, runs on the lowered LLVM module
112// before linking.
115 mlir::ModuleOp MlirModule, llvm::LLVMContext &LLVMCtx,
117 BackendDiagnosticConsumer &DiagConsumer,
118 std::unique_ptr<raw_pwrite_stream> OutputStream,
119 llvm::function_ref<void(llvm::Module &)> AddFunctionSourceLocations = {}) {
120 CodeGenOptions &CGO = CI.getCodeGenOpts();
121 switch (Action) {
123 if (OutputStream && MlirModule)
124 printCIRModule(MlirModule, *OutputStream);
125 break;
127 if (OutputStream && MlirModule &&
128 failed(mlir::writeBytecodeToFile(MlirModule, *OutputStream)) &&
130 CI.getDiagnostics().Report(diag::err_cir_bc_write_failed);
131 break;
136 StringRef saveTempsPrefix = CGO.SaveTempsFilePrefix;
137 std::string cirSaveTempsOutFile, mlirSaveTempsOutFile;
138 if (!saveTempsPrefix.empty()) {
139 SmallString<128> stem(saveTempsPrefix);
140 llvm::sys::path::replace_extension(stem, "cir");
141 cirSaveTempsOutFile = std::string(stem);
142 llvm::sys::path::replace_extension(stem, "mlir");
143 mlirSaveTempsOutFile = std::string(stem);
144 }
145
146 if (!cirSaveTempsOutFile.empty()) {
147 std::error_code ec;
148 llvm::raw_fd_ostream out(cirSaveTempsOutFile, ec);
149 if (!ec)
150 MlirModule->print(out);
151 }
152
153 // If errors occurred during codegen, stop before running the backend.
155 return;
156
157 // Read the lowering facts before lowering rewrites the module. Without the
158 // attribute (e.g. hand-written CIR) every fact defaults to off.
159 auto LangOptsAttr = MlirModule->getAttrOfType<cir::LoweringLangOptionsAttr>(
160 cir::CIRDialect::getLoweringLangOptionsAttrName());
161 const bool EnableOpenMP = LangOptsAttr && LangOptsAttr.getOpenmp();
162
163 // Route LLVM backend diagnostics (optimization remarks, unsupported
164 // features, inline-asm errors, etc.) through clang diagnostics for
165 // the remainder of the LLVM-emitting pipeline.
166 std::unique_ptr<llvm::DiagnosticHandler> OldDiagnosticHandler =
167 LLVMCtx.getDiagnosticHandler();
168 llvm::scope_exit RestoreDiagnosticHandler([&]() {
169 LLVMCtx.setDiagnosticHandler(std::move(OldDiagnosticHandler));
170 });
171 LLVMCtx.setDiagnosticHandler(DiagConsumer.createDiagnosticHandler());
172
173 // Backend components (e.g. the inline-asm parser) reach the filesystem
174 // through the context's VFS, which must be set to stay within the IO
175 // sandbox.
176 LLVMCtx.setVirtualFileSystem(CI.getVirtualFileSystemPtr());
177
178 std::unique_ptr<llvm::Module> LLVMModule =
179 lowerFromCIRToLLVMIR(MlirModule, LLVMCtx, EnableOpenMP,
180 mlirSaveTempsOutFile, &CI.getVirtualFileSystem());
181 if (!LLVMModule) {
182 // Lowering errors are already routed through the MLIR diagnostic
183 // handler. Only emit the generic error if nothing was reported.
185 CI.getDiagnostics().Report(diag::err_cir_to_llvm_lowering_failed);
186 return;
187 }
188
189 LLVMModule->setDataLayout(CI.getTarget().getDataLayoutString());
190
191 if (AddFunctionSourceLocations)
192 AddFunctionSourceLocations(*LLVMModule);
193
194 if (linkInModules(*LLVMModule, LinkModules, CGO, CI.getLangOpts(),
195 CI.getTargetOpts(), DiagConsumer))
196 return;
197
198 const LangOptions &LangOpts = CI.getLangOpts();
199
200 // Embed the offloaded SYCL device binary into the host module.
201 if (LangOpts.SYCLIsHost && !CGO.OffloadBinaryToEmbedFile.empty())
202 embedSYCLDeviceBinary(CI, *LLVMModule);
203
204 // CUDA, HIP and OpenMP offloading rely on host-side offload entries that
205 // are not emitted on the ClangIR path yet, so embedding their device
206 // objects would produce a host object that cannot be registered.
207 // LangOptions::CUDA is also set for HIP.
208 if (!CGO.OffloadObjects.empty() &&
209 (LangOpts.CUDA || !LangOpts.OMPTargetTriples.empty())) {
210 DiagnosticsEngine &Diags = CI.getDiagnostics();
211 Diags.Report(Diags.getCustomDiagID(
213 "ClangIR code gen Not Yet Implemented: embedding offload objects "
214 "for CUDA, HIP or OpenMP offloading"));
215 return;
216 }
217
218 // If there is device offloading code embed it in the host now.
219 EmbedObject(LLVMModule.get(), CGO, CI.getVirtualFileSystem(),
220 CI.getDiagnostics());
221
222 EmbedBitcode(LLVMModule.get(), CGO, llvm::MemoryBufferRef());
223
225 emitBackendOutput(CI, CGO, LLVMModule.get(), BEAction,
226 CI.getVirtualFileSystemPtr(), std::move(OutputStream));
227 break;
228 }
229 }
230}
231
233
234 virtual void anchor();
235
237
239
240 std::unique_ptr<raw_pwrite_stream> OutputStream;
241
242 ASTContext *Context{nullptr};
244 std::unique_ptr<CIRGenerator> Gen;
245 const FrontendOptions &FEOptions;
246 CodeGenOptions &CGO;
247
248 llvm::LLVMContext &LLVMCtx;
250
251 std::optional<CIRDiagnosticHandler> MLIRDiagHandler;
252
253 // Translates LLVM backend diagnostics (raised while lowering CIR to LLVM
254 // IR and while running emitBackendOutput) into clang diagnostics; shared
255 // with classic CodeGen's BackendConsumer.
256 BackendDiagnosticConsumer DiagConsumer;
257
258public:
260 CodeGenOptions &CGO, std::unique_ptr<raw_pwrite_stream> OS,
261 llvm::LLVMContext &LLVMCtx,
263 : Action(Action), CI(CI), OutputStream(std::move(OS)),
264 FS(&CI.getVirtualFileSystem()),
265 Gen(std::make_unique<CIRGenerator>(CI.getDiagnostics(), std::move(FS),
266 CI.getCodeGenOpts())),
267 FEOptions(CI.getFrontendOpts()), CGO(CGO), LLVMCtx(LLVMCtx),
268 LinkModules(LinkModules),
269 DiagConsumer(CI.getDiagnostics(), CI.getCodeGenOpts()) {}
270
271 void Initialize(ASTContext &Ctx) override {
272 assert(!Context && "initialized multiple times");
273 Context = &Ctx;
274 DiagConsumer.setSourceManager(&Ctx.getSourceManager());
275 Gen->Initialize(Ctx);
276 // Install the MLIR diagnostic handler now that CIRGenerator owns its
277 // MLIRContext. Lifetime is tied to this consumer, which spans CIRGen,
278 // CIR-to-CIR passes, and CIR-to-LLVM lowering.
279 MLIRDiagHandler.emplace(&Gen->getMLIRContext(), CI.getDiagnostics(),
280 CI.getSourceManager(), CI.getFileManager());
281 }
282
284 Gen->HandleTopLevelDecl(D);
285 return true;
286 }
287
289 Gen->HandleCXXStaticMemberVarInstantiation(VD);
290 }
291
293 const OpenACCRoutineDecl *RD) override {
294 Gen->HandleOpenACCRoutineReference(FD, RD);
295 }
296
298 Gen->HandleInlineFunctionDefinition(D);
299 }
300
302 Gen->HandleTranslationUnit(C);
303
304 if (!FEOptions.ClangIRDisableCIRVerifier) {
305 if (!Gen->verifyModule()) {
306 // Verifier output already routed through ClangIRDiagnosticHandler.
307 // Only emit the generic fatal if nothing more specific was reported.
308 if (!CI.getDiagnostics().hasErrorOccurred())
309 CI.getDiagnostics().Report(
310 diag::err_cir_verification_failed_pre_passes);
311 llvm::report_fatal_error(
312 "CIR codegen: module verification error before running CIR passes");
313 return;
314 }
315 }
316
317 mlir::ModuleOp MlirModule = Gen->getModule();
318 mlir::MLIRContext &MlirCtx = Gen->getMLIRContext();
319
320 if (!FEOptions.ClangIRDisablePasses) {
321 std::string LibOptOptions = FEOptions.ClangIRLibOptOptions;
322
323 // Setup and run CIR pipeline.
324 const bool EnableLibOpt =
325 FEOptions.ClangIRLibOptEnabled && (CGO.OptimizationLevel > 0);
327 MlirModule, MlirCtx, !FEOptions.ClangIRDisableCIRVerifier,
328 FEOptions.ClangIREnableIdiomRecognizer, CGO.OptimizationLevel > 0,
329 EnableLibOpt, LibOptOptions, FEOptions.ClangIRCallConvLowering)
330 .failed()) {
331 // Pass-side errors already routed through ClangIRDiagnosticHandler.
332 // Skip the generic catch-all if a specific diagnostic was emitted.
333 if (!CI.getDiagnostics().hasErrorOccurred())
334 CI.getDiagnostics().Report(diag::err_cir_to_cir_transform_failed);
335 return;
336 }
337 }
338
339 // CIRGen-only step: map the emitted LLVM functions back to their source
340 // declarations so backend diagnostics point at the original source.
341 auto AddFunctionSourceLocations = [&](llvm::Module &LLVMModule) {
342 for (llvm::Function &F : LLVMModule.functions())
343 if (const Decl *FD = Gen->getDeclForMangledName(F.getName()))
344 DiagConsumer.addFunctionSourceLocation(
345 F.getName(), FD->getASTContext().getFullLoc(FD->getLocation()));
346 };
347 emitCIRModuleOutput(Action, CI, MlirModule, LLVMCtx, LinkModules,
348 DiagConsumer, std::move(OutputStream),
349 AddFunctionSourceLocations);
350 }
351
354 Context->getSourceManager(),
355 "CIR generation of declaration");
356 Gen->HandleTagDeclDefinition(D);
357 }
358
359 void HandleTagDeclRequiredDefinition(const TagDecl *D) override {
360 Gen->HandleTagDeclRequiredDefinition(D);
361 }
362
364 Gen->CompleteTentativeDefinition(D);
365 }
366
367 void HandleVTable(CXXRecordDecl *RD) override { Gen->HandleVTable(RD); }
368};
369} // namespace cir
370
371void CIRGenConsumer::anchor() {}
372
374 : Ctx(std::make_unique<llvm::LLVMContext>()), Action(Act) {}
375
376CIRGenAction::~CIRGenAction() { MLIRMod.release(); }
377
379 Ctx->getLibraryOptions().assign(CI.getLibraryOptions());
380 Ctx->setVirtualFileSystem(CI.getVirtualFileSystemPtr());
381 if (clang::loadLinkModules(CI, *Ctx, LinkModules,
382 /*OnlyInternalized=*/false))
383 return false;
385}
386
387static std::unique_ptr<raw_pwrite_stream>
388getOutputStream(CompilerInstance &CI, StringRef InFile,
390
392 if (getCurrentFileKind().getLanguage() != Language::CIR) {
394 return;
395 }
396
398 DiagnosticsEngine &Diags = CI.getDiagnostics();
400
401 std::unique_ptr<raw_pwrite_stream> OS = CI.takeOutputStream();
402 if (!OS)
404 if (!OS)
405 return;
406
407 std::optional<llvm::MemoryBufferRef> MainFile =
409 if (!MainFile)
410 return;
411
412 mlir::MLIRContext MLIRContext;
413 cir::registerAllDialects(MLIRContext);
414
415 // Route parser and verifier errors through clang's diagnostics. Parse
416 // errors point into the .cir input. Verifier errors use the location of
417 // the failing op, which for CIR emitted by CIRGen is a location in the
418 // original source file; that file is not loaded in the SourceManager, so
419 // the handler reports such errors with the original location as text.
420 // TODO: Decide where errors in CIRGen-produced input should point: at the
421 // .cir text, or at the original source.
422 CIRDiagnosticHandler DiagHandler(&MLIRContext, Diags, SM,
423 CI.getFileManager());
424
425 mlir::OwningOpRef<mlir::ModuleOp> Module =
426 mlir::parseSourceString<mlir::ModuleOp>(MainFile->getBuffer(),
427 mlir::ParserConfig(&MLIRContext),
428 MainFile->getBufferIdentifier());
429 if (!Module) {
430 if (!Diags.hasErrorOccurred())
431 Diags.Report(diag::err_invalid_cir);
432 return;
433 }
434
435 // CIR is lowered for the target ABI of its own triple, so a module emitted
436 // for a different target cannot be retargeted by overriding its triple.
437 auto ModuleTriple = mlir::dyn_cast_if_present<mlir::StringAttr>(
438 (*Module)->getAttr(cir::CIRDialect::getTripleAttrName()));
439 if (!ModuleTriple) {
440 Diags.Report(diag::err_cir_input_missing_triple);
441 return;
442 }
443 const std::string &TargetTriple = CI.getTarget().getTriple().str();
444 if (ModuleTriple.getValue() != TargetTriple) {
445 Diags.Report(diag::err_cir_input_triple_mismatch)
446 << ModuleTriple.getValue() << TargetTriple;
447 return;
448 }
449
450 // The CIR-to-CIR pipeline is not run: CIR printed by -emit-cir has already
451 // been through it, and its lowering passes are not idempotent.
452 // TODO: Decide from a pipeline-stage attribute on the module which passes
453 // still have to run, once -emit-cir can stop before ABI lowering.
454 BackendDiagnosticConsumer DiagConsumer(Diags, CI.getCodeGenOpts());
455 DiagConsumer.setSourceManager(&SM);
456 emitCIRModuleOutput(Action, CI, *Module, *Ctx, LinkModules, DiagConsumer,
457 std::move(OS));
458}
459
460static std::unique_ptr<raw_pwrite_stream>
461getOutputStream(CompilerInstance &CI, StringRef InFile,
463 switch (Action) {
465 return CI.createDefaultOutputFile(false, InFile, "s");
467 return CI.createDefaultOutputFile(false, InFile, "cir");
469 return CI.createDefaultOutputFile(true, InFile, "cirbc");
471 return CI.createDefaultOutputFile(false, InFile, "ll");
473 return CI.createDefaultOutputFile(true, InFile, "bc");
475 return CI.createDefaultOutputFile(true, InFile, "o");
476 }
477 llvm_unreachable("Invalid CIRGenAction::OutputType");
478}
479
480std::unique_ptr<ASTConsumer>
482 std::unique_ptr<llvm::raw_pwrite_stream> Out = CI.takeOutputStream();
483
484 if (!Out)
485 Out = getOutputStream(CI, InFile, Action);
486
487 auto Result = std::make_unique<cir::CIRGenConsumer>(
488 Action, CI, CI.getCodeGenOpts(), std::move(Out), *Ctx, LinkModules);
489
490 return Result;
491}
492
493void EmitAssemblyAction::anchor() {}
496
497void EmitCIRAction::anchor() {}
499
500void EmitCIRBCAction::anchor() {}
502
503void EmitLLVMAction::anchor() {}
505
506void EmitBCAction::anchor() {}
508
509void 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:913
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()
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:241
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:946
bool hasErrorOccurred() const
Definition Diagnostic.h:913
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.
Represents a function declaration or definition.
Definition Decl.h:2071
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:1319
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:3868
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)
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:74
static void printCIRModule(mlir::ModuleOp MLIRModule, raw_ostream &OS)
void registerAllDialects(mlir::DialectRegistry &registry)
static void embedSYCLDeviceBinary(CompilerInstance &CI, llvm::Module &M)
static std::unique_ptr< llvm::Module > lowerFromCIRToLLVMIR(mlir::ModuleOp MLIRModule, llvm::LLVMContext &LLVMCtx, bool EnableOpenMP, llvm::StringRef mlirSaveTempsOutFile={}, llvm::vfs::FileSystem *fs=nullptr)
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