41 "dx-source-in-debug-module",
42 cl::desc(
"Embed source code into debug module on DirectX target"),
51 DXILWriterLegacy() : ModulePass(ID), OS(
dbgs()) {
55 explicit DXILWriterLegacy(raw_ostream &o) : ModulePass(ID), OS(
o) {
59 StringRef getPassName()
const override {
return "Bitcode Writer"; }
61 bool runOnModule(
Module &M)
override {
65 void getAnalysisUsage(AnalysisUsage &AU)
const override {
70static void legalizeLifetimeIntrinsics(
Module &M) {
75 Intrinsic::lifetime_end};
85 Attr = Attr.addFnAttribute(Ctx, Attribute::NoUnwind);
94 "Expected user of a lifetime intrinsic function to be a CallInst");
108 "The pointer operand of a lifetime intrinsic call must be an "
110 std::optional<TypeSize> AllocSize =
112 assert(AllocSize.has_value() &&
113 "Expected the allocation size of AllocaInst to be known");
116 {ConstantInt::get(I64Ty, AllocSize.value().getFixedValue()),
125 F->eraseFromParent();
129static void removeLifetimeIntrinsics(
Module &M) {
131 Intrinsic::lifetime_end};
139 assert(CI &&
"Expected user of lifetime function to be a CallInst");
141 assert(BCI &&
"Expected pointer operand of CallInst to be a BitCastInst");
145 F->eraseFromParent();
155 M.getOrInsertNamedMetadata(Name)->addOperand(
162 DXILEmbedderLegacy() : ModulePass(ID) {
166 StringRef getPassName()
const override {
return "DXIL Embedder"; }
168 bool runOnModule(
Module &M)
override;
170 void getAnalysisUsage(AnalysisUsage &AU)
const override {
186 replaceNamedMetadataArray(M,
"dx.source.contents",
187 {EmptyString, EmptyString});
188 replaceNamedMetadataArray(M,
"dx.source.defines", {});
189 replaceNamedMetadataArray(M,
"dx.source.mainFileName", {EmptyString});
190 replaceNamedMetadataArray(M,
"dx.source.args", {});
197 if (
NamedMDNode *Flags = M.getModuleFlagsMetadata()) {
199 M.getModuleFlagsMetadata(FlagEntries);
200 Flags->eraseFromParent();
202 if (Entry.Key->getString() ==
"Dwarf Version" ||
203 Entry.Key->getString() ==
"Debug Info Version") {
206 M.addModuleFlag(Entry.Behavior, Entry.Key->getString(), Entry.Val);
214#ifdef EXPENSIVE_CHECKS
216 "The module must not contain any debug info here."
217 "Shader modules with debug info must have !DICompileUnit metadata.");
231 ModuleConstant, GlobalName);
233 GV->setAlignment(
Align(4));
240 legalizeLifetimeIntrinsics(M);
242 bool HasDebugInfo = !M.debug_compile_units().empty();
248 "Missing debug info for embedding into the container");
252 std::string ILDBData;
263 std::string DXILData =
269 removeLifetimeIntrinsics(M);
282bool DXILEmbedderLegacy::runOnModule(
Module &M) {
291char DXILWriterLegacy::ID = 0;
299 return new DXILWriterLegacy(Str);
302char DXILEmbedderLegacy::ID = 0;
303INITIALIZE_PASS(DXILEmbedderLegacy,
"dxil-embedder",
"Embed DXIL",
false,
true)
306 return new DXILEmbedderLegacy();
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
static bool runEmbedderOnModule(Module &M)
static GlobalVariable * createSectionGlobal(Module &M, StringRef Data, StringRef GlobalName, StringRef SectionName)
This file provides a bitcode writing pass.
Module.h This file contains the declarations for the Module class.
This header defines various interfaces for pass management in LLVM.
This is the interface to build a ModuleSummaryIndex for a module.
ModuleAnalysisManager MAM
#define INITIALIZE_PASS_DEPENDENCY(depName)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
an instruction to allocate memory on the stack
LLVM_ABI std::optional< TypeSize > getAllocationSize(const DataLayout &DL) const
Get allocation size in bytes.
void setPreservesAll()
Set by analyses that do not transform their input at all.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Functions, function parameters, and return types can have attributes to indicate how they should be t...
This class represents a no-op cast from one type to another.
AttributeSet getParamAttributes(unsigned ArgNo) const
Return the param attributes for this call.
Value * getArgOperand(unsigned i) const
void addParamAttr(unsigned ArgNo, Attribute::AttrKind Kind)
Adds the attribute to the indicated argument.
This class represents a function call, abstracting a target machine's calling convention.
static CallInst * Create(FunctionType *Ty, Value *F, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
static LLVM_ABI CastInst * Create(Instruction::CastOps, Value *S, Type *Ty, const Twine &Name="", InsertPosition InsertBefore=nullptr)
Provides a way to construct any of the CastInst subclasses using an opcode instead of the subclass's ...
static Constant * get(LLVMContext &Context, ArrayRef< ElementTy > Elts)
get() constructor - Return a constant with array type with an element count and element type matching...
This is an important base class in LLVM.
PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM)
PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM)
A handy container for a FunctionType+Callee-pointer pair, which can be passed around as a single enti...
@ PrivateLinkage
Like Internal, but omit from symbol table.
LLVM_ABI InstListType::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
LLVM_ABI const DataLayout & getDataLayout() const
Get the data layout of the module this instruction belongs to.
static LLVM_ABI IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
This is an important class for using LLVM in a threaded context.
static LLVM_ABI MDString * get(LLVMContext &Context, StringRef Str)
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
Legacy wrapper pass to provide the ModuleSummaryIndex object.
A Module instance is used to store all the information related to an LLVM module.
LLVM_ABI StringRef getName() const
LLVM_ABI void eraseFromParent()
Drop all references and remove the node from parent module.
static LLVM_ABI PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
static LLVM_ABI PointerType * get(LLVMContext &C, unsigned AddressSpace)
This constructs an opaque pointer to an object in a numbered address space.
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
reference emplace_back(ArgTypes &&... Args)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
The instances of the Type class are immutable: once they are created, they are never changed.
static LLVM_ABI Type * getVoidTy(LLVMContext &C)
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
self_iterator getIterator()
This class implements an extremely fast bulk output stream that can only output to a stream.
A raw_ostream that writes to an std::string.
Pass manager infrastructure for declaring and invalidating analyses.
LLVM_ABI StringRef getName(ID id)
Return the LLVM name for an intrinsic, such as "llvm.ppc.altivec.lvx".
LLVM_ABI StringRef getBaseName(ID id)
Return the LLVM name for an intrinsic, without encoded types for overloading, such as "llvm....
initializer< Ty > init(const Ty &Val)
cl::opt< bool > EmbedDebug
cl::opt< std::string > PdbDebugPath
cl::opt< bool > SlimDebug
cl::opt< bool > SourceInDebugModule
void WriteDXILToFile(Module &M, raw_ostream &Out)
Write the specified module to the specified raw output stream.
This is an optimization pass for GlobalISel generic memory operations.
ArrayRef< CharT > arrayRefFromStringRef(StringRef Input)
Construct an array ref of bytes from a string ref.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
ModulePass * createDXILWriterLegacyPass(raw_ostream &Str)
void initializeDXILWriterLegacyPass(PassRegistry &)
Initializer for dxil writer pass.
ModulePass * createDXILEmbedderLegacyPass()
LLVM_ABI size_t writeModule(const Module &M, uint8_t *Dest, size_t MaxSize)
Fuzzer friendly interface for the llvm bitcode printer.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
LLVM_ABI bool StripDebugInfo(Module &M)
Strip debug info in the module if it exists.
LLVM_ABI void appendToCompilerUsed(Module &M, ArrayRef< GlobalValue * > Values)
Adds global values to the llvm.compiler.used list.
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
LLVM_ABI std::unique_ptr< Module > CloneModule(const Module &M)
Return an exact copy of the specified module.
void initializeDXILEmbedderLegacyPass(PassRegistry &)
Initializer for dxil embedder pass.
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
LLVM_ABI void reportFatalUsageError(Error Err)
Report a fatal error that does not indicate a bug in LLVM.
This struct is a compact representation of a valid (non-zero power of two) alignment.