C++: PhiOperand -> PhiInputOperand

Also added `PhiInstruction::getAnInputOperand()`, and renamed `PhiInstruction::getAnOperandDefinitionInstruction()` to `getAnInput()` for consistency with other `Instruction` classes.
This commit is contained in:
Dave Bartolomeo
2019-03-12 11:57:53 -07:00
parent b5a3edfdae
commit b0ad64c3e7
13 changed files with 68 additions and 47 deletions

View File

@@ -15,7 +15,7 @@ module InstructionSanity {
/**
* Holds if the instruction `instr` should be expected to have an operand
* with operand tag `tag`. Only holds for singleton operand tags. Tags with
* parameters, such as `PhiOperand` and `PositionalArgumentOperand` are handled
* parameters, such as `PhiInputOperand` and `PositionalArgumentOperand` are handled
* separately in `unexpectedOperand`.
*/
private predicate expectsOperand(Instruction instr, OperandTag tag) {
@@ -87,7 +87,7 @@ module InstructionSanity {
*/
query predicate missingPhiOperand(PhiInstruction instr, IRBlock pred) {
pred = instr.getBlock().getAPredecessor() and
not exists(PhiOperand operand |
not exists(PhiInputOperand operand |
operand = instr.getAnOperand() and
operand.getPredecessorBlock() = pred
)
@@ -1622,15 +1622,22 @@ class PhiInstruction extends Instruction {
result instanceof PhiMemoryAccess
}
/**
* Gets all of the instruction's `PhiInputOperand`s, representing the values that flow from each predecessor block.
*/
final PhiInputOperand getAnInputOperand() {
result = this.getAnOperand()
}
/**
* Gets an instruction that defines the input to one of the operands of this
* instruction. It's possible for more than one operand to have the same
* defining instruction, so this predicate will have the same number of
* results as `getAnOperand()` or fewer.
* results as `getAnInputOperand()` or fewer.
*/
pragma[noinline]
final Instruction getAnOperandDefinitionInstruction() {
result = this.getAnOperand().(PhiOperand).getDefinitionInstruction()
final Instruction getAnInput() {
result = this.getAnInputOperand().getDefinitionInstruction()
}
}

View File

@@ -379,12 +379,12 @@ class SideEffectOperand extends TypedOperand {
/**
* An operand of a `PhiInstruction`.
*/
class PhiOperand extends MemoryOperand, TPhiOperand {
class PhiInputOperand extends MemoryOperand, TPhiOperand {
PhiInstruction useInstr;
Instruction defInstr;
IRBlock predecessorBlock;
PhiOperand() {
PhiInputOperand() {
this = TPhiOperand(useInstr, defInstr, predecessorBlock)
}

View File

@@ -10,8 +10,8 @@ int getConstantValue(Instruction instr) {
result = getConstantValue(instr.(CopyInstruction).getSourceValue()) or
exists(PhiInstruction phi |
phi = instr and
result = max(Instruction def | def = phi.getAnOperandDefinitionInstruction() | getConstantValueToPhi(def)) and
result = min(Instruction def | def = phi.getAnOperandDefinitionInstruction() | getConstantValueToPhi(def))
result = max(Instruction def | def = phi.getAnInput() | getConstantValueToPhi(def)) and
result = min(Instruction def | def = phi.getAnInput() | getConstantValueToPhi(def))
)
}
@@ -19,7 +19,7 @@ pragma[noinline]
int getConstantValueToPhi(Instruction def) {
exists(PhiInstruction phi |
result = getConstantValue(def) and
def = phi.getAnOperandDefinitionInstruction()
def = phi.getAnInput()
)
}

View File

@@ -73,7 +73,7 @@ private predicate operandEscapesDomain(Operand operand) {
not isArgumentForParameter(_, operand, _) and
not isOnlyEscapesViaReturnArgument(operand) and
not operand.getUseInstruction() instanceof ReturnValueInstruction and
not operand instanceof PhiOperand
not operand instanceof PhiInputOperand
}
/**
@@ -171,7 +171,7 @@ private predicate operandEscapesNonReturn(Operand operand) {
or
isOnlyEscapesViaReturnArgument(operand) and resultEscapesNonReturn(operand.getUseInstruction())
or
operand instanceof PhiOperand and
operand instanceof PhiInputOperand and
resultEscapesNonReturn(operand.getUseInstruction())
or
operandEscapesDomain(operand)
@@ -194,7 +194,7 @@ private predicate operandMayReachReturn(Operand operand) {
or
isOnlyEscapesViaReturnArgument(operand) and resultMayReachReturn(operand.getUseInstruction())
or
operand instanceof PhiOperand and
operand instanceof PhiInputOperand and
resultMayReachReturn(operand.getUseInstruction())
}

View File

@@ -15,7 +15,7 @@ module InstructionSanity {
/**
* Holds if the instruction `instr` should be expected to have an operand
* with operand tag `tag`. Only holds for singleton operand tags. Tags with
* parameters, such as `PhiOperand` and `PositionalArgumentOperand` are handled
* parameters, such as `PhiInputOperand` and `PositionalArgumentOperand` are handled
* separately in `unexpectedOperand`.
*/
private predicate expectsOperand(Instruction instr, OperandTag tag) {
@@ -87,7 +87,7 @@ module InstructionSanity {
*/
query predicate missingPhiOperand(PhiInstruction instr, IRBlock pred) {
pred = instr.getBlock().getAPredecessor() and
not exists(PhiOperand operand |
not exists(PhiInputOperand operand |
operand = instr.getAnOperand() and
operand.getPredecessorBlock() = pred
)
@@ -1622,15 +1622,22 @@ class PhiInstruction extends Instruction {
result instanceof PhiMemoryAccess
}
/**
* Gets all of the instruction's `PhiInputOperand`s, representing the values that flow from each predecessor block.
*/
final PhiInputOperand getAnInputOperand() {
result = this.getAnOperand()
}
/**
* Gets an instruction that defines the input to one of the operands of this
* instruction. It's possible for more than one operand to have the same
* defining instruction, so this predicate will have the same number of
* results as `getAnOperand()` or fewer.
* results as `getAnInputOperand()` or fewer.
*/
pragma[noinline]
final Instruction getAnOperandDefinitionInstruction() {
result = this.getAnOperand().(PhiOperand).getDefinitionInstruction()
final Instruction getAnInput() {
result = this.getAnInputOperand().getDefinitionInstruction()
}
}

View File

@@ -379,12 +379,12 @@ class SideEffectOperand extends TypedOperand {
/**
* An operand of a `PhiInstruction`.
*/
class PhiOperand extends MemoryOperand, TPhiOperand {
class PhiInputOperand extends MemoryOperand, TPhiOperand {
PhiInstruction useInstr;
Instruction defInstr;
IRBlock predecessorBlock;
PhiOperand() {
PhiInputOperand() {
this = TPhiOperand(useInstr, defInstr, predecessorBlock)
}

View File

@@ -10,8 +10,8 @@ int getConstantValue(Instruction instr) {
result = getConstantValue(instr.(CopyInstruction).getSourceValue()) or
exists(PhiInstruction phi |
phi = instr and
result = max(Instruction def | def = phi.getAnOperandDefinitionInstruction() | getConstantValueToPhi(def)) and
result = min(Instruction def | def = phi.getAnOperandDefinitionInstruction() | getConstantValueToPhi(def))
result = max(Instruction def | def = phi.getAnInput() | getConstantValueToPhi(def)) and
result = min(Instruction def | def = phi.getAnInput() | getConstantValueToPhi(def))
)
}
@@ -19,7 +19,7 @@ pragma[noinline]
int getConstantValueToPhi(Instruction def) {
exists(PhiInstruction phi |
result = getConstantValue(def) and
def = phi.getAnOperandDefinitionInstruction()
def = phi.getAnInput()
)
}

View File

@@ -15,7 +15,7 @@ module InstructionSanity {
/**
* Holds if the instruction `instr` should be expected to have an operand
* with operand tag `tag`. Only holds for singleton operand tags. Tags with
* parameters, such as `PhiOperand` and `PositionalArgumentOperand` are handled
* parameters, such as `PhiInputOperand` and `PositionalArgumentOperand` are handled
* separately in `unexpectedOperand`.
*/
private predicate expectsOperand(Instruction instr, OperandTag tag) {
@@ -87,7 +87,7 @@ module InstructionSanity {
*/
query predicate missingPhiOperand(PhiInstruction instr, IRBlock pred) {
pred = instr.getBlock().getAPredecessor() and
not exists(PhiOperand operand |
not exists(PhiInputOperand operand |
operand = instr.getAnOperand() and
operand.getPredecessorBlock() = pred
)
@@ -1622,15 +1622,22 @@ class PhiInstruction extends Instruction {
result instanceof PhiMemoryAccess
}
/**
* Gets all of the instruction's `PhiInputOperand`s, representing the values that flow from each predecessor block.
*/
final PhiInputOperand getAnInputOperand() {
result = this.getAnOperand()
}
/**
* Gets an instruction that defines the input to one of the operands of this
* instruction. It's possible for more than one operand to have the same
* defining instruction, so this predicate will have the same number of
* results as `getAnOperand()` or fewer.
* results as `getAnInputOperand()` or fewer.
*/
pragma[noinline]
final Instruction getAnOperandDefinitionInstruction() {
result = this.getAnOperand().(PhiOperand).getDefinitionInstruction()
final Instruction getAnInput() {
result = this.getAnInputOperand().getDefinitionInstruction()
}
}

View File

@@ -379,12 +379,12 @@ class SideEffectOperand extends TypedOperand {
/**
* An operand of a `PhiInstruction`.
*/
class PhiOperand extends MemoryOperand, TPhiOperand {
class PhiInputOperand extends MemoryOperand, TPhiOperand {
PhiInstruction useInstr;
Instruction defInstr;
IRBlock predecessorBlock;
PhiOperand() {
PhiInputOperand() {
this = TPhiOperand(useInstr, defInstr, predecessorBlock)
}

View File

@@ -10,8 +10,8 @@ int getConstantValue(Instruction instr) {
result = getConstantValue(instr.(CopyInstruction).getSourceValue()) or
exists(PhiInstruction phi |
phi = instr and
result = max(Instruction def | def = phi.getAnOperandDefinitionInstruction() | getConstantValueToPhi(def)) and
result = min(Instruction def | def = phi.getAnOperandDefinitionInstruction() | getConstantValueToPhi(def))
result = max(Instruction def | def = phi.getAnInput() | getConstantValueToPhi(def)) and
result = min(Instruction def | def = phi.getAnInput() | getConstantValueToPhi(def))
)
}
@@ -19,7 +19,7 @@ pragma[noinline]
int getConstantValueToPhi(Instruction def) {
exists(PhiInstruction phi |
result = getConstantValue(def) and
def = phi.getAnOperandDefinitionInstruction()
def = phi.getAnInput()
)
}

View File

@@ -73,7 +73,7 @@ private predicate operandEscapesDomain(Operand operand) {
not isArgumentForParameter(_, operand, _) and
not isOnlyEscapesViaReturnArgument(operand) and
not operand.getUseInstruction() instanceof ReturnValueInstruction and
not operand instanceof PhiOperand
not operand instanceof PhiInputOperand
}
/**
@@ -171,7 +171,7 @@ private predicate operandEscapesNonReturn(Operand operand) {
or
isOnlyEscapesViaReturnArgument(operand) and resultEscapesNonReturn(operand.getUseInstruction())
or
operand instanceof PhiOperand and
operand instanceof PhiInputOperand and
resultEscapesNonReturn(operand.getUseInstruction())
or
operandEscapesDomain(operand)
@@ -194,7 +194,7 @@ private predicate operandMayReachReturn(Operand operand) {
or
isOnlyEscapesViaReturnArgument(operand) and resultMayReachReturn(operand.getUseInstruction())
or
operand instanceof PhiOperand and
operand instanceof PhiInputOperand and
resultMayReachReturn(operand.getUseInstruction())
}

View File

@@ -377,7 +377,7 @@ private predicate boundedNonPhiOperand(NonPhiOperand op, Bound b, int delta, boo
* - `upper = false` : `op2 >= op1 + delta`
*/
private predicate boundFlowStepPhi(
PhiOperand op2, Operand op1, int delta, boolean upper, Reason reason
PhiInputOperand op2, Operand op1, int delta, boolean upper, Reason reason
) {
op2.getDefinitionInstruction().(CopyInstruction).getSourceValueOperand() = op1 and
(upper = true or upper = false) and
@@ -393,7 +393,7 @@ private predicate boundFlowStepPhi(
private predicate boundedPhiOperand(
PhiOperand op, Bound b, int delta, boolean upper, boolean fromBackEdge, int origdelta,
PhiInputOperand op, Bound b, int delta, boolean upper, boolean fromBackEdge, int origdelta,
Reason reason
) {
exists(NonPhiOperand op2, int d1, int d2, Reason r1, Reason r2 |
@@ -446,7 +446,7 @@ private predicate unequalOperand(Operand op, Bound b, int delta, Reason reason)
private predicate boundedPhiCandValidForEdge(
PhiInstruction phi, Bound b, int delta, boolean upper, boolean fromBackEdge, int origdelta,
Reason reason, PhiOperand op
Reason reason, PhiInputOperand op
) {
boundedPhiCand(phi, upper, b, delta, fromBackEdge, origdelta, reason) and
(
@@ -469,7 +469,7 @@ private int weakenDelta(boolean upper, int delta) {
}
private predicate boundedPhiInp(
PhiInstruction phi, PhiOperand op, Bound b, int delta, boolean upper, boolean fromBackEdge,
PhiInstruction phi, PhiInputOperand op, Bound b, int delta, boolean upper, boolean fromBackEdge,
int origdelta, Reason reason
) {
phi.getAnOperand() = op and
@@ -499,12 +499,12 @@ private predicate boundedPhiInp(
pragma[noinline]
private predicate boundedPhiInp1(
PhiInstruction phi, PhiOperand op, Bound b, int delta, boolean upper
PhiInstruction phi, PhiInputOperand op, Bound b, int delta, boolean upper
) {
boundedPhiInp(phi, op, b, delta, upper, _, _, _)
}
private predicate selfBoundedPhiInp(PhiInstruction phi, PhiOperand op, boolean upper) {
private predicate selfBoundedPhiInp(PhiInstruction phi, PhiInputOperand op, boolean upper) {
exists(int d, ValueNumberBound phibound |
phibound.getInstruction() = phi and
boundedPhiInp(phi, op, phibound, d, upper, _, _, _) and
@@ -521,7 +521,7 @@ private predicate boundedPhiCand(
PhiInstruction phi, boolean upper, Bound b, int delta, boolean fromBackEdge, int origdelta,
Reason reason
) {
exists(PhiOperand op |
exists(PhiInputOperand op |
boundedPhiInp(phi, op, b, delta, upper, fromBackEdge, origdelta, reason)
)
}
@@ -556,7 +556,7 @@ private predicate boundedInstruction(
Instruction i, Bound b, int delta, boolean upper, boolean fromBackEdge, int origdelta, Reason reason
) {
i instanceof PhiInstruction and
forex(PhiOperand op | op = i.getAnOperand() |
forex(PhiInputOperand op | op = i.getAnOperand() |
boundedPhiCandValidForEdge(i, b, delta, upper, fromBackEdge, origdelta, reason, op)
)
or

View File

@@ -22,8 +22,8 @@ IntValue getConstantValue(Instruction instr) {
result = getConstantValue(instr.(CopyInstruction).getSourceValue()) or
exists(PhiInstruction phi |
phi = instr and
result = max(PhiOperand operand | operand = phi.getAnOperand() | getConstantValue(operand.getDefinitionInstruction())) and
result = min(PhiOperand operand | operand = phi.getAnOperand() | getConstantValue(operand.getDefinitionInstruction()))
result = max(PhiInputOperand operand | operand = phi.getAnOperand() | getConstantValue(operand.getDefinitionInstruction())) and
result = min(PhiInputOperand operand | operand = phi.getAnOperand() | getConstantValue(operand.getDefinitionInstruction()))
)
}
@@ -63,7 +63,7 @@ predicate valueFlowStep(Instruction i, Operand op, int delta) {
)
}
predicate backEdge(PhiInstruction phi, PhiOperand op) {
predicate backEdge(PhiInstruction phi, PhiInputOperand op) {
phi.getAnOperand() = op and
phi.getBlock() = op.getPredecessorBlock().getBackEdgeSuccessor(_)
}