Skip to content

Commit 6fb53fb

Browse files
committed
custom pass
1 parent 0eb9285 commit 6fb53fb

File tree

7 files changed

+69
-9
lines changed

7 files changed

+69
-9
lines changed

include/dxc/HLSL/DxilGenerationPass.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ FunctionPass *createMatrixBitcastLowerPass();
8282
ModulePass *createDxilCleanupAddrSpaceCastPass();
8383
ModulePass *createDxilRenameResourcesPass();
8484
ModulePass *createDxilScalarizeVectorIntrinsicsPass();
85+
ModulePass *createDxilStripDebugSensitiveInfoPass();
8586

8687
void initializeDxilLowerCreateHandleForLibPass(llvm::PassRegistry &);
8788
void initializeDxilAllocateResourcesForLibPass(llvm::PassRegistry &);
@@ -117,6 +118,7 @@ void initializeMatrixBitcastLowerPassPass(llvm::PassRegistry &);
117118
void initializeDxilCleanupAddrSpaceCastPass(llvm::PassRegistry &);
118119
void initializeDxilRenameResourcesPass(llvm::PassRegistry &);
119120
void initializeDxilScalarizeVectorIntrinsicsPass(llvm::PassRegistry &);
121+
void initializeDxilStripDebugSensitiveInfoPass(llvm::PassRegistry &);
120122

121123
ModulePass *createDxilValidateWaveSensitivityPass();
122124
void initializeDxilValidateWaveSensitivityPass(llvm::PassRegistry &);

include/dxc/HLSL/DxilLinker.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class DxilLinker {
4242
void SetValidatorVersion(unsigned valMajor, unsigned valMinor) {
4343
m_valMajor = valMajor, m_valMinor = valMinor;
4444
}
45+
void SetStripDebug(bool StripDebug) { m_StripDebug = StripDebug; }
4546
virtual bool HasLibNameRegistered(llvm::StringRef name) = 0;
4647
virtual bool RegisterLib(llvm::StringRef name,
4748
std::unique_ptr<llvm::Module> pModule,
@@ -56,9 +57,11 @@ class DxilLinker {
5657

5758
protected:
5859
DxilLinker(llvm::LLVMContext &Ctx, unsigned valMajor, unsigned valMinor)
59-
: m_ctx(Ctx), m_valMajor(valMajor), m_valMinor(valMinor) {}
60+
: m_ctx(Ctx), m_valMajor(valMajor), m_valMinor(valMinor),
61+
m_StripDebug(false) {}
6062
llvm::LLVMContext &m_ctx;
6163
unsigned m_valMajor, m_valMinor;
64+
bool m_StripDebug;
6265
};
6366

6467
} // namespace hlsl

lib/HLSL/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ add_llvm_library(LLVMHLSL
2727
DxilRenameResourcesPass.cpp
2828
DxilScalarizeVectorIntrinsics.cpp
2929
DxilSimpleGVNHoist.cpp
30+
DxilStripDebugSensitiveInfo.cpp
3031
DxilSignatureValidation.cpp
3132
DxilTargetLowering.cpp
3233
DxilTargetTransformInfo.cpp

lib/HLSL/DxilLinker.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -349,9 +349,9 @@ namespace {
349349
// Create module from link defines.
350350
struct DxilLinkJob {
351351
DxilLinkJob(LLVMContext &Ctx, dxilutil::ExportMap &exportMap,
352-
unsigned valMajor, unsigned valMinor)
352+
unsigned valMajor, unsigned valMinor, bool StripDebug)
353353
: m_ctx(Ctx), m_exportMap(exportMap), m_valMajor(valMajor),
354-
m_valMinor(valMinor) {}
354+
m_valMinor(valMinor), m_StripDebug(StripDebug) {}
355355
std::unique_ptr<llvm::Module>
356356
Link(std::pair<DxilFunctionLinkInfo *, DxilLib *> &entryLinkPair,
357357
const ShaderModel *pSM);
@@ -394,6 +394,7 @@ struct DxilLinkJob {
394394
LLVMContext &m_ctx;
395395
dxilutil::ExportMap &m_exportMap;
396396
unsigned m_valMajor, m_valMinor;
397+
bool m_StripDebug;
397398
};
398399
} // namespace
399400

@@ -1296,6 +1297,9 @@ void DxilLinkJob::RunPreparePass(Module &M) {
12961297
PM.add(createDxilEmitMetadataPass());
12971298
PM.add(createDxilFinalizePreservesPass());
12981299

1300+
if (m_StripDebug)
1301+
PM.add(createDxilStripDebugSensitiveInfoPass());
1302+
12991303
PM.run(M);
13001304
}
13011305

@@ -1488,7 +1492,7 @@ DxilLinkerImpl::Link(StringRef entry, StringRef profile,
14881492
return nullptr;
14891493
}
14901494

1491-
DxilLinkJob linkJob(m_ctx, exportMap, m_valMajor, m_valMinor);
1495+
DxilLinkJob linkJob(m_ctx, exportMap, m_valMajor, m_valMinor, m_StripDebug);
14921496

14931497
SetVector<DxilLib *> libSet;
14941498
SetVector<StringRef> addedFunctionSet;
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
///////////////////////////////////////////////////////////////////////////////
2+
// //
3+
// DxilStripDebugSensitiveInfo.cpp //
4+
// Copyright (C) Microsoft Corporation. All rights reserved. //
5+
// This file is distributed under the University of Illinois Open Source //
6+
// License. See LICENSE.TXT for details. //
7+
// //
8+
// Pass to strip debug-sensitive information from DXIL modules. //
9+
// //
10+
///////////////////////////////////////////////////////////////////////////////
11+
12+
#include "dxc/DXIL/DxilModule.h"
13+
#include "dxc/HLSL/DxilGenerationPass.h"
14+
#include "llvm/IR/Module.h"
15+
#include "llvm/Pass.h"
16+
17+
using namespace llvm;
18+
using namespace hlsl;
19+
20+
namespace {
21+
22+
class DxilStripDebugSensitiveInfo : public ModulePass {
23+
public:
24+
static char ID;
25+
explicit DxilStripDebugSensitiveInfo() : ModulePass(ID) {}
26+
27+
StringRef getPassName() const override {
28+
return "DXIL Strip Debug-Sensitive Information";
29+
}
30+
31+
bool runOnModule(Module &M) override {
32+
if (!M.HasDxilModule())
33+
return false;
34+
return M.GetOrCreateDxilModule().StripNamesSensitiveToDebug();
35+
}
36+
};
37+
38+
char DxilStripDebugSensitiveInfo::ID = 0;
39+
40+
} // namespace
41+
42+
ModulePass *llvm::createDxilStripDebugSensitiveInfoPass() {
43+
return new DxilStripDebugSensitiveInfo();
44+
}
45+
46+
INITIALIZE_PASS(DxilStripDebugSensitiveInfo, "hlsl-dxil-strip-debug-info",
47+
"HLSL DXIL Strip Debug-Sensitive Information", false, false)

tools/clang/tools/dxcompiler/dxclinker.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ HRESULT STDMETHODCALLTYPE DxcLinker::Link(
306306
dxcutil::GetValidatorVersion(&valMajor, &valMinor);
307307
}
308308
m_pLinker->SetValidatorVersion(valMajor, valMinor);
309+
m_pLinker->SetStripDebug(opts.StripDebug);
309310

310311
// Root signature-only container validation is only supported on 1.5 and
311312
// above.
@@ -416,9 +417,6 @@ HRESULT STDMETHODCALLTYPE DxcLinker::Link(
416417
&ShaderHashContent, pReflectionStream, pRootSigStream, nullptr,
417418
nullptr);
418419

419-
if (opts.StripDebug)
420-
inputs.pM->GetOrCreateDxilModule().StripNamesSensitiveToDebug();
421-
422420
if (needsValidation) {
423421
valHR = dxcutil::ValidateAndAssembleToContainer(inputs);
424422
} else {

tools/clang/tools/dxcompiler/dxcompilerobj.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "clang/Lex/Preprocessor.h"
2525
#include "clang/Sema/SemaHLSL.h"
2626
#include "llvm/Bitcode/ReaderWriter.h"
27+
#include "llvm/IR/LegacyPassManager.h"
2728
#include "llvm/IR/LLVMContext.h"
2829
#include "llvm/Support/TimeProfiler.h"
2930
#include "llvm/Support/Timer.h"
@@ -32,6 +33,7 @@
3233
#include "dxc/DXIL/DxilModule.h"
3334
#include "dxc/DXIL/DxilPDB.h"
3435
#include "dxc/DxcBindingTable/DxcBindingTable.h"
36+
#include "dxc/HLSL/DxilGenerationPass.h"
3537
#include "dxc/DxilContainer/DxilContainerAssembler.h"
3638
#include "dxc/DxilRootSignature/DxilRootSignature.h"
3739
#include "dxc/HLSL/HLSLExtensionsCodegenHelper.h"
@@ -1048,8 +1050,11 @@ class DxcCompiler : public IDxcCompiler3,
10481050

10491051
inputs.pVersionInfo = static_cast<IDxcVersionInfo *>(this);
10501052

1051-
if (opts.StripDebug)
1052-
inputs.pM->GetOrCreateDxilModule().StripNamesSensitiveToDebug();
1053+
if (opts.StripDebug) {
1054+
legacy::PassManager PM;
1055+
PM.add(createDxilStripDebugSensitiveInfoPass());
1056+
PM.run(*inputs.pM);
1057+
}
10531058

10541059
if (needsValidation) {
10551060
valHR = dxcutil::ValidateAndAssembleToContainer(inputs);

0 commit comments

Comments
 (0)