use of com.taobao.android.dx.rop.code.LocalItem in project atlas by alibaba.
the class PhiTypeResolver method resolveResultType.
/**
* Resolves the result of a phi insn based on its operands. The "void"
* type, which is a nonsensical type for a register, is used for
* registers defined by as-of-yet-unresolved phi operations.
*
* @return true if the result type changed, false if no change
*/
boolean resolveResultType(PhiInsn insn) {
insn.updateSourcesToDefinitions(ssaMeth);
RegisterSpecList sources = insn.getSources();
// Start by finding the first non-void operand
RegisterSpec first = null;
int firstIndex = -1;
int szSources = sources.size();
for (int i = 0; i < szSources; i++) {
RegisterSpec rs = sources.get(i);
if (rs.getBasicType() != Type.BT_VOID) {
first = rs;
firstIndex = i;
}
}
if (first == null) {
// All operands are void -- we're not ready to resolve yet
return false;
}
LocalItem firstLocal = first.getLocalItem();
Type mergedType = first.getType();
boolean sameLocals = true;
for (int i = 0; i < szSources; i++) {
if (i == firstIndex) {
continue;
}
RegisterSpec rs = sources.get(i);
// Just skip void (unresolved phi results) for now
if (rs.getBasicType() == Type.BT_VOID) {
continue;
}
sameLocals = sameLocals && equalsHandlesNulls(firstLocal, rs.getLocalItem());
mergedType = (Type) Merger.mergeType(mergedType, rs.getType());
}
Type newResultType;
if (mergedType != null) {
newResultType = mergedType;
} else {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < szSources; i++) {
sb.append(sources.get(i).toString());
sb.append(' ');
}
throw new RuntimeException("Couldn't map types in phi insn:" + sb);
}
LocalItem newLocal = sameLocals ? firstLocal : null;
RegisterSpec result = insn.getResult();
if ((result.getTypeBearer() == newResultType) && equalsHandlesNulls(newLocal, result.getLocalItem())) {
return false;
}
insn.changeResultType(newResultType, newLocal);
return true;
}
use of com.taobao.android.dx.rop.code.LocalItem in project atlas by alibaba.
the class OutputFinisher method addConstants.
/**
* Helper for {@link #getAllConstants} which adds all the info for
* a single {@code RegisterSpec}.
*
* @param result {@code non-null;} result set to add to
* @param spec {@code null-ok;} register spec to add
*/
private static void addConstants(HashSet<Constant> result, RegisterSpec spec) {
if (spec == null) {
return;
}
LocalItem local = spec.getLocalItem();
CstString name = local.getName();
CstString signature = local.getSignature();
Type type = spec.getType();
if (type != Type.KNOWN_NULL) {
result.add(CstType.intern(type));
}
if (name != null) {
result.add(name);
}
if (signature != null) {
result.add(signature);
}
}
Aggregations