1 /*
2 * Copyright (c) 2000, 2021, 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 *
852 // - every instruction has a result operand
853 // - every instruction has an CodeEmitInfo operand (can be revisited later)
854 // - every instruction has a LIR_OpCode operand
855 // - LIR_OpN, means an instruction that has N input operands
856 //
857 // class hierarchy:
858 //
859 class LIR_Op;
860 class LIR_Op0;
861 class LIR_OpLabel;
862 class LIR_Op1;
863 class LIR_OpBranch;
864 class LIR_OpConvert;
865 class LIR_OpAllocObj;
866 class LIR_OpReturn;
867 class LIR_OpRoundFP;
868 class LIR_Op2;
869 class LIR_OpDelay;
870 class LIR_Op3;
871 class LIR_OpAllocArray;
872 class LIR_OpCall;
873 class LIR_OpJavaCall;
874 class LIR_OpRTCall;
875 class LIR_OpArrayCopy;
876 class LIR_OpUpdateCRC32;
877 class LIR_OpLock;
878 class LIR_OpTypeCheck;
879 class LIR_OpCompareAndSwap;
880 class LIR_OpProfileCall;
881 class LIR_OpProfileType;
882 #ifdef ASSERT
883 class LIR_OpAssert;
884 #endif
885
886 // LIR operation codes
887 enum LIR_Code {
888 lir_none
889 , begin_op0
890 , lir_label
891 , lir_nop
896 , lir_breakpoint
897 , lir_rtcall
898 , lir_membar
899 , lir_membar_acquire
900 , lir_membar_release
901 , lir_membar_loadload
902 , lir_membar_storestore
903 , lir_membar_loadstore
904 , lir_membar_storeload
905 , lir_get_thread
906 , lir_on_spin_wait
907 , end_op0
908 , begin_op1
909 , lir_fxch
910 , lir_fld
911 , lir_push
912 , lir_pop
913 , lir_null_check
914 , lir_return
915 , lir_leal
916 , lir_branch
917 , lir_cond_float_branch
918 , lir_move
919 , lir_convert
920 , lir_alloc_object
921 , lir_monaddr
922 , lir_roundfp
923 , lir_safepoint
924 , lir_unwind
925 , end_op1
926 , begin_op2
927 , lir_cmp
928 , lir_cmp_l2i
929 , lir_ucmp_fd2i
930 , lir_cmp_fd2i
931 , lir_cmove
932 , lir_add
933 , lir_sub
934 , lir_mul
935 , lir_div
936 , lir_rem
937 , lir_sqrt
938 , lir_abs
939 , lir_neg
940 , lir_tan
941 , lir_log10
942 , lir_logic_and
943 , lir_logic_or
944 , lir_logic_xor
945 , lir_shl
946 , lir_shr
947 , lir_ushr
948 , lir_alloc_array
949 , lir_throw
950 , lir_xadd
951 , lir_xchg
952 , end_op2
953 , begin_op3
954 , lir_idiv
955 , lir_irem
956 , lir_fmad
957 , lir_fmaf
958 , end_op3
959 , begin_opJavaCall
960 , lir_static_call
961 , lir_optvirtual_call
962 , lir_icvirtual_call
963 , lir_dynamic_call
964 , end_opJavaCall
965 , begin_opArrayCopy
966 , lir_arraycopy
967 , end_opArrayCopy
968 , begin_opUpdateCRC32
969 , lir_updatecrc32
970 , end_opUpdateCRC32
971 , begin_opLock
972 , lir_lock
973 , lir_unlock
974 , end_opLock
975 , begin_delay_slot
976 , lir_delay_slot
977 , end_delay_slot
978 , begin_opTypeCheck
979 , lir_instanceof
980 , lir_checkcast
981 , lir_store_check
982 , end_opTypeCheck
983 , begin_opCompareAndSwap
984 , lir_cas_long
985 , lir_cas_obj
986 , lir_cas_int
987 , end_opCompareAndSwap
988 , begin_opMDOProfile
989 , lir_profile_call
990 , lir_profile_type
991 , end_opMDOProfile
992 , begin_opAssert
993 , lir_assert
994 , end_opAssert
995 };
996
997
998 enum LIR_Condition {
999 lir_cond_equal
1000 , lir_cond_notEqual
1001 , lir_cond_less
1002 , lir_cond_lessEqual
1003 , lir_cond_greaterEqual
1004 , lir_cond_greater
1005 , lir_cond_belowEqual
1006 , lir_cond_aboveEqual
1007 , lir_cond_always
1008 , lir_cond_unknown = -1
1009 };
1010
1011
1012 enum LIR_PatchCode {
1013 lir_patch_none,
1014 lir_patch_low,
1111 virtual void print_instr(outputStream* out) const = 0;
1112 virtual void print_on(outputStream* st) const PRODUCT_RETURN;
1113
1114 virtual bool is_patching() { return false; }
1115 virtual LIR_OpCall* as_OpCall() { return NULL; }
1116 virtual LIR_OpJavaCall* as_OpJavaCall() { return NULL; }
1117 virtual LIR_OpLabel* as_OpLabel() { return NULL; }
1118 virtual LIR_OpDelay* as_OpDelay() { return NULL; }
1119 virtual LIR_OpLock* as_OpLock() { return NULL; }
1120 virtual LIR_OpAllocArray* as_OpAllocArray() { return NULL; }
1121 virtual LIR_OpAllocObj* as_OpAllocObj() { return NULL; }
1122 virtual LIR_OpRoundFP* as_OpRoundFP() { return NULL; }
1123 virtual LIR_OpBranch* as_OpBranch() { return NULL; }
1124 virtual LIR_OpReturn* as_OpReturn() { return NULL; }
1125 virtual LIR_OpRTCall* as_OpRTCall() { return NULL; }
1126 virtual LIR_OpConvert* as_OpConvert() { return NULL; }
1127 virtual LIR_Op0* as_Op0() { return NULL; }
1128 virtual LIR_Op1* as_Op1() { return NULL; }
1129 virtual LIR_Op2* as_Op2() { return NULL; }
1130 virtual LIR_Op3* as_Op3() { return NULL; }
1131 virtual LIR_OpArrayCopy* as_OpArrayCopy() { return NULL; }
1132 virtual LIR_OpUpdateCRC32* as_OpUpdateCRC32() { return NULL; }
1133 virtual LIR_OpTypeCheck* as_OpTypeCheck() { return NULL; }
1134 virtual LIR_OpCompareAndSwap* as_OpCompareAndSwap() { return NULL; }
1135 virtual LIR_OpProfileCall* as_OpProfileCall() { return NULL; }
1136 virtual LIR_OpProfileType* as_OpProfileType() { return NULL; }
1137 #ifdef ASSERT
1138 virtual LIR_OpAssert* as_OpAssert() { return NULL; }
1139 #endif
1140
1141 virtual void verify() const {}
1142 };
1143
1144 // for calls
1145 class LIR_OpCall: public LIR_Op {
1146 friend class LIR_OpVisitState;
1147
1148 protected:
1149 address _addr;
1150 LIR_OprList* _arguments;
1382 class LIR_OpRTCall: public LIR_OpCall {
1383 friend class LIR_OpVisitState;
1384
1385 private:
1386 LIR_Opr _tmp;
1387 public:
1388 LIR_OpRTCall(address addr, LIR_Opr tmp,
1389 LIR_Opr result, LIR_OprList* arguments, CodeEmitInfo* info = NULL)
1390 : LIR_OpCall(lir_rtcall, addr, result, arguments, info)
1391 , _tmp(tmp) {}
1392
1393 virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1394 virtual void emit_code(LIR_Assembler* masm);
1395 virtual LIR_OpRTCall* as_OpRTCall() { return this; }
1396
1397 LIR_Opr tmp() const { return _tmp; }
1398
1399 virtual void verify() const;
1400 };
1401
1402
1403 class LIR_OpBranch: public LIR_Op {
1404 friend class LIR_OpVisitState;
1405
1406 private:
1407 LIR_Condition _cond;
1408 Label* _label;
1409 BlockBegin* _block; // if this is a branch to a block, this is the block
1410 BlockBegin* _ublock; // if this is a float-branch, this is the unorderd block
1411 CodeStub* _stub; // if this is a branch to a stub, this is the stub
1412
1413 public:
1414 LIR_OpBranch(LIR_Condition cond, Label* lbl)
1415 : LIR_Op(lir_branch, LIR_OprFact::illegalOpr, (CodeEmitInfo*) NULL)
1416 , _cond(cond)
1417 , _label(lbl)
1418 , _block(NULL)
1419 , _ublock(NULL)
1420 , _stub(NULL) { }
1421
1422 LIR_OpBranch(LIR_Condition cond, BlockBegin* block);
1423 LIR_OpBranch(LIR_Condition cond, CodeStub* stub);
1424
1425 // for unordered comparisons
1426 LIR_OpBranch(LIR_Condition cond, BlockBegin* block, BlockBegin* ublock);
1427
1428 LIR_Condition cond() const { return _cond; }
1429 Label* label() const { return _label; }
1430 BlockBegin* block() const { return _block; }
1431 BlockBegin* ublock() const { return _ublock; }
1432 CodeStub* stub() const { return _stub; }
1433
1434 void change_block(BlockBegin* b);
1435 void change_ublock(BlockBegin* b);
1436 void negate_cond();
1437
1438 virtual void emit_code(LIR_Assembler* masm);
1439 virtual LIR_OpBranch* as_OpBranch() { return this; }
1440 virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1441 };
1442
1443 class LIR_OpReturn: public LIR_Op1 {
1444 friend class LIR_OpVisitState;
1445
1446 private:
1447 C1SafepointPollStub* _stub;
1448
1449 public:
1450 LIR_OpReturn(LIR_Opr opr);
1451
1452 C1SafepointPollStub* stub() const { return _stub; }
1453 virtual LIR_OpReturn* as_OpReturn() { return this; }
1454 };
1455
1456 class ConversionStub;
1457
1458 class LIR_OpConvert: public LIR_Op1 {
1459 friend class LIR_OpVisitState;
1460
1461 private:
1462 Bytecodes::Code _bytecode;
1595 // LIR_Op2
1596 class LIR_Op2: public LIR_Op {
1597 friend class LIR_OpVisitState;
1598
1599 int _fpu_stack_size; // for sin/cos implementation on Intel
1600
1601 protected:
1602 LIR_Opr _opr1;
1603 LIR_Opr _opr2;
1604 BasicType _type;
1605 LIR_Opr _tmp1;
1606 LIR_Opr _tmp2;
1607 LIR_Opr _tmp3;
1608 LIR_Opr _tmp4;
1609 LIR_Opr _tmp5;
1610 LIR_Condition _condition;
1611
1612 void verify() const;
1613
1614 public:
1615 LIR_Op2(LIR_Code code, LIR_Condition condition, LIR_Opr opr1, LIR_Opr opr2, CodeEmitInfo* info = NULL)
1616 : LIR_Op(code, LIR_OprFact::illegalOpr, info)
1617 , _fpu_stack_size(0)
1618 , _opr1(opr1)
1619 , _opr2(opr2)
1620 , _type(T_ILLEGAL)
1621 , _tmp1(LIR_OprFact::illegalOpr)
1622 , _tmp2(LIR_OprFact::illegalOpr)
1623 , _tmp3(LIR_OprFact::illegalOpr)
1624 , _tmp4(LIR_OprFact::illegalOpr)
1625 , _tmp5(LIR_OprFact::illegalOpr)
1626 , _condition(condition) {
1627 assert(code == lir_cmp || code == lir_assert, "code check");
1628 }
1629
1630 LIR_Op2(LIR_Code code, LIR_Condition condition, LIR_Opr opr1, LIR_Opr opr2, LIR_Opr result, BasicType type)
1631 : LIR_Op(code, result, NULL)
1632 , _fpu_stack_size(0)
1633 , _opr1(opr1)
1634 , _opr2(opr2)
1635 , _type(type)
1636 , _tmp1(LIR_OprFact::illegalOpr)
1637 , _tmp2(LIR_OprFact::illegalOpr)
1638 , _tmp3(LIR_OprFact::illegalOpr)
1639 , _tmp4(LIR_OprFact::illegalOpr)
1640 , _tmp5(LIR_OprFact::illegalOpr)
1641 , _condition(condition) {
1642 assert(code == lir_cmove, "code check");
1643 assert(type != T_ILLEGAL, "cmove should have type");
1644 }
1645
1646 LIR_Op2(LIR_Code code, LIR_Opr opr1, LIR_Opr opr2, LIR_Opr result = LIR_OprFact::illegalOpr,
1647 CodeEmitInfo* info = NULL, BasicType type = T_ILLEGAL)
1648 : LIR_Op(code, result, info)
1649 , _fpu_stack_size(0)
1650 , _opr1(opr1)
1651 , _opr2(opr2)
1652 , _type(type)
1653 , _tmp1(LIR_OprFact::illegalOpr)
1654 , _tmp2(LIR_OprFact::illegalOpr)
1655 , _tmp3(LIR_OprFact::illegalOpr)
1656 , _tmp4(LIR_OprFact::illegalOpr)
1657 , _tmp5(LIR_OprFact::illegalOpr)
1658 , _condition(lir_cond_unknown) {
1659 assert(code != lir_cmp && is_in_range(code, begin_op2, end_op2), "code check");
1660 }
1661
1662 LIR_Op2(LIR_Code code, LIR_Opr opr1, LIR_Opr opr2, LIR_Opr result, LIR_Opr tmp1, LIR_Opr tmp2 = LIR_OprFact::illegalOpr,
1663 LIR_Opr tmp3 = LIR_OprFact::illegalOpr, LIR_Opr tmp4 = LIR_OprFact::illegalOpr, LIR_Opr tmp5 = LIR_OprFact::illegalOpr)
1664 : LIR_Op(code, result, NULL)
1665 , _fpu_stack_size(0)
1666 , _opr1(opr1)
1667 , _opr2(opr2)
1668 , _type(T_ILLEGAL)
1669 , _tmp1(tmp1)
1670 , _tmp2(tmp2)
1671 , _tmp3(tmp3)
1672 , _tmp4(tmp4)
1673 , _tmp5(tmp5)
1674 , _condition(lir_cond_unknown) {
1675 assert(code != lir_cmp && is_in_range(code, begin_op2, end_op2), "code check");
1676 }
1677
1678 LIR_Opr in_opr1() const { return _opr1; }
1679 LIR_Opr in_opr2() const { return _opr2; }
1680 BasicType type() const { return _type; }
1681 LIR_Opr tmp1_opr() const { return _tmp1; }
1682 LIR_Opr tmp2_opr() const { return _tmp2; }
1683 LIR_Opr tmp3_opr() const { return _tmp3; }
1684 LIR_Opr tmp4_opr() const { return _tmp4; }
1685 LIR_Opr tmp5_opr() const { return _tmp5; }
1686 LIR_Condition condition() const {
1687 assert(code() == lir_cmp || code() == lir_cmove || code() == lir_assert, "only valid for cmp and cmove and assert"); return _condition;
1688 }
1689 void set_condition(LIR_Condition condition) {
1690 assert(code() == lir_cmp || code() == lir_cmove, "only valid for cmp and cmove"); _condition = condition;
1691 }
1692
1693 void set_fpu_stack_size(int size) { _fpu_stack_size = size; }
1694 int fpu_stack_size() const { return _fpu_stack_size; }
1695
1696 void set_in_opr1(LIR_Opr opr) { _opr1 = opr; }
1697 void set_in_opr2(LIR_Opr opr) { _opr2 = opr; }
1698
1699 virtual void emit_code(LIR_Assembler* masm);
1700 virtual LIR_Op2* as_Op2() { return this; }
1701 virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1702 };
1703
1704 class LIR_OpAllocArray : public LIR_Op {
1705 friend class LIR_OpVisitState;
1706
1707 private:
1708 LIR_Opr _klass;
1709 LIR_Opr _len;
1710 LIR_Opr _tmp1;
1711 LIR_Opr _tmp2;
1712 LIR_Opr _tmp3;
1713 LIR_Opr _tmp4;
1714 BasicType _type;
1715 CodeStub* _stub;
1716
1717 public:
1718 LIR_OpAllocArray(LIR_Opr klass, LIR_Opr len, LIR_Opr result, LIR_Opr t1, LIR_Opr t2, LIR_Opr t3, LIR_Opr t4, BasicType type, CodeStub* stub)
1719 : LIR_Op(lir_alloc_array, result, NULL)
1720 , _klass(klass)
1721 , _len(len)
1722 , _tmp1(t1)
1723 , _tmp2(t2)
1747
1748 private:
1749 LIR_Opr _opr1;
1750 LIR_Opr _opr2;
1751 LIR_Opr _opr3;
1752 public:
1753 LIR_Op3(LIR_Code code, LIR_Opr opr1, LIR_Opr opr2, LIR_Opr opr3, LIR_Opr result, CodeEmitInfo* info = NULL)
1754 : LIR_Op(code, result, info)
1755 , _opr1(opr1)
1756 , _opr2(opr2)
1757 , _opr3(opr3) { assert(is_in_range(code, begin_op3, end_op3), "code check"); }
1758 LIR_Opr in_opr1() const { return _opr1; }
1759 LIR_Opr in_opr2() const { return _opr2; }
1760 LIR_Opr in_opr3() const { return _opr3; }
1761
1762 virtual void emit_code(LIR_Assembler* masm);
1763 virtual LIR_Op3* as_Op3() { return this; }
1764 virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1765 };
1766
1767
1768 //--------------------------------
1769 class LabelObj: public CompilationResourceObj {
1770 private:
1771 Label _label;
1772 public:
1773 LabelObj() {}
1774 Label* label() { return &_label; }
1775 };
1776
1777
1778 class LIR_OpLock: public LIR_Op {
1779 friend class LIR_OpVisitState;
1780
1781 private:
1782 LIR_Opr _hdr;
1783 LIR_Opr _obj;
1784 LIR_Opr _lock;
1785 LIR_Opr _scratch;
1786 CodeStub* _stub;
1969 //--------------------------------LIR_List---------------------------------------------------
1970 // Maintains a list of LIR instructions (one instance of LIR_List per basic block)
1971 // The LIR instructions are appended by the LIR_List class itself;
1972 //
1973 // Notes:
1974 // - all offsets are(should be) in bytes
1975 // - local positions are specified with an offset, with offset 0 being local 0
1976
1977 class LIR_List: public CompilationResourceObj {
1978 private:
1979 LIR_OpList _operations;
1980
1981 Compilation* _compilation;
1982 #ifndef PRODUCT
1983 BlockBegin* _block;
1984 #endif
1985 #ifdef ASSERT
1986 const char * _file;
1987 int _line;
1988 #endif
1989
1990 public:
1991 void append(LIR_Op* op) {
1992 if (op->source() == NULL)
1993 op->set_source(_compilation->current_instruction());
1994 #ifndef PRODUCT
1995 if (PrintIRWithLIR) {
1996 _compilation->maybe_print_current_instruction();
1997 op->print(); tty->cr();
1998 }
1999 #endif // PRODUCT
2000
2001 _operations.append(op);
2002
2003 #ifdef ASSERT
2004 op->verify();
2005 op->set_file_and_line(_file, _line);
2006 _file = NULL;
2007 _line = 0;
2008 #endif
2009 }
2010
2011 LIR_List(Compilation* compilation, BlockBegin* block = NULL);
2012
2013 #ifdef ASSERT
2014 void set_file_and_line(const char * file, int line);
2015 #endif
2016
2017 //---------- accessors ---------------
2018 LIR_OpList* instructions_list() { return &_operations; }
2019 int length() const { return _operations.length(); }
2020 LIR_Op* at(int i) const { return _operations.at(i); }
2021
2022 NOT_PRODUCT(BlockBegin* block() const { return _block; });
2023
2024 // insert LIR_Ops in buffer to right places in LIR_List
2025 void append(LIR_InsertionBuffer* buffer);
2026
2027 //---------- mutators ---------------
2028 void insert_before(int i, LIR_List* op_list) { _operations.insert_before(i, op_list->instructions_list()); }
2029 void insert_before(int i, LIR_Op* op) { _operations.insert_before(i, op); }
2030 void remove_at(int i) { _operations.remove_at(i); }
2031
2032 //---------- printing -------------
2033 void print_instructions() PRODUCT_RETURN;
2034
2035
2036 //---------- instructions -------------
2116 void throw_exception(LIR_Opr exceptionPC, LIR_Opr exceptionOop, CodeEmitInfo* info) {
2117 append(new LIR_Op2(lir_throw, exceptionPC, exceptionOop, LIR_OprFact::illegalOpr, info));
2118 }
2119 void unwind_exception(LIR_Opr exceptionOop) {
2120 append(new LIR_Op1(lir_unwind, exceptionOop));
2121 }
2122
2123 void push(LIR_Opr opr) { append(new LIR_Op1(lir_push, opr)); }
2124 void pop(LIR_Opr reg) { append(new LIR_Op1(lir_pop, reg)); }
2125
2126 void cmp(LIR_Condition condition, LIR_Opr left, LIR_Opr right, CodeEmitInfo* info = NULL) {
2127 append(new LIR_Op2(lir_cmp, condition, left, right, info));
2128 }
2129 void cmp(LIR_Condition condition, LIR_Opr left, int right, CodeEmitInfo* info = NULL) {
2130 cmp(condition, left, LIR_OprFact::intConst(right), info);
2131 }
2132
2133 void cmp_mem_int(LIR_Condition condition, LIR_Opr base, int disp, int c, CodeEmitInfo* info);
2134 void cmp_reg_mem(LIR_Condition condition, LIR_Opr reg, LIR_Address* addr, CodeEmitInfo* info);
2135
2136 void cmove(LIR_Condition condition, LIR_Opr src1, LIR_Opr src2, LIR_Opr dst, BasicType type) {
2137 append(new LIR_Op2(lir_cmove, condition, src1, src2, dst, type));
2138 }
2139
2140 void cas_long(LIR_Opr addr, LIR_Opr cmp_value, LIR_Opr new_value,
2141 LIR_Opr t1, LIR_Opr t2, LIR_Opr result = LIR_OprFact::illegalOpr);
2142 void cas_obj(LIR_Opr addr, LIR_Opr cmp_value, LIR_Opr new_value,
2143 LIR_Opr t1, LIR_Opr t2, LIR_Opr result = LIR_OprFact::illegalOpr);
2144 void cas_int(LIR_Opr addr, LIR_Opr cmp_value, LIR_Opr new_value,
2145 LIR_Opr t1, LIR_Opr t2, LIR_Opr result = LIR_OprFact::illegalOpr);
2146
2147 void abs (LIR_Opr from, LIR_Opr to, LIR_Opr tmp) { append(new LIR_Op2(lir_abs , from, tmp, to)); }
2148 void negate(LIR_Opr from, LIR_Opr to, LIR_Opr tmp = LIR_OprFact::illegalOpr) { append(new LIR_Op2(lir_neg, from, tmp, to)); }
2149 void sqrt(LIR_Opr from, LIR_Opr to, LIR_Opr tmp) { append(new LIR_Op2(lir_sqrt, from, tmp, to)); }
2150 void fmad(LIR_Opr from, LIR_Opr from1, LIR_Opr from2, LIR_Opr to) { append(new LIR_Op3(lir_fmad, from, from1, from2, to)); }
2151 void fmaf(LIR_Opr from, LIR_Opr from1, LIR_Opr from2, LIR_Opr to) { append(new LIR_Op3(lir_fmaf, from, from1, from2, to)); }
2152 void log10 (LIR_Opr from, LIR_Opr to, LIR_Opr tmp) { append(new LIR_Op2(lir_log10, from, LIR_OprFact::illegalOpr, to, tmp)); }
2153 void tan (LIR_Opr from, LIR_Opr to, LIR_Opr tmp1, LIR_Opr tmp2) { append(new LIR_Op2(lir_tan , from, tmp1, to, tmp2)); }
2154
2155 void add (LIR_Opr left, LIR_Opr right, LIR_Opr res) { append(new LIR_Op2(lir_add, left, right, res)); }
2156 void sub (LIR_Opr left, LIR_Opr right, LIR_Opr res, CodeEmitInfo* info = NULL) { append(new LIR_Op2(lir_sub, left, right, res, info)); }
2157 void mul (LIR_Opr left, LIR_Opr right, LIR_Opr res) { append(new LIR_Op2(lir_mul, left, right, res)); }
2158 void mul (LIR_Opr left, LIR_Opr right, LIR_Opr res, LIR_Opr tmp) { append(new LIR_Op2(lir_mul, left, right, res, tmp)); }
|
1 /*
2 * Copyright (c) 2000, 2022, 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 *
852 // - every instruction has a result operand
853 // - every instruction has an CodeEmitInfo operand (can be revisited later)
854 // - every instruction has a LIR_OpCode operand
855 // - LIR_OpN, means an instruction that has N input operands
856 //
857 // class hierarchy:
858 //
859 class LIR_Op;
860 class LIR_Op0;
861 class LIR_OpLabel;
862 class LIR_Op1;
863 class LIR_OpBranch;
864 class LIR_OpConvert;
865 class LIR_OpAllocObj;
866 class LIR_OpReturn;
867 class LIR_OpRoundFP;
868 class LIR_Op2;
869 class LIR_OpDelay;
870 class LIR_Op3;
871 class LIR_OpAllocArray;
872 #ifdef RISCV
873 class LIR_Op4;
874 #endif
875 class LIR_OpCall;
876 class LIR_OpJavaCall;
877 class LIR_OpRTCall;
878 class LIR_OpArrayCopy;
879 class LIR_OpUpdateCRC32;
880 class LIR_OpLock;
881 class LIR_OpTypeCheck;
882 class LIR_OpCompareAndSwap;
883 class LIR_OpProfileCall;
884 class LIR_OpProfileType;
885 #ifdef ASSERT
886 class LIR_OpAssert;
887 #endif
888
889 // LIR operation codes
890 enum LIR_Code {
891 lir_none
892 , begin_op0
893 , lir_label
894 , lir_nop
899 , lir_breakpoint
900 , lir_rtcall
901 , lir_membar
902 , lir_membar_acquire
903 , lir_membar_release
904 , lir_membar_loadload
905 , lir_membar_storestore
906 , lir_membar_loadstore
907 , lir_membar_storeload
908 , lir_get_thread
909 , lir_on_spin_wait
910 , end_op0
911 , begin_op1
912 , lir_fxch
913 , lir_fld
914 , lir_push
915 , lir_pop
916 , lir_null_check
917 , lir_return
918 , lir_leal
919 #ifndef RISCV
920 , lir_branch
921 , lir_cond_float_branch
922 #endif
923 , lir_move
924 , lir_convert
925 , lir_alloc_object
926 , lir_monaddr
927 , lir_roundfp
928 , lir_safepoint
929 , lir_unwind
930 , end_op1
931 , begin_op2
932 #ifdef RISCV
933 , lir_branch
934 , lir_cond_float_branch
935 #endif
936 , lir_cmp
937 , lir_cmp_l2i
938 , lir_ucmp_fd2i
939 , lir_cmp_fd2i
940 #ifndef RISCV
941 , lir_cmove
942 #endif
943 , lir_add
944 , lir_sub
945 , lir_mul
946 , lir_div
947 , lir_rem
948 , lir_sqrt
949 , lir_abs
950 , lir_neg
951 , lir_tan
952 , lir_log10
953 , lir_logic_and
954 , lir_logic_or
955 , lir_logic_xor
956 , lir_shl
957 , lir_shr
958 , lir_ushr
959 , lir_alloc_array
960 , lir_throw
961 , lir_xadd
962 , lir_xchg
963 , end_op2
964 , begin_op3
965 , lir_idiv
966 , lir_irem
967 , lir_fmad
968 , lir_fmaf
969 , end_op3
970 #ifdef RISCV
971 , begin_op4
972 , lir_cmove
973 , end_op4
974 #endif
975 , begin_opJavaCall
976 , lir_static_call
977 , lir_optvirtual_call
978 , lir_icvirtual_call
979 , lir_dynamic_call
980 , end_opJavaCall
981 , begin_opArrayCopy
982 , lir_arraycopy
983 , end_opArrayCopy
984 , begin_opUpdateCRC32
985 , lir_updatecrc32
986 , end_opUpdateCRC32
987 , begin_opLock
988 , lir_lock
989 , lir_unlock
990 , end_opLock
991 , begin_delay_slot
992 , lir_delay_slot
993 , end_delay_slot
994 , begin_opTypeCheck
995 , lir_instanceof
996 , lir_checkcast
997 , lir_store_check
998 , end_opTypeCheck
999 , begin_opCompareAndSwap
1000 , lir_cas_long
1001 , lir_cas_obj
1002 , lir_cas_int
1003 , end_opCompareAndSwap
1004 , begin_opMDOProfile
1005 , lir_profile_call
1006 , lir_profile_type
1007 , end_opMDOProfile
1008 , begin_opAssert
1009 , lir_assert
1010 , end_opAssert
1011 #if defined(RISCV) && defined(INCLUDE_ZGC)
1012 , begin_opZLoadBarrierTest
1013 , lir_zloadbarrier_test
1014 , end_opZLoadBarrierTest
1015 #endif
1016 };
1017
1018
1019 enum LIR_Condition {
1020 lir_cond_equal
1021 , lir_cond_notEqual
1022 , lir_cond_less
1023 , lir_cond_lessEqual
1024 , lir_cond_greaterEqual
1025 , lir_cond_greater
1026 , lir_cond_belowEqual
1027 , lir_cond_aboveEqual
1028 , lir_cond_always
1029 , lir_cond_unknown = -1
1030 };
1031
1032
1033 enum LIR_PatchCode {
1034 lir_patch_none,
1035 lir_patch_low,
1132 virtual void print_instr(outputStream* out) const = 0;
1133 virtual void print_on(outputStream* st) const PRODUCT_RETURN;
1134
1135 virtual bool is_patching() { return false; }
1136 virtual LIR_OpCall* as_OpCall() { return NULL; }
1137 virtual LIR_OpJavaCall* as_OpJavaCall() { return NULL; }
1138 virtual LIR_OpLabel* as_OpLabel() { return NULL; }
1139 virtual LIR_OpDelay* as_OpDelay() { return NULL; }
1140 virtual LIR_OpLock* as_OpLock() { return NULL; }
1141 virtual LIR_OpAllocArray* as_OpAllocArray() { return NULL; }
1142 virtual LIR_OpAllocObj* as_OpAllocObj() { return NULL; }
1143 virtual LIR_OpRoundFP* as_OpRoundFP() { return NULL; }
1144 virtual LIR_OpBranch* as_OpBranch() { return NULL; }
1145 virtual LIR_OpReturn* as_OpReturn() { return NULL; }
1146 virtual LIR_OpRTCall* as_OpRTCall() { return NULL; }
1147 virtual LIR_OpConvert* as_OpConvert() { return NULL; }
1148 virtual LIR_Op0* as_Op0() { return NULL; }
1149 virtual LIR_Op1* as_Op1() { return NULL; }
1150 virtual LIR_Op2* as_Op2() { return NULL; }
1151 virtual LIR_Op3* as_Op3() { return NULL; }
1152 #ifdef RISCV
1153 virtual LIR_Op4* as_Op4() { return NULL; }
1154 #endif
1155 virtual LIR_OpArrayCopy* as_OpArrayCopy() { return NULL; }
1156 virtual LIR_OpUpdateCRC32* as_OpUpdateCRC32() { return NULL; }
1157 virtual LIR_OpTypeCheck* as_OpTypeCheck() { return NULL; }
1158 virtual LIR_OpCompareAndSwap* as_OpCompareAndSwap() { return NULL; }
1159 virtual LIR_OpProfileCall* as_OpProfileCall() { return NULL; }
1160 virtual LIR_OpProfileType* as_OpProfileType() { return NULL; }
1161 #ifdef ASSERT
1162 virtual LIR_OpAssert* as_OpAssert() { return NULL; }
1163 #endif
1164
1165 virtual void verify() const {}
1166 };
1167
1168 // for calls
1169 class LIR_OpCall: public LIR_Op {
1170 friend class LIR_OpVisitState;
1171
1172 protected:
1173 address _addr;
1174 LIR_OprList* _arguments;
1406 class LIR_OpRTCall: public LIR_OpCall {
1407 friend class LIR_OpVisitState;
1408
1409 private:
1410 LIR_Opr _tmp;
1411 public:
1412 LIR_OpRTCall(address addr, LIR_Opr tmp,
1413 LIR_Opr result, LIR_OprList* arguments, CodeEmitInfo* info = NULL)
1414 : LIR_OpCall(lir_rtcall, addr, result, arguments, info)
1415 , _tmp(tmp) {}
1416
1417 virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1418 virtual void emit_code(LIR_Assembler* masm);
1419 virtual LIR_OpRTCall* as_OpRTCall() { return this; }
1420
1421 LIR_Opr tmp() const { return _tmp; }
1422
1423 virtual void verify() const;
1424 };
1425
1426 class LIR_OpReturn: public LIR_Op1 {
1427 friend class LIR_OpVisitState;
1428
1429 private:
1430 C1SafepointPollStub* _stub;
1431
1432 public:
1433 LIR_OpReturn(LIR_Opr opr);
1434
1435 C1SafepointPollStub* stub() const { return _stub; }
1436 virtual LIR_OpReturn* as_OpReturn() { return this; }
1437 };
1438
1439 class ConversionStub;
1440
1441 class LIR_OpConvert: public LIR_Op1 {
1442 friend class LIR_OpVisitState;
1443
1444 private:
1445 Bytecodes::Code _bytecode;
1578 // LIR_Op2
1579 class LIR_Op2: public LIR_Op {
1580 friend class LIR_OpVisitState;
1581
1582 int _fpu_stack_size; // for sin/cos implementation on Intel
1583
1584 protected:
1585 LIR_Opr _opr1;
1586 LIR_Opr _opr2;
1587 BasicType _type;
1588 LIR_Opr _tmp1;
1589 LIR_Opr _tmp2;
1590 LIR_Opr _tmp3;
1591 LIR_Opr _tmp4;
1592 LIR_Opr _tmp5;
1593 LIR_Condition _condition;
1594
1595 void verify() const;
1596
1597 public:
1598 LIR_Op2(LIR_Code code, LIR_Condition condition, LIR_Opr opr1, LIR_Opr opr2, CodeEmitInfo* info = NULL, BasicType type = T_ILLEGAL)
1599 : LIR_Op(code, LIR_OprFact::illegalOpr, info)
1600 , _fpu_stack_size(0)
1601 , _opr1(opr1)
1602 , _opr2(opr2)
1603 , _type(type)
1604 , _tmp1(LIR_OprFact::illegalOpr)
1605 , _tmp2(LIR_OprFact::illegalOpr)
1606 , _tmp3(LIR_OprFact::illegalOpr)
1607 , _tmp4(LIR_OprFact::illegalOpr)
1608 , _tmp5(LIR_OprFact::illegalOpr)
1609 , _condition(condition) {
1610 assert(code == lir_cmp || code == lir_assert RISCV_ONLY(|| code == lir_branch || code == lir_cond_float_branch), "code check");
1611 }
1612
1613 LIR_Op2(LIR_Code code, LIR_Condition condition, LIR_Opr opr1, LIR_Opr opr2, LIR_Opr result, BasicType type)
1614 : LIR_Op(code, result, NULL)
1615 , _fpu_stack_size(0)
1616 , _opr1(opr1)
1617 , _opr2(opr2)
1618 , _type(type)
1619 , _tmp1(LIR_OprFact::illegalOpr)
1620 , _tmp2(LIR_OprFact::illegalOpr)
1621 , _tmp3(LIR_OprFact::illegalOpr)
1622 , _tmp4(LIR_OprFact::illegalOpr)
1623 , _tmp5(LIR_OprFact::illegalOpr)
1624 , _condition(condition) {
1625 assert(code == lir_cmove, "code check");
1626 assert(type != T_ILLEGAL, "cmove should have type");
1627 }
1628
1629 LIR_Op2(LIR_Code code, LIR_Opr opr1, LIR_Opr opr2, LIR_Opr result = LIR_OprFact::illegalOpr,
1630 CodeEmitInfo* info = NULL, BasicType type = T_ILLEGAL)
1631 : LIR_Op(code, result, info)
1632 , _fpu_stack_size(0)
1633 , _opr1(opr1)
1634 , _opr2(opr2)
1635 , _type(type)
1636 , _tmp1(LIR_OprFact::illegalOpr)
1637 , _tmp2(LIR_OprFact::illegalOpr)
1638 , _tmp3(LIR_OprFact::illegalOpr)
1639 , _tmp4(LIR_OprFact::illegalOpr)
1640 , _tmp5(LIR_OprFact::illegalOpr)
1641 , _condition(lir_cond_unknown) {
1642 assert(code != lir_cmp && RISCV_ONLY(code != lir_branch && code != lir_cond_float_branch &&) is_in_range(code, begin_op2, end_op2), "code check");
1643 }
1644
1645 LIR_Op2(LIR_Code code, LIR_Opr opr1, LIR_Opr opr2, LIR_Opr result, LIR_Opr tmp1, LIR_Opr tmp2 = LIR_OprFact::illegalOpr,
1646 LIR_Opr tmp3 = LIR_OprFact::illegalOpr, LIR_Opr tmp4 = LIR_OprFact::illegalOpr, LIR_Opr tmp5 = LIR_OprFact::illegalOpr)
1647 : LIR_Op(code, result, NULL)
1648 , _fpu_stack_size(0)
1649 , _opr1(opr1)
1650 , _opr2(opr2)
1651 , _type(T_ILLEGAL)
1652 , _tmp1(tmp1)
1653 , _tmp2(tmp2)
1654 , _tmp3(tmp3)
1655 , _tmp4(tmp4)
1656 , _tmp5(tmp5)
1657 , _condition(lir_cond_unknown) {
1658 assert(code != lir_cmp && RISCV_ONLY(code != lir_branch && code != lir_cond_float_branch &&) is_in_range(code, begin_op2, end_op2), "code check");
1659 }
1660
1661 LIR_Opr in_opr1() const { return _opr1; }
1662 LIR_Opr in_opr2() const { return _opr2; }
1663 BasicType type() const { return _type; }
1664 LIR_Opr tmp1_opr() const { return _tmp1; }
1665 LIR_Opr tmp2_opr() const { return _tmp2; }
1666 LIR_Opr tmp3_opr() const { return _tmp3; }
1667 LIR_Opr tmp4_opr() const { return _tmp4; }
1668 LIR_Opr tmp5_opr() const { return _tmp5; }
1669 LIR_Condition condition() const {
1670 #ifdef RISCV
1671 assert(code() == lir_cmp || code() == lir_branch || code() == lir_cond_float_branch || code() == lir_assert, "only valid for branch and assert"); return _condition;
1672 #else
1673 assert(code() == lir_cmp || code() == lir_cmove || code() == lir_assert, "only valid for cmp and cmove and assert"); return _condition;
1674 #endif
1675 }
1676 void set_condition(LIR_Condition condition) {
1677 #ifdef RISCV
1678 assert(code() == lir_cmp || code() == lir_branch || code() == lir_cond_float_branch, "only valid for branch"); _condition = condition;
1679 #else
1680 assert(code() == lir_cmp || code() == lir_cmove, "only valid for cmp and cmove"); _condition = condition;
1681 #endif
1682 }
1683
1684 void set_fpu_stack_size(int size) { _fpu_stack_size = size; }
1685 int fpu_stack_size() const { return _fpu_stack_size; }
1686
1687 void set_in_opr1(LIR_Opr opr) { _opr1 = opr; }
1688 void set_in_opr2(LIR_Opr opr) { _opr2 = opr; }
1689
1690 virtual void emit_code(LIR_Assembler* masm);
1691 virtual LIR_Op2* as_Op2() { return this; }
1692 virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1693 };
1694
1695 #ifdef RISCV
1696 class LIR_OpBranch: public LIR_Op2 {
1697 #else
1698 class LIR_OpBranch: public LIR_Op {
1699 #endif
1700 friend class LIR_OpVisitState;
1701
1702 private:
1703 #ifndef RISCV
1704 LIR_Condition _cond;
1705 #endif
1706 Label* _label;
1707 BlockBegin* _block; // if this is a branch to a block, this is the block
1708 BlockBegin* _ublock; // if this is a float-branch, this is the unordered block
1709 CodeStub* _stub; // if this is a branch to a stub, this is the stub
1710
1711 public:
1712 LIR_OpBranch(LIR_Condition cond, Label* lbl)
1713 #ifdef RISCV
1714 : LIR_Op2(lir_branch, cond, LIR_OprFact::illegalOpr, LIR_OprFact::illegalOpr, (CodeEmitInfo*) NULL)
1715 #else
1716 : LIR_Op(lir_branch, LIR_OprFact::illegalOpr, (CodeEmitInfo*) NULL)
1717 , _cond(cond)
1718 #endif
1719 , _label(lbl)
1720 , _block(NULL)
1721 , _ublock(NULL)
1722 , _stub(NULL) { }
1723
1724 LIR_OpBranch(LIR_Condition cond, BlockBegin* block);
1725 LIR_OpBranch(LIR_Condition cond, CodeStub* stub);
1726
1727 // for unordered comparisons
1728 LIR_OpBranch(LIR_Condition cond, BlockBegin* block, BlockBegin* ublock);
1729
1730 #ifdef RISCV
1731 LIR_Condition cond() const { return condition(); }
1732 void set_cond(LIR_Condition cond) { set_condition(cond); }
1733 #else
1734 LIR_Condition cond() const { return _cond; }
1735 void set_cond(LIR_Condition cond) { _cond = cond; }
1736 #endif
1737 Label* label() const { return _label; }
1738 BlockBegin* block() const { return _block; }
1739 BlockBegin* ublock() const { return _ublock; }
1740 CodeStub* stub() const { return _stub; }
1741
1742 void change_block(BlockBegin* b);
1743 void change_ublock(BlockBegin* b);
1744 void negate_cond();
1745
1746 virtual void emit_code(LIR_Assembler* masm);
1747 virtual LIR_OpBranch* as_OpBranch() { return this; }
1748 virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1749
1750 };
1751
1752 class LIR_OpAllocArray : public LIR_Op {
1753 friend class LIR_OpVisitState;
1754
1755 private:
1756 LIR_Opr _klass;
1757 LIR_Opr _len;
1758 LIR_Opr _tmp1;
1759 LIR_Opr _tmp2;
1760 LIR_Opr _tmp3;
1761 LIR_Opr _tmp4;
1762 BasicType _type;
1763 CodeStub* _stub;
1764
1765 public:
1766 LIR_OpAllocArray(LIR_Opr klass, LIR_Opr len, LIR_Opr result, LIR_Opr t1, LIR_Opr t2, LIR_Opr t3, LIR_Opr t4, BasicType type, CodeStub* stub)
1767 : LIR_Op(lir_alloc_array, result, NULL)
1768 , _klass(klass)
1769 , _len(len)
1770 , _tmp1(t1)
1771 , _tmp2(t2)
1795
1796 private:
1797 LIR_Opr _opr1;
1798 LIR_Opr _opr2;
1799 LIR_Opr _opr3;
1800 public:
1801 LIR_Op3(LIR_Code code, LIR_Opr opr1, LIR_Opr opr2, LIR_Opr opr3, LIR_Opr result, CodeEmitInfo* info = NULL)
1802 : LIR_Op(code, result, info)
1803 , _opr1(opr1)
1804 , _opr2(opr2)
1805 , _opr3(opr3) { assert(is_in_range(code, begin_op3, end_op3), "code check"); }
1806 LIR_Opr in_opr1() const { return _opr1; }
1807 LIR_Opr in_opr2() const { return _opr2; }
1808 LIR_Opr in_opr3() const { return _opr3; }
1809
1810 virtual void emit_code(LIR_Assembler* masm);
1811 virtual LIR_Op3* as_Op3() { return this; }
1812 virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1813 };
1814
1815 #ifdef RISCV
1816 class LIR_Op4: public LIR_Op {
1817 friend class LIR_OpVisitState;
1818 protected:
1819 LIR_Opr _opr1;
1820 LIR_Opr _opr2;
1821 LIR_Opr _opr3;
1822 LIR_Opr _opr4;
1823 BasicType _type;
1824 LIR_Opr _tmp1;
1825 LIR_Opr _tmp2;
1826 LIR_Opr _tmp3;
1827 LIR_Opr _tmp4;
1828 LIR_Opr _tmp5;
1829 LIR_Condition _condition;
1830
1831 public:
1832 LIR_Op4(LIR_Code code, LIR_Condition condition, LIR_Opr opr1, LIR_Opr opr2, LIR_Opr opr3, LIR_Opr opr4,
1833 LIR_Opr result, BasicType type)
1834 : LIR_Op(code, result, NULL)
1835 , _opr1(opr1)
1836 , _opr2(opr2)
1837 , _opr3(opr3)
1838 , _opr4(opr4)
1839 , _type(type)
1840 , _tmp1(LIR_OprFact::illegalOpr)
1841 , _tmp2(LIR_OprFact::illegalOpr)
1842 , _tmp3(LIR_OprFact::illegalOpr)
1843 , _tmp4(LIR_OprFact::illegalOpr)
1844 , _tmp5(LIR_OprFact::illegalOpr)
1845 , _condition(condition) {
1846 assert(code == lir_cmove, "code check");
1847 assert(type != T_ILLEGAL, "cmove should have type");
1848 }
1849
1850 LIR_Opr in_opr1() const { return _opr1; }
1851 LIR_Opr in_opr2() const { return _opr2; }
1852 LIR_Opr in_opr3() const { return _opr3; }
1853 LIR_Opr in_opr4() const { return _opr4; }
1854 BasicType type() const { return _type; }
1855 LIR_Opr tmp1_opr() const { return _tmp1; }
1856 LIR_Opr tmp2_opr() const { return _tmp2; }
1857 LIR_Opr tmp3_opr() const { return _tmp3; }
1858 LIR_Opr tmp4_opr() const { return _tmp4; }
1859 LIR_Opr tmp5_opr() const { return _tmp5; }
1860
1861 LIR_Condition condition() const { return _condition; }
1862 void set_condition(LIR_Condition condition) { _condition = condition; }
1863
1864 void set_in_opr1(LIR_Opr opr) { _opr1 = opr; }
1865 void set_in_opr2(LIR_Opr opr) { _opr2 = opr; }
1866 void set_in_opr3(LIR_Opr opr) { _opr3 = opr; }
1867 void set_in_opr4(LIR_Opr opr) { _opr4 = opr; }
1868 virtual void emit_code(LIR_Assembler* masm);
1869 virtual LIR_Op4* as_Op4() { return this; }
1870
1871 virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1872 };
1873 #endif
1874
1875 //--------------------------------
1876 class LabelObj: public CompilationResourceObj {
1877 private:
1878 Label _label;
1879 public:
1880 LabelObj() {}
1881 Label* label() { return &_label; }
1882 };
1883
1884
1885 class LIR_OpLock: public LIR_Op {
1886 friend class LIR_OpVisitState;
1887
1888 private:
1889 LIR_Opr _hdr;
1890 LIR_Opr _obj;
1891 LIR_Opr _lock;
1892 LIR_Opr _scratch;
1893 CodeStub* _stub;
2076 //--------------------------------LIR_List---------------------------------------------------
2077 // Maintains a list of LIR instructions (one instance of LIR_List per basic block)
2078 // The LIR instructions are appended by the LIR_List class itself;
2079 //
2080 // Notes:
2081 // - all offsets are(should be) in bytes
2082 // - local positions are specified with an offset, with offset 0 being local 0
2083
2084 class LIR_List: public CompilationResourceObj {
2085 private:
2086 LIR_OpList _operations;
2087
2088 Compilation* _compilation;
2089 #ifndef PRODUCT
2090 BlockBegin* _block;
2091 #endif
2092 #ifdef ASSERT
2093 const char * _file;
2094 int _line;
2095 #endif
2096 #ifdef RISCV
2097 LIR_Opr _cmp_opr1;
2098 LIR_Opr _cmp_opr2;
2099 #endif
2100
2101 public:
2102 void append(LIR_Op* op) {
2103 if (op->source() == NULL)
2104 op->set_source(_compilation->current_instruction());
2105 #ifndef PRODUCT
2106 if (PrintIRWithLIR) {
2107 _compilation->maybe_print_current_instruction();
2108 op->print(); tty->cr();
2109 }
2110 #endif // PRODUCT
2111
2112 #ifdef RISCV
2113 set_cmp_oprs(op);
2114 // lir_cmp set cmp oprs only on riscv
2115 if (op->code() == lir_cmp) return;
2116 #endif
2117
2118 _operations.append(op);
2119
2120 #ifdef ASSERT
2121 op->verify();
2122 op->set_file_and_line(_file, _line);
2123 _file = NULL;
2124 _line = 0;
2125 #endif
2126 }
2127
2128 LIR_List(Compilation* compilation, BlockBegin* block = NULL);
2129
2130 #ifdef ASSERT
2131 void set_file_and_line(const char * file, int line);
2132 #endif
2133
2134 #ifdef RISCV
2135 void set_cmp_oprs(LIR_Op* op);
2136 #endif
2137
2138 //---------- accessors ---------------
2139 LIR_OpList* instructions_list() { return &_operations; }
2140 int length() const { return _operations.length(); }
2141 LIR_Op* at(int i) const { return _operations.at(i); }
2142
2143 NOT_PRODUCT(BlockBegin* block() const { return _block; });
2144
2145 // insert LIR_Ops in buffer to right places in LIR_List
2146 void append(LIR_InsertionBuffer* buffer);
2147
2148 //---------- mutators ---------------
2149 void insert_before(int i, LIR_List* op_list) { _operations.insert_before(i, op_list->instructions_list()); }
2150 void insert_before(int i, LIR_Op* op) { _operations.insert_before(i, op); }
2151 void remove_at(int i) { _operations.remove_at(i); }
2152
2153 //---------- printing -------------
2154 void print_instructions() PRODUCT_RETURN;
2155
2156
2157 //---------- instructions -------------
2237 void throw_exception(LIR_Opr exceptionPC, LIR_Opr exceptionOop, CodeEmitInfo* info) {
2238 append(new LIR_Op2(lir_throw, exceptionPC, exceptionOop, LIR_OprFact::illegalOpr, info));
2239 }
2240 void unwind_exception(LIR_Opr exceptionOop) {
2241 append(new LIR_Op1(lir_unwind, exceptionOop));
2242 }
2243
2244 void push(LIR_Opr opr) { append(new LIR_Op1(lir_push, opr)); }
2245 void pop(LIR_Opr reg) { append(new LIR_Op1(lir_pop, reg)); }
2246
2247 void cmp(LIR_Condition condition, LIR_Opr left, LIR_Opr right, CodeEmitInfo* info = NULL) {
2248 append(new LIR_Op2(lir_cmp, condition, left, right, info));
2249 }
2250 void cmp(LIR_Condition condition, LIR_Opr left, int right, CodeEmitInfo* info = NULL) {
2251 cmp(condition, left, LIR_OprFact::intConst(right), info);
2252 }
2253
2254 void cmp_mem_int(LIR_Condition condition, LIR_Opr base, int disp, int c, CodeEmitInfo* info);
2255 void cmp_reg_mem(LIR_Condition condition, LIR_Opr reg, LIR_Address* addr, CodeEmitInfo* info);
2256
2257 #ifdef RISCV
2258 void cmove(LIR_Condition condition, LIR_Opr src1, LIR_Opr src2, LIR_Opr dst, BasicType type,
2259 LIR_Opr cmp_opr1 = LIR_OprFact::illegalOpr, LIR_Opr cmp_opr2 = LIR_OprFact::illegalOpr) {
2260 append(new LIR_Op4(lir_cmove, condition, src1, src2, cmp_opr1, cmp_opr2, dst, type));
2261 }
2262 #else
2263 void cmove(LIR_Condition condition, LIR_Opr src1, LIR_Opr src2, LIR_Opr dst, BasicType type) {
2264 append(new LIR_Op2(lir_cmove, condition, src1, src2, dst, type));
2265 }
2266 #endif
2267
2268 void cas_long(LIR_Opr addr, LIR_Opr cmp_value, LIR_Opr new_value,
2269 LIR_Opr t1, LIR_Opr t2, LIR_Opr result = LIR_OprFact::illegalOpr);
2270 void cas_obj(LIR_Opr addr, LIR_Opr cmp_value, LIR_Opr new_value,
2271 LIR_Opr t1, LIR_Opr t2, LIR_Opr result = LIR_OprFact::illegalOpr);
2272 void cas_int(LIR_Opr addr, LIR_Opr cmp_value, LIR_Opr new_value,
2273 LIR_Opr t1, LIR_Opr t2, LIR_Opr result = LIR_OprFact::illegalOpr);
2274
2275 void abs (LIR_Opr from, LIR_Opr to, LIR_Opr tmp) { append(new LIR_Op2(lir_abs , from, tmp, to)); }
2276 void negate(LIR_Opr from, LIR_Opr to, LIR_Opr tmp = LIR_OprFact::illegalOpr) { append(new LIR_Op2(lir_neg, from, tmp, to)); }
2277 void sqrt(LIR_Opr from, LIR_Opr to, LIR_Opr tmp) { append(new LIR_Op2(lir_sqrt, from, tmp, to)); }
2278 void fmad(LIR_Opr from, LIR_Opr from1, LIR_Opr from2, LIR_Opr to) { append(new LIR_Op3(lir_fmad, from, from1, from2, to)); }
2279 void fmaf(LIR_Opr from, LIR_Opr from1, LIR_Opr from2, LIR_Opr to) { append(new LIR_Op3(lir_fmaf, from, from1, from2, to)); }
2280 void log10 (LIR_Opr from, LIR_Opr to, LIR_Opr tmp) { append(new LIR_Op2(lir_log10, from, LIR_OprFact::illegalOpr, to, tmp)); }
2281 void tan (LIR_Opr from, LIR_Opr to, LIR_Opr tmp1, LIR_Opr tmp2) { append(new LIR_Op2(lir_tan , from, tmp1, to, tmp2)); }
2282
2283 void add (LIR_Opr left, LIR_Opr right, LIR_Opr res) { append(new LIR_Op2(lir_add, left, right, res)); }
2284 void sub (LIR_Opr left, LIR_Opr right, LIR_Opr res, CodeEmitInfo* info = NULL) { append(new LIR_Op2(lir_sub, left, right, res, info)); }
2285 void mul (LIR_Opr left, LIR_Opr right, LIR_Opr res) { append(new LIR_Op2(lir_mul, left, right, res)); }
2286 void mul (LIR_Opr left, LIR_Opr right, LIR_Opr res, LIR_Opr tmp) { append(new LIR_Op2(lir_mul, left, right, res, tmp)); }
|