diff options
| author | Yong He <yonghe@outlook.com> | 2022-02-25 20:49:31 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-02-25 20:49:31 -0800 |
| commit | c31577953d5041c82375c22d847c2eba06106c58 (patch) | |
| tree | bc685a8b63fc13cb85d160ae13df950056ca6e91 /source/slang/slang-ir-specialize-dispatch.cpp | |
| parent | 8990d270e3a0c01b1f7abbf4f79556c5ef82a096 (diff) | |
Improved SCCP, inlining and resource specialization passes, legalize `ImageSubscript` for GLSL (#2146)
Diffstat (limited to 'source/slang/slang-ir-specialize-dispatch.cpp')
| -rw-r--r-- | source/slang/slang-ir-specialize-dispatch.cpp | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/source/slang/slang-ir-specialize-dispatch.cpp b/source/slang/slang-ir-specialize-dispatch.cpp index eac5287e5..bcd7b494f 100644 --- a/source/slang/slang-ir-specialize-dispatch.cpp +++ b/source/slang/slang-ir-specialize-dispatch.cpp @@ -123,14 +123,14 @@ IRFunc* specializeDispatchFunction(SharedGenericsLoweringContext* sharedContext, // the witness table sequential ID passed in. builder->setInsertInto(newDispatchFunc); - + if (witnessTables.getCount() == 1) { // If there is only 1 case, no switch statement is necessary. builder->setInsertInto(newBlock); builder->emitBranch(defaultBlock); } - else + else if (witnessTables.getCount() > 1) { auto breakBlock = builder->emitBlock(); builder->setInsertInto(breakBlock); @@ -144,6 +144,21 @@ IRFunc* specializeDispatchFunction(SharedGenericsLoweringContext* sharedContext, caseBlocks.getCount(), caseBlocks.getBuffer()); } + else + { + // We have no witness tables that implements this interface. + // Just return a default value. + builder->setInsertInto(newBlock); + if (callInst->getDataType()->getOp() == kIROp_VoidType) + { + builder->emitReturn(); + } + else + { + auto defaultValue = builder->emitConstructorInst(callInst->getDataType(), 0, nullptr); + builder->emitReturn(defaultValue); + } + } // Remove old implementation. dispatchFunc->replaceUsesWith(newDispatchFunc); dispatchFunc->removeAndDeallocate(); |
