LLVM  16.0.0git
DXILWriterPass.cpp
Go to the documentation of this file.
1 //===- DXILWriterPass.cpp - Bitcode writing pass --------------------------===//
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 // DXILWriterPass implementation.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "DXILWriterPass.h"
14 #include "DXILBitcodeWriter.h"
15 #include "llvm/ADT/DenseMap.h"
16 #include "llvm/ADT/StringRef.h"
18 #include "llvm/IR/Constants.h"
19 #include "llvm/IR/GlobalVariable.h"
20 #include "llvm/IR/Module.h"
21 #include "llvm/IR/PassManager.h"
22 #include "llvm/InitializePasses.h"
23 #include "llvm/Pass.h"
24 #include "llvm/Support/Alignment.h"
26 
27 using namespace llvm;
28 using namespace llvm::dxil;
29 
30 namespace {
31 class WriteDXILPass : public llvm::ModulePass {
32  raw_ostream &OS; // raw_ostream to print on
33 
34 public:
35  static char ID; // Pass identification, replacement for typeid
36  WriteDXILPass() : ModulePass(ID), OS(dbgs()) {
38  }
39 
40  explicit WriteDXILPass(raw_ostream &o) : ModulePass(ID), OS(o) {
42  }
43 
44  StringRef getPassName() const override { return "Bitcode Writer"; }
45 
46  bool runOnModule(Module &M) override {
47  WriteDXILToFile(M, OS);
48  return false;
49  }
50  void getAnalysisUsage(AnalysisUsage &AU) const override {
51  AU.setPreservesAll();
52  }
53 };
54 
55 class EmbedDXILPass : public llvm::ModulePass {
56 public:
57  static char ID; // Pass identification, replacement for typeid
58  EmbedDXILPass() : ModulePass(ID) {
60  }
61 
62  StringRef getPassName() const override { return "DXIL Embedder"; }
63 
64  bool runOnModule(Module &M) override {
65  std::string Data;
66  llvm::raw_string_ostream OS(Data);
67  WriteDXILToFile(M, OS);
68 
69  Constant *ModuleConstant =
70  ConstantDataArray::get(M.getContext(), arrayRefFromStringRef(Data));
71  auto *GV = new llvm::GlobalVariable(M, ModuleConstant->getType(), true,
73  ModuleConstant, "dx.dxil");
74  GV->setSection("DXIL");
75  GV->setAlignment(Align(4));
76  appendToCompilerUsed(M, {GV});
77  return true;
78  }
79 
80  void getAnalysisUsage(AnalysisUsage &AU) const override {
81  AU.setPreservesAll();
82  }
83 };
84 } // namespace
85 
86 char WriteDXILPass::ID = 0;
87 INITIALIZE_PASS_BEGIN(WriteDXILPass, "write-bitcode", "Write Bitcode", false,
88  true)
90 INITIALIZE_PASS_END(WriteDXILPass, "write-bitcode", "Write Bitcode", false,
91  true)
92 
94  return new WriteDXILPass(Str);
95 }
96 
97 char EmbedDXILPass::ID = 0;
98 INITIALIZE_PASS(EmbedDXILPass, "dxil-embed", "Embed DXIL", false, true)
99 
100 ModulePass *llvm::createDXILEmbedderPass() { return new EmbedDXILPass(); }
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
M
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
Definition: README.txt:252
llvm::ModulePass
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
Definition: Pass.h:248
StringRef.h
Pass.h
llvm::raw_string_ostream
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:628
llvm::write
Error write(MCStreamer &Out, ArrayRef< std::string > Inputs)
Definition: DWP.cpp:549
llvm::GlobalVariable
Definition: GlobalVariable.h:39
true
basic Basic Alias true
Definition: BasicAliasAnalysis.cpp:1875
DenseMap.h
Module.h
ModuleSummaryAnalysis.h
DXILWriterPass.h
llvm::Data
@ Data
Definition: SIMachineScheduler.h:55
llvm::createDXILWriterPass
ModulePass * createDXILWriterPass(raw_ostream &Str)
Create and return a pass that writes the module to the specified ostream.
Definition: DXILWriterPass.cpp:93
llvm::dbgs
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
llvm::PassRegistry::getPassRegistry
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
Definition: PassRegistry.cpp:24
Constants.h
INITIALIZE_PASS
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:37
llvm::AnalysisUsage
Represent the analysis usage information of a pass.
Definition: PassAnalysisSupport.h:47
llvm::initializeEmbedDXILPassPass
void initializeEmbedDXILPassPass(PassRegistry &)
Initializer for dxil embedder pass.
false
Definition: StackSlotColoring.cpp:141
llvm::appendToCompilerUsed
void appendToCompilerUsed(Module &M, ArrayRef< GlobalValue * > Values)
Adds global values to the llvm.compiler.used list.
Definition: ModuleUtils.cpp:109
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
Align
uint64_t Align
Definition: ELFObjHandler.cpp:81
llvm::CallingConv::ID
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition: CallingConv.h:24
INITIALIZE_PASS_BEGIN
INITIALIZE_PASS_BEGIN(WriteDXILPass, "write-bitcode", "Write Bitcode", false, true) INITIALIZE_PASS_END(WriteDXILPass
INITIALIZE_PASS_END
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:58
llvm::Constant
This is an important base class in LLVM.
Definition: Constant.h:41
llvm::dxil
Definition: DXILBitcodeWriter.cpp:55
INITIALIZE_PASS_DEPENDENCY
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
DXILBitcodeWriter.h
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
llvm::Value::getType
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:255
llvm::ConstantDataArray::get
static Constant * get(LLVMContext &Context, ArrayRef< ElementTy > Elts)
get() constructor - Return a constant with array type with an element count and element type matching...
Definition: Constants.h:692
bitcode
write bitcode
Definition: DXILWriterPass.cpp:90
Alignment.h
llvm::AnalysisUsage::setPreservesAll
void setPreservesAll()
Set by analyses that do not transform their input at all.
Definition: PassAnalysisSupport.h:130
GlobalVariable.h
PassManager.h
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
llvm::GlobalValue::PrivateLinkage
@ PrivateLinkage
Like Internal, but omit from symbol table.
Definition: GlobalValue.h:56
llvm::initializeWriteDXILPassPass
void initializeWriteDXILPassPass(PassRegistry &)
Initializer for dxil writer pass.
ModuleUtils.h
Bitcode
write Write Bitcode
Definition: DXILWriterPass.cpp:90
llvm::dxil::WriteDXILToFile
void WriteDXILToFile(const Module &M, raw_ostream &Out)
Write the specified module to the specified raw output stream.
Definition: DXILBitcodeWriter.cpp:377
llvm::ModuleSummaryIndexWrapperPass
Legacy wrapper pass to provide the ModuleSummaryIndex object.
Definition: ModuleSummaryAnalysis.h:57
InitializePasses.h
llvm::Intrinsic::ID
unsigned ID
Definition: TargetTransformInfo.h:38