Skip to content

Commit

Permalink
[DirectX] Only embed dxil when writing object files
Browse files Browse the repository at this point in the history
When emitting assembly we don't particularly want the binary DXIL
embedded in the output. This was mostly there for testing purposes, so
we update those tests to run the test directly using `opt` and
restrict the -dxil-embed and -dxil-globals passes to running normally
only in the case where we're trying to emit a DXContainer.

Differential Revision: https://reviews.llvm.org/D158051
  • Loading branch information
bogner committed Aug 16, 2023
1 parent 939bdae commit 72017fc
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
12 changes: 6 additions & 6 deletions llvm/lib/Target/DirectX/DirectXTargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeDirectXTarget() {
initializeDXILPrepareModulePass(*PR);
initializeEmbedDXILPassPass(*PR);
initializeWriteDXILPassPass(*PR);
initializeDXContainerGlobalsPass(*PR);
initializeDXILOpLoweringLegacyPass(*PR);
initializeDXILTranslateMetadataPass(*PR);
initializeDXILResourceWrapperPass(*PR);
Expand Down Expand Up @@ -127,19 +128,18 @@ bool DirectXTargetMachine::addPassesToEmitFile(
TargetPassConfig *PassConfig = createPassConfig(PM);
PassConfig->addCodeGenPrepare();

if (TargetPassConfig::willCompleteCodeGenPipeline()) {
PM.add(createDXILEmbedderPass());
// We embed the other DXContainer globals after embedding DXIL so that the
// globals don't pollute the DXIL.
PM.add(createDXContainerGlobalsPass());
}
switch (FileType) {
case CGFT_AssemblyFile:
PM.add(createDXILPrettyPrinterPass(Out));
PM.add(createPrintModulePass(Out, "", true));
break;
case CGFT_ObjectFile:
if (TargetPassConfig::willCompleteCodeGenPipeline()) {
PM.add(createDXILEmbedderPass());
// We embed the other DXContainer globals after embedding DXIL so that the
// globals don't pollute the DXIL.
PM.add(createDXContainerGlobalsPass());

if (!MMIWP)
MMIWP = new MachineModuleInfoWrapperPass(this);
PM.add(MMIWP);
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/CodeGen/DirectX/ContainerData/DebugShaderHash.ll
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
; RUN: llc %s --filetype=asm -o - | FileCheck %s
; RUN: opt %s -dxil-embed -dxil-globals -S -o - | FileCheck %s
; RUN: llc %s --filetype=obj -o - | obj2yaml | FileCheck %s --check-prefix=DXC
target triple = "dxil-unknown-shadermodel6.5-library"

Expand Down
2 changes: 1 addition & 1 deletion llvm/test/CodeGen/DirectX/ContainerData/ShaderHash.ll
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
; RUN: llc %s --filetype=asm -o - | FileCheck %s
; RUN: opt %s -dxil-embed -dxil-globals -S -o - | FileCheck %s
; RUN: llc %s --filetype=obj -o - | obj2yaml | FileCheck %s --check-prefix=DXC
target triple = "dxil-unknown-shadermodel6.5-library"

Expand Down
1 change: 0 additions & 1 deletion llvm/test/CodeGen/DirectX/embed-dxil.ll
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
; RUN: llc %s --filetype=asm -o - | FileCheck %s
; RUN: opt %s -dxil-embed -S -o - | FileCheck %s
; RUN: llc %s --filetype=obj -o - | obj2yaml | FileCheck %s --check-prefix=DXC
target triple = "dxil-unknown-shadermodel6.5-library"
Expand Down

0 comments on commit 72017fc

Please sign in to comment.