-
Notifications
You must be signed in to change notification settings - Fork 2
[DirectX][HLSL] Add /Qsource_in_debug_module to llc and Clang DXC driver #157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dx-debug-main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3832,6 +3832,11 @@ static void RenderHLSLOptions(const ArgList &Args, ArgStringList &CmdArgs, | |
| if (!Args.hasArg(options::OPT_dxc_no_stdinc) && | ||
| !Args.hasArg(options::OPT_nostdinc)) | ||
| CmdArgs.push_back("-finclude-default-header"); | ||
|
|
||
| if (Args.hasArg(options::OPT_dxc_source_in_debug_module)) { | ||
| CmdArgs.push_back("-mllvm"); | ||
| CmdArgs.push_back("--dx-source-in-debug-module"); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we use a single dash for all llc options, just for the sake of consistency? I think most of the options are used like that.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
AFAIK most of llc options (which are rather target-specific or pass-specific) use double dash (that's what I see in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, I was judging by how they are usually forwarded in |
||
| } | ||
| } | ||
|
|
||
| static void RenderOpenACCOptions(const Driver &D, const ArgList &Args, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| // RUN: %clang_dxc -Tlib_6_7 -### /Zi /Qsource_in_debug_module %s 2>&1 | FileCheck %s | ||
| // RUN: %clang_dxc -Tlib_6_7 -### /Zi -Qsource_in_debug_module %s 2>&1 | FileCheck %s | ||
| // RUN: %clang_dxc -Tlib_6_7 -### /Zi %s 2>&1 | FileCheck %s --check-prefix=NOFLAG | ||
|
|
||
| // CHECK: "-mllvm" "--dx-source-in-debug-module" | ||
| // NOFLAG-NOT: --dx-source-in-debug-module |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,11 +28,17 @@ | |
| #include "llvm/InitializePasses.h" | ||
| #include "llvm/Pass.h" | ||
| #include "llvm/Support/Alignment.h" | ||
| #include "llvm/Support/CommandLine.h" | ||
| #include "llvm/Transforms/Utils/ModuleUtils.h" | ||
|
|
||
| using namespace llvm; | ||
| using namespace llvm::dxil; | ||
|
|
||
| static cl::opt<bool> SourceInDebugModule( | ||
| "dx-source-in-debug-module", | ||
| cl::desc("Embed source code into debug module on DirectX target"), | ||
| cl::init(false)); | ||
|
|
||
| namespace { | ||
| class WriteDXILPass : public llvm::ModulePass { | ||
| raw_ostream &OS; // raw_ostream to print on | ||
|
|
@@ -138,6 +144,16 @@ static void removeLifetimeIntrinsics(Module &M) { | |
| } | ||
| } | ||
|
|
||
| static void replaceNamedMetadataArray(Module &M, StringRef Name, | ||
| ArrayRef<Metadata *> NewOps) { | ||
| NamedMDNode *NMD = M.getNamedMetadata(Name); | ||
| if (!NMD) | ||
| return; | ||
| NMD->eraseFromParent(); | ||
| M.getOrInsertNamedMetadata(Name)->addOperand( | ||
| MDTuple::get(M.getContext(), NewOps)); | ||
| } | ||
|
|
||
| class EmbedDXILPass : public llvm::ModulePass { | ||
| public: | ||
| static char ID; // Pass identification, replacement for typeid | ||
|
|
@@ -155,6 +171,16 @@ class EmbedDXILPass : public llvm::ModulePass { | |
| // fail the Module Verifier if performed in an earlier pass | ||
| legalizeLifetimeIntrinsics(M); | ||
|
|
||
| // Replace dx.source metadata nodes with stubs. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this meant to be merged with the current upstream? I'm guessing it needs backend PDB functionality to fully implement, shouldn't it be added later?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It does not strictly require PDB emission functionality. |
||
| if (!SourceInDebugModule) { | ||
| LLVMContext &Ctx = M.getContext(); | ||
| MDString *EmptyString = MDString::get(Ctx, ""); | ||
| replaceNamedMetadataArray(M, "dx.source.contents", | ||
| {EmptyString, EmptyString}); | ||
| replaceNamedMetadataArray(M, "dx.source.defines", {}); | ||
| replaceNamedMetadataArray(M, "dx.source.mainFileName", {EmptyString}); | ||
| replaceNamedMetadataArray(M, "dx.source.args", {}); | ||
| } | ||
| const auto DIMap = DXILDebugInfoPass::run(M); | ||
| WriteDXILToFile(M, OS, DIMap); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| ; Compare source info emission with and without --dx-source-in-debug-module flag. | ||
|
|
||
| ; RUN: llc %s --filetype=obj -o %t.dxbc | ||
| ; RUN: llvm-objcopy --dump-section=DXIL=%t.dxil.bc %t.dxbc | ||
| ; RUN: llvm-dis %t.dxil.bc -o - | FileCheck %s --check-prefix=ILDB-DIS | ||
|
|
||
| ; RUN: llc %s --filetype=obj -o %t.dxbc --dx-source-in-debug-module | ||
| ; RUN: llvm-objcopy --dump-section=DXIL=%t.dxil.bc %t.dxbc | ||
| ; RUN: llvm-dis %t.dxil.bc -o - | FileCheck %s --check-prefix=ILDB-SOURCE-DIS | ||
|
|
||
| ; Without the flag, dx.source should be replaced with dummy metadata. | ||
| ; ILDB-DIS: !dx.source.contents = !{![[CONTENTS:[0-9]+]]} | ||
| ; ILDB-DIS: !dx.source.defines = !{![[EMPTY_ARR:[0-9]+]]} | ||
| ; ILDB-DIS: !dx.source.mainFileName = !{![[MAIN:[0-9]+]]} | ||
| ; ILDB-DIS: !dx.source.args = !{![[EMPTY_ARR]]} | ||
| ; ILDB-DIS: ![[CONTENTS]] = !{!"", !""} | ||
| ; ILDB-DIS: ![[EMPTY_ARR]] = !{} | ||
| ; ILDB-DIS: ![[MAIN]] = !{!""} | ||
|
|
||
| ; With the flag, dx.source should be be preserved. | ||
| ; ILDB-SOURCE-DIS: !dx.source.args = !{![[ARGS:[0-9]+]]} | ||
| ; ILDB-SOURCE-DIS: !dx.source.contents = !{![[FILE1:[0-9]+]], ![[FILE2:[0-9]+]], ![[FILE3:[0-9]+]]} | ||
| ; ILDB-SOURCE-DIS: !dx.source.mainFileName = !{![[MAIN:[0-9]+]]} | ||
| ; ILDB-SOURCE-DIS: !dx.source.defines = !{![[DEFINES:[0-9]+]]} | ||
| ; ILDB-SOURCE-DIS: ![[FILE1]] = !{!"C:\\dx-source-metadata.hlsl", | ||
| ; ILDB-SOURCE-DIS: ![[FILE2]] = !{!"C:\\a.hlsl" | ||
| ; ILDB-SOURCE-DIS: ![[FILE3]] = !{!"C:\\b.hlsl" | ||
| ; ILDB-SOURCE-DIS: ![[MAIN]] = !{!"C:\\dx-source-metadata.hlsl"} | ||
| ; ILDB-SOURCE-DIS: ![[DEFINES]] = !{!"USER_DEF0=42", !"USER_DEF1=43"} | ||
|
|
||
| target triple = "dxilv1.3-pc-shadermodel6.3-library" | ||
|
|
||
| define float @_Z3fooff(float %a, float %b) { | ||
| entry: | ||
| %add = fadd float %a, %b | ||
| ret float %add | ||
| } | ||
|
|
||
| !llvm.dbg.cu = !{!4} | ||
| !llvm.module.flags = !{!6, !7} | ||
|
|
||
| !dx.source.args = !{!0} | ||
| !dx.source.contents = !{!1, !2, !3} | ||
| !dx.source.mainFileName = !{!8} | ||
| !dx.source.defines = !{!9} | ||
|
|
||
| !0 = !{!"-g", !"-Tlib_6_3", !"-DUSER_DEF0=42", !"-DUSER_DEF1=43", !"C:\\\\dx-source-metadata.hlsl"} | ||
| !1 = !{!"C:\\dx-source-metadata.hlsl", !"#include \22a.hlsl\22\0A#include \22b.hlsl\22\0A\0Afloat foo(float a, float b) {\0A return a + b;\0A}\0A"} | ||
| !2 = !{!"C:\\a.hlsl", !"#include \22b.hlsl\22\0A"} | ||
| !3 = !{!"C:\\b.hlsl", !"#include <c.hlsl>\0A"} | ||
| !4 = distinct !DICompileUnit(language: DW_LANG_C99, file: !5, emissionKind: FullDebug) | ||
| !5 = !DIFile(filename: "dx-source-metadata.hlsl", directory: "C:\\") | ||
| !6 = !{i32 2, !"Dwarf Version", i32 4} | ||
| !7 = !{i32 2, !"Debug Info Version", i32 3} | ||
| !8 = !{!"C:\\dx-source-metadata.hlsl"} | ||
| !9 = !{!"USER_DEF0=42", !"USER_DEF1=43"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can shorten this by using
class DXCFlaglike other flags do.