use of soot.toDex.instructions.AddressInsn in project soot by Sable.
the class StmtVisitor method addPayloads.
private void addPayloads() {
// add switch payloads to the end of the insns
for (AbstractPayload payload : payloads) {
addInsn(new AddressInsn(payload), null);
addInsn(payload, null);
}
}
use of soot.toDex.instructions.AddressInsn in project soot by Sable.
the class StmtVisitor method getRealInsns.
public List<BuilderInstruction> getRealInsns(LabelAssigner labelAssigner) {
List<BuilderInstruction> finalInsns = new ArrayList<BuilderInstruction>();
for (Insn i : insns) {
if (i instanceof AddressInsn) {
// skip non-insns
continue;
}
BuilderInstruction realInsn = i.getRealInsn(labelAssigner);
finalInsns.add(realInsn);
if (insnStmtMap.containsKey(i)) {
// get tags
instructionInsnMap.put(realInsn, i);
}
LocalRegisterAssignmentInformation assignmentInfo = insnRegisterMap.get(i);
if (assignmentInfo != null)
instructionRegisterMap.put(realInsn, assignmentInfo);
if (i instanceof AbstractPayload)
instructionPayloadMap.put(realInsn, (AbstractPayload) i);
}
return finalInsns;
}
use of soot.toDex.instructions.AddressInsn in project soot by Sable.
the class RegisterAssigner method getRegsNeeded.
/**
* Gets the maximum number of registers needed by a single instruction in
* the given list of instructions.
*
* @param regsAlreadyReserved
* @param insns
* @param insnsStmtMap
* @return
*/
private int getRegsNeeded(int regsAlreadyReserved, List<Insn> insns, Map<Insn, Stmt> insnsStmtMap) {
// we only need regs that weren't
int regsNeeded = regsAlreadyReserved;
// reserved yet
for (int i = 0; i < insns.size(); i++) {
Insn insn = insns.get(i);
if (insn instanceof AddressInsn) {
// needs no regs/fitting
continue;
}
// first try to find a better opcode
Insn fittingInsn = findFittingInsn(insn);
if (fittingInsn != null) {
// use the fitting instruction and continue with next one
insns.set(i, fittingInsn);
insnsStmtMap.put(fittingInsn, insnsStmtMap.get(insn));
insnsStmtMap.remove(insn);
continue;
}
// no fitting instruction -> save if we need more registers
int newRegsNeeded = insn.getMinimumRegsNeeded();
if (newRegsNeeded > regsNeeded) {
regsNeeded = newRegsNeeded;
}
}
return regsNeeded;
}
use of soot.toDex.instructions.AddressInsn in project soot by Sable.
the class StmtVisitor method reduceInstructions.
/**
* Reduces the instruction list by removing unnecessary instruction pairs
* such as move v0 v1; move v1 v0;
* @param trapReferences
*/
private void reduceInstructions(Set<Unit> trapReferences) {
for (int i = 0; i < this.insns.size() - 1; i++) {
Insn curInsn = this.insns.get(i);
// Only consider real instructions
if (curInsn instanceof AddressInsn)
continue;
if (!isReducableMoveInstruction(curInsn.getOpcode()))
continue;
// Skip over following address instructions
Insn nextInsn = null;
int nextIndex = -1;
for (int j = i + 1; j < this.insns.size(); j++) {
Insn candidate = this.insns.get(j);
if (candidate instanceof AddressInsn)
continue;
nextInsn = candidate;
nextIndex = j;
break;
}
if (nextInsn == null || !isReducableMoveInstruction(nextInsn.getOpcode()))
continue;
// jump targets to the successor
if (nextIndex == this.insns.size() - 1)
continue;
// Check if we have a <- b; b <- a;
Register firstTarget = curInsn.getRegs().get(0);
Register firstSource = curInsn.getRegs().get(1);
Register secondTarget = nextInsn.getRegs().get(0);
Register secondSource = nextInsn.getRegs().get(1);
if (firstTarget.equals(secondSource) && secondTarget.equals(firstSource)) {
Stmt nextStmt = insnStmtMap.get(nextInsn);
// instructions may depend on the register being set.
if (nextStmt == null || (!isJumpTarget(nextStmt) && !trapReferences.contains(nextStmt))) {
insns.remove(nextIndex);
if (nextStmt != null) {
Insn nextInst = this.insns.get(nextIndex + 1);
insnStmtMap.remove(nextInsn);
insnStmtMap.put(nextInst, nextStmt);
}
}
}
}
}
use of soot.toDex.instructions.AddressInsn in project soot by Sable.
the class StmtVisitor method beginNewStmt.
protected void beginNewStmt(Stmt s) {
// It's a new statement, so we can re-use registers
regAlloc.resetImmediateConstantsPool();
addInsn(new AddressInsn(s), null);
}
Aggregations