LLVM 20.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 "DXILFlattenArrays.h"
18#include "DXILOpLowering.h"
19#include "DXILPrettyPrinter.h"
20#include "DXILResourceAccess.h"
22#include "DXILShaderFlags.h"
25#include "DirectX.h"
26#include "DirectXSubtarget.h"
30#include "llvm/CodeGen/Passes.h"
36#include "llvm/MC/SectionKind.h"
44#include <optional>
45
46using namespace llvm;
47
65}
66
68public:
70
72 const TargetMachine &TM) const override {
73 return getContext().getDXContainerSection(GO->getSection(), Kind);
74 }
75
76protected:
78 const TargetMachine &TM) const override {
79 llvm_unreachable("Not supported!");
80 }
81};
82
84public:
86 : TargetPassConfig(TM, PM) {}
87
89 return getTM<DirectXTargetMachine>();
90 }
91
92 FunctionPass *createTargetRegisterAllocator(bool) override { return nullptr; }
93 void addCodeGenPrepare() override {
99 ScalarizerPassOptions DxilScalarOptions;
100 DxilScalarOptions.ScalarizeLoadStore = true;
101 addPass(createScalarizerPass(DxilScalarOptions));
105 }
106};
107
109 StringRef CPU, StringRef FS,
110 const TargetOptions &Options,
111 std::optional<Reloc::Model> RM,
112 std::optional<CodeModel::Model> CM,
113 CodeGenOptLevel OL, bool JIT)
115 T,
116 "e-m:e-p:32:32-i1:32-i8:8-i16:16-i32:32-i64:64-f16:16-"
117 "f32:32-f64:64-n8:16:32:64",
118 TT, CPU, FS, Options, Reloc::Static, CodeModel::Small, OL),
119 TLOF(std::make_unique<DXILTargetObjectFile>()),
120 Subtarget(std::make_unique<DirectXSubtarget>(TT, CPU, FS, *this)) {
121 initAsmInfo();
122}
123
125
127#define GET_PASS_REGISTRY "DirectXPassRegistry.def"
129}
130
133 CodeGenFileType FileType, bool DisableVerify,
135 TargetPassConfig *PassConfig = createPassConfig(PM);
136 PassConfig->addCodeGenPrepare();
137
138 switch (FileType) {
141 PM.add(createPrintModulePass(Out, "", true));
142 break;
146 // We embed the other DXContainer globals after embedding DXIL so that the
147 // globals don't pollute the DXIL.
149
150 if (!MMIWP)
151 MMIWP = new MachineModuleInfoWrapperPass(this);
152 PM.add(MMIWP);
153 if (addAsmPrinter(PM, Out, DwoOut, FileType,
154 MMIWP->getMMI().getContext()))
155 return true;
156 } else
157 PM.add(createDXILWriterPass(Out));
158 break;
160 break;
161 }
162 return false;
163}
164
166 MCContext *&Ctx,
168 bool DisableVerify) {
169 return true;
170}
171
173 return new DirectXPassConfig(*this, PM);
174}
175
176const DirectXSubtarget *
178 return Subtarget.get();
179}
180
183 return TargetTransformInfo(DirectXTTIImpl(this, F));
184}
185
187 const DirectXSubtarget &STI)
188 : TargetLowering(TM) {}
#define LLVM_EXTERNAL_VISIBILITY
Definition: Compiler.h:128
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
PassBuilder PB(Machine, PassOpts->PTO, std::nullopt, &PIC)
This pass converts vector operations into scalar operations (or, optionally, operations on smaller ve...
Target-Independent Code Generator Pass Configuration Options pass.
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
implements a set of functionality in the TargetMachine class for targets that make use of the indepen...
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...
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 ...
TargetTransformInfo getTargetTransformInfo(const Function &F) const override
Get a TargetTransformInfo implementation for the target.
DirectXTargetMachine(const Target &T, const Triple &TT, StringRef CPU, StringRef FS, const TargetOptions &Options, std::optional< Reloc::Model > RM, std::optional< CodeModel::Model > CM, CodeGenOptLevel OL, bool JIT)
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:310
StringRef getSection() const
Get the custom section of this global if it has one.
Definition: GlobalObject.h:117
Context object for machine code objects.
Definition: MCContext.h:83
MCSectionDXContainer * getDXContainerSection(StringRef Section, SectionKind K)
Get the section for the provided Section name.
Definition: MCContext.cpp:872
MCContext & getContext() const
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition: MCSection.h:36
const MCContext & getContext() const
This class provides access to building LLVM's passes.
Definition: PassBuilder.h:105
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:51
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:77
Target-Independent Code Generator Pass Configuration Options.
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
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:434
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.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
void initializeShaderFlagsAnalysisWrapperPass(PassRegistry &)
Initializer for dxil::ShaderFlagsAnalysisWrapper pass.
ModulePass * createDXILDataScalarizationLegacyPass()
Pass to scalarize llvm global data into a DXIL legal form.
ModulePass * createDXILWriterPass(raw_ostream &Str)
Create and return a pass that writes the module to the specified ostream.
ModulePass * createDXILTranslateMetadataLegacyPass()
Pass to emit metadata for DXIL.
void initializeDXILFlattenArraysLegacyPass(PassRegistry &)
Initializer for DXIL Array Flatten Pass.
ModulePass * createDXILPrepareModulePass()
Pass to convert modules into DXIL-compatable modules.
ModulePass * createDXContainerGlobalsPass()
Pass for generating DXContainer part globals.
ModulePass * createDXILFlattenArraysLegacyPass()
Pass to flatten arrays into a one dimensional DXIL legal form.
Target & getTheDirectXTarget()
void initializeDXILResourceMDWrapperPass(PassRegistry &)
Initializer for DXILTranslateMetadata.
FunctionPass * createDXILResourceAccessLegacyPass()
Pass to update resource accesses to use load/store directly.
CodeGenFileType
These enums are meant to be passed into addPassesToEmitFile to indicate what type of file to emit,...
Definition: CodeGen.h:83
void initializeDXILPrepareModulePass(PassRegistry &)
Initializer for DXIL-prepare.
void initializeDXILDataScalarizationLegacyPass(PassRegistry &)
Initializer for DXIL Data Scalarization Pass.
ModulePass * createDXILFinalizeLinkageLegacyPass()
Pass to finalize linkage of functions.
void initializeEmbedDXILPassPass(PassRegistry &)
Initializer for dxil embedder pass.
CodeGenOptLevel
Code generation optimization level.
Definition: CodeGen.h:54
ModulePass * createDXILIntrinsicExpansionLegacyPass()
Pass to expand intrinsic operations that lack DXIL opCodes.
void initializeDXILFinalizeLinkageLegacyPass(PassRegistry &)
Initializer for DXILFinalizeLinkage pass.
void initializeDXILIntrinsicExpansionLegacyPass(PassRegistry &)
Initializer for DXIL Intrinsic Expansion.
ModulePass * createDXILEmbedderPass()
Create and return a pass that writes the module to a global variable in the module for later emission...
FunctionPass * createScalarizerPass(const ScalarizerPassOptions &Options=ScalarizerPassOptions())
Create a legacy pass manager instance of the Scalarizer pass.
Definition: Scalarizer.cpp:444
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.
ModulePass * createDXILPrettyPrinterLegacyPass(raw_ostream &OS)
Pass to pretty print DXIL metadata.
void initializeDXContainerGlobalsPass(PassRegistry &)
Initializer for DXContainerGlobals pass.
void initializeScalarizerLegacyPassPass(PassRegistry &)
void initializeDXILResourceAccessLegacyPass(PassRegistry &)
Initializer for DXILResourceAccess.
void initializeDXILTranslateMetadataLegacyPass(PassRegistry &)
Initializer for DXILTranslateMetadata.
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:858
RegisterTargetMachine - Helper template for registering a target machine implementation,...
bool ScalarizeLoadStore
Allow the scalarizer pass to scalarize loads and store.
Definition: Scalarizer.h:48