Search in sources :

Example 46 with VarExpr

use of org.mapleir.ir.code.expr.VarExpr in project maple-ir by LLVM-but-worse.

the class SSADefUseMap method compute.

public void compute() {
    defs.clear();
    uses.clear();
    phiDefs.clear();
    phiUses.clear();
    Set<Local> usedLocals = new HashSet<>();
    for (BasicBlock b : cfg.vertices()) {
        for (Stmt stmt : b) {
            phiUses.getNonNull(b);
            usedLocals.clear();
            for (Expr s : stmt.enumerateOnlyChildren()) if (s.getOpcode() == Opcode.LOCAL_LOAD)
                usedLocals.add(((VarExpr) s).getLocal());
            build(b, stmt, usedLocals);
        }
    }
}
Also used : VarExpr(org.mapleir.ir.code.expr.VarExpr) Expr(org.mapleir.ir.code.Expr) PhiExpr(org.mapleir.ir.code.expr.PhiExpr) BasicBlock(org.mapleir.ir.cfg.BasicBlock) Local(org.mapleir.ir.locals.Local) HashSet(java.util.HashSet) Stmt(org.mapleir.ir.code.Stmt) CopyPhiStmt(org.mapleir.ir.code.stmt.copy.CopyPhiStmt) AbstractCopyStmt(org.mapleir.ir.code.stmt.copy.AbstractCopyStmt)

Example 47 with VarExpr

use of org.mapleir.ir.code.expr.VarExpr in project maple-ir by LLVM-but-worse.

the class SreedharDestructor method init.

// ============================================================================================================= //
// =============================================== Initialization ============================================== //
// ============================================================================================================= //
private void init() {
    // init pccs
    for (CopyPhiStmt copyPhi : defuse.phiDefs.values()) {
        Local phiTarget = copyPhi.getVariable().getLocal();
        pccs.getNonNull(phiTarget).add(phiTarget);
        // System.out.println("Initphi " + phiTarget);
        for (Entry<BasicBlock, Expr> phiEntry : copyPhi.getExpression().getArguments().entrySet()) {
            if (phiEntry.getValue().getOpcode() != LOCAL_LOAD)
                throw new IllegalArgumentException("Phi arg is not local; instead is " + phiEntry.getValue().getClass().getSimpleName());
            Local phiSource = ((VarExpr) phiEntry.getValue()).getLocal();
            pccs.getNonNull(phiSource).add(phiSource);
        // System.out.println("Initphi " + phiSource);
        }
    }
    // System.out.println();
    // compute liveness
    (liveness = new SSABlockLivenessAnalyser(cfg)).compute();
    // writer.add("liveness", new LivenessDecorator<ControlFlowGraph, BasicBlock, FlowEdge<BasicBlock>>().setLiveness(liveness));
    buildInterference();
}
Also used : VarExpr(org.mapleir.ir.code.expr.VarExpr) Expr(org.mapleir.ir.code.Expr) PhiExpr(org.mapleir.ir.code.expr.PhiExpr) BasicBlock(org.mapleir.ir.cfg.BasicBlock) Local(org.mapleir.ir.locals.Local) VarExpr(org.mapleir.ir.code.expr.VarExpr) CopyPhiStmt(org.mapleir.ir.code.stmt.copy.CopyPhiStmt)

Example 48 with VarExpr

use of org.mapleir.ir.code.expr.VarExpr in project maple-ir by LLVM-but-worse.

the class ControlFlowGraph method exciseStmt.

/**
 * Excises uses of a removed statement.
 * @param c Removed statement to update def/use information with respect to.
 */
public void exciseStmt(Stmt c) {
    // delete uses
    for (Expr e : c.enumerateOnlyChildren()) {
        if (e.getOpcode() == Opcode.LOCAL_LOAD) {
            VarExpr v = (VarExpr) e;
            VersionedLocal l = (VersionedLocal) v.getLocal();
            locals.uses.get(l).remove(v);
        }
    }
    c.getBlock().remove(c);
}
Also used : VersionedLocal(org.mapleir.ir.locals.impl.VersionedLocal) VarExpr(org.mapleir.ir.code.expr.VarExpr) Expr(org.mapleir.ir.code.Expr) PhiExpr(org.mapleir.ir.code.expr.PhiExpr) VarExpr(org.mapleir.ir.code.expr.VarExpr)

Example 49 with VarExpr

use of org.mapleir.ir.code.expr.VarExpr in project maple-ir by LLVM-but-worse.

the class DefUseVerifier method verify0.

public static void verify0(ControlFlowGraph cfg) {
    LocalsPool lp = cfg.getLocals();
    Map<Local, AbstractCopyStmt> defs = new HashMap<>();
    NullPermeableHashMap<VersionedLocal, Set<VarExpr>> uses = new NullPermeableHashMap<>(SetCreator.getInstance());
    for (BasicBlock b : cfg.vertices()) {
        for (Stmt stmt : b) {
            if (stmt.getOpcode() == Opcode.LOCAL_STORE || stmt.getOpcode() == Opcode.PHI_STORE) {
                AbstractCopyStmt copy = (AbstractCopyStmt) stmt;
                defs.put(copy.getVariable().getLocal(), copy);
            }
            for (Expr e : stmt.enumerateOnlyChildren()) {
                if (e.getOpcode() == Opcode.LOCAL_LOAD) {
                    VarExpr v = (VarExpr) e;
                    uses.getNonNull((VersionedLocal) v.getLocal()).add(v);
                }
            }
        }
    }
    {
        Set<Local> dlocals = new HashSet<>();
        dlocals.addAll(defs.keySet());
        dlocals.addAll(lp.defs.keySet());
        for (Local l : dlocals) {
            if (!defs.containsKey(l)) {
                throw new IllegalStateException("(other): def of " + l);
            }
            if (!lp.defs.containsKey(l)) {
                throw new IllegalStateException("(real): def of " + l);
            }
            AbstractCopyStmt copy1 = defs.get(l);
            AbstractCopyStmt copy2 = lp.defs.get(l);
            if (copy1 != copy2) {
                throw new IllegalStateException("dtest: " + copy1 + " :: " + copy2);
            }
        }
    }
    {
        Set<VersionedLocal> ulocals = new HashSet<>();
        ulocals.addAll(uses.keySet());
        ulocals.addAll(lp.uses.keySet());
        for (VersionedLocal l : ulocals) {
            /*if(!uses.containsKey(l)) {
					throw new IllegalStateException("(other): use of " + l);
				}
				
				if(!lp.uses.containsKey(l)) {
					throw new IllegalStateException("(real): use of " + l);
				}*/
            Set<VarExpr> uses1 = uses.get(l);
            Set<VarExpr> uses2 = lp.uses.get(l);
            if (uses1 == null) {
                if (uses2.size() != 0) {
                    throw new IllegalStateException(String.format("utest1: %s, u1:null :: u2:%d", l, uses2.size()));
                }
            } else if (uses2 == null) {
                if (uses1.size() == 0) {
                    throw new IllegalStateException(String.format("utest2: %s, u1:%d :: u2:null", l, uses1.size()));
                }
            } else {
                if (uses2.size() != uses1.size()) {
                    throw new IllegalStateException(String.format("utest3: %s, u1:%d :: u2:%d", l, uses1.size(), uses2.size()));
                }
            }
        }
    }
}
Also used : VersionedLocal(org.mapleir.ir.locals.impl.VersionedLocal) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) NullPermeableHashMap(org.mapleir.stdlib.collections.map.NullPermeableHashMap) BasicBlock(org.mapleir.ir.cfg.BasicBlock) Local(org.mapleir.ir.locals.Local) VersionedLocal(org.mapleir.ir.locals.impl.VersionedLocal) Stmt(org.mapleir.ir.code.Stmt) AbstractCopyStmt(org.mapleir.ir.code.stmt.copy.AbstractCopyStmt) LocalsPool(org.mapleir.ir.locals.LocalsPool) VarExpr(org.mapleir.ir.code.expr.VarExpr) Expr(org.mapleir.ir.code.Expr) NullPermeableHashMap(org.mapleir.stdlib.collections.map.NullPermeableHashMap) AbstractCopyStmt(org.mapleir.ir.code.stmt.copy.AbstractCopyStmt) VarExpr(org.mapleir.ir.code.expr.VarExpr)

Example 50 with VarExpr

use of org.mapleir.ir.code.expr.VarExpr in project maple-ir by LLVM-but-worse.

the class SSAGenPass method collectUses.

private void collectUses(Expr e) {
    for (Expr c : e.enumerateWithSelf()) {
        if (c.getOpcode() == Opcode.LOCAL_LOAD) {
            VarExpr ve = (VarExpr) c;
            pool.uses.get(ve.getLocal()).add(ve);
        }
    }
}
Also used : ConstantExpr(org.mapleir.ir.code.expr.ConstantExpr) InitialisedObjectExpr(org.mapleir.ir.code.expr.invoke.InitialisedObjectExpr) InvocationExpr(org.mapleir.ir.code.expr.invoke.InvocationExpr) VarExpr(org.mapleir.ir.code.expr.VarExpr) Expr(org.mapleir.ir.code.Expr) PhiExpr(org.mapleir.ir.code.expr.PhiExpr) VarExpr(org.mapleir.ir.code.expr.VarExpr)

Aggregations

VarExpr (org.mapleir.ir.code.expr.VarExpr)51 Expr (org.mapleir.ir.code.Expr)37 Local (org.mapleir.ir.locals.Local)32 PhiExpr (org.mapleir.ir.code.expr.PhiExpr)31 AbstractCopyStmt (org.mapleir.ir.code.stmt.copy.AbstractCopyStmt)30 VersionedLocal (org.mapleir.ir.locals.impl.VersionedLocal)29 BasicBlock (org.mapleir.ir.cfg.BasicBlock)26 Stmt (org.mapleir.ir.code.Stmt)25 CopyPhiStmt (org.mapleir.ir.code.stmt.copy.CopyPhiStmt)25 CopyVarStmt (org.mapleir.ir.code.stmt.copy.CopyVarStmt)21 ConstantExpr (org.mapleir.ir.code.expr.ConstantExpr)15 InvocationExpr (org.mapleir.ir.code.expr.invoke.InvocationExpr)13 InitialisedObjectExpr (org.mapleir.ir.code.expr.invoke.InitialisedObjectExpr)12 BasicLocal (org.mapleir.ir.locals.impl.BasicLocal)7 NullPermeableHashMap (org.mapleir.stdlib.collections.map.NullPermeableHashMap)7 Type (org.objectweb.asm.Type)7 HashSet (java.util.HashSet)6 Constraint (org.mapleir.ir.cfg.builder.ssaopt.Constraint)6 ConditionalJumpStmt (org.mapleir.ir.code.stmt.ConditionalJumpStmt)5 PopStmt (org.mapleir.ir.code.stmt.PopStmt)5