src/share/vm/c1/c1_LIRGenerator.hpp

Mon, 12 Aug 2019 18:30:40 +0300

author
apetushkov
date
Mon, 12 Aug 2019 18:30:40 +0300
changeset 9858
b985cbb00e68
parent 8415
d109bda16490
child 9896
1b8c45b8216a
permissions
-rw-r--r--

8223147: JFR Backport
8199712: Flight Recorder
8203346: JFR: Inconsistent signature of jfr_add_string_constant
8195817: JFR.stop should require name of recording
8195818: JFR.start should increase autogenerated name by one
8195819: Remove recording=x from jcmd JFR.check output
8203921: JFR thread sampling is missing fixes from JDK-8194552
8203929: Limit amount of data for JFR.dump
8203664: JFR start failure after AppCDS archive created with JFR StartFlightRecording
8003209: JFR events for network utilization
8207392: [PPC64] Implement JFR profiling
8202835: jfr/event/os/TestSystemProcess.java fails on missing events
Summary: Backport JFR from JDK11. Initial integration
Reviewed-by: neugens

duke@435 1 /*
kevinw@8368 2 * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #ifndef SHARE_VM_C1_C1_LIRGENERATOR_HPP
stefank@2314 26 #define SHARE_VM_C1_C1_LIRGENERATOR_HPP
stefank@2314 27
stefank@2314 28 #include "c1/c1_Instruction.hpp"
stefank@2314 29 #include "c1/c1_LIR.hpp"
stefank@2314 30 #include "ci/ciMethodData.hpp"
apetushkov@9858 31 #include "jfr/support/jfrIntrinsics.hpp"
stefank@2314 32 #include "utilities/sizes.hpp"
stefank@2314 33
duke@435 34 // The classes responsible for code emission and register allocation
duke@435 35
duke@435 36
duke@435 37 class LIRGenerator;
duke@435 38 class LIREmitter;
duke@435 39 class Invoke;
duke@435 40 class SwitchRange;
duke@435 41 class LIRItem;
duke@435 42
duke@435 43 define_array(LIRItemArray, LIRItem*)
duke@435 44 define_stack(LIRItemList, LIRItemArray)
duke@435 45
duke@435 46 class SwitchRange: public CompilationResourceObj {
duke@435 47 private:
duke@435 48 int _low_key;
duke@435 49 int _high_key;
duke@435 50 BlockBegin* _sux;
duke@435 51 public:
duke@435 52 SwitchRange(int start_key, BlockBegin* sux): _low_key(start_key), _high_key(start_key), _sux(sux) {}
duke@435 53 void set_high_key(int key) { _high_key = key; }
duke@435 54
duke@435 55 int high_key() const { return _high_key; }
duke@435 56 int low_key() const { return _low_key; }
duke@435 57 BlockBegin* sux() const { return _sux; }
duke@435 58 };
duke@435 59
duke@435 60 define_array(SwitchRangeArray, SwitchRange*)
duke@435 61 define_stack(SwitchRangeList, SwitchRangeArray)
duke@435 62
duke@435 63
duke@435 64 class ResolveNode;
duke@435 65
duke@435 66 define_array(NodeArray, ResolveNode*);
duke@435 67 define_stack(NodeList, NodeArray);
duke@435 68
duke@435 69
duke@435 70 // Node objects form a directed graph of LIR_Opr
duke@435 71 // Edges between Nodes represent moves from one Node to its destinations
duke@435 72 class ResolveNode: public CompilationResourceObj {
duke@435 73 private:
duke@435 74 LIR_Opr _operand; // the source or destinaton
duke@435 75 NodeList _destinations; // for the operand
duke@435 76 bool _assigned; // Value assigned to this Node?
duke@435 77 bool _visited; // Node already visited?
duke@435 78 bool _start_node; // Start node already visited?
duke@435 79
duke@435 80 public:
duke@435 81 ResolveNode(LIR_Opr operand)
duke@435 82 : _operand(operand)
duke@435 83 , _assigned(false)
duke@435 84 , _visited(false)
duke@435 85 , _start_node(false) {};
duke@435 86
duke@435 87 // accessors
duke@435 88 LIR_Opr operand() const { return _operand; }
duke@435 89 int no_of_destinations() const { return _destinations.length(); }
duke@435 90 ResolveNode* destination_at(int i) { return _destinations[i]; }
duke@435 91 bool assigned() const { return _assigned; }
duke@435 92 bool visited() const { return _visited; }
duke@435 93 bool start_node() const { return _start_node; }
duke@435 94
duke@435 95 // modifiers
duke@435 96 void append(ResolveNode* dest) { _destinations.append(dest); }
duke@435 97 void set_assigned() { _assigned = true; }
duke@435 98 void set_visited() { _visited = true; }
duke@435 99 void set_start_node() { _start_node = true; }
duke@435 100 };
duke@435 101
duke@435 102
duke@435 103 // This is shared state to be used by the PhiResolver so the operand
duke@435 104 // arrays don't have to be reallocated for reach resolution.
duke@435 105 class PhiResolverState: public CompilationResourceObj {
duke@435 106 friend class PhiResolver;
duke@435 107
duke@435 108 private:
duke@435 109 NodeList _virtual_operands; // Nodes where the operand is a virtual register
duke@435 110 NodeList _other_operands; // Nodes where the operand is not a virtual register
duke@435 111 NodeList _vreg_table; // Mapping from virtual register to Node
duke@435 112
duke@435 113 public:
duke@435 114 PhiResolverState() {}
duke@435 115
duke@435 116 void reset(int max_vregs);
duke@435 117 };
duke@435 118
duke@435 119
duke@435 120 // class used to move value of phi operand to phi function
duke@435 121 class PhiResolver: public CompilationResourceObj {
duke@435 122 private:
duke@435 123 LIRGenerator* _gen;
duke@435 124 PhiResolverState& _state; // temporary state cached by LIRGenerator
duke@435 125
duke@435 126 ResolveNode* _loop;
duke@435 127 LIR_Opr _temp;
duke@435 128
duke@435 129 // access to shared state arrays
duke@435 130 NodeList& virtual_operands() { return _state._virtual_operands; }
duke@435 131 NodeList& other_operands() { return _state._other_operands; }
duke@435 132 NodeList& vreg_table() { return _state._vreg_table; }
duke@435 133
duke@435 134 ResolveNode* create_node(LIR_Opr opr, bool source);
duke@435 135 ResolveNode* source_node(LIR_Opr opr) { return create_node(opr, true); }
duke@435 136 ResolveNode* destination_node(LIR_Opr opr) { return create_node(opr, false); }
duke@435 137
duke@435 138 void emit_move(LIR_Opr src, LIR_Opr dest);
duke@435 139 void move_to_temp(LIR_Opr src);
duke@435 140 void move_temp_to(LIR_Opr dest);
duke@435 141 void move(ResolveNode* src, ResolveNode* dest);
duke@435 142
duke@435 143 LIRGenerator* gen() {
duke@435 144 return _gen;
duke@435 145 }
duke@435 146
duke@435 147 public:
duke@435 148 PhiResolver(LIRGenerator* _lir_gen, int max_vregs);
duke@435 149 ~PhiResolver();
duke@435 150
duke@435 151 void move(LIR_Opr src, LIR_Opr dest);
duke@435 152 };
duke@435 153
duke@435 154
duke@435 155 // only the classes below belong in the same file
duke@435 156 class LIRGenerator: public InstructionVisitor, public BlockClosure {
ysr@777 157
duke@435 158 private:
duke@435 159 Compilation* _compilation;
duke@435 160 ciMethod* _method; // method that we are compiling
duke@435 161 PhiResolverState _resolver_state;
duke@435 162 BlockBegin* _block;
duke@435 163 int _virtual_register_number;
duke@435 164 Values _instruction_for_operand;
duke@435 165 BitMap2D _vreg_flags; // flags which can be set on a per-vreg basis
duke@435 166 LIR_List* _lir;
ysr@777 167 BarrierSet* _bs;
duke@435 168
duke@435 169 LIRGenerator* gen() {
duke@435 170 return this;
duke@435 171 }
duke@435 172
rbackman@7058 173 void print_if_not_loaded(const NewInstance* new_instance) PRODUCT_RETURN;
rbackman@7058 174
duke@435 175 #ifdef ASSERT
duke@435 176 LIR_List* lir(const char * file, int line) const {
duke@435 177 _lir->set_file_and_line(file, line);
duke@435 178 return _lir;
duke@435 179 }
duke@435 180 #endif
duke@435 181 LIR_List* lir() const {
duke@435 182 return _lir;
duke@435 183 }
duke@435 184
duke@435 185 // a simple cache of constants used within a block
duke@435 186 GrowableArray<LIR_Const*> _constants;
duke@435 187 LIR_OprList _reg_for_constants;
duke@435 188 Values _unpinned_constants;
duke@435 189
duke@435 190 friend class PhiResolver;
duke@435 191
duke@435 192 // unified bailout support
duke@435 193 void bailout(const char* msg) const { compilation()->bailout(msg); }
duke@435 194 bool bailed_out() const { return compilation()->bailed_out(); }
duke@435 195
duke@435 196 void block_do_prolog(BlockBegin* block);
duke@435 197 void block_do_epilog(BlockBegin* block);
duke@435 198
duke@435 199 // register allocation
duke@435 200 LIR_Opr rlock(Value instr); // lock a free register
duke@435 201 LIR_Opr rlock_result(Value instr);
duke@435 202 LIR_Opr rlock_result(Value instr, BasicType type);
duke@435 203 LIR_Opr rlock_byte(BasicType type);
duke@435 204 LIR_Opr rlock_callee_saved(BasicType type);
duke@435 205
duke@435 206 // get a constant into a register and get track of what register was used
duke@435 207 LIR_Opr load_constant(Constant* x);
duke@435 208 LIR_Opr load_constant(LIR_Const* constant);
duke@435 209
iveresov@2138 210 // Given an immediate value, return an operand usable in logical ops.
iveresov@2138 211 LIR_Opr load_immediate(int x, BasicType type);
iveresov@2138 212
duke@435 213 void set_result(Value x, LIR_Opr opr) {
duke@435 214 assert(opr->is_valid(), "must set to valid value");
duke@435 215 assert(x->operand()->is_illegal(), "operand should never change");
duke@435 216 assert(!opr->is_register() || opr->is_virtual(), "should never set result to a physical register");
duke@435 217 x->set_operand(opr);
duke@435 218 assert(opr == x->operand(), "must be");
duke@435 219 if (opr->is_virtual()) {
duke@435 220 _instruction_for_operand.at_put_grow(opr->vreg_number(), x, NULL);
duke@435 221 }
duke@435 222 }
duke@435 223 void set_no_result(Value x) { assert(!x->has_uses(), "can't have use"); x->clear_operand(); }
duke@435 224
duke@435 225 friend class LIRItem;
duke@435 226
duke@435 227 LIR_Opr round_item(LIR_Opr opr);
duke@435 228 LIR_Opr force_to_spill(LIR_Opr value, BasicType t);
duke@435 229
duke@435 230 PhiResolverState& resolver_state() { return _resolver_state; }
duke@435 231
duke@435 232 void move_to_phi(PhiResolver* resolver, Value cur_val, Value sux_val);
duke@435 233 void move_to_phi(ValueStack* cur_state);
duke@435 234
duke@435 235 // code emission
duke@435 236 void do_ArithmeticOp_Long (ArithmeticOp* x);
duke@435 237 void do_ArithmeticOp_Int (ArithmeticOp* x);
duke@435 238 void do_ArithmeticOp_FPU (ArithmeticOp* x);
duke@435 239
duke@435 240 // platform dependent
duke@435 241 LIR_Opr getThreadPointer();
duke@435 242
duke@435 243 void do_RegisterFinalizer(Intrinsic* x);
roland@3838 244 void do_isInstance(Intrinsic* x);
duke@435 245 void do_getClass(Intrinsic* x);
duke@435 246 void do_currentThread(Intrinsic* x);
duke@435 247 void do_MathIntrinsic(Intrinsic* x);
duke@435 248 void do_ArrayCopy(Intrinsic* x);
duke@435 249 void do_CompareAndSwap(Intrinsic* x, ValueType* type);
duke@435 250 void do_NIOCheckIndex(Intrinsic* x);
duke@435 251 void do_FPIntrinsics(Intrinsic* x);
johnc@2781 252 void do_Reference_get(Intrinsic* x);
drchase@5353 253 void do_update_CRC32(Intrinsic* x);
duke@435 254
duke@435 255 void do_UnsafePrefetch(UnsafePrefetch* x, bool is_store);
duke@435 256
duke@435 257 LIR_Opr call_runtime(BasicTypeArray* signature, LIRItemList* args, address entry, ValueType* result_type, CodeEmitInfo* info);
duke@435 258 LIR_Opr call_runtime(BasicTypeArray* signature, LIR_OprList* args, address entry, ValueType* result_type, CodeEmitInfo* info);
duke@435 259
duke@435 260 // convenience functions
duke@435 261 LIR_Opr call_runtime(Value arg1, address entry, ValueType* result_type, CodeEmitInfo* info);
duke@435 262 LIR_Opr call_runtime(Value arg1, Value arg2, address entry, ValueType* result_type, CodeEmitInfo* info);
duke@435 263
duke@435 264 // GC Barriers
duke@435 265
duke@435 266 // generic interface
duke@435 267
johnc@2781 268 void pre_barrier(LIR_Opr addr_opr, LIR_Opr pre_val, bool do_load, bool patch, CodeEmitInfo* info);
duke@435 269 void post_barrier(LIR_OprDesc* addr, LIR_OprDesc* new_val);
duke@435 270
duke@435 271 // specific implementations
ysr@777 272 // pre barriers
ysr@777 273
johnc@2781 274 void G1SATBCardTableModRef_pre_barrier(LIR_Opr addr_opr, LIR_Opr pre_val,
johnc@2781 275 bool do_load, bool patch, CodeEmitInfo* info);
duke@435 276
duke@435 277 // post barriers
duke@435 278
ysr@777 279 void G1SATBCardTableModRef_post_barrier(LIR_OprDesc* addr, LIR_OprDesc* new_val);
duke@435 280 void CardTableModRef_post_barrier(LIR_OprDesc* addr, LIR_OprDesc* new_val);
dlong@7598 281 #ifdef CARDTABLEMODREF_POST_BARRIER_HELPER
dlong@7598 282 void CardTableModRef_post_barrier_helper(LIR_OprDesc* addr, LIR_Const* card_table_base);
dlong@7598 283 #endif
duke@435 284
duke@435 285
duke@435 286 static LIR_Opr result_register_for(ValueType* type, bool callee = false);
duke@435 287
duke@435 288 ciObject* get_jobject_constant(Value value);
duke@435 289
duke@435 290 LIRItemList* invoke_visit_arguments(Invoke* x);
duke@435 291 void invoke_load_arguments(Invoke* x, LIRItemList* args, const LIR_OprList* arg_list);
duke@435 292
duke@435 293 void trace_block_entry(BlockBegin* block);
duke@435 294
duke@435 295 // volatile field operations are never patchable because a klass
duke@435 296 // must be loaded to know it's volatile which means that the offset
duke@435 297 // it always known as well.
duke@435 298 void volatile_field_store(LIR_Opr value, LIR_Address* address, CodeEmitInfo* info);
duke@435 299 void volatile_field_load(LIR_Address* address, LIR_Opr result, CodeEmitInfo* info);
duke@435 300
duke@435 301 void put_Object_unsafe(LIR_Opr src, LIR_Opr offset, LIR_Opr data, BasicType type, bool is_volatile);
duke@435 302 void get_Object_unsafe(LIR_Opr dest, LIR_Opr src, LIR_Opr offset, BasicType type, bool is_volatile);
duke@435 303
duke@435 304 void arithmetic_call_op (Bytecodes::Code code, LIR_Opr result, LIR_OprList* args);
duke@435 305
iveresov@2138 306 void increment_counter(address counter, BasicType type, int step = 1);
duke@435 307 void increment_counter(LIR_Address* addr, int step = 1);
duke@435 308
duke@435 309 // is_strictfp is only needed for mul and div (and only generates different code on i486)
duke@435 310 void arithmetic_op(Bytecodes::Code code, LIR_Opr result, LIR_Opr left, LIR_Opr right, bool is_strictfp, LIR_Opr tmp, CodeEmitInfo* info = NULL);
duke@435 311 // machine dependent. returns true if it emitted code for the multiply
duke@435 312 bool strength_reduce_multiply(LIR_Opr left, int constant, LIR_Opr result, LIR_Opr tmp);
duke@435 313
duke@435 314 void store_stack_parameter (LIR_Opr opr, ByteSize offset_from_sp_in_bytes);
duke@435 315
rbackman@7058 316 void klass2reg_with_patching(LIR_Opr r, ciMetadata* obj, CodeEmitInfo* info, bool need_resolve = false);
duke@435 317
duke@435 318 // this loads the length and compares against the index
duke@435 319 void array_range_check (LIR_Opr array, LIR_Opr index, CodeEmitInfo* null_check_info, CodeEmitInfo* range_check_info);
duke@435 320 // For java.nio.Buffer.checkIndex
duke@435 321 void nio_range_check (LIR_Opr buffer, LIR_Opr index, LIR_Opr result, CodeEmitInfo* info);
duke@435 322
duke@435 323 void arithmetic_op_int (Bytecodes::Code code, LIR_Opr result, LIR_Opr left, LIR_Opr right, LIR_Opr tmp);
duke@435 324 void arithmetic_op_long (Bytecodes::Code code, LIR_Opr result, LIR_Opr left, LIR_Opr right, CodeEmitInfo* info = NULL);
duke@435 325 void arithmetic_op_fpu (Bytecodes::Code code, LIR_Opr result, LIR_Opr left, LIR_Opr right, bool is_strictfp, LIR_Opr tmp = LIR_OprFact::illegalOpr);
duke@435 326
duke@435 327 void shift_op (Bytecodes::Code code, LIR_Opr dst_reg, LIR_Opr value, LIR_Opr count, LIR_Opr tmp);
duke@435 328
duke@435 329 void logic_op (Bytecodes::Code code, LIR_Opr dst_reg, LIR_Opr left, LIR_Opr right);
duke@435 330
duke@435 331 void monitor_enter (LIR_Opr object, LIR_Opr lock, LIR_Opr hdr, LIR_Opr scratch, int monitor_no, CodeEmitInfo* info_for_exception, CodeEmitInfo* info);
bobv@2036 332 void monitor_exit (LIR_Opr object, LIR_Opr lock, LIR_Opr hdr, LIR_Opr scratch, int monitor_no);
duke@435 333
rbackman@7058 334 void new_instance (LIR_Opr dst, ciInstanceKlass* klass, bool is_unresolved, LIR_Opr scratch1, LIR_Opr scratch2, LIR_Opr scratch3, LIR_Opr scratch4, LIR_Opr klass_reg, CodeEmitInfo* info);
duke@435 335
duke@435 336 // machine dependent
duke@435 337 void cmp_mem_int(LIR_Condition condition, LIR_Opr base, int disp, int c, CodeEmitInfo* info);
duke@435 338 void cmp_reg_mem(LIR_Condition condition, LIR_Opr reg, LIR_Opr base, int disp, BasicType type, CodeEmitInfo* info);
duke@435 339 void cmp_reg_mem(LIR_Condition condition, LIR_Opr reg, LIR_Opr base, LIR_Opr disp, BasicType type, CodeEmitInfo* info);
duke@435 340
duke@435 341 void arraycopy_helper(Intrinsic* x, int* flags, ciArrayKlass** expected_type);
duke@435 342
duke@435 343 // returns a LIR_Address to address an array location. May also
duke@435 344 // emit some code as part of address calculation. If
duke@435 345 // needs_card_mark is true then compute the full address for use by
duke@435 346 // both the store and the card mark.
duke@435 347 LIR_Address* generate_address(LIR_Opr base,
duke@435 348 LIR_Opr index, int shift,
duke@435 349 int disp,
duke@435 350 BasicType type);
duke@435 351 LIR_Address* generate_address(LIR_Opr base, int disp, BasicType type) {
duke@435 352 return generate_address(base, LIR_OprFact::illegalOpr, 0, disp, type);
duke@435 353 }
duke@435 354 LIR_Address* emit_array_address(LIR_Opr array_opr, LIR_Opr index_opr, BasicType type, bool needs_card_mark);
duke@435 355
bobv@2036 356 // the helper for generate_address
bobv@2036 357 void add_large_constant(LIR_Opr src, int c, LIR_Opr dest);
bobv@2036 358
duke@435 359 // machine preferences and characteristics
duke@435 360 bool can_inline_as_constant(Value i) const;
duke@435 361 bool can_inline_as_constant(LIR_Const* c) const;
duke@435 362 bool can_store_as_constant(Value i, BasicType type) const;
duke@435 363
duke@435 364 LIR_Opr safepoint_poll_register();
iveresov@2138 365
iveresov@2138 366 void profile_branch(If* if_instr, If::Condition cond);
iveresov@2138 367 void increment_event_counter_impl(CodeEmitInfo* info,
iveresov@2138 368 ciMethod *method, int frequency,
iveresov@2138 369 int bci, bool backedge, bool notify);
iveresov@2138 370 void increment_event_counter(CodeEmitInfo* info, int bci, bool backedge);
iveresov@2138 371 void increment_invocation_counter(CodeEmitInfo *info) {
iveresov@2138 372 if (compilation()->count_invocations()) {
iveresov@2138 373 increment_event_counter(info, InvocationEntryBci, false);
iveresov@2138 374 }
iveresov@2138 375 }
iveresov@2138 376 void increment_backedge_counter(CodeEmitInfo* info, int bci) {
iveresov@2138 377 if (compilation()->count_backedges()) {
iveresov@2138 378 increment_event_counter(info, bci, true);
iveresov@2138 379 }
duke@435 380 }
duke@435 381
duke@435 382 CodeEmitInfo* state_for(Instruction* x, ValueStack* state, bool ignore_xhandler = false);
duke@435 383 CodeEmitInfo* state_for(Instruction* x);
duke@435 384
duke@435 385 // allocates a virtual register for this instruction if
duke@435 386 // one isn't already allocated. Only for Phi and Local.
duke@435 387 LIR_Opr operand_for_instruction(Instruction *x);
duke@435 388
duke@435 389 void set_block(BlockBegin* block) { _block = block; }
duke@435 390
duke@435 391 void block_prolog(BlockBegin* block);
duke@435 392 void block_epilog(BlockBegin* block);
duke@435 393
duke@435 394 void do_root (Instruction* instr);
duke@435 395 void walk (Instruction* instr);
duke@435 396
duke@435 397 void bind_block_entry(BlockBegin* block);
duke@435 398 void start_block(BlockBegin* block);
duke@435 399
duke@435 400 LIR_Opr new_register(BasicType type);
duke@435 401 LIR_Opr new_register(Value value) { return new_register(as_BasicType(value->type())); }
duke@435 402 LIR_Opr new_register(ValueType* type) { return new_register(as_BasicType(type)); }
duke@435 403
duke@435 404 // returns a register suitable for doing pointer math
duke@435 405 LIR_Opr new_pointer_register() {
duke@435 406 #ifdef _LP64
duke@435 407 return new_register(T_LONG);
duke@435 408 #else
duke@435 409 return new_register(T_INT);
duke@435 410 #endif
duke@435 411 }
duke@435 412
duke@435 413 static LIR_Condition lir_cond(If::Condition cond) {
csahu@8316 414 LIR_Condition l = lir_cond_unknown;
duke@435 415 switch (cond) {
duke@435 416 case If::eql: l = lir_cond_equal; break;
duke@435 417 case If::neq: l = lir_cond_notEqual; break;
duke@435 418 case If::lss: l = lir_cond_less; break;
duke@435 419 case If::leq: l = lir_cond_lessEqual; break;
duke@435 420 case If::geq: l = lir_cond_greaterEqual; break;
duke@435 421 case If::gtr: l = lir_cond_greater; break;
roland@4860 422 case If::aeq: l = lir_cond_aboveEqual; break;
roland@4860 423 case If::beq: l = lir_cond_belowEqual; break;
csahu@8316 424 default: fatal("You must pass valid If::Condition");
duke@435 425 };
duke@435 426 return l;
duke@435 427 }
duke@435 428
bobv@2036 429 #ifdef __SOFTFP__
bobv@2036 430 void do_soft_float_compare(If *x);
bobv@2036 431 #endif // __SOFTFP__
bobv@2036 432
duke@435 433 void init();
duke@435 434
duke@435 435 SwitchRangeArray* create_lookup_ranges(TableSwitch* x);
duke@435 436 SwitchRangeArray* create_lookup_ranges(LookupSwitch* x);
duke@435 437 void do_SwitchRanges(SwitchRangeArray* x, LIR_Opr value, BlockBegin* default_sux);
duke@435 438
rbackman@3709 439 void do_RuntimeCall(address routine, int expected_arguments, Intrinsic* x);
apetushkov@9858 440 #ifdef JFR_HAVE_INTRINSICS
rbackman@3709 441 void do_ClassIDIntrinsic(Intrinsic* x);
apetushkov@9858 442 void do_getEventWriter(Intrinsic* x);
rbackman@3709 443 #endif
roland@6103 444 ciKlass* profile_type(ciMethodData* md, int md_first_offset, int md_offset, intptr_t profiled_k,
roland@6103 445 Value arg, LIR_Opr& mdp, bool not_null, ciKlass* signature_at_call_k,
roland@6103 446 ciKlass* callee_signature_k);
roland@5914 447 void profile_arguments(ProfileCall* x);
roland@5987 448 void profile_parameters(Base* x);
roland@5987 449 void profile_parameters_at_call(ProfileCall* x);
kevinw@8368 450 LIR_Opr maybe_mask_boolean(StoreIndexed* x, LIR_Opr array, LIR_Opr value, CodeEmitInfo*& null_check_info);
rbackman@3709 451
duke@435 452 public:
duke@435 453 Compilation* compilation() const { return _compilation; }
duke@435 454 FrameMap* frame_map() const { return _compilation->frame_map(); }
duke@435 455 ciMethod* method() const { return _method; }
duke@435 456 BlockBegin* block() const { return _block; }
duke@435 457 IRScope* scope() const { return block()->scope(); }
duke@435 458
duke@435 459 int max_virtual_register_number() const { return _virtual_register_number; }
duke@435 460
duke@435 461 void block_do(BlockBegin* block);
duke@435 462
duke@435 463 // Flags that can be set on vregs
duke@435 464 enum VregFlag {
duke@435 465 must_start_in_memory = 0 // needs to be assigned a memory location at beginning, but may then be loaded in a register
duke@435 466 , callee_saved = 1 // must be in a callee saved register
duke@435 467 , byte_reg = 2 // must be in a byte register
duke@435 468 , num_vreg_flags
duke@435 469
duke@435 470 };
duke@435 471
duke@435 472 LIRGenerator(Compilation* compilation, ciMethod* method)
duke@435 473 : _compilation(compilation)
duke@435 474 , _method(method)
duke@435 475 , _virtual_register_number(LIR_OprDesc::vreg_base)
duke@435 476 , _vreg_flags(NULL, 0, num_vreg_flags) {
duke@435 477 init();
duke@435 478 }
duke@435 479
duke@435 480 // for virtual registers, maps them back to Phi's or Local's
duke@435 481 Instruction* instruction_for_opr(LIR_Opr opr);
duke@435 482 Instruction* instruction_for_vreg(int reg_num);
duke@435 483
duke@435 484 void set_vreg_flag (int vreg_num, VregFlag f);
duke@435 485 bool is_vreg_flag_set(int vreg_num, VregFlag f);
duke@435 486 void set_vreg_flag (LIR_Opr opr, VregFlag f) { set_vreg_flag(opr->vreg_number(), f); }
duke@435 487 bool is_vreg_flag_set(LIR_Opr opr, VregFlag f) { return is_vreg_flag_set(opr->vreg_number(), f); }
duke@435 488
duke@435 489 // statics
duke@435 490 static LIR_Opr exceptionOopOpr();
duke@435 491 static LIR_Opr exceptionPcOpr();
duke@435 492 static LIR_Opr divInOpr();
duke@435 493 static LIR_Opr divOutOpr();
duke@435 494 static LIR_Opr remOutOpr();
duke@435 495 static LIR_Opr shiftCountOpr();
duke@435 496 LIR_Opr syncTempOpr();
bobv@2036 497 LIR_Opr atomicLockOpr();
duke@435 498
duke@435 499 // returns a register suitable for saving the thread in a
duke@435 500 // call_runtime_leaf if one is needed.
duke@435 501 LIR_Opr getThreadTemp();
duke@435 502
duke@435 503 // visitor functionality
duke@435 504 virtual void do_Phi (Phi* x);
duke@435 505 virtual void do_Local (Local* x);
duke@435 506 virtual void do_Constant (Constant* x);
duke@435 507 virtual void do_LoadField (LoadField* x);
duke@435 508 virtual void do_StoreField (StoreField* x);
duke@435 509 virtual void do_ArrayLength (ArrayLength* x);
duke@435 510 virtual void do_LoadIndexed (LoadIndexed* x);
duke@435 511 virtual void do_StoreIndexed (StoreIndexed* x);
duke@435 512 virtual void do_NegateOp (NegateOp* x);
duke@435 513 virtual void do_ArithmeticOp (ArithmeticOp* x);
duke@435 514 virtual void do_ShiftOp (ShiftOp* x);
duke@435 515 virtual void do_LogicOp (LogicOp* x);
duke@435 516 virtual void do_CompareOp (CompareOp* x);
duke@435 517 virtual void do_IfOp (IfOp* x);
duke@435 518 virtual void do_Convert (Convert* x);
duke@435 519 virtual void do_NullCheck (NullCheck* x);
twisti@3969 520 virtual void do_TypeCast (TypeCast* x);
duke@435 521 virtual void do_Invoke (Invoke* x);
duke@435 522 virtual void do_NewInstance (NewInstance* x);
duke@435 523 virtual void do_NewTypeArray (NewTypeArray* x);
duke@435 524 virtual void do_NewObjectArray (NewObjectArray* x);
duke@435 525 virtual void do_NewMultiArray (NewMultiArray* x);
duke@435 526 virtual void do_CheckCast (CheckCast* x);
duke@435 527 virtual void do_InstanceOf (InstanceOf* x);
duke@435 528 virtual void do_MonitorEnter (MonitorEnter* x);
duke@435 529 virtual void do_MonitorExit (MonitorExit* x);
duke@435 530 virtual void do_Intrinsic (Intrinsic* x);
duke@435 531 virtual void do_BlockBegin (BlockBegin* x);
duke@435 532 virtual void do_Goto (Goto* x);
duke@435 533 virtual void do_If (If* x);
duke@435 534 virtual void do_IfInstanceOf (IfInstanceOf* x);
duke@435 535 virtual void do_TableSwitch (TableSwitch* x);
duke@435 536 virtual void do_LookupSwitch (LookupSwitch* x);
duke@435 537 virtual void do_Return (Return* x);
duke@435 538 virtual void do_Throw (Throw* x);
duke@435 539 virtual void do_Base (Base* x);
duke@435 540 virtual void do_OsrEntry (OsrEntry* x);
duke@435 541 virtual void do_ExceptionObject(ExceptionObject* x);
duke@435 542 virtual void do_RoundFP (RoundFP* x);
duke@435 543 virtual void do_UnsafeGetRaw (UnsafeGetRaw* x);
duke@435 544 virtual void do_UnsafePutRaw (UnsafePutRaw* x);
duke@435 545 virtual void do_UnsafeGetObject(UnsafeGetObject* x);
duke@435 546 virtual void do_UnsafePutObject(UnsafePutObject* x);
roland@4106 547 virtual void do_UnsafeGetAndSetObject(UnsafeGetAndSetObject* x);
duke@435 548 virtual void do_UnsafePrefetchRead (UnsafePrefetchRead* x);
duke@435 549 virtual void do_UnsafePrefetchWrite(UnsafePrefetchWrite* x);
duke@435 550 virtual void do_ProfileCall (ProfileCall* x);
roland@5921 551 virtual void do_ProfileReturnType (ProfileReturnType* x);
iveresov@2138 552 virtual void do_ProfileInvoke (ProfileInvoke* x);
never@2486 553 virtual void do_RuntimeCall (RuntimeCall* x);
jiangli@3592 554 virtual void do_MemBar (MemBar* x);
roland@4860 555 virtual void do_RangeCheckPredicate(RangeCheckPredicate* x);
roland@4947 556 #ifdef ASSERT
roland@4860 557 virtual void do_Assert (Assert* x);
roland@4947 558 #endif
dlong@7598 559
dlong@7598 560 #ifdef C1_LIRGENERATOR_MD_HPP
dlong@7598 561 #include C1_LIRGENERATOR_MD_HPP
dlong@7598 562 #endif
duke@435 563 };
duke@435 564
duke@435 565
duke@435 566 class LIRItem: public CompilationResourceObj {
duke@435 567 private:
duke@435 568 Value _value;
duke@435 569 LIRGenerator* _gen;
duke@435 570 LIR_Opr _result;
duke@435 571 bool _destroys_register;
duke@435 572 LIR_Opr _new_result;
duke@435 573
duke@435 574 LIRGenerator* gen() const { return _gen; }
duke@435 575
duke@435 576 public:
duke@435 577 LIRItem(Value value, LIRGenerator* gen) {
duke@435 578 _destroys_register = false;
duke@435 579 _gen = gen;
duke@435 580 set_instruction(value);
duke@435 581 }
duke@435 582
duke@435 583 LIRItem(LIRGenerator* gen) {
duke@435 584 _destroys_register = false;
duke@435 585 _gen = gen;
duke@435 586 _result = LIR_OprFact::illegalOpr;
duke@435 587 set_instruction(NULL);
duke@435 588 }
duke@435 589
duke@435 590 void set_instruction(Value value) {
duke@435 591 _value = value;
duke@435 592 _result = LIR_OprFact::illegalOpr;
duke@435 593 if (_value != NULL) {
duke@435 594 _gen->walk(_value);
duke@435 595 _result = _value->operand();
duke@435 596 }
duke@435 597 _new_result = LIR_OprFact::illegalOpr;
duke@435 598 }
duke@435 599
duke@435 600 Value value() const { return _value; }
duke@435 601 ValueType* type() const { return value()->type(); }
duke@435 602 LIR_Opr result() {
duke@435 603 assert(!_destroys_register || (!_result->is_register() || _result->is_virtual()),
duke@435 604 "shouldn't use set_destroys_register with physical regsiters");
duke@435 605 if (_destroys_register && _result->is_register()) {
duke@435 606 if (_new_result->is_illegal()) {
duke@435 607 _new_result = _gen->new_register(type());
duke@435 608 gen()->lir()->move(_result, _new_result);
duke@435 609 }
duke@435 610 return _new_result;
duke@435 611 } else {
duke@435 612 return _result;
duke@435 613 }
duke@435 614 return _result;
duke@435 615 }
duke@435 616
duke@435 617 void set_result(LIR_Opr opr);
duke@435 618
duke@435 619 void load_item();
duke@435 620 void load_byte_item();
duke@435 621 void load_nonconstant();
duke@435 622 // load any values which can't be expressed as part of a single store instruction
duke@435 623 void load_for_store(BasicType store_type);
duke@435 624 void load_item_force(LIR_Opr reg);
duke@435 625
duke@435 626 void dont_load_item() {
duke@435 627 // do nothing
duke@435 628 }
duke@435 629
duke@435 630 void set_destroys_register() {
duke@435 631 _destroys_register = true;
duke@435 632 }
duke@435 633
duke@435 634 bool is_constant() const { return value()->as_Constant() != NULL; }
duke@435 635 bool is_stack() { return result()->is_stack(); }
duke@435 636 bool is_register() { return result()->is_register(); }
duke@435 637
duke@435 638 ciObject* get_jobject_constant() const;
duke@435 639 jint get_jint_constant() const;
duke@435 640 jlong get_jlong_constant() const;
duke@435 641 jfloat get_jfloat_constant() const;
duke@435 642 jdouble get_jdouble_constant() const;
duke@435 643 jint get_address_constant() const;
duke@435 644 };
stefank@2314 645
stefank@2314 646 #endif // SHARE_VM_C1_C1_LIRGENERATOR_HPP

mercurial