DXIL Disassembly changed Instruction::slot to be global unique SSA Id

Used by DXIL Debugger, new behaviour is disabled when DXC_COMPATIBLE_DISASM is enabled
This commit is contained in:
Jake Turner
2024-07-27 14:34:17 +01:00
parent 1120148a54
commit cce5d94c4a
3 changed files with 27 additions and 4 deletions
@@ -2558,7 +2558,7 @@ void LLVMOrderAccumulator::processGlobals(Program *prog, bool doLiveChecking)
}
}
void LLVMOrderAccumulator::processFunction(const Function *f)
void LLVMOrderAccumulator::processFunction(const Function *f, uint32_t *nextSSAId)
{
const Function &func = *f;
@@ -2611,8 +2611,18 @@ void LLVMOrderAccumulator::processFunction(const Function *f)
uint32_t curBlock = 0;
for(Instruction *arg : func.args)
{
#if DISABLED(DXC_COMPATIBLE_DISASM)
if(arg->slot == ~0U)
{
arg->slot = *nextSSAId;
(*nextSSAId)++;
}
#else
if(arg->getName().isEmpty())
arg->slot = slot++;
#endif
}
if(!func.blocks.empty() && func.blocks[0]->name.empty())
func.blocks[0]->slot = slot++;
@@ -2636,8 +2646,16 @@ void LLVMOrderAccumulator::processFunction(const Function *f)
{
accumulate(inst);
#if DISABLED(DXC_COMPATIBLE_DISASM)
if(inst->slot == ~0U)
{
inst->slot = *nextSSAId;
(*nextSSAId)++;
}
#else
if(inst->getName().isEmpty())
inst->slot = slot++;
#endif
}
if(inst->op == Operation::Branch || inst->op == Operation::Unreachable ||
@@ -1263,7 +1263,10 @@ struct Instruction : public ForwardReferencableValue<Instruction>
uint32_t debugLoc = ~0U;
Operation op = Operation::NoOp;
uint8_t align = 0;
// number assigned to instructions that don't have names and return a value, for disassembly
// For DXC Compatibility mode: slot contains a number assigned to instructions that don't have
// names and return a value, used for disassembly
// Otherwise a unique global ID used by the debugger and disassemvbly
uint32_t slot = ~0U;
InstructionFlags &opFlags() { return (InstructionFlags &)flags; }
InstructionFlags opFlags() const { return (InstructionFlags)flags; }
@@ -1384,7 +1387,7 @@ public:
size_t firstFuncConst;
size_t numFuncConsts;
void processFunction(const Function *f);
void processFunction(const Function *f, uint32_t *nextSSAId = NULL);
void exitFunction();
private:
@@ -1645,6 +1648,7 @@ protected:
rdcarray<Metadata *> m_MetaSlots;
rdcarray<const AttributeGroup *> m_FuncAttrGroups;
uint32_t m_NextMetaSlot = 0;
uint32_t m_NextSSAId = 0;
bool m_Uselists = false;
bool m_DXCStyle = false;
@@ -1043,6 +1043,7 @@ void Program::Parse(const DXBC::Reflection *reflection)
void Program::SettleIDs()
{
RDCASSERTEQUAL(m_NextSSAId, 0);
RDCASSERTEQUAL(m_NextMetaSlot, 0);
RDCASSERT(m_MetaSlots.isEmpty());
@@ -1063,7 +1064,7 @@ void Program::SettleIDs()
uint32_t &nextMetaSlot = m_NextMetaSlot;
for(size_t i = 0; i < m_Functions.size(); i++)
{
m_Accum.processFunction(m_Functions[i]);
m_Accum.processFunction(m_Functions[i], &m_NextSSAId);
Function &func = *m_Functions[i];