v / vlib / v2 / ssa / instr.v
122 lines · 106 sloc · 1.99 KB · e21acca549c0df34c98beb389088dbf7cee4c4d0
Raw
1// Copyright (c) 2026 Alexander Medvednikov. All rights reserved.
2// Use of this source code is governed by an MIT license
3// that can be found in the LICENSE file.
4
5module ssa
6
7import v2.token
8
9pub enum OpCode {
10 // Terminators
11 ret
12 br
13 jmp
14 switch_
15 unreachable
16
17 // Binary (integer)
18 add
19 sub
20 mul
21 sdiv
22 udiv
23 srem
24 urem
25
26 // Binary (float)
27 fadd
28 fsub
29 fmul
30 fdiv
31 frem
32
33 // Bitwise
34 shl
35 lshr
36 ashr
37 and_
38 or_
39 xor
40
41 // Memory
42 alloca
43 heap_alloc // Heap allocate memory for a type (malloc+zero): returns ptr
44 load
45 store
46 get_element_ptr
47 fence
48 cmpxchg
49 atomicrmw
50
51 // Conversion
52 trunc
53 zext
54 sext
55 fptoui
56 fptosi
57 uitofp
58 sitofp
59 bitcast
60
61 // Comparisons (signed)
62 lt
63 gt
64 le
65 ge
66 eq
67 ne
68 // Comparisons (unsigned)
69 ult
70 ugt
71 ule
72 uge
73
74 // Other
75 phi
76 call
77 call_indirect // Indirect call through function pointer
78 call_sret // Call with struct return (x8 indirect return on ARM64)
79 select
80 assign // copy for phi elimination
81 inline_string_init // Create string struct by value: (string){str, len, is_lit}
82
83 // Concurrency
84 go_call // Launch goroutine: go_call fn_ref, args...
85 spawn_call // Launch OS thread: spawn_call fn_ref, args...
86
87 // Aggregate (struct/tuple) operations
88 extractvalue // Extract element from struct/tuple: extractvalue %tuple, index
89 insertvalue // Insert element into struct/tuple: insertvalue %tuple, %val, index
90 struct_init // Create struct: operands are field values in order
91}
92
93pub enum AtomicOrdering {
94 not_atomic
95 unordered
96 monotonic
97 acquire
98 release
99 acq_rel
100 seq_cst
101}
102
103pub struct Instruction {
104pub mut:
105 op OpCode
106 // Operands are IDs of other Values
107 operands []ValueID
108pub:
109 block BlockID
110 typ TypeID // Result type
111
112 pos token.Pos
113 atomic_ord AtomicOrdering
114 inline InlineHint // Inline hint for call instructions
115}
116
117pub enum InlineHint {
118 none // No hint, let optimizer decide
119 always // Always inline (e.g., V's [inline] attribute)
120 never // Never inline (e.g., V's [noinline] attribute)
121 hint // Suggest inlining (optimizer may ignore)
122}
123