summaryrefslogtreecommitdiff
path: root/source/slang/slang-ir-legalize-types.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2023-02-16 13:55:32 -0800
committerGitHub <noreply@github.com>2023-02-16 13:55:32 -0800
commit4c4826d47eeef4675daae4ae53ff76f4d5ebd84a (patch)
treeed4af0ded878e4f06e9641ce61d26ffd7c89ccbc /source/slang/slang-ir-legalize-types.cpp
parenteda88e513e8b1e2abc05e9dc8555f237d96472df (diff)
Overhaul global inst deduplication and cpp/cuda backend. (#2654)
* Overhaul global inst deduplication and cpp/cuda backend. * Update IR documentation. --------- Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source/slang/slang-ir-legalize-types.cpp')
-rw-r--r--source/slang/slang-ir-legalize-types.cpp23
1 files changed, 20 insertions, 3 deletions
diff --git a/source/slang/slang-ir-legalize-types.cpp b/source/slang/slang-ir-legalize-types.cpp
index 38503155d..d916fa691 100644
--- a/source/slang/slang-ir-legalize-types.cpp
+++ b/source/slang/slang-ir-legalize-types.cpp
@@ -1861,14 +1861,27 @@ static LegalVal legalizeInst(
// While the operands are all "simple," they might not necessarily
// be equal to the operands we started with.
//
+ ShortList<IRInst*> newArgs;
+ newArgs.setCount(argCount);
+ bool recreate = false;
for (UInt aa = 0; aa < argCount; ++aa)
{
auto legalArg = legalArgs[aa];
- inst->setOperand(aa, legalArg.getSimple());
+ newArgs[aa] = legalArg.getSimple();
+ if (newArgs[aa] != inst->getOperand(aa))
+ recreate = true;
+ }
+ if (recreate)
+ {
+ IRBuilder builder(inst->getModule());
+ builder.setInsertBefore(inst);
+ auto newInst = builder.emitIntrinsicInst(legalType.getSimple(), inst->getOp(), argCount, newArgs.getArrayView().getBuffer());
+ inst->replaceUsesWith(newInst);
+ inst->removeFromParent();
+ context->replacedInstructions.add(inst);
+ return LegalVal::simple(newInst);
}
-
inst->setFullType(legalType.getSimple());
-
return LegalVal::simple(inst);
}
@@ -1888,6 +1901,10 @@ static LegalVal legalizeInst(
legalType,
legalArgs.getBuffer());
+ if (legalVal.flavor == LegalVal::Flavor::simple)
+ {
+ inst->replaceUsesWith(legalVal.getSimple());
+ }
// After we are done, we will eliminate the
// original instruction by removing it from
// the IR.