Examples of Instr


Examples of org.jruby.compiler.ir.instructions.Instr

            IRubyObject self = (IRubyObject) interp.getSelf();
            Instr[] instrs = cfg.prepareForInterpretation();
            int n   = instrs.length;
            int ipc = 0;
            Instr lastInstr = null;
            while (ipc < n) {
                interpInstrsCount++;
                lastInstr = instrs[ipc];
               
                if (debug) System.out.println("EXEC'ing: " + lastInstr);
               
                try {
                    Label jumpTarget = lastInstr.interpret(interp, self);
                    ipc = (jumpTarget == null) ? ipc + 1 : jumpTarget.getTargetPC();
                }
                // SSS FIXME: This only catches Ruby exceptions
                // What about Java exceptions?
                catch (org.jruby.exceptions.RaiseException re) {
View Full Code Here

Examples of org.jruby.compiler.ir.instructions.Instr

        // to preserve expected code execution order
        Operand       receiver     = build(receiverNode, s);
        List<Operand> args         = setupCallArgs(callArgsNode, s);
        Operand       block        = setupCallClosure(callNode.getIterNode(), s);
        Variable      callResult   = s.getNewTemporaryVariable();
        Instr      callInstr    = new CallInstr(callResult, new MethAddr(callNode.getName()), receiver, args.toArray(new Operand[args.size()]), block);
        s.addInstr(callInstr);
        return callResult;
    }
View Full Code Here

Examples of org.jruby.compiler.ir.instructions.Instr

        } else if (iVisited instanceof Colon2MethodNode) {
            Colon2MethodNode c2mNode = (Colon2MethodNode)iVisited;
            List<Operand> args       = setupCallArgs(null, s);
            Operand       block      = setupCallClosure(null, s);
            Variable      callResult = s.getNewTemporaryVariable();
            Instr      callInstr  = new CallInstr(callResult, new MethAddr(c2mNode.getName()),
                    null, args.toArray(new Operand[args.size()]), block);
            s.addInstr(callInstr);
            return callResult;
        }
        else { throw new NotCompilableException("Not compilable: " + iVisited); }
View Full Code Here

Examples of org.jruby.compiler.ir.instructions.Instr

                Variable tmpVar = s.getNewTemporaryVariable();
                s.addInstr(new JRubyImplCallInstr(tmpVar, new MethAddr("getMetaClass"), getSelf(s), NO_ARGS));
                Label undefLabel = s.getNewLabel();
                Label defLabel   = s.getNewLabel();
                StringLiteral mName = new StringLiteral(((FCallNode)node).getName());
                Instr callInstr  = new JRubyImplCallInstr(tmpVar, new MethAddr("isMethodBound"), tmpVar, new Operand[]{mName, BooleanLiteral.FALSE});
                s.addInstr(callInstr);
                s.addInstr(new BEQInstr(tmpVar, BooleanLiteral.FALSE, undefLabel));
                s.addInstr(new CopyInstr(tmpVar, buildGetArgumentDefinition(((FCallNode) node).getArgsNode(), s, "method")));
                s.addInstr(new JumpInstr(defLabel));
                s.addInstr(new LABEL_Instr(undefLabel));
View Full Code Here

Examples of org.jruby.compiler.ir.instructions.Instr

    public Operand buildFCall(FCallNode fcallNode, IRScope s) {
        Node          callArgsNode = fcallNode.getArgsNode();
        List<Operand> args         = setupCallArgs(callArgsNode, s);
        Operand       block        = setupCallClosure(fcallNode.getIterNode(), s);
        Variable      callResult   = s.getNewTemporaryVariable();
        Instr         callInstr    = new CallInstr(callResult, new MethAddr(fcallNode.getName()), getSelf(s), args.toArray(new Operand[args.size()]), block);
        s.addInstr(callInstr);
        return callResult;
    }
View Full Code Here

Examples of org.jruby.compiler.ir.instructions.Instr

        }
       
        // get attr
        Operand  v1 = build(opAsgnNode.getReceiverNode(), s);
        Variable      getResult   = s.getNewTemporaryVariable();
        Instr callInstr = new CallInstr(getResult, new MethAddr(opAsgnNode.getVariableName()), v1,
                NO_ARGS, null);
        s.addInstr(callInstr);

        // call operator
        Operand  v2 = build(opAsgnNode.getValueNode(), s);
View Full Code Here

Examples of org.jruby.compiler.ir.instructions.Instr

    }

    public Operand buildVCall(VCallNode node, IRScope s) {
        List<Operand> args       = new ArrayList<Operand>(); args.add(getSelf(s));
        Variable      callResult = s.getNewTemporaryVariable();
        Instr         callInstr  = new CallInstr(callResult, new MethAddr(node.getName()), getSelf(s), NO_ARGS, null);
        s.addInstr(callInstr);
        return callResult;
    }
View Full Code Here

Examples of org.jruby.compiler.ir.instructions.Instr

        Map<Operand,Operand> valueMap = new HashMap<Operand,Operand>();
        Map<Variable,List<Variable>> simplificationMap = new HashMap<Variable,List<Variable>>();
        Map<String,CodeVersion> versionMap = new HashMap<String,CodeVersion>();
        ListIterator<Instr> instrs = s.getInstrs().listIterator();
        while (instrs.hasNext()) {
            Instr i = instrs.next();
            Operation iop = i.operation;
            if (iop.startsBasicBlock()) {
                valueMap = new HashMap<Operand,Operand>();
                simplificationMap = new HashMap<Variable,List<Variable>>();
                versionMap = new HashMap<String, CodeVersion>();
            }

            // Simplify instruction and record mapping between target variable and simplified value
//            System.out.println("BEFORE: " + i);
            Operand  val = i.simplifyAndGetResult(valueMap);
            Variable res = i.getResult();
//            System.out.println("For " + i + "; dst = " + res + "; val = " + val);
//            System.out.println("AFTER: " + i);
            if (val != null && res != null && res != val) {
                recordSimplification(res, val, valueMap, simplificationMap);

                if (val instanceof BreakResult) {
                    BreakResult br = (BreakResult)val;
                    i.markDead();
                    instrs.add(new CopyInstr(res, br._result));
                    instrs.add(new JumpInstr(br._jumpTarget));
                }
            }
            // Optimize some core class method calls for constant values
            else if (iop.isCall()) {
                val = null;
                CallInstr call = (CallInstr) i;
                Operand    r    = call.getReceiver();
                // SSS FIXME: r can be null for ruby/jruby internal call instructions!
                // Cannot optimize them as of now.
                if (r != null) {
                    // If 'r' is not a constant, it could actually be a compound value!
                    // Look in our value map to see if we have a simplified value for the receiver.
                    if (!r.isConstant()) {
                        Operand v = valueMap.get(r);
                        if (v != null)
                            r = v;
                    }

                    // Check if we can optimize this call based on the receiving method and receiver type
                    // Use the simplified receiver!
                    IRMethod rm = call.getTargetMethodWithReceiver(r);
                    if (rm != null) {
                        IRModule rc = rm.getDefiningIRModule();
                        if (rc != null) { // TODO: I am fairly sure I am wallpapering
                            if (rc.isCoreClass("Fixnum")) {
                                Operand[] args = call.getOperands();
                                if (args[2].isConstant()) {
                                    addMethodGuard(rm, deoptLabel, versionMap, instrs);
                                    val = ((Fixnum) r).computeValue(rm.getName(), (Constant) args[2]);
                                }
                            } else if (rc.isCoreClass("Float")) {
                                Operand[] args = call.getOperands();
                                if (args[2].isConstant()) {
                                    addMethodGuard(rm, deoptLabel, versionMap, instrs);
                                    val = ((Float) r).computeValue(rm.getName(), (Constant) args[2]);
                                }
                            } else if (rc.isCoreClass("Array")) {
                                Operand[] args = call.getOperands();
                                if (args[2] instanceof Fixnum && (rm.getName() == "[]")) {
                                    addMethodGuard(rm, deoptLabel, versionMap, instrs);
                                    val = ((Array) r).fetchCompileTimeArrayElement(((Fixnum) args[2]).value.intValue(), false);
                                }
                            }
                        }

                        // If we got a simplified value, mark the call dead and insert a copy in its place!
                        if (val != null) {
                            i.markDead();
                            instrs.add(new CopyInstr(res, val));
                            recordSimplification(res, val, valueMap, simplificationMap);
                        }
                    }
                }
            }

            // Purge all entries in valueMap that have 'res' as their simplified value to take care of RAW scenarios (because we aren't in SSA form yet!)
            if (res != null) {
                List<Variable> simplifiedVars = simplificationMap.get(res);
                if (simplifiedVars != null) {
                    for (Variable v: simplifiedVars)
                        valueMap.remove(v);
                    simplificationMap.remove(res);
                }
            }

            // If the call has been optimized away in the previous step, it is no longer a hard boundary for opts!
            if (iop.endsBasicBlock() || (iop.isCall() && !i.isDead())) {
                valueMap = new HashMap<Operand,Operand>();
                simplificationMap = new HashMap<Variable,List<Variable>>();
                versionMap = new HashMap<String, CodeVersion>();
            }
        }
View Full Code Here

Examples of org.jruby.compiler.ir.instructions.Instr

        Map<Variable, Integer> ends = new HashMap<Variable, Integer>();
        Map<Variable, Integer> starts = new HashMap<Variable, Integer>();
        SortedSet<Variable> variables = new TreeSet<Variable>();
       
        for (int i = instructions.size() - 1; i >= 0; i--) {
            Instr instr = instructions.get(i);
            Variable var = instr.result;

            if (var != null) {
                variables.add(var);
                starts.put(var, i);
            }

            for (Operand operand : instr.getOperands()) {
                if (operand != null && operand instanceof Variable && ends.get((Variable)operand) == null) {
                    ends.put((Variable)operand, i);
                    variables.add((Variable)operand);
                }
            }
View Full Code Here

Examples of org.jruby.compiler.ir.instructions.Instr

        Map<LocalVariable, Integer> ends = new HashMap<LocalVariable, Integer>();
        Map<LocalVariable, Integer> starts = new HashMap<LocalVariable, Integer>();
        Set<LocalVariable> variables = new TreeSet<LocalVariable>();

        for (int i = instructions.size() - 1; i >= 0; i--) {
            Instr instr = instructions.get(i);

            // TODO: Instruction encode whether arguments are optional/required/block
            // TODO: PErhaps this should be part of allocate and not have a generic
            //    getLiveLocalVariables...perhaps we just need this to setup static scope

            Variable variable = instr.result;

            if (variable != null && variable instanceof LocalVariable) {
                variables.add((LocalVariable) variable);
                starts.put((LocalVariable) variable, i);
            }

            for (Operand operand : instr.getOperands()) {
                if (!(operand instanceof LocalVariable)) continue;

                variable = (LocalVariable) operand;

                if (ends.get((LocalVariable) variable) == null) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.