From 9476d4543f4336a66308e55f722b0b0b2bd69dd2 Mon Sep 17 00:00:00 2001 From: Yong He Date: Thu, 16 Mar 2023 23:46:14 -0700 Subject: Fix Phi simplification bug. (#2710) * Fix Phi simplification bug. * Fix up. * Fix. * Fix. * Fix. * Fix. * Fix. * Fix test. * Fix test. --------- Co-authored-by: Yong He --- source/slang/slang-ir-validate.cpp | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'source/slang/slang-ir-validate.cpp') diff --git a/source/slang/slang-ir-validate.cpp b/source/slang/slang-ir-validate.cpp index 55e0f0168..3c720e929 100644 --- a/source/slang/slang-ir-validate.cpp +++ b/source/slang/slang-ir-validate.cpp @@ -3,6 +3,7 @@ #include "slang-ir.h" #include "slang-ir-insts.h" +#include "slang-ir-dominators.h" namespace Slang { @@ -11,6 +12,8 @@ namespace Slang // The IR module we are validating. IRModule* module; + RefPtr domTree; + // A diagnostic sink to send errors to if anything is invalid. DiagnosticSink* sink; @@ -165,9 +168,14 @@ namespace Slang // the same function (or another value with code). We need // to validate that `operandParentBlock` dominates `instParentBlock`. // - // TODO: implement this validation once we compute dominator trees. - // - // validate(context, operandParentBlock->dominates(instParentBlock), inst, "def must dominate use"); + if (context && context->domTree) + { + validate( + context, + context->domTree->dominates(operandParentBlock, instParentBlock), + inst, + "def must dominate use"); + } return; } } @@ -327,10 +335,24 @@ namespace Slang if (auto code = as(inst)) { + context->domTree = computeDominatorTree(code); validateCodeBody(context, code); + context->domTree = nullptr; } } + void validateIRInst(IRInst* inst) + { + IRValidateContext contextStorage; + IRValidateContext* context = &contextStorage; + DiagnosticSink sink; + context->module = inst->getModule(); + context->sink = &sink; + if (auto func = as(inst)) + context->domTree = computeDominatorTree(func); + validateIRInst(context, inst); + } + void validateIRModule(IRModule* module, DiagnosticSink* sink) { IRValidateContext contextStorage; -- cgit v1.2.3