Divide DXIL disassembly into two passes

First pass to settle the IDs common between disassembly styles
Second pass to display the disassembly
Divide existing MakeDXCDisassemblyString() method into helper methods to be shared
This commit is contained in:
Jake Turner
2024-04-18 16:12:05 +01:00
parent 3db925fd7a
commit 92a060ee70
3 changed files with 610 additions and 338 deletions
+21 -14
View File
@@ -2238,11 +2238,16 @@ void Program::SetValueSymtabString(Value *v, const rdcstr &s)
a->name = s;
}
uint32_t Program::GetOrAssignMetaSlot(rdcarray<Metadata *> &metaSlots, uint32_t &nextMetaSlot,
Metadata *m)
uint32_t Program::GetMetaSlot(const Metadata *m) const
{
RDCASSERTNOTEQUAL(m->slot, ~0U);
return m->slot;
}
void Program::AssignMetaSlot(rdcarray<Metadata *> &metaSlots, uint32_t &nextMetaSlot, Metadata *m)
{
if(m->slot != ~0U)
return m->slot;
return;
m->slot = nextMetaSlot++;
metaSlots.push_back(m);
@@ -2253,26 +2258,28 @@ uint32_t Program::GetOrAssignMetaSlot(rdcarray<Metadata *> &metaSlots, uint32_t
if(!c || c->isConstant)
continue;
GetOrAssignMetaSlot(metaSlots, nextMetaSlot, c);
AssignMetaSlot(metaSlots, nextMetaSlot, c);
}
return m->slot;
}
uint32_t Program::GetOrAssignMetaSlot(rdcarray<Metadata *> &metaSlots, uint32_t &nextMetaSlot,
DebugLocation &l)
uint32_t Program::GetMetaSlot(const DebugLocation *l) const
{
RDCASSERTNOTEQUAL(l->slot, ~0U);
return l->slot;
}
void Program::AssignMetaSlot(rdcarray<Metadata *> &metaSlots, uint32_t &nextMetaSlot,
DebugLocation &l)
{
if(l.slot != ~0U)
return l.slot;
return;
l.slot = nextMetaSlot++;
if(l.scope)
GetOrAssignMetaSlot(metaSlots, nextMetaSlot, l.scope);
AssignMetaSlot(metaSlots, nextMetaSlot, l.scope);
if(l.inlinedAt)
GetOrAssignMetaSlot(metaSlots, nextMetaSlot, l.inlinedAt);
return l.slot;
AssignMetaSlot(metaSlots, nextMetaSlot, l.inlinedAt);
}
const Type *Program::GetPointerType(const Type *type, Type::PointerAddrSpace addrSpace)
@@ -2551,7 +2558,7 @@ void LLVMOrderAccumulator::processGlobals(Program *prog, bool doLiveChecking)
}
}
void LLVMOrderAccumulator::processFunction(Function *f)
void LLVMOrderAccumulator::processFunction(const Function *f)
{
const Function &func = *f;
+65 -48
View File
@@ -1097,6 +1097,51 @@ struct Function : public Value
AttachedMetadata attachedMeta;
};
class LLVMOrderAccumulator
{
public:
// types in id order
rdcarray<const Type *> types;
// types in disassembly print order
rdcarray<const Type *> printOrderTypes;
// values in id order
rdcarray<const Value *> values;
// metadata in id order
rdcarray<const Metadata *> metadata;
size_t firstConst;
size_t numConsts;
void processGlobals(Program *p, bool doLiveChecking);
size_t firstFuncConst;
size_t numFuncConsts;
void processFunction(const Function *f);
void exitFunction();
private:
size_t functionWaterMark;
bool sortConsts = true;
bool liveChecking = false;
void reset(GlobalVar *g);
void reset(Alias *a);
void reset(Constant *c);
void reset(Metadata *m);
void reset(Function *f);
void reset(Block *b);
void reset(Instruction *i);
void reset(Value *v);
void accumulate(const Value *v);
void accumulate(const Metadata *m);
void accumulateTypePrintOrder(const Type *t);
void accumulateTypePrintOrder(rdcarray<const Metadata *> &visited, const Metadata *m);
void assignTypeId(const Type *t);
void assignTypeId(const Constant *c);
};
class Program : public DXBC::IDebugInfo
{
public:
@@ -1133,6 +1178,7 @@ public:
const Metadata *GetMetadataByName(const rdcstr &name) const;
uint32_t GetDirectHeapAcessCount() const { return m_directHeapAccessCount; }
protected:
void SettleIDs();
void MakeDXCDisassemblyString();
void MakeRDDisassemblyString();
@@ -1145,9 +1191,19 @@ protected:
rdcstr GetValueSymtabString(Value *v);
void SetValueSymtabString(Value *v, const rdcstr &s);
uint32_t GetOrAssignMetaSlot(rdcarray<Metadata *> &metaSlots, uint32_t &nextMetaSlot, Metadata *m);
uint32_t GetOrAssignMetaSlot(rdcarray<Metadata *> &metaSlots, uint32_t &nextMetaSlot,
DebugLocation &l);
uint32_t GetMetaSlot(const Metadata *m) const;
void AssignMetaSlot(rdcarray<Metadata *> &metaSlots, uint32_t &nextMetaSlot, Metadata *m);
uint32_t GetMetaSlot(const DebugLocation *l) const;
void AssignMetaSlot(rdcarray<Metadata *> &metaSlots, uint32_t &nextMetaSlot, DebugLocation &l);
const Metadata *FindMetadata(uint32_t slot) const;
rdcstr ArgToString(const Value *v, bool withTypes, const rdcstr &attrString = "") const;
rdcstr DisassembleComDats(int &instructionLine) const;
rdcstr DisassembleTypes(int &instructionLine) const;
rdcstr DisassembleGlobalVars(int &instructionLine) const;
rdcstr DisassembleNamedMeta() const;
rdcstr DisassembleFuncAttrGroups() const;
rdcstr DisassembleMeta() const;
const Type *GetVoidType() { return m_VoidType; }
const Type *GetBoolType() { return m_BoolType; }
@@ -1195,8 +1251,14 @@ protected:
rdcarray<DebugLocation> m_DebugLocations;
LLVMOrderAccumulator m_Accum;
rdcarray<Metadata *> m_MetaSlots;
rdcarray<const AttributeGroup *> m_FuncAttrGroups;
uint32_t m_NextMetaSlot = 0;
bool m_Uselists = false;
bool m_DXCStyle = false;
bool m_SettledIDs = false;
rdcstr m_Triple, m_Datalayout;
@@ -1210,51 +1272,6 @@ bool needsEscaping(const rdcstr &name);
rdcstr escapeString(const rdcstr &str);
rdcstr escapeStringIfNeeded(const rdcstr &name);
class LLVMOrderAccumulator
{
public:
// types in id order
rdcarray<const Type *> types;
// types in disassembly print order
rdcarray<const Type *> printOrderTypes;
// values in id order
rdcarray<const Value *> values;
// metadata in id order
rdcarray<const Metadata *> metadata;
size_t firstConst;
size_t numConsts;
void processGlobals(Program *p, bool doLiveChecking);
size_t firstFuncConst;
size_t numFuncConsts;
void processFunction(Function *f);
void exitFunction();
private:
size_t functionWaterMark;
bool sortConsts = true;
bool liveChecking = false;
void reset(GlobalVar *g);
void reset(Alias *a);
void reset(Constant *c);
void reset(Metadata *m);
void reset(Function *f);
void reset(Block *b);
void reset(Instruction *i);
void reset(Value *v);
void accumulate(const Value *v);
void accumulate(const Metadata *m);
void accumulateTypePrintOrder(const Type *t);
void accumulateTypePrintOrder(rdcarray<const Metadata *> &visited, const Metadata *m);
void assignTypeId(const Type *t);
void assignTypeId(const Constant *c);
};
}; // namespace DXIL
DECLARE_REFLECTION_ENUM(DXIL::Attribute);
File diff suppressed because it is too large Load Diff