1 /*
  2  * Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
  3  * Copyright (c) 2014, 2015, Red Hat Inc. All rights reserved.
  4  * Copyright (c) 2020, 2021, Huawei Technologies Co., Ltd. All rights reserved.
  5  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  6  *
  7  * This code is free software; you can redistribute it and/or modify it
  8  * under the terms of the GNU General Public License version 2 only, as
  9  * published by the Free Software Foundation.
 10  *
 11  * This code is distributed in the hope that it will be useful, but WITHOUT
 12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 14  * version 2 for more details (a copy is included in the LICENSE file that
 15  * accompanied this code).
 16  *
 17  * You should have received a copy of the GNU General Public License version
 18  * 2 along with this work; if not, write to the Free Software Foundation,
 19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 20  *
 21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 22  * or visit www.oracle.com if you need additional information or have any
 23  * questions.
 24  *
 25  */
 26 
 27 #ifndef CPU_RISCV_C1_MACROASSEMBLER_RISCV_HPP
 28 #define CPU_RISCV_C1_MACROASSEMBLER_RISCV_HPP
 29 
 30 using MacroAssembler::build_frame;
 31 using MacroAssembler::null_check;
 32 
 33 // C1_MacroAssembler contains high-level macros for C1
 34 
 35  private:
 36   int _rsp_offset;    // track rsp changes
 37   // initialization
 38   void pd_init() { _rsp_offset = 0; }
 39 
 40 
 41  public:
 42   void try_allocate(
 43     Register obj,                      // result: pointer to object after successful allocation
 44     Register var_size_in_bytes,        // object size in bytes if unknown at compile time; invalid otherwise
 45     int      con_size_in_bytes,        // object size in bytes if   known at compile time
 46     Register tmp1,                     // temp register
 47     Register tmp2,                     // temp register
 48     Label&   slow_case                 // continuation point if fast allocation fails
 49   );
 50 
 51   void initialize_header(Register obj, Register klass, Register len, Register tmp1, Register tmp2);
 52   void initialize_body(Register obj, Register len_in_bytes, int hdr_size_in_bytes, Register tmp1);
 53 
 54   void float_cmp(bool is_float, int unordered_result,
 55                  FloatRegister f0, FloatRegister f1,
 56                  Register result);
 57 
 58   // locking
 59   // hdr     : must be x10, contents destroyed
 60   // obj     : must point to the object to lock, contents preserved
 61   // disp_hdr: must point to the displaced header location, contents preserved
 62   // returns code offset at which to add null check debug information
 63   int lock_object  (Register swap, Register obj, Register disp_hdr, Label& slow_case);
 64 
 65   // unlocking
 66   // hdr     : contents destroyed
 67   // obj     : must point to the object to lock, contents preserved
 68   // disp_hdr: must be x10 & must point to the displaced header location, contents destroyed
 69   void unlock_object(Register swap, Register obj, Register lock, Label& slow_case);
 70 
 71   void initialize_object(
 72     Register obj,                      // result: pointer to object after successful allocation
 73     Register klass,                    // object klass
 74     Register var_size_in_bytes,        // object size in bytes if unknown at compile time; invalid otherwise
 75     int      con_size_in_bytes,        // object size in bytes if   known at compile time
 76     Register tmp1,                     // temp register
 77     Register tmp2,                     // temp register
 78     bool     is_tlab_allocated         // the object was allocated in a TLAB; relevant for the implementation of ZeroTLAB
 79   );
 80 
 81   // allocation of fixed-size objects
 82   // (can also be used to allocate fixed-size arrays, by setting
 83   // hdr_size correctly and storing the array length afterwards)
 84   // obj        : will contain pointer to allocated object
 85   // t1, t2     : temp registers - contents destroyed
 86   // header_size: size of object header in words
 87   // object_size: total size of object in words
 88   // slow_case  : exit to slow case implementation if fast allocation fails
 89   void allocate_object(Register obj, Register tmp1, Register tmp2, int header_size, int object_size, Register klass, Label& slow_case);
 90 
 91   enum {
 92     max_array_allocation_length = 0x00FFFFFF
 93   };
 94 
 95   // allocation of arrays
 96   // obj        : will contain pointer to allocated object
 97   // len        : array length in number of elements
 98   // t          : temp register - contents destroyed
 99   // header_size: size of object header in words
100   // f          : element scale factor
101   // slow_case  : exit to slow case implementation if fast allocation fails
102   void allocate_array(Register obj, Register len, Register tmp1, Register tmp2, int header_size, int f, Register klass, Label& slow_case);
103 
104   int  rsp_offset() const { return _rsp_offset; }
105 
106   void invalidate_registers(bool inv_r0, bool inv_r19, bool inv_r2, bool inv_r3, bool inv_r4, bool inv_r5) PRODUCT_RETURN;
107 
108   // This platform only uses signal-based null checks. The Label is not needed.
109   void null_check(Register r, Label *Lnull = NULL) { MacroAssembler::null_check(r); }
110 
111   void load_parameter(int offset_in_words, Register reg);
112 
113   void inline_cache_check(Register receiver, Register iCache, Label &L);
114 
115   static const int c1_double_branch_mask = 1 << 3; // depend on c1_float_cond_branch
116   void c1_cmp_branch(int cmpFlag, Register op1, Register op2, Label& label, BasicType type, bool is_far);
117   void c1_float_cmp_branch(int cmpFlag, FloatRegister op1, FloatRegister op2, Label& label,
118                            bool is_far, bool is_unordered = false);
119 
120 #endif // CPU_RISCV_C1_MACROASSEMBLER_RISCV_HPP