LLVM  15.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 
14 #include "DirectXTargetMachine.h"
16 #include "DirectX.h"
17 #include "DirectXSubtarget.h"
21 #include "llvm/CodeGen/Passes.h"
26 #include "llvm/MC/SectionKind.h"
27 #include "llvm/MC/TargetRegistry.h"
28 #include "llvm/Support/CodeGen.h"
29 #include "llvm/Support/Compiler.h"
32 
33 using namespace llvm;
34 
37  auto *PR = PassRegistry::getPassRegistry();
42 }
43 
45 public:
46  DXILTargetObjectFile() = default;
47 
49  const TargetMachine &TM) const override {
50  return getContext().getDXContainerSection(GO->getSection(), Kind);
51  }
52 
53 protected:
55  const TargetMachine &TM) const override {
56  llvm_unreachable("Not supported!");
57  }
58 };
59 
61 public:
63  : TargetPassConfig(TM, PM) {}
64 
66  return getTM<DirectXTargetMachine>();
67  }
68 
69  FunctionPass *createTargetRegisterAllocator(bool) override { return nullptr; }
70 };
71 
73  StringRef CPU, StringRef FS,
74  const TargetOptions &Options,
77  CodeGenOpt::Level OL, bool JIT)
79  "e-m:e-p:32:32-i1:32-i8:8-i16:16-i32:32-i64:64-f16:16-"
80  "f32:32-f64:64-n8:16:32:64",
81  TT, CPU, FS, Options, Reloc::Static, CodeModel::Small,
82  OL),
83  TLOF(std::make_unique<DXILTargetObjectFile>()),
84  Subtarget(std::make_unique<DirectXSubtarget>(TT, CPU, FS, *this)) {
85  initAsmInfo();
86 }
87 
89 
92  CodeGenFileType FileType, bool DisableVerify,
99  }
100  switch (FileType) {
101  case CGFT_AssemblyFile:
102  PM.add(createPrintModulePass(Out, "", true));
103  break;
104  case CGFT_ObjectFile:
106  if (!MMIWP)
107  MMIWP = new MachineModuleInfoWrapperPass(this);
108  PM.add(MMIWP);
109  if (addAsmPrinter(PM, Out, DwoOut, FileType,
110  MMIWP->getMMI().getContext()))
111  return true;
112  } else
113  PM.add(createDXILWriterPass(Out));
114  break;
115  case CGFT_Null:
116  break;
117  }
118  return false;
119 }
120 
122  MCContext *&Ctx,
123  raw_pwrite_stream &Out,
124  bool DisableVerify) {
125  return true;
126 }
127 
129  return new DirectXPassConfig(*this, PM);
130 }
131 
132 const DirectXSubtarget *
134  return Subtarget.get();
135 }
136 
139  return TargetTransformInfo(DirectXTTIImpl(this, F));
140 }
141 
143  const DirectXSubtarget &STI)
144  : TargetLowering(TM) {}
llvm::DirectXTargetMachine::getTargetTransformInfo
TargetTransformInfo getTargetTransformInfo(const Function &F) const override
Get a TargetTransformInfo implementation for the target.
Definition: DirectXTargetMachine.cpp:138
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::MachineModuleInfo::getContext
const MCContext & getContext() const
Definition: MachineModuleInfo.h:143
llvm::CGFT_ObjectFile
@ CGFT_ObjectFile
Definition: CodeGen.h:65
DirectXPassConfig::DirectXPassConfig
DirectXPassConfig(DirectXTargetMachine &TM, PassManagerBase &PM)
Definition: DirectXTargetMachine.cpp:62
llvm::TargetOptions
Definition: TargetOptions.h:124
llvm::TargetPassConfig::willCompleteCodeGenPipeline
static bool willCompleteCodeGenPipeline()
Returns true if none of the -stop-before and -stop-after options is set.
Definition: TargetPassConfig.cpp:674
T
llvm::MCContext
Context object for machine code objects.
Definition: MCContext.h:76
llvm::Function
Definition: Function.h:60
llvm::GlobalObject::getSection
StringRef getSection() const
Get the custom section of this global if it has one.
Definition: GlobalObject.h:111
llvm::Target
Target - Wrapper for Target specific information.
Definition: TargetRegistry.h:145
llvm::DirectXTargetMachine
Definition: DirectXTargetMachine.h:19
ErrorHandling.h
llvm::TargetTransformInfo
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
Definition: TargetTransformInfo.h:170
llvm::DirectXSubtarget
Definition: DirectXSubtarget.h:30
llvm::Triple
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
llvm::CGFT_Null
@ CGFT_Null
Definition: CodeGen.h:66
llvm::initializeDXILPrepareModulePass
void initializeDXILPrepareModulePass(PassRegistry &)
Initializer for DXIL-prepare.
llvm::MachineModuleInfoWrapperPass::getMMI
MachineModuleInfo & getMMI()
Definition: MachineModuleInfo.h:228
llvm::Optional< Reloc::Model >
LegacyPassManager.h
DXILWriterPass.h
llvm::createDXILWriterPass
ModulePass * createDXILWriterPass(raw_ostream &Str)
Create and return a pass that writes the module to the specified ostream.
Definition: DXILWriterPass.cpp:93
F
#define F(x, y, z)
Definition: MD5.cpp:55
llvm::TargetLoweringObjectFile
Definition: TargetLoweringObjectFile.h:45
DirectXTargetTransformInfo.h
llvm::initializeDXILTranslateMetadataPass
void initializeDXILTranslateMetadataPass(PassRegistry &)
Initializer for DXILTranslateMetadata.
DirectX.h
llvm::MSP430Attrs::CodeModel
CodeModel
Definition: MSP430Attributes.h:37
llvm::PassRegistry::getPassRegistry
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
Definition: PassRegistry.cpp:24
llvm::DirectXTargetMachine::DirectXTargetMachine
DirectXTargetMachine(const Target &T, const Triple &TT, StringRef CPU, StringRef FS, const TargetOptions &Options, Optional< Reloc::Model > RM, Optional< CodeModel::Model > CM, CodeGenOpt::Level OL, bool JIT)
Definition: DirectXTargetMachine.cpp:72
llvm::createDXILTranslateMetadataPass
ModulePass * createDXILTranslateMetadataPass()
Pass to emit metadata for DXIL.
Definition: DXILTranslateMetadata.cpp:116
llvm::DirectXTargetMachine::~DirectXTargetMachine
~DirectXTargetMachine() override
Definition: DirectXTargetMachine.cpp:88
llvm::GlobalObject
Definition: GlobalObject.h:27
llvm::TargetLowering
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
Definition: TargetLowering.h:3415
llvm::DirectXTargetLowering::DirectXTargetLowering
DirectXTargetLowering(const DirectXTargetMachine &TM, const DirectXSubtarget &STI)
Definition: DirectXTargetMachine.cpp:142
llvm::createDXILOpLoweringLegacyPass
ModulePass * createDXILOpLoweringLegacyPass()
Pass to lowering LLVM intrinsic call to DXIL op function call.
Definition: DXILOpLowering.cpp:263
llvm::DirectXTTIImpl
Definition: DirectXTargetTransformInfo.h:20
llvm::initializeEmbedDXILPassPass
void initializeEmbedDXILPassPass(PassRegistry &)
Initializer for dxil embedder pass.
llvm::CodeModel::Small
@ Small
Definition: CodeGen.h:28
llvm::RegisterTargetMachine
RegisterTargetMachine - Helper template for registering a target machine implementation,...
Definition: TargetRegistry.h:1318
IRPrintingPasses.h
Options
const char LLVMTargetMachineRef LLVMPassBuilderOptionsRef Options
Definition: PassBuilderBindings.cpp:48
DirectXPassConfig::createTargetRegisterAllocator
FunctionPass * createTargetRegisterAllocator(bool) override
createTargetRegisterAllocator - Create the register allocator pass for this target at the current opt...
Definition: DirectXTargetMachine.cpp:69
DXILTargetObjectFile
Definition: DirectXTargetMachine.cpp:44
llvm::lltok::Kind
Kind
Definition: LLToken.h:18
X
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
llvm::legacy::PassManagerBase::add
virtual void add(Pass *P)=0
Add a pass to the queue of passes to run.
llvm::MachO::FileType
FileType
Defines the file type this file represents.
Definition: InterfaceFile.h:53
Passes.h
llvm::TargetPassConfig
Target-Independent Code Generator Pass Configuration Options.
Definition: TargetPassConfig.h:84
DirectXTargetMachine.h
llvm::raw_pwrite_stream
An abstract base class for streams implementations that also support a pwrite operation.
Definition: raw_ostream.h:418
llvm::EngineKind::JIT
@ JIT
Definition: ExecutionEngine.h:524
llvm::MachineModuleInfoWrapperPass
Definition: MachineModuleInfo.h:214
LLVM_EXTERNAL_VISIBILITY
#define LLVM_EXTERNAL_VISIBILITY
Definition: Compiler.h:126
TargetPassConfig.h
llvm::initializeDXILOpLoweringLegacyPass
void initializeDXILOpLoweringLegacyPass(PassRegistry &)
Initializer for DXILOpLowering.
llvm::TargetMachine
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:77
llvm::X86AS::FS
@ FS
Definition: X86.h:196
MachineModuleInfo.h
llvm::AArch64::RM
@ RM
Definition: AArch64ISelLowering.h:471
llvm::CodeGenFileType
CodeGenFileType
These enums are meant to be passed into addPassesToEmitFile to indicate what type of file to emit,...
Definition: CodeGen.h:63
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
this
Analysis the ScalarEvolution expression for r is this
Definition: README.txt:8
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:143
TargetLoweringObjectFile.h
Compiler.h
llvm::MCSection
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition: MCSection.h:39
MCSectionDXContainer.h
llvm::DirectXTargetMachine::createPassConfig
TargetPassConfig * createPassConfig(PassManagerBase &PM) override
Create a pass configuration object to be used by addPassToEmitX methods for generating a pipeline of ...
Definition: DirectXTargetMachine.cpp:128
DXILTargetObjectFile::getExplicitSectionGlobal
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...
Definition: DirectXTargetMachine.cpp:48
llvm::CodeGenOpt::Level
Level
Definition: CodeGen.h:52
llvm::LLVMTargetMachine::initAsmInfo
void initAsmInfo()
Definition: LLVMTargetMachine.cpp:40
llvm::getTheDirectXTarget
Target & getTheDirectXTarget()
Definition: DirectXTargetInfo.cpp:19
llvm::createDXILPrepareModulePass
ModulePass * createDXILPrepareModulePass()
Pass to convert modules into DXIL-compatable modules.
Definition: DXILPrepare.cpp:182
llvm::SectionKind
SectionKind - This is a simple POD value that classifies the properties of a section.
Definition: SectionKind.h:22
std
Definition: BitVector.h:851
DirectXPassConfig::getDirectXTargetMachine
DirectXTargetMachine & getDirectXTargetMachine() const
Definition: DirectXTargetMachine.cpp:65
llvm::DirectXTargetMachine::getSubtargetImpl
const DirectXSubtarget * getSubtargetImpl(const Function &) const override
Virtual method implemented by subclasses that returns a reference to that target's TargetSubtargetInf...
Definition: DirectXTargetMachine.cpp:133
llvm::LLVMTargetMachine
This class describes a target machine that is implemented with the LLVM target-independent code gener...
Definition: TargetMachine.h:414
llvm::createDXILEmbedderPass
ModulePass * createDXILEmbedderPass()
Create and return a pass that writes the module to a global variable in the module for later emission...
Definition: DXILWriterPass.cpp:100
DXILTargetObjectFile::SelectSectionForGlobal
MCSection * SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
Definition: DirectXTargetMachine.cpp:54
SectionKind.h
llvm::DirectXTargetMachine::addPassesToEmitMC
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.
Definition: DirectXTargetMachine.cpp:121
CodeGen.h
LLVMInitializeDirectXTarget
LLVM_EXTERNAL_VISIBILITY void LLVMInitializeDirectXTarget()
Definition: DirectXTargetMachine.cpp:35
DirectXTargetInfo.h
llvm::legacy::PassManagerBase
PassManagerBase - An abstract interface to allow code to add passes to a pass manager without having ...
Definition: LegacyPassManager.h:39
TM
const char LLVMTargetMachineRef TM
Definition: PassBuilderBindings.cpp:47
llvm::DirectXTargetMachine::addPassesToEmitFile
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.
Definition: DirectXTargetMachine.cpp:90
DirectXSubtarget.h
llvm::FunctionPass
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:308
DirectXPassConfig
Definition: DirectXTargetMachine.cpp:60
llvm::CGFT_AssemblyFile
@ CGFT_AssemblyFile
Definition: CodeGen.h:64
TargetRegistry.h
llvm::LLVMTargetMachine::addAsmPrinter
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...
Definition: LLVMTargetMachine.cpp:125
llvm::createPrintModulePass
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.