| 382 | } |
| 383 | |
| 384 | bool IRContext::IsConsistent() { |
| 385 | #ifndef SPIRV_CHECK_CONTEXT |
| 386 | return true; |
| 387 | #else |
| 388 | if (AreAnalysesValid(kAnalysisDefUse)) { |
| 389 | analysis::DefUseManager new_def_use(module()); |
| 390 | if (!CompareAndPrintDifferences(*get_def_use_mgr(), new_def_use)) { |
| 391 | return false; |
| 392 | } |
| 393 | } |
| 394 | |
| 395 | return true; |
| 396 | if (AreAnalysesValid(kAnalysisIdToFuncMapping)) { |
| 397 | for (auto& fn : *module_) { |
| 398 | if (id_to_func_[fn.result_id()] != &fn) { |
| 399 | return false; |
| 400 | } |
| 401 | } |
| 402 | } |
| 403 | |
| 404 | if (AreAnalysesValid(kAnalysisIdToGraphMapping)) { |
| 405 | for (auto& g : module_->graphs()) { |
| 406 | if (id_to_graph_[g->DefInst().result_id()] != g.get()) { |
| 407 | return false; |
| 408 | } |
| 409 | } |
| 410 | } |
| 411 | |
| 412 | if (AreAnalysesValid(kAnalysisInstrToBlockMapping)) { |
| 413 | for (auto& func : *module()) { |
| 414 | for (auto& block : func) { |
| 415 | if (!block.WhileEachInst([this, &block](Instruction* inst) { |
| 416 | if (get_instr_block(inst) != &block) { |
| 417 | return false; |
| 418 | } |
| 419 | return true; |
| 420 | })) { |
| 421 | return false; |
| 422 | } |
| 423 | } |
| 424 | } |
| 425 | } |
| 426 | |
| 427 | if (!CheckCFG()) { |
| 428 | return false; |
| 429 | } |
| 430 | |
| 431 | if (AreAnalysesValid(kAnalysisDecorations)) { |
| 432 | analysis::DecorationManager* dec_mgr = get_decoration_mgr(); |
| 433 | analysis::DecorationManager current(module()); |
| 434 | |
| 435 | if (*dec_mgr != current) { |
| 436 | return false; |
| 437 | } |
| 438 | } |
| 439 | |
| 440 | if (feature_mgr_ != nullptr) { |
| 441 | FeatureManager current(grammar_); |