@@ -7117,6 +7117,74 @@ void dumpIRGeneric(IRDumpContext* context, IRGeneric* witnessTable)
7117
7117
dump (context, " }\n " );
7118
7118
}
7119
7119
7120
+ static void dumpEmbeddedDownstream (IRDumpContext* context, IRInst* inst)
7121
+ {
7122
+ auto targetInst = inst->getOperand (0 );
7123
+ auto blobInst = inst->getOperand (1 );
7124
+
7125
+ // Get the target value
7126
+ auto targetLit = as<IRIntLit>(targetInst);
7127
+ if (!targetLit)
7128
+ {
7129
+ dump (context, " EmbeddedDownstreamIR(invalid target)" );
7130
+ return ;
7131
+ }
7132
+
7133
+ // Get the blob
7134
+ auto blobLitInst = as<IRBlobLit>(blobInst);
7135
+ if (!blobLitInst)
7136
+ {
7137
+ dump (context, " EmbeddedDownstreamIR(invalid blob)" );
7138
+ return ;
7139
+ }
7140
+
7141
+ dump (context, " EmbeddedDownstreamIR(" );
7142
+ dump (context, targetLit->getValue ());
7143
+ dump (context, " : Int, " );
7144
+
7145
+ // If target is SPIR-V (6), disassemble the blob
7146
+ if (targetLit->getValue () == (IRIntegerValue)CodeGenTarget::SPIRV)
7147
+ {
7148
+ auto blob = blobLitInst->getStringSlice ();
7149
+ const uint32_t * spirvCode = (const uint32_t *)blob.begin ();
7150
+ const size_t spirvWordCount = blob.getLength () / sizeof (uint32_t );
7151
+
7152
+ // Get the compiler from the session through the module
7153
+ auto module = inst->getModule ();
7154
+ auto session = module->getSession ();
7155
+ IDownstreamCompiler* compiler = session->getOrLoadDownstreamCompiler (
7156
+ PassThroughMode::SpirvDis,
7157
+ nullptr );
7158
+
7159
+ if (compiler)
7160
+ {
7161
+ // Use glslang interface to disassemble with string output
7162
+ String disassemblyOutput;
7163
+ if (SLANG_SUCCEEDED (compiler->disassembleWithResult (spirvCode, int (spirvWordCount), disassemblyOutput)))
7164
+ {
7165
+ // Dump the captured disassembly
7166
+ dump (context, " \n " );
7167
+ dumpIndent (context);
7168
+ dump (context, disassemblyOutput);
7169
+ }
7170
+ else
7171
+ {
7172
+ dump (context, " <disassembly failed>" );
7173
+ }
7174
+ }
7175
+ else
7176
+ {
7177
+ dump (context, " <unavailable disassembler>" );
7178
+ }
7179
+ }
7180
+ else
7181
+ {
7182
+ // TODO: Add DXIL disassembly call here.
7183
+ dump (context, " <binary blob>" );
7184
+ }
7185
+ dump (context, " )" );
7186
+ }
7187
+
7120
7188
static void dumpInstExpr (IRDumpContext* context, IRInst* inst)
7121
7189
{
7122
7190
if (!inst)
@@ -7169,69 +7237,7 @@ static void dumpInstExpr(IRDumpContext* context, IRInst* inst)
7169
7237
// Special case EmbeddedDownstreamIR to show SPIR-V disassembly
7170
7238
if (op == kIROp_EmbeddedDownstreamIR )
7171
7239
{
7172
- auto targetInst = inst->getOperand (0 );
7173
- auto blobInst = inst->getOperand (1 );
7174
-
7175
- // Get the target value
7176
- auto targetLit = as<IRIntLit>(targetInst);
7177
- if (!targetLit)
7178
- {
7179
- dump (context, " EmbeddedDownstreamIR(invalid target)" );
7180
- return ;
7181
- }
7182
-
7183
- // Get the blob
7184
- auto blobLitInst = as<IRBlobLit>(blobInst);
7185
- if (!blobLitInst)
7186
- {
7187
- dump (context, " EmbeddedDownstreamIR(invalid blob)" );
7188
- return ;
7189
- }
7190
-
7191
- dump (context, " EmbeddedDownstreamIR(" );
7192
- dump (context, targetLit->getValue ());
7193
- dump (context, " : Int, " );
7194
-
7195
- // If target is SPIR-V (6), disassemble the blob
7196
- if (targetLit->getValue () == (IRIntegerValue)CodeGenTarget::SPIRV)
7197
- {
7198
- auto blob = blobLitInst->getStringSlice ();
7199
- const uint32_t * spirvCode = (const uint32_t *)blob.begin ();
7200
- const size_t spirvWordCount = blob.getLength () / sizeof (uint32_t );
7201
-
7202
- // Get the compiler from the session through the module
7203
- auto module = inst->getModule ();
7204
- auto session = module->getSession ();
7205
- IDownstreamCompiler* compiler = session->getOrLoadDownstreamCompiler (
7206
- PassThroughMode::SpirvDis,
7207
- nullptr );
7208
-
7209
- if (compiler)
7210
- {
7211
- // Use glslang interface to disassemble with string output
7212
- String disassemblyOutput;
7213
- if (SLANG_SUCCEEDED (compiler->disassembleWithResult (spirvCode, int (spirvWordCount), disassemblyOutput)))
7214
- {
7215
- // Dump the captured disassembly
7216
- dump (context, " \n " );
7217
- dumpIndent (context);
7218
- dump (context, disassemblyOutput);
7219
- }
7220
- else
7221
- {
7222
- dump (context, " <disassembly failed>" );
7223
- }
7224
- }
7225
- else
7226
- {
7227
- dump (context, " <invalid SPIR-V>" );
7228
- }
7229
- }
7230
- else
7231
- {
7232
- dump (context, " <binary blob>" );
7233
- }
7234
- dump (context, " )" );
7240
+ dumpEmbeddedDownstream (context, inst);
7235
7241
return ;
7236
7242
}
7237
7243
0 commit comments