-
Notifications
You must be signed in to change notification settings - Fork 5.8k
/
Copy pathc1_LIR.cpp
2108 lines (1811 loc) · 69.2 KB
/
c1_LIR.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) 2000, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#include "c1/c1_CodeStubs.hpp"
#include "c1/c1_InstructionPrinter.hpp"
#include "c1/c1_LIR.hpp"
#include "c1/c1_LIRAssembler.hpp"
#include "c1/c1_ValueStack.hpp"
#include "ci/ciInstance.hpp"
#include "runtime/safepointMechanism.inline.hpp"
#include "runtime/sharedRuntime.hpp"
#include "runtime/vm_version.hpp"
Register LIR_Opr::as_register() const {
return FrameMap::cpu_rnr2reg(cpu_regnr());
}
Register LIR_Opr::as_register_lo() const {
return FrameMap::cpu_rnr2reg(cpu_regnrLo());
}
Register LIR_Opr::as_register_hi() const {
return FrameMap::cpu_rnr2reg(cpu_regnrHi());
}
LIR_Opr LIR_OprFact::illegalOpr = LIR_OprFact::illegal();
LIR_Opr LIR_OprFact::nullOpr = LIR_Opr();
LIR_Opr LIR_OprFact::value_type(ValueType* type) {
ValueTag tag = type->tag();
switch (tag) {
case metaDataTag : {
ClassConstant* c = type->as_ClassConstant();
if (c != nullptr && !c->value()->is_loaded()) {
return LIR_OprFact::metadataConst(nullptr);
} else if (c != nullptr) {
return LIR_OprFact::metadataConst(c->value()->constant_encoding());
} else {
MethodConstant* m = type->as_MethodConstant();
assert (m != nullptr, "not a class or a method?");
return LIR_OprFact::metadataConst(m->value()->constant_encoding());
}
}
case objectTag : {
return LIR_OprFact::oopConst(type->as_ObjectType()->encoding());
}
case addressTag: return LIR_OprFact::addressConst(type->as_AddressConstant()->value());
case intTag : return LIR_OprFact::intConst(type->as_IntConstant()->value());
case floatTag : return LIR_OprFact::floatConst(type->as_FloatConstant()->value());
case longTag : return LIR_OprFact::longConst(type->as_LongConstant()->value());
case doubleTag : return LIR_OprFact::doubleConst(type->as_DoubleConstant()->value());
default: ShouldNotReachHere(); return LIR_OprFact::intConst(-1);
}
}
//---------------------------------------------------
LIR_Address::Scale LIR_Address::scale(BasicType type) {
int elem_size = type2aelembytes(type);
switch (elem_size) {
case 1: return LIR_Address::times_1;
case 2: return LIR_Address::times_2;
case 4: return LIR_Address::times_4;
case 8: return LIR_Address::times_8;
}
ShouldNotReachHere();
return LIR_Address::times_1;
}
//---------------------------------------------------
char LIR_Opr::type_char(BasicType t) {
switch (t) {
case T_ARRAY:
t = T_OBJECT;
case T_BOOLEAN:
case T_CHAR:
case T_FLOAT:
case T_DOUBLE:
case T_BYTE:
case T_SHORT:
case T_INT:
case T_LONG:
case T_OBJECT:
case T_ADDRESS:
case T_VOID:
return ::type2char(t);
case T_METADATA:
return 'M';
case T_ILLEGAL:
return '?';
default:
ShouldNotReachHere();
return '?';
}
}
#ifndef PRODUCT
void LIR_Opr::validate_type() const {
#ifdef ASSERT
if (!is_pointer() && !is_illegal()) {
OprKind kindfield = kind_field(); // Factored out because of compiler bug, see 8002160
switch (as_BasicType(type_field())) {
case T_LONG:
assert((kindfield == cpu_register || kindfield == stack_value) &&
size_field() == double_size, "must match");
break;
case T_FLOAT:
// FP return values can be also in CPU registers on ARM (softfp ABI)
assert((kindfield == fpu_register || kindfield == stack_value
ARM_ONLY(|| kindfield == cpu_register) ) &&
size_field() == single_size, "must match");
break;
case T_DOUBLE:
// FP return values can be also in CPU registers on ARM (softfp ABI)
assert((kindfield == fpu_register || kindfield == stack_value
ARM_ONLY(|| kindfield == cpu_register) ) &&
size_field() == double_size, "must match");
break;
case T_BOOLEAN:
case T_CHAR:
case T_BYTE:
case T_SHORT:
case T_INT:
case T_ADDRESS:
case T_OBJECT:
case T_METADATA:
case T_ARRAY:
assert((kindfield == cpu_register || kindfield == stack_value) &&
size_field() == single_size, "must match");
break;
case T_ILLEGAL:
// XXX TKR also means unknown right now
// assert(is_illegal(), "must match");
break;
default:
ShouldNotReachHere();
}
}
#endif
}
#endif // PRODUCT
bool LIR_Opr::is_oop() const {
if (is_pointer()) {
return pointer()->is_oop_pointer();
} else {
OprType t= type_field();
assert(t != unknown_type, "not set");
return t == object_type;
}
}
void LIR_Op2::verify() const {
#ifdef ASSERT
switch (code()) {
case lir_xchg:
break;
default:
assert(!result_opr()->is_register() || !result_opr()->is_oop_register(),
"can't produce oops from arith");
}
if (two_operand_lir_form) {
bool threeOperandForm = false;
#ifdef S390
// There are 3 operand shifts on S390 (see LIR_Assembler::shift_op()).
threeOperandForm =
code() == lir_shl ||
((code() == lir_shr || code() == lir_ushr) && (result_opr()->is_double_cpu() || in_opr1()->type() == T_OBJECT));
#endif
switch (code()) {
case lir_add:
case lir_sub:
case lir_mul:
case lir_div:
case lir_rem:
case lir_logic_and:
case lir_logic_or:
case lir_logic_xor:
case lir_shl:
case lir_shr:
assert(in_opr1() == result_opr() || threeOperandForm, "opr1 and result must match");
assert(in_opr1()->is_valid() && in_opr2()->is_valid(), "must be valid");
break;
// special handling for lir_ushr because of write barriers
case lir_ushr:
assert(in_opr1() == result_opr() || in_opr2()->is_constant() || threeOperandForm, "opr1 and result must match or shift count is constant");
assert(in_opr1()->is_valid() && in_opr2()->is_valid(), "must be valid");
break;
default:
break;
}
}
#endif
}
LIR_OpBranch::LIR_OpBranch(LIR_Condition cond, BlockBegin* block)
: LIR_Op2(lir_branch, cond, LIR_OprFact::illegalOpr, LIR_OprFact::illegalOpr, (CodeEmitInfo*)nullptr)
, _label(block->label())
, _block(block)
, _ublock(nullptr)
, _stub(nullptr) {
}
LIR_OpBranch::LIR_OpBranch(LIR_Condition cond, CodeStub* stub) :
LIR_Op2(lir_branch, cond, LIR_OprFact::illegalOpr, LIR_OprFact::illegalOpr, (CodeEmitInfo*)nullptr)
, _label(stub->entry())
, _block(nullptr)
, _ublock(nullptr)
, _stub(stub) {
}
LIR_OpBranch::LIR_OpBranch(LIR_Condition cond, BlockBegin* block, BlockBegin* ublock)
: LIR_Op2(lir_cond_float_branch, cond, LIR_OprFact::illegalOpr, LIR_OprFact::illegalOpr, (CodeEmitInfo*)nullptr)
, _label(block->label())
, _block(block)
, _ublock(ublock)
, _stub(nullptr)
{
}
void LIR_OpBranch::change_block(BlockBegin* b) {
assert(_block != nullptr, "must have old block");
assert(_block->label() == label(), "must be equal");
_block = b;
_label = b->label();
}
void LIR_OpBranch::change_ublock(BlockBegin* b) {
assert(_ublock != nullptr, "must have old block");
_ublock = b;
}
void LIR_OpBranch::negate_cond() {
switch (cond()) {
case lir_cond_equal: set_cond(lir_cond_notEqual); break;
case lir_cond_notEqual: set_cond(lir_cond_equal); break;
case lir_cond_less: set_cond(lir_cond_greaterEqual); break;
case lir_cond_lessEqual: set_cond(lir_cond_greater); break;
case lir_cond_greaterEqual: set_cond(lir_cond_less); break;
case lir_cond_greater: set_cond(lir_cond_lessEqual); break;
default: ShouldNotReachHere();
}
}
LIR_OpTypeCheck::LIR_OpTypeCheck(LIR_Code code, LIR_Opr result, LIR_Opr object, ciKlass* klass,
LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3,
bool fast_check, CodeEmitInfo* info_for_exception, CodeEmitInfo* info_for_patch,
CodeStub* stub)
: LIR_Op(code, result, nullptr)
, _object(object)
, _array(LIR_OprFact::illegalOpr)
, _klass(klass)
, _tmp1(tmp1)
, _tmp2(tmp2)
, _tmp3(tmp3)
, _info_for_patch(info_for_patch)
, _info_for_exception(info_for_exception)
, _stub(stub)
, _profiled_method(nullptr)
, _profiled_bci(-1)
, _should_profile(false)
, _fast_check(fast_check)
{
if (code == lir_checkcast) {
assert(info_for_exception != nullptr, "checkcast throws exceptions");
} else if (code == lir_instanceof) {
assert(info_for_exception == nullptr, "instanceof throws no exceptions");
} else {
ShouldNotReachHere();
}
}
LIR_OpTypeCheck::LIR_OpTypeCheck(LIR_Code code, LIR_Opr object, LIR_Opr array, LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, CodeEmitInfo* info_for_exception)
: LIR_Op(code, LIR_OprFact::illegalOpr, nullptr)
, _object(object)
, _array(array)
, _klass(nullptr)
, _tmp1(tmp1)
, _tmp2(tmp2)
, _tmp3(tmp3)
, _info_for_patch(nullptr)
, _info_for_exception(info_for_exception)
, _stub(nullptr)
, _profiled_method(nullptr)
, _profiled_bci(-1)
, _should_profile(false)
, _fast_check(false)
{
if (code == lir_store_check) {
_stub = new ArrayStoreExceptionStub(object, info_for_exception);
assert(info_for_exception != nullptr, "store_check throws exceptions");
} else {
ShouldNotReachHere();
}
}
LIR_OpArrayCopy::LIR_OpArrayCopy(LIR_Opr src, LIR_Opr src_pos, LIR_Opr dst, LIR_Opr dst_pos, LIR_Opr length,
LIR_Opr tmp, ciArrayKlass* expected_type, int flags, CodeEmitInfo* info)
: LIR_Op(lir_arraycopy, LIR_OprFact::illegalOpr, info)
, _src(src)
, _src_pos(src_pos)
, _dst(dst)
, _dst_pos(dst_pos)
, _length(length)
, _tmp(tmp)
, _expected_type(expected_type)
, _flags(flags) {
#if defined(X86) || defined(AARCH64) || defined(S390) || defined(RISCV) || defined(PPC64)
if (expected_type != nullptr && flags == 0) {
_stub = nullptr;
} else {
_stub = new ArrayCopyStub(this);
}
#else
_stub = new ArrayCopyStub(this);
#endif
}
LIR_OpUpdateCRC32::LIR_OpUpdateCRC32(LIR_Opr crc, LIR_Opr val, LIR_Opr res)
: LIR_Op(lir_updatecrc32, res, nullptr)
, _crc(crc)
, _val(val) {
}
//-------------------verify--------------------------
void LIR_Op1::verify() const {
switch(code()) {
case lir_move:
assert(in_opr()->is_valid() && result_opr()->is_valid(), "must be");
break;
case lir_null_check:
assert(in_opr()->is_register(), "must be");
break;
case lir_return:
assert(in_opr()->is_register() || in_opr()->is_illegal(), "must be");
break;
default:
break;
}
}
void LIR_OpRTCall::verify() const {
assert(strcmp(Runtime1::name_for_address(addr()), "<unknown function>") != 0, "unknown function");
}
//-------------------visits--------------------------
// complete rework of LIR instruction visitor.
// The virtual call for each instruction type is replaced by a big
// switch that adds the operands for each instruction
void LIR_OpVisitState::visit(LIR_Op* op) {
// copy information from the LIR_Op
reset();
set_op(op);
switch (op->code()) {
// LIR_Op0
case lir_breakpoint: // result and info always invalid
case lir_membar: // result and info always invalid
case lir_membar_acquire: // result and info always invalid
case lir_membar_release: // result and info always invalid
case lir_membar_loadload: // result and info always invalid
case lir_membar_storestore: // result and info always invalid
case lir_membar_loadstore: // result and info always invalid
case lir_membar_storeload: // result and info always invalid
case lir_on_spin_wait:
{
assert(op->as_Op0() != nullptr, "must be");
assert(op->_info == nullptr, "info not used by this instruction");
assert(op->_result->is_illegal(), "not used");
break;
}
case lir_nop: // may have info, result always invalid
case lir_std_entry: // may have result, info always invalid
case lir_osr_entry: // may have result, info always invalid
case lir_get_thread: // may have result, info always invalid
{
assert(op->as_Op0() != nullptr, "must be");
if (op->_info != nullptr) do_info(op->_info);
if (op->_result->is_valid()) do_output(op->_result);
break;
}
// LIR_OpLabel
case lir_label: // result and info always invalid
{
assert(op->as_OpLabel() != nullptr, "must be");
assert(op->_info == nullptr, "info not used by this instruction");
assert(op->_result->is_illegal(), "not used");
break;
}
// LIR_Op1
case lir_push: // input always valid, result and info always invalid
case lir_pop: // input always valid, result and info always invalid
case lir_leal: // input and result always valid, info always invalid
case lir_monaddr: // input and result always valid, info always invalid
case lir_null_check: // input and info always valid, result always invalid
case lir_move: // input and result always valid, may have info
case lir_sqrt: // FP Ops have no info, but input and result
case lir_abs:
case lir_neg:
case lir_f2hf:
case lir_hf2f:
{
assert(op->as_Op1() != nullptr, "must be");
LIR_Op1* op1 = (LIR_Op1*)op;
if (op1->_info) do_info(op1->_info);
if (op1->_opr->is_valid()) do_input(op1->_opr);
if (op1->_tmp->is_valid()) do_temp(op1->_tmp);
if (op1->_result->is_valid()) do_output(op1->_result);
break;
}
case lir_return:
{
assert(op->as_OpReturn() != nullptr, "must be");
LIR_OpReturn* op_ret = (LIR_OpReturn*)op;
if (op_ret->_info) do_info(op_ret->_info);
if (op_ret->_opr->is_valid()) do_input(op_ret->_opr);
if (op_ret->_result->is_valid()) do_output(op_ret->_result);
if (op_ret->stub() != nullptr) do_stub(op_ret->stub());
break;
}
case lir_safepoint:
{
assert(op->as_Op1() != nullptr, "must be");
LIR_Op1* op1 = (LIR_Op1*)op;
assert(op1->_info != nullptr, ""); do_info(op1->_info);
if (op1->_opr->is_valid()) do_temp(op1->_opr); // safepoints on SPARC need temporary register
assert(op1->_tmp->is_illegal(), "not used");
assert(op1->_result->is_illegal(), "safepoint does not produce value");
break;
}
// LIR_OpConvert;
case lir_convert: // input and result always valid, info always invalid
{
assert(op->as_OpConvert() != nullptr, "must be");
LIR_OpConvert* opConvert = (LIR_OpConvert*)op;
assert(opConvert->_info == nullptr, "must be");
if (opConvert->_opr->is_valid()) do_input(opConvert->_opr);
if (opConvert->_result->is_valid()) do_output(opConvert->_result);
do_stub(opConvert->_stub);
break;
}
// LIR_OpBranch;
case lir_branch: // may have info, input and result register always invalid
case lir_cond_float_branch: // may have info, input and result register always invalid
{
assert(op->as_OpBranch() != nullptr, "must be");
LIR_OpBranch* opBranch = (LIR_OpBranch*)op;
assert(opBranch->_tmp1->is_illegal() && opBranch->_tmp2->is_illegal() &&
opBranch->_tmp3->is_illegal() && opBranch->_tmp4->is_illegal() &&
opBranch->_tmp5->is_illegal(), "not used");
if (opBranch->_opr1->is_valid()) do_input(opBranch->_opr1);
if (opBranch->_opr2->is_valid()) do_input(opBranch->_opr2);
if (opBranch->_info != nullptr) do_info(opBranch->_info);
assert(opBranch->_result->is_illegal(), "not used");
if (opBranch->_stub != nullptr) opBranch->stub()->visit(this);
break;
}
// LIR_OpAllocObj
case lir_alloc_object:
{
assert(op->as_OpAllocObj() != nullptr, "must be");
LIR_OpAllocObj* opAllocObj = (LIR_OpAllocObj*)op;
if (opAllocObj->_info) do_info(opAllocObj->_info);
if (opAllocObj->_opr->is_valid()) { do_input(opAllocObj->_opr);
do_temp(opAllocObj->_opr);
}
if (opAllocObj->_tmp1->is_valid()) do_temp(opAllocObj->_tmp1);
if (opAllocObj->_tmp2->is_valid()) do_temp(opAllocObj->_tmp2);
if (opAllocObj->_tmp3->is_valid()) do_temp(opAllocObj->_tmp3);
if (opAllocObj->_tmp4->is_valid()) do_temp(opAllocObj->_tmp4);
if (opAllocObj->_result->is_valid()) do_output(opAllocObj->_result);
if (opAllocObj->_stub != nullptr) do_stub(opAllocObj->_stub);
break;
}
// LIR_Op2
case lir_cmp:
case lir_cmp_l2i:
case lir_ucmp_fd2i:
case lir_cmp_fd2i:
case lir_add:
case lir_sub:
case lir_rem:
case lir_logic_and:
case lir_logic_or:
case lir_logic_xor:
case lir_shl:
case lir_shr:
case lir_ushr:
case lir_xadd:
case lir_xchg:
case lir_assert:
{
assert(op->as_Op2() != nullptr, "must be");
LIR_Op2* op2 = (LIR_Op2*)op;
assert(op2->_tmp2->is_illegal() && op2->_tmp3->is_illegal() &&
op2->_tmp4->is_illegal() && op2->_tmp5->is_illegal(), "not used");
if (op2->_info) do_info(op2->_info);
if (op2->_opr1->is_valid()) do_input(op2->_opr1);
if (op2->_opr2->is_valid()) do_input(op2->_opr2);
if (op2->_tmp1->is_valid()) do_temp(op2->_tmp1);
if (op2->_result->is_valid()) do_output(op2->_result);
if (op->code() == lir_xchg || op->code() == lir_xadd) {
// on ARM and PPC, return value is loaded first so could
// destroy inputs. On other platforms that implement those
// (x86, sparc), the extra constrainsts are harmless.
if (op2->_opr1->is_valid()) do_temp(op2->_opr1);
if (op2->_opr2->is_valid()) do_temp(op2->_opr2);
}
break;
}
// special handling for cmove: right input operand must not be equal
// to the result operand, otherwise the backend fails
case lir_cmove:
{
assert(op->as_Op4() != nullptr, "must be");
LIR_Op4* op4 = (LIR_Op4*)op;
assert(op4->_info == nullptr && op4->_tmp1->is_illegal() && op4->_tmp2->is_illegal() &&
op4->_tmp3->is_illegal() && op4->_tmp4->is_illegal() && op4->_tmp5->is_illegal(), "not used");
assert(op4->_opr1->is_valid() && op4->_opr2->is_valid() && op4->_result->is_valid(), "used");
do_input(op4->_opr1);
do_input(op4->_opr2);
if (op4->_opr3->is_valid()) do_input(op4->_opr3);
if (op4->_opr4->is_valid()) do_input(op4->_opr4);
do_temp(op4->_opr2);
do_output(op4->_result);
break;
}
// vspecial handling for strict operations: register input operands
// as temp to guarantee that they do not overlap with other
// registers
case lir_mul:
case lir_div:
{
assert(op->as_Op2() != nullptr, "must be");
LIR_Op2* op2 = (LIR_Op2*)op;
assert(op2->_info == nullptr, "not used");
assert(op2->_opr1->is_valid(), "used");
assert(op2->_opr2->is_valid(), "used");
assert(op2->_result->is_valid(), "used");
assert(op2->_tmp2->is_illegal() && op2->_tmp3->is_illegal() &&
op2->_tmp4->is_illegal() && op2->_tmp5->is_illegal(), "not used");
do_input(op2->_opr1); do_temp(op2->_opr1);
do_input(op2->_opr2); do_temp(op2->_opr2);
if (op2->_tmp1->is_valid()) do_temp(op2->_tmp1);
do_output(op2->_result);
break;
}
case lir_throw: {
assert(op->as_Op2() != nullptr, "must be");
LIR_Op2* op2 = (LIR_Op2*)op;
if (op2->_info) do_info(op2->_info);
if (op2->_opr1->is_valid()) do_temp(op2->_opr1);
if (op2->_opr2->is_valid()) do_input(op2->_opr2); // exception object is input parameter
assert(op2->_result->is_illegal(), "no result");
assert(op2->_tmp2->is_illegal() && op2->_tmp3->is_illegal() &&
op2->_tmp4->is_illegal() && op2->_tmp5->is_illegal(), "not used");
break;
}
case lir_unwind: {
assert(op->as_Op1() != nullptr, "must be");
LIR_Op1* op1 = (LIR_Op1*)op;
assert(op1->_info == nullptr, "no info");
assert(op1->_opr->is_valid(), "exception oop"); do_input(op1->_opr);
assert(op1->_tmp->is_illegal(), "not used");
assert(op1->_result->is_illegal(), "no result");
break;
}
// LIR_Op3
case lir_idiv:
case lir_irem: {
assert(op->as_Op3() != nullptr, "must be");
LIR_Op3* op3= (LIR_Op3*)op;
if (op3->_info) do_info(op3->_info);
if (op3->_opr1->is_valid()) do_input(op3->_opr1);
// second operand is input and temp, so ensure that second operand
// and third operand get not the same register
if (op3->_opr2->is_valid()) do_input(op3->_opr2);
if (op3->_opr2->is_valid()) do_temp(op3->_opr2);
if (op3->_opr3->is_valid()) do_temp(op3->_opr3);
if (op3->_result->is_valid()) do_output(op3->_result);
break;
}
case lir_fmad:
case lir_fmaf: {
assert(op->as_Op3() != nullptr, "must be");
LIR_Op3* op3= (LIR_Op3*)op;
assert(op3->_info == nullptr, "no info");
do_input(op3->_opr1);
do_input(op3->_opr2);
do_input(op3->_opr3);
do_output(op3->_result);
break;
}
// LIR_OpJavaCall
case lir_static_call:
case lir_optvirtual_call:
case lir_icvirtual_call:
case lir_dynamic_call: {
LIR_OpJavaCall* opJavaCall = op->as_OpJavaCall();
assert(opJavaCall != nullptr, "must be");
if (opJavaCall->_receiver->is_valid()) do_input(opJavaCall->_receiver);
// only visit register parameters
int n = opJavaCall->_arguments->length();
for (int i = opJavaCall->_receiver->is_valid() ? 1 : 0; i < n; i++) {
if (!opJavaCall->_arguments->at(i)->is_pointer()) {
do_input(*opJavaCall->_arguments->adr_at(i));
}
}
if (opJavaCall->_info) do_info(opJavaCall->_info);
if (FrameMap::method_handle_invoke_SP_save_opr() != LIR_OprFact::illegalOpr &&
opJavaCall->is_method_handle_invoke()) {
opJavaCall->_method_handle_invoke_SP_save_opr = FrameMap::method_handle_invoke_SP_save_opr();
do_temp(opJavaCall->_method_handle_invoke_SP_save_opr);
}
do_call();
if (opJavaCall->_result->is_valid()) do_output(opJavaCall->_result);
break;
}
// LIR_OpRTCall
case lir_rtcall: {
assert(op->as_OpRTCall() != nullptr, "must be");
LIR_OpRTCall* opRTCall = (LIR_OpRTCall*)op;
// only visit register parameters
int n = opRTCall->_arguments->length();
for (int i = 0; i < n; i++) {
if (!opRTCall->_arguments->at(i)->is_pointer()) {
do_input(*opRTCall->_arguments->adr_at(i));
}
}
if (opRTCall->_info) do_info(opRTCall->_info);
if (opRTCall->_tmp->is_valid()) do_temp(opRTCall->_tmp);
do_call();
if (opRTCall->_result->is_valid()) do_output(opRTCall->_result);
break;
}
// LIR_OpArrayCopy
case lir_arraycopy: {
assert(op->as_OpArrayCopy() != nullptr, "must be");
LIR_OpArrayCopy* opArrayCopy = (LIR_OpArrayCopy*)op;
assert(opArrayCopy->_result->is_illegal(), "unused");
assert(opArrayCopy->_src->is_valid(), "used"); do_input(opArrayCopy->_src); do_temp(opArrayCopy->_src);
assert(opArrayCopy->_src_pos->is_valid(), "used"); do_input(opArrayCopy->_src_pos); do_temp(opArrayCopy->_src_pos);
assert(opArrayCopy->_dst->is_valid(), "used"); do_input(opArrayCopy->_dst); do_temp(opArrayCopy->_dst);
assert(opArrayCopy->_dst_pos->is_valid(), "used"); do_input(opArrayCopy->_dst_pos); do_temp(opArrayCopy->_dst_pos);
assert(opArrayCopy->_length->is_valid(), "used"); do_input(opArrayCopy->_length); do_temp(opArrayCopy->_length);
assert(opArrayCopy->_tmp->is_valid(), "used"); do_temp(opArrayCopy->_tmp);
if (opArrayCopy->_info) do_info(opArrayCopy->_info);
// the implementation of arraycopy always has a call into the runtime
do_call();
break;
}
// LIR_OpUpdateCRC32
case lir_updatecrc32: {
assert(op->as_OpUpdateCRC32() != nullptr, "must be");
LIR_OpUpdateCRC32* opUp = (LIR_OpUpdateCRC32*)op;
assert(opUp->_crc->is_valid(), "used"); do_input(opUp->_crc); do_temp(opUp->_crc);
assert(opUp->_val->is_valid(), "used"); do_input(opUp->_val); do_temp(opUp->_val);
assert(opUp->_result->is_valid(), "used"); do_output(opUp->_result);
assert(opUp->_info == nullptr, "no info for LIR_OpUpdateCRC32");
break;
}
// LIR_OpLock
case lir_lock:
case lir_unlock: {
assert(op->as_OpLock() != nullptr, "must be");
LIR_OpLock* opLock = (LIR_OpLock*)op;
if (opLock->_info) do_info(opLock->_info);
// TODO: check if these operands really have to be temp
// (or if input is sufficient). This may have influence on the oop map!
assert(opLock->_lock->is_valid(), "used"); do_temp(opLock->_lock);
assert(opLock->_hdr->is_valid(), "used"); do_temp(opLock->_hdr);
assert(opLock->_obj->is_valid(), "used"); do_temp(opLock->_obj);
if (opLock->_scratch->is_valid()) do_temp(opLock->_scratch);
assert(opLock->_result->is_illegal(), "unused");
do_stub(opLock->_stub);
break;
}
// LIR_OpDelay
case lir_delay_slot: {
assert(op->as_OpDelay() != nullptr, "must be");
LIR_OpDelay* opDelay = (LIR_OpDelay*)op;
visit(opDelay->delay_op());
break;
}
// LIR_OpTypeCheck
case lir_instanceof:
case lir_checkcast:
case lir_store_check: {
assert(op->as_OpTypeCheck() != nullptr, "must be");
LIR_OpTypeCheck* opTypeCheck = (LIR_OpTypeCheck*)op;
if (opTypeCheck->_info_for_exception) do_info(opTypeCheck->_info_for_exception);
if (opTypeCheck->_info_for_patch) do_info(opTypeCheck->_info_for_patch);
if (opTypeCheck->_object->is_valid()) do_input(opTypeCheck->_object);
if (op->code() == lir_store_check && opTypeCheck->_object->is_valid()) {
do_temp(opTypeCheck->_object);
}
if (opTypeCheck->_array->is_valid()) do_input(opTypeCheck->_array);
if (opTypeCheck->_tmp1->is_valid()) do_temp(opTypeCheck->_tmp1);
if (opTypeCheck->_tmp2->is_valid()) do_temp(opTypeCheck->_tmp2);
if (opTypeCheck->_tmp3->is_valid()) do_temp(opTypeCheck->_tmp3);
if (opTypeCheck->_result->is_valid()) do_output(opTypeCheck->_result);
if (opTypeCheck->_stub != nullptr) do_stub(opTypeCheck->_stub);
break;
}
// LIR_OpCompareAndSwap
case lir_cas_long:
case lir_cas_obj:
case lir_cas_int: {
assert(op->as_OpCompareAndSwap() != nullptr, "must be");
LIR_OpCompareAndSwap* opCmpAndSwap = (LIR_OpCompareAndSwap*)op;
if (opCmpAndSwap->_info) do_info(opCmpAndSwap->_info);
assert(opCmpAndSwap->_addr->is_valid(), "used"); do_input(opCmpAndSwap->_addr);
do_temp(opCmpAndSwap->_addr);
assert(opCmpAndSwap->_cmp_value->is_valid(), "used"); do_input(opCmpAndSwap->_cmp_value);
do_temp(opCmpAndSwap->_cmp_value);
assert(opCmpAndSwap->_new_value->is_valid(), "used"); do_input(opCmpAndSwap->_new_value);
do_temp(opCmpAndSwap->_new_value);
if (opCmpAndSwap->_tmp1->is_valid()) do_temp(opCmpAndSwap->_tmp1);
if (opCmpAndSwap->_tmp2->is_valid()) do_temp(opCmpAndSwap->_tmp2);
if (opCmpAndSwap->_result->is_valid()) do_output(opCmpAndSwap->_result);
break;
}
// LIR_OpAllocArray;
case lir_alloc_array: {
assert(op->as_OpAllocArray() != nullptr, "must be");
LIR_OpAllocArray* opAllocArray = (LIR_OpAllocArray*)op;
if (opAllocArray->_info) do_info(opAllocArray->_info);
if (opAllocArray->_klass->is_valid()) { do_input(opAllocArray->_klass);
do_temp(opAllocArray->_klass);
}
if (opAllocArray->_len->is_valid()) { do_input(opAllocArray->_len);
do_temp(opAllocArray->_len);
}
if (opAllocArray->_tmp1->is_valid()) do_temp(opAllocArray->_tmp1);
if (opAllocArray->_tmp2->is_valid()) do_temp(opAllocArray->_tmp2);
if (opAllocArray->_tmp3->is_valid()) do_temp(opAllocArray->_tmp3);
if (opAllocArray->_tmp4->is_valid()) do_temp(opAllocArray->_tmp4);
if (opAllocArray->_result->is_valid()) do_output(opAllocArray->_result);
if (opAllocArray->_stub != nullptr) do_stub(opAllocArray->_stub);
break;
}
// LIR_OpLoadKlass
case lir_load_klass:
{
LIR_OpLoadKlass* opLoadKlass = op->as_OpLoadKlass();
assert(opLoadKlass != nullptr, "must be");
do_input(opLoadKlass->_obj);
do_output(opLoadKlass->_result);
if (opLoadKlass->_info) do_info(opLoadKlass->_info);
break;
}
// LIR_OpProfileCall:
case lir_profile_call: {
assert(op->as_OpProfileCall() != nullptr, "must be");
LIR_OpProfileCall* opProfileCall = (LIR_OpProfileCall*)op;
if (opProfileCall->_recv->is_valid()) do_temp(opProfileCall->_recv);
assert(opProfileCall->_mdo->is_valid(), "used"); do_temp(opProfileCall->_mdo);
assert(opProfileCall->_tmp1->is_valid(), "used"); do_temp(opProfileCall->_tmp1);
break;
}
// LIR_OpProfileType:
case lir_profile_type: {
assert(op->as_OpProfileType() != nullptr, "must be");
LIR_OpProfileType* opProfileType = (LIR_OpProfileType*)op;
do_input(opProfileType->_mdp); do_temp(opProfileType->_mdp);
do_input(opProfileType->_obj);
do_temp(opProfileType->_tmp);
break;
}
default:
op->visit(this);
}
}
void LIR_Op::visit(LIR_OpVisitState* state) {
ShouldNotReachHere();
}
void LIR_OpVisitState::do_stub(CodeStub* stub) {
if (stub != nullptr) {
stub->visit(this);
}
}
XHandlers* LIR_OpVisitState::all_xhandler() {
XHandlers* result = nullptr;
int i;
for (i = 0; i < info_count(); i++) {
if (info_at(i)->exception_handlers() != nullptr) {
result = info_at(i)->exception_handlers();
break;
}
}
#ifdef ASSERT
for (i = 0; i < info_count(); i++) {
assert(info_at(i)->exception_handlers() == nullptr ||
info_at(i)->exception_handlers() == result,
"only one xhandler list allowed per LIR-operation");
}
#endif
if (result != nullptr) {
return result;
} else {
return new XHandlers();
}
return result;
}
#ifdef ASSERT
bool LIR_OpVisitState::no_operands(LIR_Op* op) {
visit(op);
return opr_count(inputMode) == 0 &&
opr_count(outputMode) == 0 &&
opr_count(tempMode) == 0 &&
info_count() == 0 &&
!has_call() &&
!has_slow_case();
}
#endif
// LIR_OpReturn
LIR_OpReturn::LIR_OpReturn(LIR_Opr opr) :
LIR_Op1(lir_return, opr, (CodeEmitInfo*)nullptr /* info */),
_stub(nullptr) {
if (VM_Version::supports_stack_watermark_barrier()) {
_stub = new C1SafepointPollStub();
}
}
//---------------------------------------------------
void LIR_OpJavaCall::emit_code(LIR_Assembler* masm) {
masm->emit_call(this);
}
void LIR_OpRTCall::emit_code(LIR_Assembler* masm) {
masm->emit_rtcall(this);
}
void LIR_OpLabel::emit_code(LIR_Assembler* masm) {
masm->emit_opLabel(this);
}
void LIR_OpArrayCopy::emit_code(LIR_Assembler* masm) {
masm->emit_arraycopy(this);
ArrayCopyStub* code_stub = stub();
if (code_stub != nullptr) {
masm->append_code_stub(code_stub);
}
}
void LIR_OpUpdateCRC32::emit_code(LIR_Assembler* masm) {
masm->emit_updatecrc32(this);