Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:36:52

0001 //===--- CodeGenAction.h - LLVM Code Generation Frontend Action -*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLVM_CLANG_CODEGEN_CODEGENACTION_H
0010 #define LLVM_CLANG_CODEGEN_CODEGENACTION_H
0011 
0012 #include "clang/Frontend/FrontendAction.h"
0013 #include <memory>
0014 
0015 namespace llvm {
0016   class LLVMContext;
0017   class Module;
0018 }
0019 
0020 namespace clang {
0021 class BackendConsumer;
0022 class CodeGenerator;
0023 
0024 class CodeGenAction : public ASTFrontendAction {
0025 private:
0026   // Let BackendConsumer access LinkModule.
0027   friend class BackendConsumer;
0028 
0029   /// Info about module to link into a module we're generating.
0030   struct LinkModule {
0031     /// The module to link in.
0032     std::unique_ptr<llvm::Module> Module;
0033 
0034     /// If true, we set attributes on Module's functions according to our
0035     /// CodeGenOptions and LangOptions, as though we were generating the
0036     /// function ourselves.
0037     bool PropagateAttrs;
0038 
0039     /// If true, we use LLVM module internalizer.
0040     bool Internalize;
0041 
0042     /// Bitwise combination of llvm::LinkerFlags used when we link the module.
0043     unsigned LinkFlags;
0044   };
0045 
0046   unsigned Act;
0047   std::unique_ptr<llvm::Module> TheModule;
0048 
0049   /// Bitcode modules to link in to our module.
0050   SmallVector<LinkModule, 4> LinkModules;
0051   llvm::LLVMContext *VMContext;
0052   bool OwnsVMContext;
0053 
0054   std::unique_ptr<llvm::Module> loadModule(llvm::MemoryBufferRef MBRef);
0055 
0056   /// Load bitcode modules to link into our module from the options.
0057   bool loadLinkModules(CompilerInstance &CI);
0058 
0059 protected:
0060   bool BeginSourceFileAction(CompilerInstance &CI) override;
0061 
0062   /// Create a new code generation action.  If the optional \p _VMContext
0063   /// parameter is supplied, the action uses it without taking ownership,
0064   /// otherwise it creates a fresh LLVM context and takes ownership.
0065   CodeGenAction(unsigned _Act, llvm::LLVMContext *_VMContext = nullptr);
0066 
0067   bool hasIRSupport() const override;
0068 
0069   std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
0070                                                  StringRef InFile) override;
0071 
0072   void ExecuteAction() override;
0073 
0074   void EndSourceFileAction() override;
0075 
0076 public:
0077   ~CodeGenAction() override;
0078 
0079   /// Take the generated LLVM module, for use after the action has been run.
0080   /// The result may be null on failure.
0081   std::unique_ptr<llvm::Module> takeModule();
0082 
0083   /// Take the LLVM context used by this action.
0084   llvm::LLVMContext *takeLLVMContext();
0085 
0086   CodeGenerator *getCodeGenerator() const;
0087 
0088   BackendConsumer *BEConsumer = nullptr;
0089 };
0090 
0091 class EmitAssemblyAction : public CodeGenAction {
0092   virtual void anchor();
0093 public:
0094   EmitAssemblyAction(llvm::LLVMContext *_VMContext = nullptr);
0095 };
0096 
0097 class EmitBCAction : public CodeGenAction {
0098   virtual void anchor();
0099 public:
0100   EmitBCAction(llvm::LLVMContext *_VMContext = nullptr);
0101 };
0102 
0103 class EmitLLVMAction : public CodeGenAction {
0104   virtual void anchor();
0105 public:
0106   EmitLLVMAction(llvm::LLVMContext *_VMContext = nullptr);
0107 };
0108 
0109 class EmitLLVMOnlyAction : public CodeGenAction {
0110   virtual void anchor();
0111 public:
0112   EmitLLVMOnlyAction(llvm::LLVMContext *_VMContext = nullptr);
0113 };
0114 
0115 class EmitCodeGenOnlyAction : public CodeGenAction {
0116   virtual void anchor();
0117 public:
0118   EmitCodeGenOnlyAction(llvm::LLVMContext *_VMContext = nullptr);
0119 };
0120 
0121 class EmitObjAction : public CodeGenAction {
0122   virtual void anchor();
0123 public:
0124   EmitObjAction(llvm::LLVMContext *_VMContext = nullptr);
0125 };
0126 
0127 }
0128 
0129 #endif