43 void findLoopBackEdges(
jitdata* jd);
47 void buildLoopTree(
jitdata* jd);
48 void storeLoopsInHeaders(
jitdata* jd);
50 void sortLoopsInBasicblocks(
jitdata* jd);
68 log_text(
"----- Basic Blocks -----");
71 std::stringstream
str;
88 for (
s4 i = 0;
i < bb->successorcount;
i++)
90 str << bb->successors[
i]->nr <<
" ";
97 log_text(
"------ Dominators ------");
100 std::stringstream
str;
101 str << bb->nr <<
" --> ";
103 str << bb->ld->dom->nr;
114 log_text(
"------ Dominator Tree ------");
115 printDominatorTree(jd->ld->root, 0);
119 for (
size_t i = 0;
i < jd->ld->loops.size();
i++)
122 std::stringstream
str;
124 for (
size_t j = 0; j < loop->
nodes.size(); j++)
126 str <<
" " << loop->
nodes[j]->nr;
143 log_text(
"------ Loop Tree ------");
144 printLoopTree(jd->ld->rootLoop, 0);
146 log_text(
"------------------------");
149 void printDominatorTree(
basicblock* block,
int level)
151 std::stringstream
str;
154 for (
int i = 0;
i < level;
i++)
157 for (
int j = 0; j <
INDENT - 1; j++)
168 for (
size_t i = 0;
i < block->ld->children.size();
i++)
170 printDominatorTree(block->ld->children[
i], level + 1);
176 std::stringstream
str;
179 for (
int i = 0;
i < level;
i++)
182 for (
int j = 0; j <
INDENT - 1; j++)
198 printLoopTree(loop->
children[
i], level + 1);
202 void findLoopBackEdges(
jitdata* jd)
205 for (std::vector<Edge>::const_iterator edge = jd->ld->depthBackEdges.begin(); edge != jd->ld->depthBackEdges.end(); ++edge)
212 if (ancestor == edge->to)
214 jd->ld->loopBackEdges.push_back(*edge);
219 ancestor = ancestor->ld->dom;
230 for (std::vector<Edge>::const_iterator edge = jd->ld->loopBackEdges.begin(); edge != jd->ld->loopBackEdges.end(); ++edge)
238 jd->ld->loops.push_back(loop);
244 head->ld->loops.insert(loop);
247 reverseDepthFirstTraversal(foot, loop);
253 if (next->ld->visited == loop)
259 loop->
nodes.push_back(next);
262 next->ld->loops.insert(loop);
265 next->ld->visited =
loop;
280 std::sort(jd->ld->loops.begin(), jd->ld->loops.end(), &compareLoopHeaders);
283 for (
size_t i = 1;
i < jd->ld->loops.size();
i++)
291 assert(second->
footers.size() == 1);
295 for (std::vector<basicblock*>::const_iterator it2 = second->
nodes.begin(); it2 != second->
nodes.end(); ++it2)
300 if (find(first->
nodes.begin(), first->
nodes.end(), node) == first->
nodes.end())
302 first->
nodes.push_back(node);
306 node->ld->loops.erase(second);
307 node->ld->loops.insert(first);
311 first->
header->ld->loops.erase(second);
315 jd->ld->loops.erase(jd->ld->loops.begin() +
i);
324 void buildLoopTree(
jitdata* jd)
326 std::queue<LoopContainer*> successors;
330 for (std::vector<LoopContainer*>::const_iterator it = jd->ld->loops.begin(); it != jd->ld->loops.end(); ++it)
332 (*it)->
parent = jd->ld->rootLoop;
333 successors.push(*it);
337 while (!successors.empty())
343 for (std::vector<LoopContainer*>::const_iterator it = jd->ld->loops.begin(); it != jd->ld->loops.end(); ++it)
348 for (std::vector<basicblock*>::const_iterator nodeIt = current->
nodes.begin(); nodeIt != current->
nodes.end(); ++nodeIt)
353 if (candidate->
header == *nodeIt)
361 successors.push(candidate);
369 for (std::vector<LoopContainer*>::const_iterator it = jd->ld->loops.begin(); it != jd->ld->loops.end(); ++it)
377 void storeLoopsInHeaders(
jitdata* jd)
379 for (std::vector<LoopContainer*>::const_iterator it = jd->ld->loops.begin(); it != jd->ld->loops.end(); ++it)
381 (*it)->header->ld->loop = (*it);
388 for (std::vector<LoopContainer*>::iterator childIt = loop->
children.begin(); childIt != loop->
children.end(); ++childIt)
390 computeLoopDepth(*childIt, depth + 1);
394 void sortLoopsInBasicblocks(
jitdata* jd)
398 block->ld->loops.sort();
412 findLoopBackEdges(jd);
416 storeLoopsInHeaders(jd);
417 computeLoopDepth(jd->ld->rootLoop, 0);
418 sortLoopsInBasicblocks(jd);
VariableSet writtenVariables
void removePartiallyRedundantChecks(jitdata *jd)
Represents a single loop.
VariableSet invariantVariables
void printBasicBlocks(jitdata *)
void findLeaves(jitdata *jd)
Marks all basicblocks which are leaves.
void analyzeLoops(jitdata *jd)
Analyzes all loops and for every loop it finds.
void createRoot(jitdata *jd)
MachineBasicBlock * current
jlong jlong jlong jlong jint depth
basicblock ** predecessors
void buildDominatorTree(jitdata *jd)
Uses the immediate dominators to build a dominator tree which can be traversed from the root to the l...
std::vector< basicblock * > footers
void removeFullyRedundantChecks(jitdata *jd)
Removes all array bound checks that are fully redundant.
bool findFreeVariable(jitdata *jd)
void removeArrayBoundChecks(jitdata *jd)
std::vector< basicblock * > nodes
struct LoopContainer LoopContainer
static java_object_t * next
std::vector< LoopContainer * > children
void groupArrayBoundsChecks(jitdata *jd)
void calculateDominators(jitdata *jd)
Calculates the immediate dominators of all basicblocks.