1 /*
 2  * Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.
 3  * Copyright (c) 2014, 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_LINEARSCAN_RISCV_HPP
28 #define CPU_RISCV_C1_LINEARSCAN_RISCV_HPP
29 
30 inline bool LinearScan::is_processed_reg_num(int reg_num)
31 {
32   return reg_num <= FrameMap::last_cpu_reg() || reg_num >= pd_nof_cpu_regs_frame_map;
33 }
34 
35 inline int LinearScan::num_physical_regs(BasicType type) {
36   return 1;
37 }
38 
39 
40 inline bool LinearScan::requires_adjacent_regs(BasicType type) {
41   return false;
42 }
43 
44 inline bool LinearScan::is_caller_save(int assigned_reg) {
45   assert(assigned_reg >= 0 && assigned_reg < nof_regs, "should call this only for registers");
46   if (assigned_reg < pd_first_callee_saved_reg) {
47     return true;
48   }
49   if (assigned_reg > pd_last_callee_saved_reg && assigned_reg < pd_first_callee_saved_fpu_reg_1) {
50     return true;
51   }
52   if (assigned_reg > pd_last_callee_saved_fpu_reg_1 && assigned_reg < pd_first_callee_saved_fpu_reg_2) {
53     return true;
54   }
55   if (assigned_reg > pd_last_callee_saved_fpu_reg_2 && assigned_reg < pd_last_fpu_reg) {
56     return true;
57   }
58   return false;
59 }
60 
61 
62 inline void LinearScan::pd_add_temps(LIR_Op* op) {
63 }
64 
65 
66 // Implementation of LinearScanWalker
67 
68 inline bool LinearScanWalker::pd_init_regs_for_alloc(Interval* cur)
69 {
70   if (allocator()->gen()->is_vreg_flag_set(cur->reg_num(), LIRGenerator::callee_saved)) {
71     assert(cur->type() != T_FLOAT && cur->type() != T_DOUBLE, "cpu regs only");
72     _first_reg = pd_first_callee_saved_reg;
73     _last_reg = pd_last_callee_saved_reg;
74     return true;
75   } else if (cur->type() == T_INT || cur->type() == T_LONG || cur->type() == T_OBJECT ||
76              cur->type() == T_ADDRESS || cur->type() == T_METADATA) {
77     _first_reg = pd_first_cpu_reg;
78     _last_reg = pd_last_allocatable_cpu_reg;
79     return true;
80   }
81   return false;
82 }
83 
84 
85 #endif // CPU_RISCV_C1_LINEARSCAN_RISCV_HPP