Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:27

0001 //===-- CodeGenTargetMachineImpl.h ------------------------------*- 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 /// \file This file describes the CodeGenTargetMachineImpl class, which
0010 /// implements a set of functionality used by \c TargetMachine classes in
0011 /// LLVM that make use of the target-independent code generator.
0012 //===----------------------------------------------------------------------===//
0013 #ifndef LLVM_CODEGEN_CODEGENTARGETMACHINEIMPL_H
0014 #define LLVM_CODEGEN_CODEGENTARGETMACHINEIMPL_H
0015 #include "llvm/Target/TargetMachine.h"
0016 
0017 namespace llvm {
0018 
0019 /// \brief implements a set of functionality in the \c TargetMachine class
0020 /// for targets that make use of the independent code generator (CodeGen)
0021 /// library. Must not be used directly in code unless to inherit its
0022 /// implementation.
0023 class CodeGenTargetMachineImpl : public TargetMachine {
0024 protected: // Can only create subclasses.
0025   CodeGenTargetMachineImpl(const Target &T, StringRef DataLayoutString,
0026                            const Triple &TT, StringRef CPU, StringRef FS,
0027                            const TargetOptions &Options, Reloc::Model RM,
0028                            CodeModel::Model CM, CodeGenOptLevel OL);
0029 
0030   void initAsmInfo();
0031 
0032   /// Reset internal state.
0033   virtual void reset() {};
0034 
0035 public:
0036   /// Get a TargetTransformInfo implementation for the target.
0037   ///
0038   /// The TTI returned uses the common code generator to answer queries about
0039   /// the IR.
0040   TargetTransformInfo getTargetTransformInfo(const Function &F) const override;
0041 
0042   /// Create a pass configuration object to be used by addPassToEmitX methods
0043   /// for generating a pipeline of CodeGen passes.
0044   virtual TargetPassConfig *createPassConfig(PassManagerBase &PM) override;
0045 
0046   /// Add passes to the specified pass manager to get the specified file
0047   /// emitted.  Typically this will involve several steps of code generation.
0048   /// \p MMIWP is an optional parameter that, if set to non-nullptr,
0049   /// will be used to set the MachineModuloInfo for this PM.
0050   bool
0051   addPassesToEmitFile(PassManagerBase &PM, raw_pwrite_stream &Out,
0052                       raw_pwrite_stream *DwoOut, CodeGenFileType FileType,
0053                       bool DisableVerify = true,
0054                       MachineModuleInfoWrapperPass *MMIWP = nullptr) override;
0055 
0056   /// Add passes to the specified pass manager to get machine code emitted with
0057   /// the MCJIT. This method returns true if machine code is not supported. It
0058   /// fills the MCContext Ctx pointer which can be used to build custom
0059   /// MCStreamer.
0060   bool addPassesToEmitMC(PassManagerBase &PM, MCContext *&Ctx,
0061                          raw_pwrite_stream &Out,
0062                          bool DisableVerify = true) override;
0063 
0064   /// Adds an AsmPrinter pass to the pipeline that prints assembly or
0065   /// machine code from the MI representation.
0066   bool addAsmPrinter(PassManagerBase &PM, raw_pwrite_stream &Out,
0067                      raw_pwrite_stream *DwoOut, CodeGenFileType FileType,
0068                      MCContext &Context) override;
0069 
0070   Expected<std::unique_ptr<MCStreamer>>
0071   createMCStreamer(raw_pwrite_stream &Out, raw_pwrite_stream *DwoOut,
0072                    CodeGenFileType FileType, MCContext &Ctx) override;
0073 };
0074 
0075 /// Helper method for getting the code model, returning Default if
0076 /// CM does not have a value. The tiny and kernel models will produce
0077 /// an error, so targets that support them or require more complex codemodel
0078 /// selection logic should implement and call their own getEffectiveCodeModel.
0079 inline CodeModel::Model
0080 getEffectiveCodeModel(std::optional<CodeModel::Model> CM,
0081                       CodeModel::Model Default) {
0082   if (CM) {
0083     // By default, targets do not support the tiny and kernel models.
0084     if (*CM == CodeModel::Tiny)
0085       report_fatal_error("Target does not support the tiny CodeModel", false);
0086     if (*CM == CodeModel::Kernel)
0087       report_fatal_error("Target does not support the kernel CodeModel", false);
0088     return *CM;
0089   }
0090   return Default;
0091 }
0092 
0093 } // namespace llvm
0094 
0095 #endif