com.ibm.wala.ssa.InstanceOfPiPolicy Maven / Gradle / Ivy
/*
* Copyright (c) 2007 IBM Corporation.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*/
package com.ibm.wala.ssa;
import com.ibm.wala.util.collections.Pair;
import java.util.Collections;
import java.util.List;
/**
* A pi node policy with the following rule:
*
* If we have the following code:
*
*
S1: c = v1 instanceof T S2: if (c == 0) { ... }
*
* replace it with:
*
* S1: c = v1 instanceof T S2: if (c == 0) { v2 = PI(v1, S1) .... }
*
* The same pattern holds if the test is c == 1. This renaming allows SSA-based analysis to reason
* about the type of v2 depending on the outcome of the branch.
*/
public class InstanceOfPiPolicy implements SSAPiNodePolicy {
private static final InstanceOfPiPolicy singleton = new InstanceOfPiPolicy();
public static InstanceOfPiPolicy createInstanceOfPiPolicy() {
return singleton;
}
private InstanceOfPiPolicy() {}
@Override
public Pair getPi(
SSAConditionalBranchInstruction cond,
SSAInstruction def1,
SSAInstruction def2,
SymbolTable symbolTable) {
if (def1 instanceof SSAInstanceofInstruction) {
if (symbolTable.isBooleanOrZeroOneConstant(cond.getUse(1))) {
return Pair.make(def1.getUse(0), def1);
}
}
if (def2 instanceof SSAInstanceofInstruction) {
if (symbolTable.isBooleanOrZeroOneConstant(cond.getUse(0))) {
return Pair.make(def2.getUse(0), def2);
}
}
return null;
}
@Override
public boolean equals(Object obj) {
return this == obj;
}
@Override
public int hashCode() {
return 12;
}
@Override
public Pair getPi(
SSAAbstractInvokeInstruction call, SymbolTable symbolTable) {
return null;
}
@Override
public List> getPis(
SSAConditionalBranchInstruction cond,
SSAInstruction def1,
SSAInstruction def2,
SymbolTable symbolTable) {
return Collections.singletonList(getPi(cond, def1, def2, symbolTable));
}
}