blob: 340a9d292e50b4e4796db486ac7321c1e9f45147 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
#include "slang-ir-deduplicate-generic-children.h"
#include "slang-ir-clone.h"
#include "slang-ir-util.h"
#include "slang-ir.h"
namespace Slang
{
bool deduplicateGenericChildren(IRGeneric* genericInst)
{
bool changed = false;
GenericChildrenMigrationContext ctx;
ctx.init(genericInst, genericInst, nullptr);
List<IRInst*> instsToRemove;
for (auto inst = genericInst->getFirstBlock()->getFirstInst(); inst; inst = inst->getNextInst())
{
auto deduped = ctx.deduplicate(inst);
if (deduped != inst)
{
inst->replaceUsesWith(deduped);
instsToRemove.add(inst);
changed = true;
}
}
for (auto inst : instsToRemove)
inst->removeAndDeallocate();
return changed;
}
bool deduplicateGenericChildren(IRModule* module)
{
bool changed = false;
for (auto inst : module->getGlobalInsts())
{
if (auto gen = as<IRGeneric>(inst))
{
changed |= deduplicateGenericChildren(gen);
}
}
return changed;
}
} // namespace Slang
|