Fri, 29 Apr 2016 00:06:10 +0800
Added MIPS 64-bit port.
1 /*
2 * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
25 /*
26 * This file has been modified by Loongson Technology in 2015. These
27 * modifications are Copyright (c) 2015 Loongson Technology, and are made
28 * available on the same license terms set forth above.
29 */
31 #ifndef SHARE_VM_OPTO_OUTPUT_HPP
32 #define SHARE_VM_OPTO_OUTPUT_HPP
34 #include "opto/block.hpp"
35 #include "opto/node.hpp"
36 #ifdef TARGET_ARCH_MODEL_x86_32
37 # include "adfiles/ad_x86_32.hpp"
38 #endif
39 #ifdef TARGET_ARCH_MODEL_x86_64
40 # include "adfiles/ad_x86_64.hpp"
41 #endif
42 #ifdef TARGET_ARCH_MODEL_mips_64
43 # include "adfiles/ad_mips_64.hpp"
44 #endif
45 #ifdef TARGET_ARCH_MODEL_sparc
46 # include "adfiles/ad_sparc.hpp"
47 #endif
48 #ifdef TARGET_ARCH_MODEL_zero
49 # include "adfiles/ad_zero.hpp"
50 #endif
51 #ifdef TARGET_ARCH_MODEL_arm
52 # include "adfiles/ad_arm.hpp"
53 #endif
54 #ifdef TARGET_ARCH_MODEL_ppc_32
55 # include "adfiles/ad_ppc_32.hpp"
56 #endif
57 #ifdef TARGET_ARCH_MODEL_ppc_64
58 # include "adfiles/ad_ppc_64.hpp"
59 #endif
61 class Arena;
62 class Bundle;
63 class Block;
64 class Block_Array;
65 class Node;
66 class Node_Array;
67 class Node_List;
68 class PhaseCFG;
69 class PhaseChaitin;
70 class Pipeline_Use_Element;
71 class Pipeline_Use;
73 #ifndef PRODUCT
74 #define DEBUG_ARG(x) , x
75 #else
76 #define DEBUG_ARG(x)
77 #endif
79 // Define the initial sizes for allocation of the resizable code buffer
80 enum {
81 initial_code_capacity = 16 * 1024,
82 initial_stub_capacity = 4 * 1024,
83 initial_const_capacity = 4 * 1024,
84 initial_locs_capacity = 3 * 1024
85 };
87 //------------------------------Scheduling----------------------------------
88 // This class contains all the information necessary to implement instruction
89 // scheduling and bundling.
90 class Scheduling {
92 private:
93 // Arena to use
94 Arena *_arena;
96 // Control-Flow Graph info
97 PhaseCFG *_cfg;
99 // Register Allocation info
100 PhaseRegAlloc *_regalloc;
102 // Number of nodes in the method
103 uint _node_bundling_limit;
105 // List of scheduled nodes. Generated in reverse order
106 Node_List _scheduled;
108 // List of nodes currently available for choosing for scheduling
109 Node_List _available;
111 // For each instruction beginning a bundle, the number of following
112 // nodes to be bundled with it.
113 Bundle *_node_bundling_base;
115 // Mapping from register to Node
116 Node_List _reg_node;
118 // Free list for pinch nodes.
119 Node_List _pinch_free_list;
121 // Latency from the beginning of the containing basic block (base 1)
122 // for each node.
123 unsigned short *_node_latency;
125 // Number of uses of this node within the containing basic block.
126 short *_uses;
128 // Schedulable portion of current block. Skips Region/Phi/CreateEx up
129 // front, branch+proj at end. Also skips Catch/CProj (same as
130 // branch-at-end), plus just-prior exception-throwing call.
131 uint _bb_start, _bb_end;
133 // Latency from the end of the basic block as scheduled
134 unsigned short *_current_latency;
136 // Remember the next node
137 Node *_next_node;
139 // Use this for an unconditional branch delay slot
140 Node *_unconditional_delay_slot;
142 // Pointer to a Nop
143 MachNopNode *_nop;
145 // Length of the current bundle, in instructions
146 uint _bundle_instr_count;
148 // Current Cycle number, for computing latencies and bundling
149 uint _bundle_cycle_number;
151 // Bundle information
152 Pipeline_Use_Element _bundle_use_elements[resource_count];
153 Pipeline_Use _bundle_use;
155 // Dump the available list
156 void dump_available() const;
158 public:
159 Scheduling(Arena *arena, Compile &compile);
161 // Destructor
162 NOT_PRODUCT( ~Scheduling(); )
164 // Step ahead "i" cycles
165 void step(uint i);
167 // Step ahead 1 cycle, and clear the bundle state (for example,
168 // at a branch target)
169 void step_and_clear();
171 Bundle* node_bundling(const Node *n) {
172 assert(valid_bundle_info(n), "oob");
173 return (&_node_bundling_base[n->_idx]);
174 }
176 bool valid_bundle_info(const Node *n) const {
177 return (_node_bundling_limit > n->_idx);
178 }
180 bool starts_bundle(const Node *n) const {
181 return (_node_bundling_limit > n->_idx && _node_bundling_base[n->_idx].starts_bundle());
182 }
184 // Do the scheduling
185 void DoScheduling();
187 // Compute the local latencies walking forward over the list of
188 // nodes for a basic block
189 void ComputeLocalLatenciesForward(const Block *bb);
191 // Compute the register antidependencies within a basic block
192 void ComputeRegisterAntidependencies(Block *bb);
193 void verify_do_def( Node *n, OptoReg::Name def, const char *msg );
194 void verify_good_schedule( Block *b, const char *msg );
195 void anti_do_def( Block *b, Node *def, OptoReg::Name def_reg, int is_def );
196 void anti_do_use( Block *b, Node *use, OptoReg::Name use_reg );
198 // Add a node to the current bundle
199 void AddNodeToBundle(Node *n, const Block *bb);
201 // Add a node to the list of available nodes
202 void AddNodeToAvailableList(Node *n);
204 // Compute the local use count for the nodes in a block, and compute
205 // the list of instructions with no uses in the block as available
206 void ComputeUseCount(const Block *bb);
208 // Choose an instruction from the available list to add to the bundle
209 Node * ChooseNodeToBundle();
211 // See if this Node fits into the currently accumulating bundle
212 bool NodeFitsInBundle(Node *n);
214 // Decrement the use count for a node
215 void DecrementUseCounts(Node *n, const Block *bb);
217 // Garbage collect pinch nodes for reuse by other blocks.
218 void garbage_collect_pinch_nodes();
219 // Clean up a pinch node for reuse (helper for above).
220 void cleanup_pinch( Node *pinch );
222 // Information for statistics gathering
223 #ifndef PRODUCT
224 private:
225 // Gather information on size of nops relative to total
226 uint _branches, _unconditional_delays;
228 static uint _total_nop_size, _total_method_size;
229 static uint _total_branches, _total_unconditional_delays;
230 static uint _total_instructions_per_bundle[Pipeline::_max_instrs_per_cycle+1];
232 public:
233 static void print_statistics();
235 static void increment_instructions_per_bundle(uint i) {
236 _total_instructions_per_bundle[i]++;
237 }
239 static void increment_nop_size(uint s) {
240 _total_nop_size += s;
241 }
243 static void increment_method_size(uint s) {
244 _total_method_size += s;
245 }
246 #endif
248 };
250 #endif // SHARE_VM_OPTO_OUTPUT_HPP