Package org.jruby.compiler.ir.dataflow

Examples of org.jruby.compiler.ir.dataflow.DataFlowVar


//            System.out.println("TF: Processing: " + i);

            // v is defined => It is no longer live before 'i'
            Variable v = i.getResult();
            if (v != null) {
                DataFlowVar dv = lvp.getDFVar(v);
                _tmp.clear(dv._id);
//                System.out.println("cleared live flag for: " + v);
            }

            // Check if 'i' is a call and uses a closure!
            // If so, we need to process the closure for live variable info.
            if (i instanceof CallInstr) {
                CallInstr c = (CallInstr) i;
                // SSS FIXME: This relies on the local opt. pass having run already
                // so that the built closure from the previous instr. is propagated to the call site here.
                // Formalize this dependency somewhere?
                Operand o = c.getClosureArg();
//                   System.out.println("Processing closure: " + o + "-------");
                if ((o != null) && (o instanceof MetaObject)) {
                    IRClosure cl = (IRClosure)((MetaObject)o).scope;
                    if (c.isLVADataflowBarrier()) {
                        processClosure(cl, lvp.getAllVars());

                        // Mark all variables live if 'c' is a dataflow barrier!
//                        System.out.println(".. call is a data flow barrier ..");
                        for (int j = 0; j < _setSize; j++)
                            _tmp.set(j);
                    }
                    else {
                        // Propagate current LVA state through the closure
                        // SSS FIXME: Think through this .. Is there any way out of having
                        // to recompute the entire lva for the closure each time through?

                        // 1. Collect variables live at this point.
                        List<Variable> liveVars = new ArrayList<Variable>();
                        for (int j = 0; j < _tmp.size(); j++) {
                            if (_tmp.get(j) == true) {
//                                System.out.println(lvp.getVariable(j) + " is live on exit of closure!");
                                liveVars.add(lvp.getVariable(j));
                            }
                        }
//                        System.out.println(" .. collected live on exit ..");

                        // 2. Run LVA on the closure
                        LiveVariablesProblem xlvp = processClosure(cl, liveVars);

//                        System.out.println("------- done with closure" + o);

                        // 3. Collect variables live on entry of the closure and merge that info into the current problem.
                        for (Variable y: xlvp.getVarsLiveOnEntry()) {
                            DataFlowVar dv = lvp.getDFVar(y);
                            // This can be null for vars used, but not defined!  Yes, the source program is buggy ..
                            if (dv != null) {
//                                System.out.println(y + " is live on entry of the closure!");
                                _tmp.set(dv._id);
                            }
                        }
                    }
                }
                else if (c.isLVADataflowBarrier()) {
                    // Mark all variables live if 'c' is a dataflow barrier!
//                    System.out.println(".. call is a data flow barrier ..");
                    for (int j = 0; j < _setSize; j++)
                        _tmp.set(j);
                }
            }

            // Now, for all variables used by 'i' mark them live before 'i'
            for (Variable x: i.getUsedVariables()) {
                DataFlowVar dv = lvp.getDFVar(x);
                // This can be null for vars used, but not defined!  Yes, the source program is buggy ..
                if (dv != null) {
                    _tmp.set(dv._id);
//                    System.out.println("set live flag for: " + x);
                }
View Full Code Here


        while (it.hasPrevious()) {
            Instr i = it.previous();
//            System.out.println("DEAD?? " + i);
            Variable v = i.getResult();
            if (v != null) {
                DataFlowVar dv = lvp.getDFVar(v);
                    // If 'v' is not live at the instruction site, and it has no side effects, mark it dead!
                if ((_tmp.get(dv._id) == false) && !i.hasSideEffects()) {
//                    System.out.println("YES!");
                    i.markDead();
                    it.remove();
                }
                else if (_tmp.get(dv._id) == false) {
//                    System.out.println("NO!  has side effects! Op is: " + i.operation);
                }
                else {
//                    System.out.println("NO! LIVE result:" + v);
                    _tmp.clear(dv._id);
                }
            }
            else {
//                System.out.println("IGNORING! No result!");
            }

            if (i instanceof CallInstr) {
                CallInstr c = (CallInstr) i;
                if (c.isLVADataflowBarrier()) {
                    // Mark all variables live if 'c' is a dataflow barrier!
                    for (int j = 0; j < _setSize; j++)
                        _tmp.set(j);
                }
                else {
                    Operand o = c.getClosureArg();
                    if ((o != null) && (o instanceof MetaObject)) {
                        // 2. Run LVA on the closure
                        IRClosure cl = (IRClosure)((MetaObject)o).scope;
                        CFG x = cl.getCFG();
                        LiveVariablesProblem xlvp = (LiveVariablesProblem)x.getDataFlowSolution(lvp.getName());
                        // 3. Collect variables live on entry and merge that info into the current problem.
                        for (Variable y: xlvp.getVarsLiveOnEntry()) {
                            DataFlowVar dv = lvp.getDFVar(y);
                            // This can be null for vars used, but not defined!  Yes, the source program is buggy ..
                            if (dv != null)
                                _tmp.set(dv._id);
                        }
                    }
                }
            }

            // Do not mark this instruction's operands live if the instruction itself is dead!
            if (!i.isDead()) {
               for (Variable x: i.getUsedVariables()) {
                   DataFlowVar dv = lvp.getDFVar(x);
                   if (dv != null)
                       _tmp.set(dv._id);
               }
            }
        }
View Full Code Here

    public DataFlowVar   getDFVar(Variable v)  { return _dfVarMap.get(v); }
    public Variable      getVariable(int id)   { return _varDfVarMap.get(id); }
    public FlowGraphNode buildFlowGraphNode(BasicBlock bb) { return new LiveVariableNode(this, bb)}

    private void addDFVar(Variable v, boolean recordVar)  {
        DataFlowVar dfv = new DataFlowVar(this);
        _dfVarMap.put(v, dfv);
        _varDfVarMap.put(dfv._id, v);
        if (recordVar)
            _udVars.add(v);
    }
View Full Code Here

TOP

Related Classes of org.jruby.compiler.ir.dataflow.DataFlowVar

Copyright © 2018 www.massapicom. 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.