From 0c6e0c25a1bb5d7dd1055d89a8f7a6ff4191a1d7 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Tue, 19 Dec 2017 20:18:24 -0800 Subject: [PATCH] Two NFC changes: - Add a DominanceInfo::dominates helper functions that takes two instructions, as analogues to the properlyDominates ones. - Further generalize some SILBuilder code to be more defensive in the face of incorrect or partially constructed SIL instructions. These are cleanups, NFC. --- include/swift/SIL/Dominance.h | 6 ++++++ lib/SIL/SILBuilder.cpp | 5 +++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/include/swift/SIL/Dominance.h b/include/swift/SIL/Dominance.h index 79e20d8314f..539c580d0a0 100644 --- a/include/swift/SIL/Dominance.h +++ b/include/swift/SIL/Dominance.h @@ -52,6 +52,11 @@ public: /// Does instruction A properly dominate instruction B? bool properlyDominates(SILInstruction *a, SILInstruction *b); + /// Does instruction A dominate instruction B? + bool dominates(SILInstruction *a, SILInstruction *b) { + return a == b || properlyDominates(a, b); + } + /// Does value A properly dominate instruction B? bool properlyDominates(SILValue a, SILInstruction *b); @@ -74,6 +79,7 @@ public: } using DominatorTreeBase::properlyDominates; + using DominatorTreeBase::dominates; bool isValid(SILFunction *F) const { return getNode(&F->front()) != nullptr; diff --git a/lib/SIL/SILBuilder.cpp b/lib/SIL/SILBuilder.cpp index 43f9a26b804..8dc3d5ba18a 100644 --- a/lib/SIL/SILBuilder.cpp +++ b/lib/SIL/SILBuilder.cpp @@ -417,8 +417,9 @@ void SILBuilder::addOpenedArchetypeOperands(SILInstruction *I) { while (I && I->getNumOperands() == 1 && I->getNumTypeDependentOperands() == 0) { - // All the open instructions are single-value instructions. - auto SVI = dyn_cast(I->getOperand(0)); + // All the open instructions are single-value instructions. Operands may + // be null when code is being transformed. + auto SVI = dyn_cast_or_null(I->getOperand(0)); // Within SimplifyCFG this function may be called for an instruction // within unreachable code. And within an unreachable block it can happen // that defs do not dominate uses (because there is no dominance defined).