45 // helper macro for short definition of timer
46 #define TIME_LINEAR_SCAN(timer_name) TraceTime _block_timer("", _total_timer.timer(LinearScanTimers::timer_name), TimeLinearScan || TimeEachLinearScan, Verbose);
47
48 #else
49 #define TIME_LINEAR_SCAN(timer_name)
50 #endif
51
52 #ifdef ASSERT
53
54 // helper macro for short definition of trace-output inside code
55 #define TRACE_LINEAR_SCAN(level, code) \
56 if (TraceLinearScanLevel >= level) { \
57 code; \
58 }
59 #else
60 #define TRACE_LINEAR_SCAN(level, code)
61 #endif
62
63 // Map BasicType to spill size in 32-bit words, matching VMReg's notion of words
64 #ifdef _LP64
65 static int type2spill_size[T_CONFLICT+1]={ -1, 0, 0, 0, 1, 1, 1, 2, 1, 1, 1, 2, 2, 2, 0, 2, 1, 2, 1, -1};
66 #else
67 static int type2spill_size[T_CONFLICT+1]={ -1, 0, 0, 0, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 0, 1, -1, 1, 1, -1};
68 #endif
69
70
71 // Implementation of LinearScan
72
73 LinearScan::LinearScan(IR* ir, LIRGenerator* gen, FrameMap* frame_map)
74 : _compilation(ir->compilation())
75 , _ir(ir)
76 , _gen(gen)
77 , _frame_map(frame_map)
78 , _cached_blocks(*ir->linear_scan_order())
79 , _num_virtual_regs(gen->max_virtual_register_number())
80 , _has_fpu_registers(false)
81 , _num_calls(-1)
82 , _max_spills(0)
83 , _unused_spill_slot(-1)
84 , _intervals(0) // initialized later with correct length
85 , _new_intervals_from_allocation(nullptr)
86 , _sorted_intervals(nullptr)
87 , _needs_full_resort(false)
242 if (result > 2000) {
243 bailout("too many stack slots used");
244 }
245
246 return result;
247 }
248
249 void LinearScan::assign_spill_slot(Interval* it) {
250 // assign the canonical spill slot of the parent (if a part of the interval
251 // is already spilled) or allocate a new spill slot
252 if (it->canonical_spill_slot() >= 0) {
253 it->assign_reg(it->canonical_spill_slot());
254 } else {
255 int spill = allocate_spill_slot(type2spill_size[it->type()] == 2);
256 it->set_canonical_spill_slot(spill);
257 it->assign_reg(spill);
258 }
259 }
260
261 void LinearScan::propagate_spill_slots() {
262 if (!frame_map()->finalize_frame(max_spills())) {
263 bailout("frame too large");
264 }
265 }
266
267 // create a new interval with a predefined reg_num
268 // (only used for parent intervals that are created during the building phase)
269 Interval* LinearScan::create_interval(int reg_num) {
270 assert(_intervals.at(reg_num) == nullptr, "overwriting existing interval");
271
272 Interval* interval = new Interval(reg_num);
273 _intervals.at_put(reg_num, interval);
274
275 // assign register number for precolored intervals
276 if (reg_num < LIR_Opr::vreg_base) {
277 interval->assign_reg(reg_num);
278 }
279 return interval;
280 }
281
282 // assign a new reg_num to the interval and append it to the list of intervals
2933 int pos = 0;
2934 while (pos < nof_stack) {
2935 Value expression = cur_state->stack_at(pos);
2936 pos += append_scope_value(op_id, expression, expressions);
2937
2938 assert(expressions->length() == pos, "must match");
2939 }
2940 assert(expressions->length() == cur_state->stack_size(), "wrong number of stack entries");
2941 }
2942
2943 // describe monitors
2944 int nof_locks = cur_state->locks_size();
2945 if (nof_locks > 0) {
2946 int lock_offset = cur_state->caller_state() != nullptr ? cur_state->caller_state()->total_locks_size() : 0;
2947 monitors = new GrowableArray<MonitorValue*>(nof_locks);
2948 for (int i = 0; i < nof_locks; i++) {
2949 monitors->append(location_for_monitor_index(lock_offset + i));
2950 }
2951 }
2952
2953 return new IRScopeDebugInfo(cur_scope, cur_state->bci(), locals, expressions, monitors, caller_debug_info);
2954 }
2955
2956
2957 void LinearScan::compute_debug_info(CodeEmitInfo* info, int op_id) {
2958 TRACE_LINEAR_SCAN(3, tty->print_cr("creating debug information at op_id %d", op_id));
2959
2960 IRScope* innermost_scope = info->scope();
2961 ValueStack* innermost_state = info->stack();
2962
2963 assert(innermost_scope != nullptr && innermost_state != nullptr, "why is it missing?");
2964
2965 DEBUG_ONLY(check_stack_depth(info, innermost_state->stack_size()));
2966
2967 if (info->_scope_debug_info == nullptr) {
2968 // compute debug information
2969 info->_scope_debug_info = compute_debug_info_for_scope(op_id, innermost_scope, innermost_state, innermost_state);
2970 } else {
2971 // debug information already set. Check that it is correct from the current point of view
2972 DEBUG_ONLY(assert_equal(info->_scope_debug_info, compute_debug_info_for_scope(op_id, innermost_scope, innermost_state, innermost_state)));
2973 }
|
45 // helper macro for short definition of timer
46 #define TIME_LINEAR_SCAN(timer_name) TraceTime _block_timer("", _total_timer.timer(LinearScanTimers::timer_name), TimeLinearScan || TimeEachLinearScan, Verbose);
47
48 #else
49 #define TIME_LINEAR_SCAN(timer_name)
50 #endif
51
52 #ifdef ASSERT
53
54 // helper macro for short definition of trace-output inside code
55 #define TRACE_LINEAR_SCAN(level, code) \
56 if (TraceLinearScanLevel >= level) { \
57 code; \
58 }
59 #else
60 #define TRACE_LINEAR_SCAN(level, code)
61 #endif
62
63 // Map BasicType to spill size in 32-bit words, matching VMReg's notion of words
64 #ifdef _LP64
65 static int type2spill_size[T_CONFLICT+1]={ -1, 0, 0, 0, 1, 1, 1, 2, 1, 1, 1, 2, 2, 2, 2, 0, 2, 1, 2, 1, -1};
66 #else
67 static int type2spill_size[T_CONFLICT+1]={ -1, 0, 0, 0, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 1, 0, 1, -1, 1, 1, -1};
68 #endif
69
70
71 // Implementation of LinearScan
72
73 LinearScan::LinearScan(IR* ir, LIRGenerator* gen, FrameMap* frame_map)
74 : _compilation(ir->compilation())
75 , _ir(ir)
76 , _gen(gen)
77 , _frame_map(frame_map)
78 , _cached_blocks(*ir->linear_scan_order())
79 , _num_virtual_regs(gen->max_virtual_register_number())
80 , _has_fpu_registers(false)
81 , _num_calls(-1)
82 , _max_spills(0)
83 , _unused_spill_slot(-1)
84 , _intervals(0) // initialized later with correct length
85 , _new_intervals_from_allocation(nullptr)
86 , _sorted_intervals(nullptr)
87 , _needs_full_resort(false)
242 if (result > 2000) {
243 bailout("too many stack slots used");
244 }
245
246 return result;
247 }
248
249 void LinearScan::assign_spill_slot(Interval* it) {
250 // assign the canonical spill slot of the parent (if a part of the interval
251 // is already spilled) or allocate a new spill slot
252 if (it->canonical_spill_slot() >= 0) {
253 it->assign_reg(it->canonical_spill_slot());
254 } else {
255 int spill = allocate_spill_slot(type2spill_size[it->type()] == 2);
256 it->set_canonical_spill_slot(spill);
257 it->assign_reg(spill);
258 }
259 }
260
261 void LinearScan::propagate_spill_slots() {
262 if (!frame_map()->finalize_frame(max_spills(), compilation()->needs_stack_repair())) {
263 bailout("frame too large");
264 }
265 }
266
267 // create a new interval with a predefined reg_num
268 // (only used for parent intervals that are created during the building phase)
269 Interval* LinearScan::create_interval(int reg_num) {
270 assert(_intervals.at(reg_num) == nullptr, "overwriting existing interval");
271
272 Interval* interval = new Interval(reg_num);
273 _intervals.at_put(reg_num, interval);
274
275 // assign register number for precolored intervals
276 if (reg_num < LIR_Opr::vreg_base) {
277 interval->assign_reg(reg_num);
278 }
279 return interval;
280 }
281
282 // assign a new reg_num to the interval and append it to the list of intervals
2933 int pos = 0;
2934 while (pos < nof_stack) {
2935 Value expression = cur_state->stack_at(pos);
2936 pos += append_scope_value(op_id, expression, expressions);
2937
2938 assert(expressions->length() == pos, "must match");
2939 }
2940 assert(expressions->length() == cur_state->stack_size(), "wrong number of stack entries");
2941 }
2942
2943 // describe monitors
2944 int nof_locks = cur_state->locks_size();
2945 if (nof_locks > 0) {
2946 int lock_offset = cur_state->caller_state() != nullptr ? cur_state->caller_state()->total_locks_size() : 0;
2947 monitors = new GrowableArray<MonitorValue*>(nof_locks);
2948 for (int i = 0; i < nof_locks; i++) {
2949 monitors->append(location_for_monitor_index(lock_offset + i));
2950 }
2951 }
2952
2953 return new IRScopeDebugInfo(cur_scope, cur_state->bci(), locals, expressions, monitors, caller_debug_info, cur_state->should_reexecute());
2954 }
2955
2956
2957 void LinearScan::compute_debug_info(CodeEmitInfo* info, int op_id) {
2958 TRACE_LINEAR_SCAN(3, tty->print_cr("creating debug information at op_id %d", op_id));
2959
2960 IRScope* innermost_scope = info->scope();
2961 ValueStack* innermost_state = info->stack();
2962
2963 assert(innermost_scope != nullptr && innermost_state != nullptr, "why is it missing?");
2964
2965 DEBUG_ONLY(check_stack_depth(info, innermost_state->stack_size()));
2966
2967 if (info->_scope_debug_info == nullptr) {
2968 // compute debug information
2969 info->_scope_debug_info = compute_debug_info_for_scope(op_id, innermost_scope, innermost_state, innermost_state);
2970 } else {
2971 // debug information already set. Check that it is correct from the current point of view
2972 DEBUG_ONLY(assert_equal(info->_scope_debug_info, compute_debug_info_for_scope(op_id, innermost_scope, innermost_state, innermost_state)));
2973 }
|