@@ -67,6 +67,40 @@ module InstructionSanity {
6767 not tag instanceof UnmodeledUseOperand
6868 }
6969
70+ /**
71+ * Holds if `Phi` instruction `instr` is missing an operand corresponding to
72+ * the predecessor block `pred`.
73+ */
74+ query predicate missingPhiOperand ( PhiInstruction instr , IRBlock pred ) {
75+ pred = instr .getBlock ( ) .getAPredecessor ( ) and
76+ not exists ( PhiOperand operand |
77+ exists ( instr .getOperand ( operand ) ) and
78+ operand .getPredecessorBlock ( ) = pred
79+ )
80+ }
81+
82+ /**
83+ * Holds if an instruction, other than `ExitFunction`, has no successors.
84+ */
85+ query predicate instructionWithoutSuccessor ( Instruction instr ) {
86+ not exists ( instr .getASuccessor ( ) ) and
87+ not instr instanceof ExitFunctionInstruction and
88+ // Phi instructions aren't linked into the instruction-level flow graph.
89+ not instr instanceof PhiInstruction
90+ }
91+
92+ /**
93+ * Holds if a `Phi` instruction is present in a block with fewer than two
94+ * predecessors.
95+ */
96+ query predicate unnecessaryPhiInstruction ( PhiInstruction instr ) {
97+ count ( instr .getBlock ( ) .getAPredecessor ( ) ) < 2
98+ }
99+
100+ /**
101+ * Holds if instruction `op` consumes an operand `operand` that was defined in
102+ * a different function.
103+ */
70104 query predicate operandAcrossFunctions (
71105 Instruction op , Instruction operand , OperandTag tag
72106 ) {
@@ -296,8 +330,7 @@ class Instruction extends Construction::TInstruction {
296330
297331 /**
298332 * Gets the size of the result produced by this instruction, in bytes. If the
299- * instruction does not produce a result, or if the result does not have a
300- * known constant size, this predicate does not hold.
333+ * result does not have a known constant size, this predicate does not hold.
301334 *
302335 * If `this.isGLValue()` holds for this instruction, the value of
303336 * `getResultSize()` will always be the size of a pointer.
@@ -312,7 +345,6 @@ class Instruction extends Construction::TInstruction {
312345 else if resultType instanceof UnknownType then
313346 result = Construction:: getInstructionResultSize ( this )
314347 else (
315- not resultType instanceof VoidType and
316348 result = resultType .getSize ( )
317349 )
318350 }
0 commit comments