diff options
| author | Yong He <yonghe@outlook.com> | 2023-02-16 13:55:32 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-02-16 13:55:32 -0800 |
| commit | 4c4826d47eeef4675daae4ae53ff76f4d5ebd84a (patch) | |
| tree | ed4af0ded878e4f06e9641ce61d26ffd7c89ccbc /source/slang/slang-ir-legalize-types.cpp | |
| parent | eda88e513e8b1e2abc05e9dc8555f237d96472df (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.cpp | 23 |
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. |
