Assign type IDs recursively for constants

* In case a type is only referenced via e.g. bitcast -> gep we need to recurse
  to assign type IDs in this case.
This commit is contained in:
baldurk
2023-02-16 13:04:04 +00:00
parent 5efe9bc0b2
commit 62aa7b49a5
2 changed files with 15 additions and 0 deletions
@@ -2513,6 +2513,7 @@ void LLVMOrderAccumulator::processGlobals(Program *prog)
{
assignTypeId(inst->args[a]->type);
accumulate(cast<Metadata>(inst->args[a]));
assignTypeId(cast<Constant>(inst->args[a]));
}
assignTypeId(inst->type);
for(size_t m = 0; m < inst->getAttachedMeta().size(); m++)
@@ -2716,6 +2717,19 @@ void LLVMOrderAccumulator::assignTypeId(const Type *t)
types.push_back(t);
}
void LLVMOrderAccumulator::assignTypeId(const Constant *c)
{
if(!c)
return;
assignTypeId(c->type);
if(c->isCast())
assignTypeId(cast<Constant>(c->getInner()));
else if(c->isCompound())
for(Value *v : c->getMembers())
assignTypeId(cast<Constant>(v));
}
void LLVMOrderAccumulator::accumulate(const Value *v)
{
Value *value = (Value *)v;
@@ -1172,6 +1172,7 @@ private:
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