Package com.tonic.analysis.ssa.analysis
Class DefUseChains
- java.lang.Object
-
- com.tonic.analysis.ssa.analysis.DefUseChains
-
public class DefUseChains extends Object
Def-use chains mapping each SSA value to its defining instruction and its uses.
-
-
Constructor Summary
Constructors Constructor Description DefUseChains(IRMethod method)Creates empty chains for the given method.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcompute()Computes def-use chains for all values in the method.SSAValuegetDefinedValue(IRInstruction instr)Gets the value defined by the specified instruction.IRInstructiongetDefinition(SSAValue value)Gets the instruction that defines the specified value.Map<SSAValue,IRInstruction>getDefinitions()Map<IRInstruction,SSAValue>getInstrDefs()Map<IRInstruction,Set<SSAValue>>getInstrUses()IRMethodgetMethod()intgetUseCount(SSAValue value)Gets the number of uses of the specified value.Set<SSAValue>getUsedValues(IRInstruction instr)Gets all values used by the specified instruction.Map<SSAValue,Set<IRInstruction>>getUses()Set<IRInstruction>getUses(SSAValue value)Gets all instructions that use the specified value.booleanhasUses(SSAValue value)Checks if the specified value has any uses.booleanisDeadCode(IRInstruction instr)Checks if an instruction is dead code.
-
-
-
Constructor Detail
-
DefUseChains
public DefUseChains(IRMethod method)
Creates empty chains for the given method.- Parameters:
method- the method to analyze
-
-
Method Detail
-
getMethod
public IRMethod getMethod()
- Returns:
- the method
-
getDefinitions
public Map<SSAValue,IRInstruction> getDefinitions()
- Returns:
- the definitions
-
getUses
public Map<SSAValue,Set<IRInstruction>> getUses()
- Returns:
- the uses
-
getInstrUses
public Map<IRInstruction,Set<SSAValue>> getInstrUses()
- Returns:
- the instr uses
-
getInstrDefs
public Map<IRInstruction,SSAValue> getInstrDefs()
- Returns:
- the instr defs
-
compute
public void compute()
Computes def-use chains for all values in the method.
-
getDefinition
public IRInstruction getDefinition(SSAValue value)
Gets the instruction that defines the specified value.- Parameters:
value- the value to query- Returns:
- the defining instruction, or null if none exists
-
getUses
public Set<IRInstruction> getUses(SSAValue value)
Gets all instructions that use the specified value.- Parameters:
value- the value to query- Returns:
- the set of instructions that use the value
-
getUsedValues
public Set<SSAValue> getUsedValues(IRInstruction instr)
Gets all values used by the specified instruction.- Parameters:
instr- the instruction to query- Returns:
- the set of values used by the instruction
-
getDefinedValue
public SSAValue getDefinedValue(IRInstruction instr)
Gets the value defined by the specified instruction.- Parameters:
instr- the instruction to query- Returns:
- the defined value, or null if the instruction defines no value
-
hasUses
public boolean hasUses(SSAValue value)
Checks if the specified value has any uses.- Parameters:
value- the value to check- Returns:
- true if the value has at least one use
-
getUseCount
public int getUseCount(SSAValue value)
Gets the number of uses of the specified value.- Parameters:
value- the value to query- Returns:
- the use count
-
isDeadCode
public boolean isDeadCode(IRInstruction instr)
Checks if an instruction is dead code.- Parameters:
instr- the instruction to check- Returns:
- true if the instruction defines a value that has no uses
-
-