equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
43 // Map dense integer indices to Blocks. Uses classic doubling-array trick. |
43 // Map dense integer indices to Blocks. Uses classic doubling-array trick. |
44 // Abstractly provides an infinite array of Block*'s, initialized to NULL. |
44 // Abstractly provides an infinite array of Block*'s, initialized to NULL. |
45 // Note that the constructor just zeros things, and since I use Arena |
45 // Note that the constructor just zeros things, and since I use Arena |
46 // allocation I do not need a destructor to reclaim storage. |
46 // allocation I do not need a destructor to reclaim storage. |
47 class Block_Array : public ResourceObj { |
47 class Block_Array : public ResourceObj { |
|
48 friend class VMStructs; |
48 uint _size; // allocated size, as opposed to formal limit |
49 uint _size; // allocated size, as opposed to formal limit |
49 debug_only(uint _limit;) // limit to formal domain |
50 debug_only(uint _limit;) // limit to formal domain |
50 protected: |
51 protected: |
51 Block **_blocks; |
52 Block **_blocks; |
52 void grow( uint i ); // Grow array node to fit |
53 void grow( uint i ); // Grow array node to fit |
70 uint Max() const { debug_only(return _limit); return _size; } |
71 uint Max() const { debug_only(return _limit); return _size; } |
71 }; |
72 }; |
72 |
73 |
73 |
74 |
74 class Block_List : public Block_Array { |
75 class Block_List : public Block_Array { |
|
76 friend class VMStructs; |
75 public: |
77 public: |
76 uint _cnt; |
78 uint _cnt; |
77 Block_List() : Block_Array(Thread::current()->resource_area()), _cnt(0) {} |
79 Block_List() : Block_Array(Thread::current()->resource_area()), _cnt(0) {} |
78 void push( Block *b ) { map(_cnt++,b); } |
80 void push( Block *b ) { map(_cnt++,b); } |
79 Block *pop() { return _blocks[--_cnt]; } |
81 Block *pop() { return _blocks[--_cnt]; } |
85 void print(); |
87 void print(); |
86 }; |
88 }; |
87 |
89 |
88 |
90 |
89 class CFGElement : public ResourceObj { |
91 class CFGElement : public ResourceObj { |
|
92 friend class VMStructs; |
90 public: |
93 public: |
91 float _freq; // Execution frequency (estimate) |
94 float _freq; // Execution frequency (estimate) |
92 |
95 |
93 CFGElement() : _freq(0.0f) {} |
96 CFGElement() : _freq(0.0f) {} |
94 virtual bool is_block() { return false; } |
97 virtual bool is_block() { return false; } |
100 //------------------------------Block------------------------------------------ |
103 //------------------------------Block------------------------------------------ |
101 // This class defines a Basic Block. |
104 // This class defines a Basic Block. |
102 // Basic blocks are used during the output routines, and are not used during |
105 // Basic blocks are used during the output routines, and are not used during |
103 // any optimization pass. They are created late in the game. |
106 // any optimization pass. They are created late in the game. |
104 class Block : public CFGElement { |
107 class Block : public CFGElement { |
|
108 friend class VMStructs; |
105 public: |
109 public: |
106 // Nodes in this block, in order |
110 // Nodes in this block, in order |
107 Node_List _nodes; |
111 Node_List _nodes; |
108 |
112 |
109 // Basic blocks have a Node which defines Control for all Nodes pinned in |
113 // Basic blocks have a Node which defines Control for all Nodes pinned in |
339 |
343 |
340 |
344 |
341 //------------------------------PhaseCFG--------------------------------------- |
345 //------------------------------PhaseCFG--------------------------------------- |
342 // Build an array of Basic Block pointers, one per Node. |
346 // Build an array of Basic Block pointers, one per Node. |
343 class PhaseCFG : public Phase { |
347 class PhaseCFG : public Phase { |
|
348 friend class VMStructs; |
344 private: |
349 private: |
345 // Build a proper looking cfg. Return count of basic blocks |
350 // Build a proper looking cfg. Return count of basic blocks |
346 uint build_cfg(); |
351 uint build_cfg(); |
347 |
352 |
348 // Perform DFS search. |
353 // Perform DFS search. |
513 float get_prob() const { return _prob; } |
518 float get_prob() const { return _prob; } |
514 }; |
519 }; |
515 |
520 |
516 //------------------------------CFGLoop------------------------------------------- |
521 //------------------------------CFGLoop------------------------------------------- |
517 class CFGLoop : public CFGElement { |
522 class CFGLoop : public CFGElement { |
|
523 friend class VMStructs; |
518 int _id; |
524 int _id; |
519 int _depth; |
525 int _depth; |
520 CFGLoop *_parent; // root of loop tree is the method level "pseudo" loop, it's parent is null |
526 CFGLoop *_parent; // root of loop tree is the method level "pseudo" loop, it's parent is null |
521 CFGLoop *_sibling; // null terminated list |
527 CFGLoop *_sibling; // null terminated list |
522 CFGLoop *_child; // first child, use child's sibling to visit all immediately nested loops |
528 CFGLoop *_child; // first child, use child's sibling to visit all immediately nested loops |
564 |
570 |
565 //----------------------------------CFGEdge------------------------------------ |
571 //----------------------------------CFGEdge------------------------------------ |
566 // A edge between two basic blocks that will be embodied by a branch or a |
572 // A edge between two basic blocks that will be embodied by a branch or a |
567 // fall-through. |
573 // fall-through. |
568 class CFGEdge : public ResourceObj { |
574 class CFGEdge : public ResourceObj { |
|
575 friend class VMStructs; |
569 private: |
576 private: |
570 Block * _from; // Source basic block |
577 Block * _from; // Source basic block |
571 Block * _to; // Destination basic block |
578 Block * _to; // Destination basic block |
572 float _freq; // Execution frequency (estimate) |
579 float _freq; // Execution frequency (estimate) |
573 int _state; |
580 int _state; |
700 }; |
707 }; |
701 |
708 |
702 //------------------------------PhaseBlockLayout------------------------------- |
709 //------------------------------PhaseBlockLayout------------------------------- |
703 // Rearrange blocks into some canonical order, based on edges and their frequencies |
710 // Rearrange blocks into some canonical order, based on edges and their frequencies |
704 class PhaseBlockLayout : public Phase { |
711 class PhaseBlockLayout : public Phase { |
|
712 friend class VMStructs; |
705 PhaseCFG &_cfg; // Control flow graph |
713 PhaseCFG &_cfg; // Control flow graph |
706 |
714 |
707 GrowableArray<CFGEdge *> *edges; |
715 GrowableArray<CFGEdge *> *edges; |
708 Trace **traces; |
716 Trace **traces; |
709 Block **next; |
717 Block **next; |