diff --git a/cpp/ql/src/semmle/code/cpp/ir/implementation/raw/Instruction.qll b/cpp/ql/src/semmle/code/cpp/ir/implementation/raw/Instruction.qll index 449d7544a04b..dcad960d8dfd 100644 --- a/cpp/ql/src/semmle/code/cpp/ir/implementation/raw/Instruction.qll +++ b/cpp/ql/src/semmle/code/cpp/ir/implementation/raw/Instruction.qll @@ -751,6 +751,9 @@ class BinaryInstruction extends Instruction { result = getAnOperand().(RightOperand).getDefinitionInstruction() } + /** + * Holds if this instruction's operands are `op1` and `op2`, in either order. + */ final predicate hasOperands(Operand op1, Operand op2) { op1 = getAnOperand().(LeftOperand) and op2 = getAnOperand().(RightOperand) or diff --git a/cpp/ql/src/semmle/code/cpp/ir/implementation/raw/gvn/ValueNumbering.qll b/cpp/ql/src/semmle/code/cpp/ir/implementation/raw/gvn/ValueNumbering.qll index d5c6752479eb..c03ddf991626 100644 --- a/cpp/ql/src/semmle/code/cpp/ir/implementation/raw/gvn/ValueNumbering.qll +++ b/cpp/ql/src/semmle/code/cpp/ir/implementation/raw/gvn/ValueNumbering.qll @@ -83,6 +83,10 @@ class ValueNumber extends TValueNumber { instr order by instr.getBlock().getDisplayIndex(), instr.getDisplayIndexInBlock() ) } + + final Operand getAUse() { + this = valueNumber(result.getDefinitionInstruction()) + } } /** @@ -212,7 +216,7 @@ private predicate uniqueValueNumber(Instruction instr, FunctionIR funcIR) { /** * Gets the value number assigned to `instr`, if any. Returns at most one result. */ -ValueNumber valueNumber(Instruction instr) { +cached ValueNumber valueNumber(Instruction instr) { result = nonUniqueValueNumber(instr) or exists(FunctionIR funcIR | uniqueValueNumber(instr, funcIR) and @@ -220,6 +224,13 @@ ValueNumber valueNumber(Instruction instr) { ) } +/** + * Gets the value number assigned to `instr`, if any. Returns at most one result. + */ +ValueNumber valueNumberOfOperand(Operand op) { + result = valueNumber(op.getDefinitionInstruction()) +} + /** * Gets the value number assigned to `instr`, if any, unless that instruction is assigned a unique * value number. diff --git a/cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/Instruction.qll b/cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/Instruction.qll index 449d7544a04b..dcad960d8dfd 100644 --- a/cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/Instruction.qll +++ b/cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/Instruction.qll @@ -751,6 +751,9 @@ class BinaryInstruction extends Instruction { result = getAnOperand().(RightOperand).getDefinitionInstruction() } + /** + * Holds if this instruction's operands are `op1` and `op2`, in either order. + */ final predicate hasOperands(Operand op1, Operand op2) { op1 = getAnOperand().(LeftOperand) and op2 = getAnOperand().(RightOperand) or diff --git a/cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/gvn/ValueNumbering.qll b/cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/gvn/ValueNumbering.qll index d5c6752479eb..c03ddf991626 100644 --- a/cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/gvn/ValueNumbering.qll +++ b/cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/gvn/ValueNumbering.qll @@ -83,6 +83,10 @@ class ValueNumber extends TValueNumber { instr order by instr.getBlock().getDisplayIndex(), instr.getDisplayIndexInBlock() ) } + + final Operand getAUse() { + this = valueNumber(result.getDefinitionInstruction()) + } } /** @@ -212,7 +216,7 @@ private predicate uniqueValueNumber(Instruction instr, FunctionIR funcIR) { /** * Gets the value number assigned to `instr`, if any. Returns at most one result. */ -ValueNumber valueNumber(Instruction instr) { +cached ValueNumber valueNumber(Instruction instr) { result = nonUniqueValueNumber(instr) or exists(FunctionIR funcIR | uniqueValueNumber(instr, funcIR) and @@ -220,6 +224,13 @@ ValueNumber valueNumber(Instruction instr) { ) } +/** + * Gets the value number assigned to `instr`, if any. Returns at most one result. + */ +ValueNumber valueNumberOfOperand(Operand op) { + result = valueNumber(op.getDefinitionInstruction()) +} + /** * Gets the value number assigned to `instr`, if any, unless that instruction is assigned a unique * value number.