LLVM 22.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
17
18namespace llvm {
19
20/// \brief implements a set of functionality in the \c TargetMachine class
21/// for targets that make use of the independent code generator (CodeGen)
22/// library. Must not be used directly in code unless to inherit its
23/// implementation.
25protected: // Can only create subclasses.
26 CodeGenTargetMachineImpl(const Target &T, StringRef DataLayoutString,
27 const Triple &TT, StringRef CPU, StringRef FS,
30
31 void initAsmInfo();
32
33 /// Reset internal state.
34 virtual void reset() {};
35
36public:
37 /// Get a TargetTransformInfo implementation for the target.
38 ///
39 /// The TTI returned uses the common code generator to answer queries about
40 /// the IR.
41 TargetTransformInfo getTargetTransformInfo(const Function &F) const override;
42
43 /// Create a pass configuration object to be used by addPassToEmitX methods
44 /// for generating a pipeline of CodeGen passes.
45 virtual TargetPassConfig *createPassConfig(PassManagerBase &PM) override;
46
47 /// Add passes to the specified pass manager to get the specified file
48 /// emitted. Typically this will involve several steps of code generation.
49 /// \p MMIWP is an optional parameter that, if set to non-nullptr,
50 /// will be used to set the MachineModuloInfo for this PM.
51 bool
52 addPassesToEmitFile(PassManagerBase &PM, raw_pwrite_stream &Out,
53 raw_pwrite_stream *DwoOut, CodeGenFileType FileType,
54 bool DisableVerify = true,
55 MachineModuleInfoWrapperPass *MMIWP = nullptr) override;
56
57 /// Add passes to the specified pass manager to get machine code emitted with
58 /// the MCJIT. This method returns true if machine code is not supported. It
59 /// fills the MCContext Ctx pointer which can be used to build custom
60 /// MCStreamer.
61 bool addPassesToEmitMC(PassManagerBase &PM, MCContext *&Ctx,
63 bool DisableVerify = true) override;
64
65 /// Adds an AsmPrinter pass to the pipeline that prints assembly or
66 /// machine code from the MI representation.
67 bool addAsmPrinter(PassManagerBase &PM, raw_pwrite_stream &Out,
68 raw_pwrite_stream *DwoOut, CodeGenFileType FileType,
69 MCContext &Context) override;
70
73 CodeGenFileType FileType, MCContext &Ctx) override;
74};
75
76/// Helper method for getting the code model, returning Default if
77/// CM does not have a value. The tiny and kernel models will produce
78/// an error, so targets that support them or require more complex codemodel
79/// selection logic should implement and call their own getEffectiveCodeModel.
81getEffectiveCodeModel(std::optional<CodeModel::Model> CM,
83 if (CM) {
84 // By default, targets do not support the tiny and kernel models.
85 if (*CM == CodeModel::Tiny)
86 reportFatalUsageError("Target does not support the tiny CodeModel");
87 if (*CM == CodeModel::Kernel)
88 reportFatalUsageError("Target does not support the kernel CodeModel");
89 return *CM;
90 }
91 return Default;
92}
93
94} // namespace llvm
95
96#endif
static MCStreamer * createMCStreamer(const Triple &T, MCContext &Context, std::unique_ptr< MCAsmBackend > &&MAB, std::unique_ptr< MCObjectWriter > &&OW, std::unique_ptr< MCCodeEmitter > &&Emitter)
#define LLVM_ABI
Definition: Compiler.h:213
static LVOptions Options
Definition: LVOptions.cpp:25
#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...
virtual void reset()
Reset internal state.
Tagged union holding either a T or a Error.
Definition: Error.h:485
Context object for machine code objects.
Definition: MCContext.h:83
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:83
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:47
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:435
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:111
CodeGenOptLevel
Code generation optimization level.
Definition: CodeGen.h:82
@ Default
The result values are uniform if and only if all operands are uniform.
LLVM_ABI void reportFatalUsageError(Error Err)
Report a fatal error that does not indicate a bug in LLVM.
Definition: Error.cpp:180