LLVM 20.0.0git
CodeGenTargetMachineImpl.h
Go to the documentation of this file.
1//===-- CodeGenTargetMachineImpl.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 CodeGenTargetMachineImpl 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_CODEGENTARGETMACHINEIMPL_H
14#define LLVM_CODEGEN_CODEGENTARGETMACHINEIMPL_H
16
17namespace 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.
24protected: // Can only create subclasses.
25 CodeGenTargetMachineImpl(const Target &T, StringRef DataLayoutString,
26 const Triple &TT, StringRef CPU, StringRef FS,
29
30 void initAsmInfo();
31
32 /// Reset internal state.
33 virtual void reset() {};
34
35public:
36 /// Get a TargetTransformInfo implementation for the target.
37 ///
38 /// The TTI returned uses the common code generator to answer queries about
39 /// the IR.
41
42 /// Create a pass configuration object to be used by addPassToEmitX methods
43 /// for generating a pipeline of CodeGen passes.
45
46 /// Add passes to the specified pass manager to get the specified file
47 /// emitted. Typically this will involve several steps of code generation.
48 /// \p MMIWP is an optional parameter that, if set to non-nullptr,
49 /// will be used to set the MachineModuloInfo for this PM.
50 bool
52 raw_pwrite_stream *DwoOut, CodeGenFileType FileType,
53 bool DisableVerify = true,
54 MachineModuleInfoWrapperPass *MMIWP = nullptr) override;
55
56 /// Add passes to the specified pass manager to get machine code emitted with
57 /// the MCJIT. This method returns true if machine code is not supported. It
58 /// fills the MCContext Ctx pointer which can be used to build custom
59 /// MCStreamer.
62 bool DisableVerify = true) override;
63
64 /// Adds an AsmPrinter pass to the pipeline that prints assembly or
65 /// machine code from the MI representation.
67 raw_pwrite_stream *DwoOut, CodeGenFileType FileType,
68 MCContext &Context) override;
69
72 CodeGenFileType FileType, MCContext &Ctx) override;
73};
74
75/// Helper method for getting the code model, returning Default if
76/// CM does not have a value. The tiny and kernel models will produce
77/// an error, so targets that support them or require more complex codemodel
78/// selection logic should implement and call their own getEffectiveCodeModel.
80getEffectiveCodeModel(std::optional<CodeModel::Model> CM,
82 if (CM) {
83 // By default, targets do not support the tiny and kernel models.
84 if (*CM == CodeModel::Tiny)
85 report_fatal_error("Target does not support the tiny CodeModel", false);
86 if (*CM == CodeModel::Kernel)
87 report_fatal_error("Target does not support the kernel CodeModel", false);
88 return *CM;
89 }
90 return Default;
91}
92
93} // namespace llvm
94
95#endif
#define F(x, y, z)
Definition: MD5.cpp:55
implements a set of functionality in the TargetMachine class for targets that make use of the indepen...
Expected< std::unique_ptr< MCStreamer > > createMCStreamer(raw_pwrite_stream &Out, raw_pwrite_stream *DwoOut, CodeGenFileType FileType, MCContext &Ctx) override
bool addPassesToEmitFile(PassManagerBase &PM, raw_pwrite_stream &Out, raw_pwrite_stream *DwoOut, CodeGenFileType FileType, bool DisableVerify=true, MachineModuleInfoWrapperPass *MMIWP=nullptr) override
Add passes to the specified pass manager to get the specified file emitted.
bool addPassesToEmitMC(PassManagerBase &PM, MCContext *&Ctx, raw_pwrite_stream &Out, bool DisableVerify=true) override
Add passes to the specified pass manager to get machine code emitted with the MCJIT.
TargetTransformInfo getTargetTransformInfo(const Function &F) const override
Get a TargetTransformInfo implementation for the target.
virtual void reset()
Reset internal state.
bool addAsmPrinter(PassManagerBase &PM, raw_pwrite_stream &Out, raw_pwrite_stream *DwoOut, CodeGenFileType FileType, MCContext &Context) override
Adds an AsmPrinter pass to the pipeline that prints assembly or machine code from the MI representati...
virtual TargetPassConfig * createPassConfig(PassManagerBase &PM) override
Create a pass configuration object to be used by addPassToEmitX methods for generating a pipeline of ...
Tagged union holding either a T or a Error.
Definition: Error.h:481
Context object for machine code objects.
Definition: MCContext.h:83
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:77
TargetOptions Options
Target-Independent Code Generator Pass Configuration Options.
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
Target - Wrapper for Target specific information.
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
PassManagerBase - An abstract interface to allow code to add passes to a pass manager without having ...
An abstract base class for streams implementations that also support a pwrite operation.
Definition: raw_ostream.h:434
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
CodeModel::Model getEffectiveCodeModel(std::optional< CodeModel::Model > CM, CodeModel::Model Default)
Helper method for getting the code model, returning Default if CM does not have a value.
CodeGenFileType
These enums are meant to be passed into addPassesToEmitFile to indicate what type of file to emit,...
Definition: CodeGen.h:83
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:167
CodeGenOptLevel
Code generation optimization level.
Definition: CodeGen.h:54
@ Default
The result values are uniform if and only if all operands are uniform.