1+ // ===-- CodeGenCommonTMImpl.h -----------------------------------*- C++ -*-===//
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+ // /
9+ // / \file This file describes the CodeGenCommonTMImpl class, which
10+ // / implements a set of functionality used by \c TargetMachine classes in
11+ // / LLVM that make use of the target-independent code generator.
12+ // ===----------------------------------------------------------------------===//
13+ #ifndef LLVM_CODEGEN_CODEGENCOMMONTMIMPL_H
14+ #define LLVM_CODEGEN_CODEGENCOMMONTMIMPL_H
15+ #include " llvm/Target/TargetMachine.h"
16+
17+ namespace llvm {
18+
19+ // / \brief implements a set of functionality in the \c TargetMachine class
20+ // / for targets that make use of the independent code generator (CodeGen)
21+ // / library. Must not be used directly in code unless to inherit its
22+ // / implementation.
23+ class CodeGenCommonTMImpl : public TargetMachine {
24+ protected: // Can only create subclasses.
25+ CodeGenCommonTMImpl (const Target &T, StringRef DataLayoutString,
26+ const Triple &TT, StringRef CPU, StringRef FS,
27+ const TargetOptions &Options, Reloc::Model RM,
28+ CodeModel::Model CM, CodeGenOptLevel OL);
29+
30+ void initAsmInfo ();
31+
32+ public:
33+ // / Get a TargetTransformInfo implementation for the target.
34+ // /
35+ // / The TTI returned uses the common code generator to answer queries about
36+ // / the IR.
37+ TargetTransformInfo getTargetTransformInfo (const Function &F) const override ;
38+
39+ // / Create a pass configuration object to be used by addPassToEmitX methods
40+ // / for generating a pipeline of CodeGen passes.
41+ virtual TargetPassConfig *createPassConfig (PassManagerBase &PM) override ;
42+
43+ // / Add passes to the specified pass manager to get the specified file
44+ // / emitted. Typically this will involve several steps of code generation.
45+ // / \p MMIWP is an optional parameter that, if set to non-nullptr,
46+ // / will be used to set the MachineModuloInfo for this PM.
47+ bool
48+ addPassesToEmitFile (PassManagerBase &PM, raw_pwrite_stream &Out,
49+ raw_pwrite_stream *DwoOut, CodeGenFileType FileType,
50+ bool DisableVerify = true ,
51+ MachineModuleInfoWrapperPass *MMIWP = nullptr ) override ;
52+
53+ // / Add passes to the specified pass manager to get machine code emitted with
54+ // / the MCJIT. This method returns true if machine code is not supported. It
55+ // / fills the MCContext Ctx pointer which can be used to build custom
56+ // / MCStreamer.
57+ bool addPassesToEmitMC (PassManagerBase &PM, MCContext *&Ctx,
58+ raw_pwrite_stream &Out,
59+ bool DisableVerify = true ) override ;
60+
61+ // / Adds an AsmPrinter pass to the pipeline that prints assembly or
62+ // / machine code from the MI representation.
63+ bool addAsmPrinter (PassManagerBase &PM, raw_pwrite_stream &Out,
64+ raw_pwrite_stream *DwoOut, CodeGenFileType FileType,
65+ MCContext &Context) override ;
66+
67+ Expected<std::unique_ptr<MCStreamer>>
68+ createMCStreamer (raw_pwrite_stream &Out, raw_pwrite_stream *DwoOut,
69+ CodeGenFileType FileType, MCContext &Ctx) override ;
70+ };
71+
72+ // / Helper method for getting the code model, returning Default if
73+ // / CM does not have a value. The tiny and kernel models will produce
74+ // / an error, so targets that support them or require more complex codemodel
75+ // / selection logic should implement and call their own getEffectiveCodeModel.
76+ inline CodeModel::Model
77+ getEffectiveCodeModel (std::optional<CodeModel::Model> CM,
78+ CodeModel::Model Default) {
79+ if (CM) {
80+ // By default, targets do not support the tiny and kernel models.
81+ if (*CM == CodeModel::Tiny)
82+ report_fatal_error (" Target does not support the tiny CodeModel" , false );
83+ if (*CM == CodeModel::Kernel)
84+ report_fatal_error (" Target does not support the kernel CodeModel" , false );
85+ return *CM;
86+ }
87+ return Default;
88+ }
89+
90+ } // namespace llvm
91+
92+ #endif
0 commit comments