1b1994897Sopenharmony_ci# Copyright (c) 2021-2022 Huawei Device Co., Ltd.
2b1994897Sopenharmony_ci# Licensed under the Apache License, Version 2.0 (the "License");
3b1994897Sopenharmony_ci# you may not use this file except in compliance with the License.
4b1994897Sopenharmony_ci# You may obtain a copy of the License at
5b1994897Sopenharmony_ci#
6b1994897Sopenharmony_ci# http://www.apache.org/licenses/LICENSE-2.0
7b1994897Sopenharmony_ci#
8b1994897Sopenharmony_ci# Unless required by applicable law or agreed to in writing, software
9b1994897Sopenharmony_ci# distributed under the License is distributed on an "AS IS" BASIS,
10b1994897Sopenharmony_ci# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11b1994897Sopenharmony_ci# See the License for the specific language governing permissions and
12b1994897Sopenharmony_ci# limitations under the License.
13b1994897Sopenharmony_ci
14b1994897Sopenharmony_cidoc: |
15b1994897Sopenharmony_ci  opcode
16b1994897Sopenharmony_ci    Opcode of the instruction
17b1994897Sopenharmony_ci
18b1994897Sopenharmony_ci  signature
19b1994897Sopenharmony_ci    Describes signature of the instruction. Properties of the operands are separated by '-' symbol.
20b1994897Sopenharmony_ci    For info about operand tokens see the 'legend' section
21b1994897Sopenharmony_ci
22b1994897Sopenharmony_ci    Note: any check instructions might be eliminated by optimizer, thus operand checks (nc, zc, bc, ngc) qualifiers have
23b1994897Sopenharmony_ci          not mandatory meaning.
24b1994897Sopenharmony_ci
25b1994897Sopenharmony_ci  base
26b1994897Sopenharmony_ci    C++ base that represent this opcode. In far future if we managed to generate also instruction classes,
27b1994897Sopenharmony_ci    this field become redundant
28b1994897Sopenharmony_ci
29b1994897Sopenharmony_ci  flags
30b1994897Sopenharmony_ci    Properties of the instruction, such as: arithmetic, binop, throw, etc
31b1994897Sopenharmony_ci
32b1994897Sopenharmony_ci  modes
33b1994897Sopenharmony_ci    Modes which the instruction can be used in
34b1994897Sopenharmony_ci
35b1994897Sopenharmony_citemplates:
36b1994897Sopenharmony_ci  # Templates aim to reduce boilerplate in instruction description.
37b1994897Sopenharmony_ci  # Templates are denoted by a '$' symbol in the first character of the string.
38b1994897Sopenharmony_ci  verify_unary:
39b1994897Sopenharmony_ci    - equal_common_types
40b1994897Sopenharmony_ci    - float_src_eq_dst_size
41b1994897Sopenharmony_ci    - integer_src_ge_dst_size
42b1994897Sopenharmony_ci  verify_binary_int:
43b1994897Sopenharmony_ci    - equal_common_types
44b1994897Sopenharmony_ci    - integer_src_ge_dst_size
45b1994897Sopenharmony_ci  verify_binary:
46b1994897Sopenharmony_ci    - equal_common_types
47b1994897Sopenharmony_ci    - integer_src_ge_dst_size
48b1994897Sopenharmony_ci    - float_src_eq_dst_size
49b1994897Sopenharmony_ci
50b1994897Sopenharmony_ciinstructions:
51b1994897Sopenharmony_ci  - opcode: Compare
52b1994897Sopenharmony_ci    base: CompareInst
53b1994897Sopenharmony_ci    signature: [d-bool, real, real]
54b1994897Sopenharmony_ci    flags: [acc_read, acc_write, ifcvt]
55b1994897Sopenharmony_ci    description: Compare two integer or reference values according to condition code(for reference only CC_EQ).
56b1994897Sopenharmony_ci
57b1994897Sopenharmony_ci  - opcode: Cmp
58b1994897Sopenharmony_ci    base: CmpInst
59b1994897Sopenharmony_ci    signature: [d-int, number, number]
60b1994897Sopenharmony_ci    flags: [acc_read, acc_write, ifcvt]
61b1994897Sopenharmony_ci    description:  Compare two float or integer values.
62b1994897Sopenharmony_ci
63b1994897Sopenharmony_ci  - opcode: CompareAnyType
64b1994897Sopenharmony_ci    base: CompareAnyTypeInst
65b1994897Sopenharmony_ci    signature: [d-bool, any]
66b1994897Sopenharmony_ci    flags: [acc_read, acc_write, ifcvt]
67b1994897Sopenharmony_ci    description:  Compare any type value and type.
68b1994897Sopenharmony_ci
69b1994897Sopenharmony_ci  - opcode: CastAnyTypeValue
70b1994897Sopenharmony_ci    base: CastAnyTypeValueInst
71b1994897Sopenharmony_ci    signature: [d-real, any]
72b1994897Sopenharmony_ci    flags: [acc_read, acc_write]
73b1994897Sopenharmony_ci    description:  Cast any dynamic type value to compiler type value.
74b1994897Sopenharmony_ci
75b1994897Sopenharmony_ci  - opcode: CastValueToAnyType
76b1994897Sopenharmony_ci    base: CastValueToAnyTypeInst
77b1994897Sopenharmony_ci    signature: [d-any, real]
78b1994897Sopenharmony_ci    flags: [acc_read, acc_write, no_cse]
79b1994897Sopenharmony_ci    description:  Cast compiler type value to any dynamic type value.
80b1994897Sopenharmony_ci
81b1994897Sopenharmony_ci  - opcode: Constant
82b1994897Sopenharmony_ci    base: ConstantInst
83b1994897Sopenharmony_ci    signature: [d-i32-i64-f32-f64]
84b1994897Sopenharmony_ci    flags: [no_cse, ifcvt]
85b1994897Sopenharmony_ci    description: Constant value.
86b1994897Sopenharmony_ci    verification:
87b1994897Sopenharmony_ci      - start_block_instruction
88b1994897Sopenharmony_ci
89b1994897Sopenharmony_ci  - opcode: Parameter
90b1994897Sopenharmony_ci    base: ParameterInst
91b1994897Sopenharmony_ci    signature: [d-real-any]
92b1994897Sopenharmony_ci    flags: [no_cse, no_hoist]
93b1994897Sopenharmony_ci    description: Method's parameter.
94b1994897Sopenharmony_ci    verification:
95b1994897Sopenharmony_ci      - start_block_instruction
96b1994897Sopenharmony_ci
97b1994897Sopenharmony_ci  - opcode: LoadString
98b1994897Sopenharmony_ci    base: LoadFromPool
99b1994897Sopenharmony_ci    signature: [d-ref, save_state]
100b1994897Sopenharmony_ci    flags: [load, can_throw, no_hoist, no_cse, require_state, runtime_call, acc_write]
101b1994897Sopenharmony_ci    description: Load string from pool.
102b1994897Sopenharmony_ci
103b1994897Sopenharmony_ci  - opcode: Return
104b1994897Sopenharmony_ci    base: FixedInputsInst1
105b1994897Sopenharmony_ci    signature: [real-any]
106b1994897Sopenharmony_ci    flags: [cf, no_dce, no_hoist, no_cse, barrier, acc_read, terminator]
107b1994897Sopenharmony_ci    description: Return value from method.
108b1994897Sopenharmony_ci
109b1994897Sopenharmony_ci  - opcode: Intrinsic
110b1994897Sopenharmony_ci    base: IntrinsicInst
111b1994897Sopenharmony_ci    signature: [d-real-void, real-dyn]
112b1994897Sopenharmony_ci    flags: [no_dce, no_hoist, no_cse, barrier, require_state, runtime_call]
113b1994897Sopenharmony_ci    description: Call runtime intrinsics directly.
114b1994897Sopenharmony_ci
115b1994897Sopenharmony_ci    ##############################################################################
116b1994897Sopenharmony_ci    # Special pseudo instructions
117b1994897Sopenharmony_ci    #
118b1994897Sopenharmony_ci  - opcode: Phi
119b1994897Sopenharmony_ci    base: PhiInst
120b1994897Sopenharmony_ci    signature: [d-real-ref, real-ref-dyn]
121b1994897Sopenharmony_ci    flags: [no_cse, no_hoist]
122b1994897Sopenharmony_ci    description: Phi instruction
123b1994897Sopenharmony_ci
124b1994897Sopenharmony_ci  - opcode: SpillFill
125b1994897Sopenharmony_ci    base: SpillFillInst
126b1994897Sopenharmony_ci    signature: []
127b1994897Sopenharmony_ci    flags: [no_cse, no_dce]
128b1994897Sopenharmony_ci    description: Pseudo instruction that inserted by Register Allocator.
129b1994897Sopenharmony_ci
130b1994897Sopenharmony_ci  - opcode: SaveState
131b1994897Sopenharmony_ci    base: SaveStateInst
132b1994897Sopenharmony_ci    signature: [d-real-pseudo, real-dyn]
133b1994897Sopenharmony_ci    flags: [no_hoist, no_cse]
134b1994897Sopenharmony_ci    description: >-
135b1994897Sopenharmony_ci      Contains information about virtual registers that must be saved before leaving compiled code. Constructed for all
136b1994897Sopenharmony_ci      call instructions and all instructions that can throw.
137b1994897Sopenharmony_ci
138b1994897Sopenharmony_ci  - opcode: If
139b1994897Sopenharmony_ci    base: IfInst
140b1994897Sopenharmony_ci    signature: [real, real]
141b1994897Sopenharmony_ci    flags: [cf, no_dce, no_hoist, no_cse, barrier, low_level, acc_read]
142b1994897Sopenharmony_ci    description: Performs compare and jump.
143b1994897Sopenharmony_ci
144b1994897Sopenharmony_ci  - opcode: IfImm
145b1994897Sopenharmony_ci    base: IfImmInst
146b1994897Sopenharmony_ci    signature: [real]
147b1994897Sopenharmony_ci    flags: [cf, no_dce, no_hoist, no_cse, barrier, acc_read]
148b1994897Sopenharmony_ci    description: Performs compare with immediate and jump.
149b1994897Sopenharmony_ci
150b1994897Sopenharmony_ci  - opcode: Try
151b1994897Sopenharmony_ci    base: TryInst
152b1994897Sopenharmony_ci    signature: []
153b1994897Sopenharmony_ci    flags: [no_dce, no_hoist, no_cse, barrier]
154b1994897Sopenharmony_ci    modes: [jit_aot, bytecode_opt]
155b1994897Sopenharmony_ci    description: Pseudo instruction, inserted in the beginning of try-block.
156b1994897Sopenharmony_ci
157b1994897Sopenharmony_ci  - opcode: CatchPhi
158b1994897Sopenharmony_ci    base: CatchPhiInst
159b1994897Sopenharmony_ci    signature: [d-real-ref, real-ref-dyn]
160b1994897Sopenharmony_ci    flags: [no_hoist, no_cse]
161b1994897Sopenharmony_ci    modes: [jit_aot, bytecode_opt]
162b1994897Sopenharmony_ci    description: >-
163b1994897Sopenharmony_ci      Pseudo instruction, which is inserted in the Catch handler basic block, and defines virtual registers at each throwing
164b1994897Sopenharmony_ci      instruction of the appropriate try-block.
165b1994897Sopenharmony_ci
166b1994897Sopenharmony_citypes:
167b1994897Sopenharmony_ci  - name: i8
168b1994897Sopenharmony_ci  - name: i16
169b1994897Sopenharmony_ci  - name: i32
170b1994897Sopenharmony_ci  - name: i64
171b1994897Sopenharmony_ci  - name: u8
172b1994897Sopenharmony_ci  - name: u16
173b1994897Sopenharmony_ci  - name: u32
174b1994897Sopenharmony_ci  - name: u64
175b1994897Sopenharmony_ci  - name: f32
176b1994897Sopenharmony_ci  - name: f64
177b1994897Sopenharmony_ci  - name: bool
178b1994897Sopenharmony_ci  - name: ref
179b1994897Sopenharmony_ci  - name: ptr
180b1994897Sopenharmony_ci  - name: void
181b1994897Sopenharmony_ci  - name: any
182b1994897Sopenharmony_ci
183b1994897Sopenharmony_ciarch_info:
184b1994897Sopenharmony_ci- name: arm64
185b1994897Sopenharmony_ci  regs_count: 32
186b1994897Sopenharmony_ci  temp_regs: [16, 17, 20]
187b1994897Sopenharmony_ci  fp_regs_count: 32
188b1994897Sopenharmony_ci  fp_temp_regs: [30, 31]
189b1994897Sopenharmony_ci
190b1994897Sopenharmony_ci- name: arm32
191b1994897Sopenharmony_ci  regs_count: 16
192b1994897Sopenharmony_ci  temp_regs: [8, 9, 12]
193b1994897Sopenharmony_ci  fp_regs_count: 32
194b1994897Sopenharmony_ci  fp_temp_regs: [14, 15]
195b1994897Sopenharmony_ci
196b1994897Sopenharmony_ci- name: x86_64
197b1994897Sopenharmony_ci  regs_count: 16
198b1994897Sopenharmony_ci  temp_regs: [12, 13, 14]
199b1994897Sopenharmony_ci  fp_regs_count: 16
200b1994897Sopenharmony_ci  fp_temp_regs: [13, 14, 15]
201b1994897Sopenharmony_ci
202b1994897Sopenharmony_cilegend:
203b1994897Sopenharmony_ci  "Operand tokens":
204b1994897Sopenharmony_ci    d: operand is a destination, operand is a source when 'd' is not specified
205b1994897Sopenharmony_ci    i8: signed 8-bit integer
206b1994897Sopenharmony_ci    i16: signed 16-bit integer
207b1994897Sopenharmony_ci    i32: signed 32-bit integer
208b1994897Sopenharmony_ci    i64: signed 64-bit integer
209b1994897Sopenharmony_ci    u8: unsigned 8-bit integer
210b1994897Sopenharmony_ci    u16: unsigned 16-bit integer
211b1994897Sopenharmony_ci    u32: unsigned 32-bit integer
212b1994897Sopenharmony_ci    u64: unsigned 64-bit integer
213b1994897Sopenharmony_ci    f32: single precision float
214b1994897Sopenharmony_ci    f64: double precision float
215b1994897Sopenharmony_ci    bool: boolean type
216b1994897Sopenharmony_ci    ref: object reference type
217b1994897Sopenharmony_ci    ptr: pointer type
218b1994897Sopenharmony_ci    void: void type
219b1994897Sopenharmony_ci    int: type union of [bool, i8, i16, i32, i64, u8, u16, u32, u64]
220b1994897Sopenharmony_ci    float: type union of [f32, f64]
221b1994897Sopenharmony_ci    number: type union of [int, float]
222b1994897Sopenharmony_ci    real: type union of [number, ref]
223b1994897Sopenharmony_ci    any: the type is not statically defined(For dynamic languages)
224b1994897Sopenharmony_ci    pseudo: pseudo destination - instruction doesn't actually write to the register
225b1994897Sopenharmony_ci    zc: zero check - input must be the ZeroCheck instruction
226b1994897Sopenharmony_ci    bc: bounds check - input must be the BoundsCheck instruction
227b1994897Sopenharmony_ci    nc: null check - input must be the NullCheck instruction
228b1994897Sopenharmony_ci    ngc: negative check - input should be the NegativeCheck instruction
229b1994897Sopenharmony_ci    save_state: definition of the given input must be SaveState instruction
230b1994897Sopenharmony_ci    dyn: dynamic operands, means that operand can repeat zero or more times
231b1994897Sopenharmony_ci
232b1994897Sopenharmony_civerification:
233b1994897Sopenharmony_ci  equal_type_classes: |
234b1994897Sopenharmony_ci    Type classes of instruction's operands are equal. Type classes are int, float, ref (see operand_tokens for info)
235b1994897Sopenharmony_ci  float_src_eq_dst_size: |
236b1994897Sopenharmony_ci    If instrucion's type is float then size of source operands shall be equal to size of destination.
237b1994897Sopenharmony_ci  integer_src_ge_dst_size: |
238b1994897Sopenharmony_ci    If instrucion's type is integer then size of source operands shall be greater than or equal to size of destination.
239b1994897Sopenharmony_ci  start_block_instruction: |
240b1994897Sopenharmony_ci    Instruction can only reside in start basic block.
241b1994897Sopenharmony_ci
242b1994897Sopenharmony_ciflags:
243b1994897Sopenharmony_ci  cf: Instruction affects control flow
244b1994897Sopenharmony_ci  terminator: Execution will be terminated at the given instruction
245b1994897Sopenharmony_ci  load: Instruction loads from memory
246b1994897Sopenharmony_ci  store: Instruction stores into memory
247b1994897Sopenharmony_ci  can_throw: Instruction can throw exception
248b1994897Sopenharmony_ci  call: Call instruction.
249b1994897Sopenharmony_ci  is_check: Instruction has runtime-checks and has `can_throw` flag
250b1994897Sopenharmony_ci  no_dce: Instruction that can't be deleted on DCE
251b1994897Sopenharmony_ci  no_cse: Instruction has unique vn class and CSE can't be applied
252b1994897Sopenharmony_ci  no_dst: Instruction has no destination operand
253b1994897Sopenharmony_ci  pseudo_dst: Instruction has pseudo destination operand, i.e. it doesn't affect on dataflow
254b1994897Sopenharmony_ci  implicit_runtime_call: Instruction may call runtime before loading source, which can be moved by GC during that call
255b1994897Sopenharmony_ci  low_level: Low level instruction
256b1994897Sopenharmony_ci  no_hoist: Instruction can't be hoisted
257b1994897Sopenharmony_ci  barrier: Instruction is a barrier for scheduling
258b1994897Sopenharmony_ci  ref_special: Instruction which can not be moved throught runtime calls
259b1994897Sopenharmony_ci  ifcvt: Instruction can be used in if-conversion
260b1994897Sopenharmony_ci  require_state: Instruction may call runtime, thus, it requires SaveState in the inputs
261b1994897Sopenharmony_ci  runtime_call: Instruction must call runtime
262b1994897Sopenharmony_ci  commutative: Instruction is commutative(Add, OR, And e.t.c.)
263b1994897Sopenharmony_ci  alloc: Instruction that allocates a new object on the heap
264b1994897Sopenharmony_ci  acc_read: Read the accumulator register
265b1994897Sopenharmony_ci  acc_write: Write the accumulator register
266b1994897Sopenharmony_ci  heap_inv: Invalidates heap
267b1994897Sopenharmony_ci  mem_barrier: we need encode memory barrier after the instruction(for return.void before)
268b1994897Sopenharmony_ci  native: Instruction is used to generate unmanaged (native) code
269b1994897Sopenharmony_ci  can_deoptimize: deoptimization may occur with jump to the interpreter
270b1994897Sopenharmony_ci
271b1994897Sopenharmony_cimodes:
272b1994897Sopenharmony_ci  jit_aot: JIT or AOT compiler
273b1994897Sopenharmony_ci  bytecode_opt: Bytecode optimizer
274b1994897Sopenharmony_ci  irtoc: Ir-To-Code tool
275