LLVM 17.0.0git
DirectXTargetMachine.cpp
Go to the documentation of this file.
1//===- DirectXTargetMachine.cpp - DirectX Target Implementation -*- 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
10/// This file contains DirectX target initializer.
11///
12//===----------------------------------------------------------------------===//
13
16#include "DXILShaderFlags.h"
18#include "DirectX.h"
19#include "DirectXSubtarget.h"
23#include "llvm/CodeGen/Passes.h"
28#include "llvm/MC/SectionKind.h"
35#include <optional>
36
37using namespace llvm;
38
49}
50
52public:
54
56 const TargetMachine &TM) const override {
57 return getContext().getDXContainerSection(GO->getSection(), Kind);
58 }
59
60protected:
62 const TargetMachine &TM) const override {
63 llvm_unreachable("Not supported!");
64 }
65};
66
68public:
70 : TargetPassConfig(TM, PM) {}
71
73 return getTM<DirectXTargetMachine>();
74 }
75
76 FunctionPass *createTargetRegisterAllocator(bool) override { return nullptr; }
77 void addCodeGenPrepare() override {
81 }
82};
83
85 StringRef CPU, StringRef FS,
87 std::optional<Reloc::Model> RM,
88 std::optional<CodeModel::Model> CM,
89 CodeGenOpt::Level OL, bool JIT)
91 "e-m:e-p:32:32-i1:32-i8:8-i16:16-i32:32-i64:64-f16:16-"
92 "f32:32-f64:64-n8:16:32:64",
93 TT, CPU, FS, Options, Reloc::Static, CodeModel::Small,
94 OL),
95 TLOF(std::make_unique<DXILTargetObjectFile>()),
96 Subtarget(std::make_unique<DirectXSubtarget>(TT, CPU, FS, *this)) {
98}
99
101
106 if (PassName == "print-dxil-resource") {
108 return true;
109 }
110 if (PassName == "print-dx-shader-flags") {
112 return true;
113 }
114 return false;
115 });
116
118 MAM.registerPass([&] { return DXILResourceAnalysis(); });
119 MAM.registerPass([&] { return dxil::ShaderFlagsAnalysis(); });
120 });
121}
122
125 CodeGenFileType FileType, bool DisableVerify,
127 TargetPassConfig *PassConfig = createPassConfig(PM);
128 PassConfig->addCodeGenPrepare();
129
132 // We embed the other DXContainer globals after embedding DXIL so that the
133 // globals don't pollute the DXIL.
135 }
136 switch (FileType) {
139 PM.add(createPrintModulePass(Out, "", true));
140 break;
141 case CGFT_ObjectFile:
143 if (!MMIWP)
144 MMIWP = new MachineModuleInfoWrapperPass(this);
145 PM.add(MMIWP);
146 if (addAsmPrinter(PM, Out, DwoOut, FileType,
147 MMIWP->getMMI().getContext()))
148 return true;
149 } else
150 PM.add(createDXILWriterPass(Out));
151 break;
152 case CGFT_Null:
153 break;
154 }
155 return false;
156}
157
159 MCContext *&Ctx,
161 bool DisableVerify) {
162 return true;
163}
164
166 return new DirectXPassConfig(*this, PM);
167}
168
169const DirectXSubtarget *
171 return Subtarget.get();
172}
173
176 return TargetTransformInfo(DirectXTTIImpl(this, F));
177}
178
180 const DirectXSubtarget &STI)
181 : TargetLowering(TM) {}
#define LLVM_EXTERNAL_VISIBILITY
Definition: Compiler.h:127
This file provides a bitcode writing pass.
LLVM_EXTERNAL_VISIBILITY void LLVMInitializeDirectXTarget()
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
This file contains an interface for creating legacy passes to print out IR in various granularities.
static LVOptions Options
Definition: LVOptions.cpp:25
#define F(x, y, z)
Definition: MD5.cpp:55
ModuleAnalysisManager MAM
const char LLVMTargetMachineRef TM
PassBuilder PB(Machine, PassOpts->PTO, std::nullopt, &PIC)
Target-Independent Code Generator Pass Configuration Options pass.
static const char PassName[]
DXILTargetObjectFile()=default
MCSection * SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
MCSection * getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
Targets should implement this method to assign a section to globals with an explicit section specfied...
FunctionPass * createTargetRegisterAllocator(bool) override
createTargetRegisterAllocator - Create the register allocator pass for this target at the current opt...
void addCodeGenPrepare() override
Add pass to prepare the LLVM IR for code generation.
DirectXPassConfig(DirectXTargetMachine &TM, PassManagerBase &PM)
DirectXTargetMachine & getDirectXTargetMachine() const
A container for analyses that lazily runs them and caches their results.
Definition: PassManager.h:620
bool registerPass(PassBuilderT &&PassBuilder)
Register an analysis pass with the manager.
Definition: PassManager.h:836
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
Analysis pass that exposes the DXILResource for a module.
Printer pass for the DXILResourceAnalysis results.
DirectXTargetLowering(const DirectXTargetMachine &TM, const DirectXSubtarget &STI)
TargetPassConfig * createPassConfig(PassManagerBase &PM) override
Create a pass configuration object to be used by addPassToEmitX methods for generating a pipeline of ...
DirectXTargetMachine(const Target &T, const Triple &TT, StringRef CPU, StringRef FS, const TargetOptions &Options, std::optional< Reloc::Model > RM, std::optional< CodeModel::Model > CM, CodeGenOpt::Level OL, bool JIT)
TargetTransformInfo getTargetTransformInfo(const Function &F) const override
Get a TargetTransformInfo implementation for the target.
const DirectXSubtarget * getSubtargetImpl(const Function &) const override
Virtual method implemented by subclasses that returns a reference to that target's TargetSubtargetInf...
bool addPassesToEmitFile(PassManagerBase &PM, raw_pwrite_stream &Out, raw_pwrite_stream *DwoOut, CodeGenFileType FileType, bool DisableVerify, MachineModuleInfoWrapperPass *MMIWP) 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) override
Add passes to the specified pass manager to get machine code emitted with the MCJIT.
void registerPassBuilderCallbacks(PassBuilder &PB) override
Allow the target to modify the pass pipeline.
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:308
StringRef getSection() const
Get the custom section of this global if it has one.
Definition: GlobalObject.h:117
This class describes a target machine that is implemented with the LLVM target-independent code gener...
bool addAsmPrinter(PassManagerBase &PM, raw_pwrite_stream &Out, raw_pwrite_stream *DwoOut, CodeGenFileType FileType, MCContext &Context)
Adds an AsmPrinter pass to the pipeline that prints assembly or machine code from the MI representati...
Context object for machine code objects.
Definition: MCContext.h:76
MCSectionDXContainer * getDXContainerSection(StringRef Section, SectionKind K)
Get the section for the provided Section name.
Definition: MCContext.cpp:858
MCContext & getContext() const
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition: MCSection.h:39
const MCContext & getContext() const
This class provides access to building LLVM's passes.
Definition: PassBuilder.h:96
void registerAnalysisRegistrationCallback(const std::function< void(CGSCCAnalysisManager &)> &C)
{{@ Register callbacks for analysis registration with this PassBuilder instance.
Definition: PassBuilder.h:514
void registerPipelineParsingCallback(const std::function< bool(StringRef Name, CGSCCPassManager &, ArrayRef< PipelineElement >)> &C)
{{@ Register pipeline parsing callbacks with this pass builder instance.
Definition: PassBuilder.h:536
LLVM_ATTRIBUTE_MINSIZE std::enable_if_t<!std::is_same< PassT, PassManager >::value > addPass(PassT &&Pass)
Definition: PassManager.h:544
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
SectionKind - This is a simple POD value that classifies the properties of a section.
Definition: SectionKind.h:22
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:78
Target-Independent Code Generator Pass Configuration Options.
LLVMTargetMachine * TM
virtual void addCodeGenPrepare()
Add pass to prepare the LLVM IR for code generation.
AnalysisID addPass(AnalysisID PassID)
Utilities for targets to add passes to the pass manager.
static bool willCompleteCodeGenPipeline()
Returns true if none of the -stop-before and -stop-after options is set.
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
Printer pass for ShaderFlagsAnalysis results.
PassManagerBase - An abstract interface to allow code to add passes to a pass manager without having ...
virtual void add(Pass *P)=0
Add a pass to the queue of passes to run.
An abstract base class for streams implementations that also support a pwrite operation.
Definition: raw_ostream.h:428
Interfaces for registering analysis passes, producing common pass manager configurations,...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Level
Code generation optimization level.
Definition: CodeGen.h:57
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
void initializeShaderFlagsAnalysisWrapperPass(PassRegistry &)
Initializer for dxil::ShaderFlagsAnalysisWrapper pass.
ModulePass * createDXILWriterPass(raw_ostream &Str)
Create and return a pass that writes the module to the specified ostream.
ModulePass * createDXILPrepareModulePass()
Pass to convert modules into DXIL-compatable modules.
ModulePass * createDXContainerGlobalsPass()
Pass for generating DXContainer part globals.
Target & getTheDirectXTarget()
ModulePass * createDXILTranslateMetadataPass()
Pass to emit metadata for DXIL.
CodeGenFileType
These enums are meant to be passed into addPassesToEmitFile to indicate what type of file to emit,...
Definition: CodeGen.h:84
@ CGFT_AssemblyFile
Definition: CodeGen.h:85
@ CGFT_Null
Definition: CodeGen.h:87
@ CGFT_ObjectFile
Definition: CodeGen.h:86
ModulePass * createDXILPrettyPrinterPass(raw_ostream &OS)
Pass to pretty print DXIL metadata.
void initializeDXILPrepareModulePass(PassRegistry &)
Initializer for DXIL-prepare.
void initializeDXILResourceWrapperPass(PassRegistry &)
Initializer for DXILTranslateMetadata.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
void initializeEmbedDXILPassPass(PassRegistry &)
Initializer for dxil embedder pass.
ModulePass * createDXILEmbedderPass()
Create and return a pass that writes the module to a global variable in the module for later emission...
ModulePass * createDXILOpLoweringLegacyPass()
Pass to lowering LLVM intrinsic call to DXIL op function call.
ModulePass * createPrintModulePass(raw_ostream &OS, const std::string &Banner="", bool ShouldPreserveUseListOrder=false)
Create and return a pass that writes the module to the specified raw_ostream.
void initializeDXILOpLoweringLegacyPass(PassRegistry &)
Initializer for DXILOpLowering.
void initializeWriteDXILPassPass(PassRegistry &)
Initializer for dxil writer pass.
void initializeDXILTranslateMetadataPass(PassRegistry &)
Initializer for DXILTranslateMetadata.
Definition: BitVector.h:851
RegisterTargetMachine - Helper template for registering a target machine implementation,...