Skip to content

Commit cd6da10

Browse files
committed
[SPIRV] Added new stub pass for NonSemantic DI
The commit adds new empty pass for emission of NonSemantic.Shader.DebugInfo.100 instructions. The pass is a basis for future development and can be (and likely will be) a subject of change. In addition to that there is additional unused function which main purpose is to be basis of accessing global metadata which is inaccessible in MIR. Accessing such metadata is necessary for emitting such instructions like DebugCompilationUnit or DebugSource.
1 parent d23959b commit cd6da10

File tree

4 files changed

+59
-0
lines changed

4 files changed

+59
-0
lines changed

llvm/lib/Target/SPIRV/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ add_llvm_target(SPIRVCodeGen
4040
SPIRVSubtarget.cpp
4141
SPIRVTargetMachine.cpp
4242
SPIRVUtils.cpp
43+
SPIRVEmitNonSemanticDI.cpp
4344

4445
LINK_COMPONENTS
4546
Analysis

llvm/lib/Target/SPIRV/SPIRV.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ FunctionPass *createSPIRVRegularizerPass();
2626
FunctionPass *createSPIRVPreLegalizerPass();
2727
FunctionPass *createSPIRVPostLegalizerPass();
2828
ModulePass *createSPIRVEmitIntrinsicsPass(SPIRVTargetMachine *TM);
29+
MachineFunctionPass *createSPIRVEmitNonSemanticDIPass();
2930
InstructionSelector *
3031
createSPIRVInstructionSelector(const SPIRVTargetMachine &TM,
3132
const SPIRVSubtarget &Subtarget,
@@ -36,6 +37,7 @@ void initializeSPIRVConvergenceRegionAnalysisWrapperPassPass(PassRegistry &);
3637
void initializeSPIRVPreLegalizerPass(PassRegistry &);
3738
void initializeSPIRVPostLegalizerPass(PassRegistry &);
3839
void initializeSPIRVEmitIntrinsicsPass(PassRegistry &);
40+
void initializeSPIRVEmitNonSemanticDIPass(PassRegistry &);
3941
} // namespace llvm
4042

4143
#endif // LLVM_LIB_TARGET_SPIRV_SPIRV_H
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#include "llvm/CodeGen/MachineFunction.h"
2+
#include "llvm/CodeGen/MachineFunctionPass.h"
3+
#include "llvm/CodeGen/MachineModuleInfo.h"
4+
#include "llvm/IR/DebugInfoMetadata.h"
5+
#include "llvm/IR/Metadata.h"
6+
#include "llvm/PassRegistry.h"
7+
#include "llvm/Support/Casting.h"
8+
9+
namespace llvm {
10+
struct SPIRVEmitNonSemanticDI : public MachineFunctionPass {
11+
static char ID;
12+
SPIRVEmitNonSemanticDI();
13+
14+
bool runOnMachineFunction(MachineFunction &MF) override;
15+
};
16+
17+
void initializeSPIRVEmitNonSemanticDIPass(PassRegistry &);
18+
19+
FunctionPass *createSPIRVEmitNonSemanticDIPass() {
20+
return new SPIRVEmitNonSemanticDI();
21+
}
22+
} // namespace llvm
23+
24+
using namespace llvm;
25+
26+
INITIALIZE_PASS(SPIRVEmitNonSemanticDI, "spirv-nonsemantic-debug-info",
27+
"SPIRV NonSemantic.Shader.DebugInfo.100 emitter", false, false)
28+
29+
char SPIRVEmitNonSemanticDI::ID = 0;
30+
31+
SPIRVEmitNonSemanticDI::SPIRVEmitNonSemanticDI() : MachineFunctionPass(ID) {
32+
initializeSPIRVEmitNonSemanticDIPass(*PassRegistry::getPassRegistry());
33+
}
34+
35+
[[maybe_unused]]
36+
static void findCompileUnitDI(const MachineFunction &MF) {
37+
MachineModuleInfo &MMI = MF.getMMI();
38+
const Module *M = MMI.getModule();
39+
NamedMDNode *DbgCu = M->getNamedMetadata("llvm.dbg.cu");
40+
std::string FilePath;
41+
if (DbgCu) {
42+
unsigned NumOp = DbgCu->getNumOperands();
43+
if (NumOp) {
44+
if (const auto *CompileUnit =
45+
dyn_cast<DICompileUnit>(DbgCu->getOperand(0))) {
46+
DIFile *File = CompileUnit->getFile();
47+
FilePath = ((File->getDirectory() + "/" + File->getFilename())).str();
48+
}
49+
}
50+
}
51+
}
52+
53+
bool SPIRVEmitNonSemanticDI::runOnMachineFunction(MachineFunction &MF) {
54+
return false;
55+
}

llvm/lib/Target/SPIRV/SPIRVTargetMachine.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ void SPIRVPassConfig::addPreLegalizeMachineIR() {
199199
bool SPIRVPassConfig::addLegalizeMachineIR() {
200200
addPass(new Legalizer());
201201
addPass(createSPIRVPostLegalizerPass());
202+
addPass(createSPIRVEmitNonSemanticDIPass());
202203
return false;
203204
}
204205

0 commit comments

Comments
 (0)