harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfur...@apache.org
Subject svn commit: r620737 - in /harmony/enhanced/drlvm/trunk: src/test/regression/excludes/ vm/jitrino/src/optimizer/ vm/jitrino/src/shared/
Date Tue, 12 Feb 2008 09:59:36 GMT
Author: mfursov
Date: Tue Feb 12 01:59:31 2008
New Revision: 620737

URL: http://svn.apache.org/viewvc?rev=620737&view=rev
Log:
Fix for HARMONY-4785 [drlvm][jit][opt] EHWA asserts on statprof in server_static mode

Modified:
    harmony/enhanced/drlvm/trunk/src/test/regression/excludes/exclude.linux.x86
    harmony/enhanced/drlvm/trunk/src/test/regression/excludes/exclude.linux.x86_64
    harmony/enhanced/drlvm/trunk/src/test/regression/excludes/exclude.windows.x86
    harmony/enhanced/drlvm/trunk/src/test/regression/excludes/exclude.windows.x86_64
    harmony/enhanced/drlvm/trunk/vm/jitrino/src/optimizer/FlowGraph.cpp
    harmony/enhanced/drlvm/trunk/vm/jitrino/src/optimizer/deadcodeeliminator.cpp
    harmony/enhanced/drlvm/trunk/vm/jitrino/src/optimizer/deadcodeeliminator.h
    harmony/enhanced/drlvm/trunk/vm/jitrino/src/optimizer/hashvaluenumberer.cpp
    harmony/enhanced/drlvm/trunk/vm/jitrino/src/optimizer/optimizer.cpp
    harmony/enhanced/drlvm/trunk/vm/jitrino/src/shared/ControlFlowGraph.cpp
    harmony/enhanced/drlvm/trunk/vm/jitrino/src/shared/ControlFlowGraph.h
    harmony/enhanced/drlvm/trunk/vm/jitrino/src/shared/Dominator.cpp
    harmony/enhanced/drlvm/trunk/vm/jitrino/src/shared/Dominator.h
    harmony/enhanced/drlvm/trunk/vm/jitrino/src/shared/LoopTree.cpp
    harmony/enhanced/drlvm/trunk/vm/jitrino/src/shared/LoopTree.h

Modified: harmony/enhanced/drlvm/trunk/src/test/regression/excludes/exclude.linux.x86
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/src/test/regression/excludes/exclude.linux.x86?rev=620737&r1=620736&r2=620737&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/src/test/regression/excludes/exclude.linux.x86 (original)
+++ harmony/enhanced/drlvm/trunk/src/test/regression/excludes/exclude.linux.x86 Tue Feb 12
01:59:31 2008
@@ -1,2 +1 @@
 # Check corresponding JIRA for details
-H4785

Modified: harmony/enhanced/drlvm/trunk/src/test/regression/excludes/exclude.linux.x86_64
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/src/test/regression/excludes/exclude.linux.x86_64?rev=620737&r1=620736&r2=620737&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/src/test/regression/excludes/exclude.linux.x86_64 (original)
+++ harmony/enhanced/drlvm/trunk/src/test/regression/excludes/exclude.linux.x86_64 Tue Feb
12 01:59:31 2008
@@ -4,5 +4,3 @@
 H4265
 # Test crashes on SOE
 H4292
-# Check corresponding JIRA for details
-H4785

Modified: harmony/enhanced/drlvm/trunk/src/test/regression/excludes/exclude.windows.x86
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/src/test/regression/excludes/exclude.windows.x86?rev=620737&r1=620736&r2=620737&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/src/test/regression/excludes/exclude.windows.x86 (original)
+++ harmony/enhanced/drlvm/trunk/src/test/regression/excludes/exclude.windows.x86 Tue Feb
12 01:59:31 2008
@@ -1,2 +0,0 @@
-# Check corresponding JIRA for details
-H4785

Modified: harmony/enhanced/drlvm/trunk/src/test/regression/excludes/exclude.windows.x86_64
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/src/test/regression/excludes/exclude.windows.x86_64?rev=620737&r1=620736&r2=620737&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/src/test/regression/excludes/exclude.windows.x86_64 (original)
+++ harmony/enhanced/drlvm/trunk/src/test/regression/excludes/exclude.windows.x86_64 Tue Feb
12 01:59:31 2008
@@ -4,5 +4,3 @@
 H4265
 # Test fails without any diagnstics with exit code 128
 H4292
-# Check corresponding JIRA for details
-H4785

Modified: harmony/enhanced/drlvm/trunk/vm/jitrino/src/optimizer/FlowGraph.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/jitrino/src/optimizer/FlowGraph.cpp?rev=620737&r1=620736&r2=620737&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/jitrino/src/optimizer/FlowGraph.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/jitrino/src/optimizer/FlowGraph.cpp Tue Feb 12 01:59:31
2008
@@ -892,92 +892,6 @@
 #endif
 }
 
-static void normalizePseudoThrow(IRManager& irm) {
-//the main idea of the method: 
-//1. normalize loops -> make sure there is only one backedge
-//2. move pseudothrows to the source node of backedge
-
-    OptPass::computeLoops(irm, true);
-    LoopTree* lt = irm.getLoopTree();
-    if (!lt->hasLoops()) {
-        return;
-    }
-    ControlFlowGraph& cfg = irm.getFlowGraph();
-    const Nodes& nodes = cfg.getNodes();
-    MemoryManager tmpMM("normalizePseudoThrow");
-    StlMap<Node*, Node*> loopHeadToDispatchMap(tmpMM);
-    Edges backedges(tmpMM);
-    Edges edgesToRemove(tmpMM);
-    for (Nodes::const_iterator it = nodes.begin(), end = nodes.end(); it!=end; ++it) {
-        Node* node = *it;
-        Node* head = lt->getLoopHeader(node, false);
-        if (head == NULL) {
-            continue;
-        }
-        const Edges& edges = node->getOutEdges();
-        bool isBackedgeSrc = false;
-        for (Edges::const_iterator ite = edges.begin(), ende = edges.end(); ite!=ende; ++ite)
{
-            Edge* e = *ite;
-            if (lt->isBackEdge(e)) {
-                backedges.push_back(e);
-                isBackedgeSrc = true;
-                break;
-            }
-        }
-        Inst* i = (Inst*)node->getLastInst();
-        bool isPseudoThrow = i->getOpcode() == Op_PseudoThrow;
-        if (!isBackedgeSrc && isPseudoThrow) {
-            i->unlink();
-            Edge* exceptionEdge = node->getExceptionEdge();
-            Node* dispatch = exceptionEdge->getTargetNode();
-            while (lt->getLoopHeader(dispatch, false) == head) { //select dispatch that
is out of the loop. Otherwise loop structure will be invalid
-                dispatch = dispatch->getExceptionEdgeTarget();
-                assert(dispatch);
-            }
-            loopHeadToDispatchMap[head] = dispatch;
-            edgesToRemove.push_back(exceptionEdge);
-            if (node == head) {
-                Node* parentHead = lt->getLoopHeader(head, true);
-                if (parentHead && loopHeadToDispatchMap.find(parentHead) == loopHeadToDispatchMap.end())
{
-                    while (lt->getLoopHeader(dispatch, false) == parentHead) {
-                        dispatch = dispatch->getExceptionEdgeTarget();
-                        assert(dispatch);
-                    }
-                    loopHeadToDispatchMap[parentHead] = dispatch;
-                }
-            }
-        }
-    }
-    
-    for (Edges::const_iterator it = edgesToRemove.begin(), end = edgesToRemove.end(); it!=end;
++it) {
-        Edge* e = *it;
-        cfg.removeEdge(e);
-    }
-
-    for (Edges::const_iterator it = backedges.begin(), end = backedges.end(); it!=end; ++it)
{
-        Edge* backedge = *it;
-        Node* node = backedge->getSourceNode();
-        Node* head = backedge->getTargetNode();
-        Inst* i = (Inst*)node->getLastInst();
-        bool isPseudoThrow = i->getOpcode() == Op_PseudoThrow;
-        if (isPseudoThrow || node->isCatchBlock()) {
-            continue;
-        }
-        Node* dispatch = node->getExceptionEdgeTarget();
-        if (!dispatch) {
-            StlMap<Node*, Node*>::const_iterator it2 = loopHeadToDispatchMap.find(head);
-            assert(it2!=loopHeadToDispatchMap.end());
-            dispatch = it2->second;
-        } else {
-            node = cfg.spliceBlockOnEdge(backedge, irm.getInstFactory().makeLabel());
-        }
-        Inst* pi = irm.getInstFactory().makePseudoThrow();
-        pi->setBCOffset(head->getLabelInst()->getBCOffset());
-        node->appendInst(pi);
-        cfg.addEdge(node, dispatch);
-    }
-}
-
 void FlowGraph::doTranslatorCleanupPhase(IRManager& irm) {
     uint32 id = irm.getCompilationContext()->getCurrentSessionNum();
     const char* stage = "trans_cleanup";
@@ -1161,13 +1075,8 @@
     }
     
     // Remove extra PseudoThrow insts
-    if (irm.getOptimizerFlags().rept_aggressive) {
-        DeadCodeEliminator dce(irm);
-        dce.removeExtraPseudoThrow();
-    } else {
-        normalizePseudoThrow(irm);
-    }
-
+    DeadCodeEliminator dce(irm);
+    dce.removeExtraPseudoThrow();
 
     //process all methods marked with @Inline pragma
     if (Log::isLogEnabled(LogStream::IRDUMP)) {

Modified: harmony/enhanced/drlvm/trunk/vm/jitrino/src/optimizer/deadcodeeliminator.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/jitrino/src/optimizer/deadcodeeliminator.cpp?rev=620737&r1=620736&r2=620737&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/jitrino/src/optimizer/deadcodeeliminator.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/jitrino/src/optimizer/deadcodeeliminator.cpp Tue Feb 12
01:59:31 2008
@@ -32,6 +32,8 @@
 #include "optimizer.h"
 #include "XTimer.h"
 #include "PMFAction.h"
+#include "Dominator.h"
+#include "FlowGraph.h"
 
 namespace Jitrino {
 
@@ -44,7 +46,16 @@
 DeadCodeEliminationPass::_run(IRManager& irm){
     DeadCodeEliminator dce(irm);
     {
+        //create loops mapping to be able to fix infinite loops after the optimization
+        MemoryManager tmpMM("HashValueNumberingPass::_run");
+        InfiniteLoopsInfo loopsMapping(tmpMM);
+        DeadCodeEliminator::createLoop2DispatchMapping(irm.getFlowGraph(), loopsMapping);
+
+        //perform optimization
         dce.eliminateDeadCode(false);
+
+        //fix infinite loops if found
+        DeadCodeEliminator::fixInfiniteLoops(irm, loopsMapping);
     }
 }
 
@@ -1191,5 +1202,114 @@
     }
     return;
 }
+
+void DeadCodeEliminator::createLoop2DispatchMapping(ControlFlowGraph& cfg, InfiniteLoopsInfo&
info) {
+    LoopTree* lt = cfg.getLoopTree();
+    if (!lt->isValid()) {
+        lt->rebuild(false, true);
+    }
+    info.hasLoops = lt->hasLoops();
+    if (!info.hasLoops) {
+        return;
+    }
+
+    //algorithm: 
+    //for every loop find ANY node in a loop with dispatch edge that leads out of the loop
+    //add the dispatch node to the mapping. Add nothing if dispatch is unwind
+    //ANY dispatch is suitable to be used for infinite loop, because the point of interruption
of infinite loop is undefined.
+    const Nodes& nodes = cfg.getNodes();
+    for (Nodes::const_iterator it = nodes.begin(), end = nodes.end(); it!=end; ++it) {
+        Node* node = *it;
+        if (lt->getLoopDepth(node) == 0) {
+            continue;
+        }
+        Edge* exceptionEdge = node->getExceptionEdge();
+        if (exceptionEdge == NULL) {
+            continue;
+        }
+        Node* dispatch = exceptionEdge->getTargetNode();
+        Node* loopHead = lt->getLoopHeader(node, false);
+        while (dispatch && lt->getLoopHeader(dispatch, false) == loopHead) {
+            dispatch = dispatch->getExceptionEdgeTarget();
+        }
+        if (dispatch) {
+            info.map[loopHead] = dispatch;
+        }
+    }
+}
+
+void DeadCodeEliminator::fixInfiniteLoops(IRManager& irm, const InfiniteLoopsInfo&
info) {
+    if (!info.hasLoops) {
+        return;
+    }
+    //Find infinite loops and use mapping provided to add pseudoThrows.
+    //To find infinite loops use dominator trees: 
+    //    LoopHead == dominates on incoming edge source. 
+    //    Infinite loop == LoopHead with no paths to Exit node: when Exit node does not postdominate
on LoopHead
+    if (Log::isEnabled()) {
+        Log::out()<<"Performing infinite loops check "<<std::endl;
+    }
+
+    ControlFlowGraph& cfg = irm.getFlowGraph();
+    MemoryManager tmpMM("fixInfiniteLoops");
+    OptPass::computeDominators(irm);
+    DominatorTree* dom = irm.getDominatorTree();
+    DominatorBuilder db;
+    DominatorTree* postDom = db.computeDominators(tmpMM, &cfg, true, true);
+
+    Node* exitNode = cfg.getExitNode();
+    Nodes infiniteLoopHeads(tmpMM);
+
+    //searching for infinite loops
+    Nodes nodes(tmpMM);
+    cfg.getNodes(nodes);
+    for (Nodes::const_iterator it = nodes.begin(), end = nodes.end(); it!=end; ++it) {
+        Node* node = *it;
+        if (postDom->dominates(exitNode, node)) { //the node is reachable from Exit node
+            continue;
+        }
+        //ok, this is dead code or endless loop -> check if this is a loop
+        const Edges& inEdges = node->getInEdges();
+        for (Edges::const_iterator eit = inEdges.begin(), eend = inEdges.end(); eit !=eend;
eit++) {
+            Edge* edge = *eit;
+            Node* srcNode = edge->getSourceNode();
+            if (dom->dominates(node, srcNode)) { //ok, this is loop head
+                infiniteLoopHeads.push_back(node);
+                break;
+            }
+        }
+    }
+    
+    //fixing infinite loops
+    for (Nodes::const_iterator it = infiniteLoopHeads.begin(), end = infiniteLoopHeads.end();
it!=end; ++it) {
+        Node* node = *it;
+        Node* dispatch = NULL;
+        StlMap<Node*, Node*>::const_iterator mit = info.map.find(node);
+        if (mit!=info.map.end()) {
+            dispatch = mit->second;
+        } else {
+            dispatch = cfg.getUnwindNode();
+            if (dispatch == NULL) {
+                dispatch = cfg.createDispatchNode(irm.getInstFactory().makeLabel());
+                cfg.addEdge(dispatch, exitNode);
+                cfg.setUnwindNode(dispatch);
+            }
+        }
+        assert(dispatch!=NULL);
+        cfg.splitNodeAtInstruction(node->getFirstInst(), true, false, irm.getInstFactory().makeLabel());
+        node->appendInst(irm.getInstFactory().makePseudoThrow());
+        cfg.addEdge(node, dispatch);
+        if (Log::isEnabled()) {
+            Log::out() <<"  Found infinite loop: node:";FlowGraph::print(Log::out(),
node); Log::out()<<std::endl;
+            Log::out() <<"      connecting loop to :";FlowGraph::print(Log::out(),
dispatch); Log::out()<<std::endl;
+        }
+    }
+    
+    if (Log::isEnabled()) {
+        Log::out()<<"Infinite loops check finished."<<std::endl;
+    }
+
+}
+
 
 } //namespace Jitrino 

Modified: harmony/enhanced/drlvm/trunk/vm/jitrino/src/optimizer/deadcodeeliminator.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/jitrino/src/optimizer/deadcodeeliminator.h?rev=620737&r1=620736&r2=620737&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/jitrino/src/optimizer/deadcodeeliminator.h (original)
+++ harmony/enhanced/drlvm/trunk/vm/jitrino/src/optimizer/deadcodeeliminator.h Tue Feb 12
01:59:31 2008
@@ -37,6 +37,18 @@
 class Node;
 class BitSet;
 
+///the structure that holds info to fix infinite loops.
+class InfiniteLoopsInfo {
+public:
+    InfiniteLoopsInfo(MemoryManager& mm) : map(mm), hasLoops(false) {}
+    
+    ///loop header to dispatch node mapping
+    StlMap<Node*, Node*> map;
+    
+    ////caches if cfg has loops
+    bool hasLoops;
+};
+
 class DeadCodeEliminator {
 public:
     DeadCodeEliminator(IRManager& irm);
@@ -45,6 +57,13 @@
     static Opnd* copyPropagate(Opnd*);
     bool eliminateUnreachableCode(); // returns true if any node is eliminated
     void removeExtraPseudoThrow();
+    
+    ///creates a mapping of loop-header to dispatch nodes that can be used later to fix infinite
loops
+    static void createLoop2DispatchMapping(ControlFlowGraph& cfg, InfiniteLoopsInfo&
info);
+
+    ///looks for infinite loops in code and adds pseudothrow inst using dispatch node provided
by 'info' 
+    static void fixInfiniteLoops(IRManager& irm, const InfiniteLoopsInfo& info);
+
 private:
     void sweepInst(Node* node, Inst* inst, BitSet& usefulInstSet, BitSet& usefulVarSet,
uint8 *usedInstWidth, uint32 minInstId, uint32 maxInstId, bool canRemoveStvars);
     void sweepInst1(Node* node, Inst* inst, BitSet& usefulInstSet, BitSet& usefulVarSet,

Modified: harmony/enhanced/drlvm/trunk/vm/jitrino/src/optimizer/hashvaluenumberer.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/jitrino/src/optimizer/hashvaluenumberer.cpp?rev=620737&r1=620736&r2=620737&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/jitrino/src/optimizer/hashvaluenumberer.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/jitrino/src/optimizer/hashvaluenumberer.cpp Tue Feb 12
01:59:31 2008
@@ -48,8 +48,18 @@
     computeDominators(irm);
     DominatorTree* dominatorTree = irm.getDominatorTree();
     assert(dominatorTree && dominatorTree->isValid());
+
+    //create loops mapping to be able to fix infinite loops after the optimization
+    MemoryManager tmpMM("HashValueNumberingPass::_run");
+    InfiniteLoopsInfo loopsMapping(tmpMM);
+    DeadCodeEliminator::createLoop2DispatchMapping(irm.getFlowGraph(), loopsMapping);
+
+    //do the optimizations
     HashValueNumberer valueNumberer(irm, *dominatorTree);
     valueNumberer.doValueNumbering();
+
+    //fix infinite loops if found
+    DeadCodeEliminator::fixInfiniteLoops(irm, loopsMapping);
 }
 
 class SparseCseMap : public SparseScopedMap<CSEHashKey, Inst *> {

Modified: harmony/enhanced/drlvm/trunk/vm/jitrino/src/optimizer/optimizer.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/jitrino/src/optimizer/optimizer.cpp?rev=620737&r1=620736&r2=620737&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/jitrino/src/optimizer/optimizer.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/jitrino/src/optimizer/optimizer.cpp Tue Feb 12 01:59:31
2008
@@ -176,8 +176,6 @@
     //classic_abcd
     optimizerFlags.dump_abcd_stats = getBoolArg("dump_abcd_stats", false);
 
-    optimizerFlags.rept_aggressive= getBoolArg("rept_aggressive", true);
-
     optimizerFlags.abcdFlags = new (mm) AbcdFlags;
     memset(optimizerFlags.abcdFlags, sizeof(AbcdFlags), 0);
 

Modified: harmony/enhanced/drlvm/trunk/vm/jitrino/src/shared/ControlFlowGraph.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/jitrino/src/shared/ControlFlowGraph.cpp?rev=620737&r1=620736&r2=620737&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/jitrino/src/shared/ControlFlowGraph.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/jitrino/src/shared/ControlFlowGraph.cpp Tue Feb 12 01:59:31
2008
@@ -442,12 +442,12 @@
 
 // this utility splits a node at a particular instruction, leaving the instruction in the
 // same node and moving all insts (before inst : splitAfter=false/after inst : splitAfter=true

-// to the newly created note
+// to the newly created node
 // returns the new node created
 Node* ControlFlowGraph::splitNodeAtInstruction(CFGInst *inst, bool splitAfter, bool keepDispatch,
CFGInst* labelInst) {
     Node *node = inst->getNode();
     Node* dispatchNode = keepDispatch ? node->getExceptionEdgeTarget() : NULL;
-    Node* newNode =  splitNode(node, splitAfter, labelInst);
+    Node* newNode =  splitNode(node, true, labelInst);
     if (inst == node->getLastInst()) {
         assert(!splitAfter || (node->getOutDegree() == 1 && node->getUnconditionalEdge()!=NULL)
             || (node->getOutDegree()==2 && node->getExceptionEdgeTarget()!=NULL));
@@ -827,11 +827,11 @@
     assert(node->isBlockNode());
     Node* newNode = createBlockNode(inst);
     if(newBlockAtEnd) {
-        // move edges
+        // move out edges
         moveOutEdges(node, newNode);
         addEdge(node, newNode);
     } else { // new block at beginning
-        // move edges
+        // move in edges
         moveInEdges(node, newNode);
         addEdge(newNode, node);
     }

Modified: harmony/enhanced/drlvm/trunk/vm/jitrino/src/shared/ControlFlowGraph.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/jitrino/src/shared/ControlFlowGraph.h?rev=620737&r1=620736&r2=620737&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/jitrino/src/shared/ControlFlowGraph.h (original)
+++ harmony/enhanced/drlvm/trunk/vm/jitrino/src/shared/ControlFlowGraph.h Tue Feb 12 01:59:31
2008
@@ -1707,6 +1707,10 @@
         assert(currentPreNumber == currentPostNumber);
         if (isForward) {
             nodeCount = currentPreNumber;
+        } else {
+            // getNodesDFS changes traversalNum for nodes. But traversalNum assumes direct
traversal.
+            // so drop the ordering number here to force CFG recompute ordering before using
node->traversalNum values again
+            lastOrderingTraversalNumber = lastModifiedTraversalNumber-1;
         }
     }
     
@@ -1798,9 +1802,9 @@
     /// The given field is assigned to the <code>traversalNumber</code> value
every time the profile information is recalculated.
     uint32 lastProfileUpdateTraversalNumber;
 
-    /// The temporaty field used by ordering algorithms.
+    /// The temporary field used by ordering algorithms.
     uint32 currentPreNumber;
-    /// The temporaty field used by ordering algorithms.
+    /// The temporary field used by ordering algorithms.
     uint32 currentPostNumber;
 
     /// Tells whether the graph is annotated with the edge profile.

Modified: harmony/enhanced/drlvm/trunk/vm/jitrino/src/shared/Dominator.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/jitrino/src/shared/Dominator.cpp?rev=620737&r1=620736&r2=620737&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/jitrino/src/shared/Dominator.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/jitrino/src/shared/Dominator.cpp Tue Feb 12 01:59:31 2008
@@ -155,7 +155,12 @@
 bool DominatorTree::dominates(Node* a, Node* b) {
     assert(a != NULL && b != NULL);
     assert(a->getId() < numNodes && b->getId() < numNodes);
-    return a==b || isAncestor(tree[a->getId()], tree[b->getId()]);
+    DominatorNode* na = tree[a->getId()];
+    DominatorNode* nb = tree[b->getId()];
+    if (na == NULL || nb == NULL) {
+        return false;
+    }
+    return a==b || isAncestor(na, nb);
 }
 
 

Modified: harmony/enhanced/drlvm/trunk/vm/jitrino/src/shared/Dominator.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/jitrino/src/shared/Dominator.h?rev=620737&r1=620736&r2=620737&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/jitrino/src/shared/Dominator.h (original)
+++ harmony/enhanced/drlvm/trunk/vm/jitrino/src/shared/Dominator.h Tue Feb 12 01:59:31 2008
@@ -70,8 +70,12 @@
 
     // Returns the immediate (post)dominator of n.  Return NULL if no nodes (post)dominate
n.
     Node* getIdom(Node* n)    {
-        DominatorNode* idom = getDominatorNode(n)->getParent();
-        return (idom == NULL) ? NULL : idom->getNode();
+        DominatorNode* ndom = getDominatorNode(n);
+        if (ndom == NULL) { //unreachable node -> have no dominator info
+            return NULL;
+        }
+        DominatorNode* pdom = ndom->getParent();
+        return (pdom == NULL) ? NULL : pdom->getNode();
     }
 
     // Returns the dominator tree node associated with this CFG node.

Modified: harmony/enhanced/drlvm/trunk/vm/jitrino/src/shared/LoopTree.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/jitrino/src/shared/LoopTree.cpp?rev=620737&r1=620736&r2=620737&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/jitrino/src/shared/LoopTree.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/jitrino/src/shared/LoopTree.cpp Tue Feb 12 01:59:31 2008
@@ -142,27 +142,26 @@
      child = NULL;
 }
 
-void LoopNode::backwardMarkNode(Node* node) {
-    if(node->getTraversalNum() > loopTree->fg->getTraversalNum()) {
+void LoopNode::backwardMarkNode(Node* node, DominatorTree* dom) {
+    if (node->getTraversalNum() > loopTree->fg->getTraversalNum()) {
         return;
     }
 
-    markNode(node);
+    assert(node->getTraversalNum() == loopTree->fg->getTraversalNum());
+    loopTree->headerMap[node->getDfNum()] = this;
+    nodesInLoop.push_back(node);
+    node->setTraversalNum(node->getTraversalNum()+1);
 
     const Edges& inEdges = node->getInEdges();
     for(Edges::const_iterator eiter = inEdges.begin(); eiter != inEdges.end(); ++eiter) {
         Edge* e = *eiter;
-        backwardMarkNode(e->getSourceNode());
+        Node* srcNode = e->getSourceNode();
+        if (dom->dominates(header, srcNode)) {
+            backwardMarkNode(srcNode, dom);
+        }
     }
 }
 
-void LoopNode::markNode(Node* node) {
-    assert(node->getTraversalNum() == loopTree->fg->getTraversalNum());
-    loopTree->headerMap[node->getDfNum()] = this;
-    nodesInLoop.push_back(node);
-    node->setTraversalNum(node->getTraversalNum()+1);
-}
-
 // 
 // traverse graph backward starting from tail until header is reached
 //
@@ -170,16 +169,10 @@
     DominatorTree* dom = loopTree->fg->getDominatorTree();
     assert(dom->isValid());
 
-    markNode(header);
-    // starting backward traversal
-    const Edges& inEdges = header->getInEdges();
-    for (Edges::const_iterator ite = inEdges.begin(), ende = inEdges.end(); ite!=ende; ++ite)
{
-        Edge* edge = *ite;
-        Node* tail = edge->getSourceNode();
-        if (dom->dominates(header, tail)) {
-              backwardMarkNode(tail);          
-        }
-    }
+    assert(header->getTraversalNum() == loopTree->fg->getTraversalNum()); 
+    backwardMarkNode(header, dom);
+    
+    //restore traversal nums
     uint32 fgTraversalNum = loopTree->fg->getTraversalNum();
     for (Nodes::const_iterator it = nodesInLoop.begin(), end = nodesInLoop.end(); it!=end;
++it) {
         Node* node = *it;
@@ -228,19 +221,21 @@
 
 
 
-void LoopTree::rebuild(bool doNormalization) {
+void LoopTree::rebuild(bool doNormalization, bool ignoreUnreachable) {
     if (isValid() && (!doNormalization || normalized)) {
         return;
     }
+    assert(!(ignoreUnreachable && doNormalization)); //incompatible modes.
+
     normalized = false;
 
     DominatorTree* dom = fg->getDominatorTree();
     if ( dom==NULL || !dom->isValid()) {
         DominatorBuilder db;
-        dom = db.computeDominators(mm, fg, false, false);
+        dom = db.computeDominators(mm, fg, false, ignoreUnreachable);
         fg->setDominatorTree(dom);
     }
-    
+
     headers.clear();
     findLoopHeaders(headers);
 
@@ -255,9 +250,9 @@
     }
 
     if (isValid()) {
-        return; // double check after normalization
+        return; // double check after normalization -> if already normalized and valid
-> return
     }
-    
+
     //cleanup
     headerMap.clear();
     ((LoopNode*)root)->clear();
@@ -266,9 +261,9 @@
     headerMap.resize(numBlocks); 
 
     formLoopHierarchy(headers);
-    
+
     computeOrder(); // compute pre/post nums for loop nodes
-    
+
     traversalNum = fg->getTraversalNum();
 }
 
@@ -281,7 +276,11 @@
 
 LoopNode* LoopTree::getLoopNode(const Node* node, bool containingLoop) const {
     assert(isValid());
-    LoopNode* loop = headerMap[node->getDfNum()];
+    uint32 df = node->getDfNum();
+    if (df >= headerMap.size()) {
+        return NULL; //invalid DF can be caused by unreachable node
+    }
+    LoopNode* loop = headerMap[df];
     if (loop == NULL) {
         return NULL;
     }

Modified: harmony/enhanced/drlvm/trunk/vm/jitrino/src/shared/LoopTree.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/jitrino/src/shared/LoopTree.h?rev=620737&r1=620736&r2=620737&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/jitrino/src/shared/LoopTree.h (original)
+++ harmony/enhanced/drlvm/trunk/vm/jitrino/src/shared/LoopTree.h Tue Feb 12 01:59:31 2008
@@ -63,8 +63,7 @@
     LoopNode(MemoryManager& mm, LoopTree* lt, Node* hd)  : loopTree(lt), header(hd),
nodesInLoop(mm){}
 
     void markNodesOfLoop();
-    void markNode(Node* node);
-    void backwardMarkNode(Node* currentTail);
+    void backwardMarkNode(Node* currentTail, DominatorTree* dom);
     void clear();
 
     LoopTree* loopTree;
@@ -80,7 +79,7 @@
     LoopTree(MemoryManager& mm, ControlFlowGraph* f, EdgeCoalescerCallback* coalesceCallback
= NULL); 
 
     // rebuilds loop tree if needed.
-    void rebuild(bool doNormalization);
+    void rebuild(bool doNormalization, bool ignoreUnreachable = false);
 
     bool hasLoops() const { assert(isValid()); return ((LoopNode*)root)->getChild()!=NULL;}
//root node is artificial
 



Mime
View raw message