ruby-llvm 20.1.7 → 22.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/ext/ruby-llvm-support/Rakefile +5 -4
- data/ext/ruby-llvm-support/support.cpp +75 -4
- data/lib/llvm/analysis.rb +9 -0
- data/lib/llvm/analysis_ffi.rb +1 -2
- data/lib/llvm/core/attribute.rb +41 -2
- data/lib/llvm/core/bitcode.rb +24 -6
- data/lib/llvm/core/bitcode_ffi.rb +1 -2
- data/lib/llvm/core/builder.rb +140 -21
- data/lib/llvm/core/context.rb +7 -2
- data/lib/llvm/core/module.rb +79 -23
- data/lib/llvm/core/pass_manager.rb +1 -0
- data/lib/llvm/core/type.rb +139 -63
- data/lib/llvm/core/value.rb +156 -42
- data/lib/llvm/core.rb +7 -4
- data/lib/llvm/core_ffi.rb +11 -34
- data/lib/llvm/core_ffi_v2.rb +5 -0
- data/lib/llvm/execution_engine.rb +59 -39
- data/lib/llvm/execution_engine_ffi.rb +5 -6
- data/lib/llvm/linker.rb +13 -5
- data/lib/llvm/linker_ffi.rb +1 -2
- data/lib/llvm/lljit.rb +9 -9
- data/lib/llvm/owned_string.rb +48 -0
- data/lib/llvm/pass_builder.rb +21 -18
- data/lib/llvm/support.rb +11 -7
- data/lib/llvm/target.rb +40 -23
- data/lib/llvm/target_ffi.rb +5 -6
- data/lib/llvm/transforms/ipo.rb +1 -0
- data/lib/llvm/transforms/pass_manager_builder.rb +1 -0
- data/lib/llvm/transforms/scalar.rb +1 -0
- data/lib/llvm/transforms/utils.rb +1 -0
- data/lib/llvm/transforms/vectorize.rb +1 -0
- data/lib/llvm/version.rb +24 -3
- data/lib/llvm.rb +10 -3
- metadata +11 -55
- data/lib/llvm/config.rb +0 -14
data/lib/llvm/core/builder.rb
CHANGED
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
+
# typed: strict
|
|
2
3
|
|
|
3
4
|
module LLVM
|
|
4
5
|
class Builder
|
|
5
6
|
extend Gem::Deprecate
|
|
6
7
|
|
|
7
8
|
# Important: Call #dispose to free backend memory after use.
|
|
9
|
+
#: -> void
|
|
8
10
|
def initialize
|
|
9
|
-
@ptr = C.create_builder()
|
|
11
|
+
@ptr = C.create_builder() #: FFI::Pointer?
|
|
12
|
+
raise RuntimeError if @ptr.null? || ptr.nil?
|
|
10
13
|
end
|
|
11
14
|
|
|
15
|
+
#: FFI::Pointer?
|
|
16
|
+
attr_reader :ptr
|
|
17
|
+
|
|
18
|
+
#: -> void
|
|
12
19
|
def dispose
|
|
13
20
|
return if @ptr.nil?
|
|
14
21
|
C.dispose_builder(@ptr)
|
|
@@ -16,6 +23,7 @@ module LLVM
|
|
|
16
23
|
end
|
|
17
24
|
|
|
18
25
|
# @private
|
|
26
|
+
#: -> FFI::Pointer?
|
|
19
27
|
def to_ptr
|
|
20
28
|
@ptr
|
|
21
29
|
end
|
|
@@ -25,6 +33,7 @@ module LLVM
|
|
|
25
33
|
# @param [LLVM::BasicBlock] block
|
|
26
34
|
# @param [LLVM::Instruction] instruction
|
|
27
35
|
# @return [LLVM::Builder]
|
|
36
|
+
#: (BasicBlock, Instruction) -> self
|
|
28
37
|
def position(block, instruction)
|
|
29
38
|
raise ArgumentError, "Block must be LLVM::BasicBlock" if !block.is_a?(LLVM::BasicBlock)
|
|
30
39
|
|
|
@@ -38,6 +47,7 @@ module LLVM
|
|
|
38
47
|
#
|
|
39
48
|
# @param [LLVM::Instruction] instruction
|
|
40
49
|
# @return [LLVM::Builder]
|
|
50
|
+
#: (Instruction) -> self
|
|
41
51
|
def position_before(instruction)
|
|
42
52
|
raise ArgumentError, "Instruction must be LLVM::Instruction" if !instruction.is_a?(LLVM::Instruction)
|
|
43
53
|
|
|
@@ -49,6 +59,7 @@ module LLVM
|
|
|
49
59
|
#
|
|
50
60
|
# @param [LLVM::BasicBlock] block
|
|
51
61
|
# @return [LLVM::Builder]
|
|
62
|
+
#: (BasicBlock) -> self
|
|
52
63
|
def position_at_end(block)
|
|
53
64
|
raise ArgumentError, "Block must be LLVM::BasicBlock" if !block.is_a?(LLVM::BasicBlock)
|
|
54
65
|
|
|
@@ -59,12 +70,14 @@ module LLVM
|
|
|
59
70
|
# The BasicBlock at which the Builder is currently positioned.
|
|
60
71
|
#
|
|
61
72
|
# @return [LLVM::BasicBlock]
|
|
73
|
+
#: -> BasicBlock
|
|
62
74
|
def insert_block
|
|
63
75
|
BasicBlock.from_ptr(C.get_insert_block(self))
|
|
64
76
|
end
|
|
65
77
|
|
|
66
78
|
# @return [LLVM::Instruction]
|
|
67
79
|
# @LLVMinst ret
|
|
80
|
+
#: -> Value
|
|
68
81
|
def ret_void
|
|
69
82
|
Instruction.from_ptr(C.build_ret_void(self))
|
|
70
83
|
end
|
|
@@ -72,6 +85,7 @@ module LLVM
|
|
|
72
85
|
# @param [LLVM::Value] val The value to return
|
|
73
86
|
# @return [LLVM::Instruction]
|
|
74
87
|
# @LLVMinst ret
|
|
88
|
+
#: (?Value?) -> Value
|
|
75
89
|
def ret(val = nil)
|
|
76
90
|
unless [LLVM::Value, NilClass].any? { |c| val.is_a?(c) }
|
|
77
91
|
raise ArgumentError, "Trying to build LLVM ret with non-value: #{val.inspect}"
|
|
@@ -84,22 +98,23 @@ module LLVM
|
|
|
84
98
|
# @param [Array<LLVM::Value>] vals
|
|
85
99
|
# @return [LLVM::Instruction]
|
|
86
100
|
# @LLVMinst ret
|
|
101
|
+
#: (*Value) -> Value
|
|
87
102
|
def aggregate_ret(*vals)
|
|
88
103
|
FFI::MemoryPointer.new(FFI.type_size(:pointer) * vals.size) do |vals_ptr|
|
|
89
104
|
vals_ptr.write_array_of_pointer(vals)
|
|
90
|
-
Instruction.from_ptr(C.build_aggregate_ret(self, vals_ptr, vals.size))
|
|
91
|
-
end
|
|
105
|
+
return Instruction.from_ptr(C.build_aggregate_ret(self, vals_ptr, vals.size))
|
|
106
|
+
end #: as Value
|
|
92
107
|
end
|
|
93
108
|
|
|
94
109
|
# Unconditional branching (i.e. goto)
|
|
95
110
|
# @param [LLVM::BasicBlock] block Where to jump
|
|
96
111
|
# @return [LLVM::Instruction]
|
|
97
112
|
# @LLVMinst br
|
|
113
|
+
#: (BasicBlock) -> Value
|
|
98
114
|
def br(block)
|
|
99
115
|
raise ArgumentError, "Trying to build LLVM br with non-block: #{block.inspect}" if !block.is_a?(LLVM::BasicBlock)
|
|
100
116
|
|
|
101
|
-
Instruction.from_ptr(
|
|
102
|
-
C.build_br(self, block))
|
|
117
|
+
Instruction.from_ptr(C.build_br(self, block))
|
|
103
118
|
end
|
|
104
119
|
|
|
105
120
|
# Indirect branching (i.e. computed goto)
|
|
@@ -107,9 +122,11 @@ module LLVM
|
|
|
107
122
|
# @param [Integer] num_dests Number of possible destinations to be added
|
|
108
123
|
# @return [LLVM::Instruction]
|
|
109
124
|
# @LLVMinst indirectbr
|
|
125
|
+
#: (BasicBlock, Integer) -> Value
|
|
110
126
|
def ibr(addr, num_dests)
|
|
111
127
|
IndirectBr.from_ptr(
|
|
112
|
-
C.build_indirect_br(self, addr, num_dests)
|
|
128
|
+
C.build_indirect_br(self, addr, num_dests)
|
|
129
|
+
)
|
|
113
130
|
end
|
|
114
131
|
|
|
115
132
|
# Conditional branching (i.e. if)
|
|
@@ -118,6 +135,7 @@ module LLVM
|
|
|
118
135
|
# @param [LLVM::BasicBlock] iffalse Where to jump if condition is false
|
|
119
136
|
# @return [LLVM::Instruction]
|
|
120
137
|
# @LLVMinst br
|
|
138
|
+
#: (Value, BasicBlock, BasicBlock) -> Value
|
|
121
139
|
def cond(cond, iftrue, iffalse)
|
|
122
140
|
raise ArgumentError, "Trying to build LLVM cond br with non-block (true branch): #{iftrue.inspect}" if !iftrue.is_a?(LLVM::BasicBlock)
|
|
123
141
|
|
|
@@ -125,10 +143,10 @@ module LLVM
|
|
|
125
143
|
|
|
126
144
|
cond2 = cond_condition(cond)
|
|
127
145
|
|
|
128
|
-
Instruction.from_ptr(
|
|
129
|
-
C.build_cond_br(self, cond2, iftrue, iffalse))
|
|
146
|
+
Instruction.from_ptr(C.build_cond_br(self, cond2, iftrue, iffalse))
|
|
130
147
|
end
|
|
131
148
|
|
|
149
|
+
#: ((Value | bool)) -> Value
|
|
132
150
|
private def cond_condition(cond)
|
|
133
151
|
case cond
|
|
134
152
|
when LLVM::Value
|
|
@@ -153,6 +171,7 @@ module LLVM
|
|
|
153
171
|
# values to basic blocks. When a value is matched, control will jump
|
|
154
172
|
# to the corresponding basic block.
|
|
155
173
|
# @return [LLVM::Instruction]
|
|
174
|
+
#: (Value, BasicBlock, Hash[Value, BasicBlock]) -> Value
|
|
156
175
|
def switch(val, default, cases)
|
|
157
176
|
inst = SwitchInst.from_ptr(C.build_switch(self, val, default, cases.size))
|
|
158
177
|
cases.each do |(c, block)|
|
|
@@ -170,33 +189,37 @@ module LLVM
|
|
|
170
189
|
# @return [LLVM::Instruction] The value returned by 'fun', unless an
|
|
171
190
|
# unwind instruction occurs
|
|
172
191
|
# @LLVMinst invoke
|
|
192
|
+
#: (untyped, [Value], BasicBlock, BasicBlock, ?String) -> InvokeInst
|
|
173
193
|
def invoke(fun, args, normal, exception, name = "")
|
|
174
194
|
invoke2(nil, fun, args, normal, exception, name)
|
|
175
195
|
end
|
|
176
196
|
|
|
197
|
+
#: (Type?, untyped, [Value], BasicBlock, BasicBlock, ?String) -> InvokeInst
|
|
177
198
|
def invoke2(type, fun, args, normal, exception, name = "")
|
|
178
199
|
type, fun = call2_infer_function_and_type(type, fun)
|
|
179
200
|
|
|
180
201
|
arg_count = args.size
|
|
181
|
-
invoke_ins = nil
|
|
202
|
+
invoke_ins = nil #: InvokeInst?
|
|
182
203
|
FFI::MemoryPointer.new(FFI.type_size(:pointer) * arg_count) do |args_ptr|
|
|
183
204
|
args_ptr.write_array_of_pointer(args)
|
|
184
205
|
ins = C.build_invoke2(self, type, fun, args_ptr, arg_count, normal, exception, name)
|
|
185
|
-
invoke_ins = InvokeInst.from_ptr(ins)
|
|
206
|
+
invoke_ins = InvokeInst.from_ptr(ins) #: as InvokeInst
|
|
186
207
|
end
|
|
187
208
|
|
|
188
209
|
if fun.is_a?(Function)
|
|
189
210
|
invoke_ins.call_conv = fun.call_conv
|
|
190
211
|
end
|
|
191
212
|
|
|
192
|
-
invoke_ins
|
|
213
|
+
invoke_ins #: as !nil
|
|
193
214
|
end
|
|
194
215
|
|
|
195
216
|
# @return LLVM::Value
|
|
217
|
+
#: (Type, untyped, Integer, ?String) -> Value
|
|
196
218
|
def landing_pad(type, personality_function, num_clauses, name = '')
|
|
197
219
|
C.build_landing_pad(self, type, personality_function, num_clauses, name)
|
|
198
220
|
end
|
|
199
221
|
|
|
222
|
+
#: (Type, untyped, Integer, ?String) -> Value
|
|
200
223
|
def landing_pad_cleanup(type, personality_function, num_clauses, name = '')
|
|
201
224
|
lp = landing_pad(type, personality_function, num_clauses, name)
|
|
202
225
|
C.set_cleanup(lp, 1)
|
|
@@ -205,6 +228,7 @@ module LLVM
|
|
|
205
228
|
|
|
206
229
|
# Builds an unwind Instruction.
|
|
207
230
|
# @LLVMinst unwind
|
|
231
|
+
#: -> void
|
|
208
232
|
def unwind
|
|
209
233
|
raise DeprecationError
|
|
210
234
|
end
|
|
@@ -213,6 +237,7 @@ module LLVM
|
|
|
213
237
|
# provide hints to the optimizer.
|
|
214
238
|
# @return [LLVM::Instruction]
|
|
215
239
|
# @LLVMinst unreachable
|
|
240
|
+
#: -> Value
|
|
216
241
|
def unreachable
|
|
217
242
|
Instruction.from_ptr(C.build_unreachable(self))
|
|
218
243
|
end
|
|
@@ -223,6 +248,7 @@ module LLVM
|
|
|
223
248
|
# @param [String] name Name of the result in LLVM IR
|
|
224
249
|
# @return [LLVM::Instruction] The integer sum of the two operands
|
|
225
250
|
# @LLVMinst add
|
|
251
|
+
#: (Value, Value, ?String) -> Value
|
|
226
252
|
def add(lhs, rhs, name = "")
|
|
227
253
|
Instruction.from_ptr(C.build_add(self, lhs, rhs, name))
|
|
228
254
|
end
|
|
@@ -233,6 +259,7 @@ module LLVM
|
|
|
233
259
|
# @param [String] name Name of the result in LLVM IR
|
|
234
260
|
# @return [LLVM::Instruction] The integer sum of the two operands
|
|
235
261
|
# @LLVMinst add
|
|
262
|
+
#: (Value, Value, ?String) -> Value
|
|
236
263
|
def nsw_add(lhs, rhs, name = "")
|
|
237
264
|
Instruction.from_ptr(C.build_nsw_add(self, lhs, rhs, name))
|
|
238
265
|
end
|
|
@@ -243,6 +270,7 @@ module LLVM
|
|
|
243
270
|
# @param [String] name Name of the result in LLVM IR
|
|
244
271
|
# @return [LLVM::Instruction] The integer sum of the two operands
|
|
245
272
|
# @LLVMinst add
|
|
273
|
+
#: (Value, Value, ?String) -> Value
|
|
246
274
|
def nuw_add(lhs, rhs, name = "")
|
|
247
275
|
Instruction.from_ptr(C.build_nuw_add(self, lhs, rhs, name))
|
|
248
276
|
end
|
|
@@ -252,6 +280,7 @@ module LLVM
|
|
|
252
280
|
# @param [String] name Name of the result in LLVM IR
|
|
253
281
|
# @return [LLVM::Instruction] The floating point sum of the two operands
|
|
254
282
|
# @LLVMinst fadd
|
|
283
|
+
#: (Value, Value, ?String) -> Value
|
|
255
284
|
def fadd(lhs, rhs, name = "")
|
|
256
285
|
Instruction.from_ptr(C.build_f_add(self, lhs, rhs, name))
|
|
257
286
|
end
|
|
@@ -262,6 +291,7 @@ module LLVM
|
|
|
262
291
|
# @param [String] name Name of the result in LLVM IR
|
|
263
292
|
# @return [LLVM::Instruction] The integer difference of the two operands
|
|
264
293
|
# @LLVMinst sub
|
|
294
|
+
#: (Value, Value, ?String) -> Value
|
|
265
295
|
def sub(lhs, rhs, name = "")
|
|
266
296
|
Instruction.from_ptr(C.build_sub(self, lhs, rhs, name))
|
|
267
297
|
end
|
|
@@ -272,6 +302,7 @@ module LLVM
|
|
|
272
302
|
# @param [String] name Name of the result in LLVM IR
|
|
273
303
|
# @return [LLVM::Instruction] The integer difference of the two operands
|
|
274
304
|
# @LLVMinst sub
|
|
305
|
+
#: (Value, Value, ?String) -> Value
|
|
275
306
|
def nsw_sub(lhs, rhs, name = "")
|
|
276
307
|
Instruction.from_ptr(C.build_nsw_sub(self, lhs, rhs, name))
|
|
277
308
|
end
|
|
@@ -282,6 +313,7 @@ module LLVM
|
|
|
282
313
|
# @param [String] name Name of the result in LLVM IR
|
|
283
314
|
# @return [LLVM::Instruction] The integer difference of the two operands
|
|
284
315
|
# @LLVMinst sub
|
|
316
|
+
#: (Value, Value, ?String) -> Value
|
|
285
317
|
def nuw_sub(lhs, rhs, name = "")
|
|
286
318
|
Instruction.from_ptr(C.build_nuw_sub(self, lhs, rhs, name))
|
|
287
319
|
end
|
|
@@ -292,6 +324,7 @@ module LLVM
|
|
|
292
324
|
# @return [LLVM::Instruction] The floating point difference of the two
|
|
293
325
|
# operands
|
|
294
326
|
# @LLVMinst fsub
|
|
327
|
+
#: (Value, Value, ?String) -> Value
|
|
295
328
|
def fsub(lhs, rhs, name = "")
|
|
296
329
|
Instruction.from_ptr(C.build_f_sub(self, lhs, rhs, name))
|
|
297
330
|
end
|
|
@@ -302,6 +335,7 @@ module LLVM
|
|
|
302
335
|
# @param [String] name Name of the result in LLVM IR
|
|
303
336
|
# @return [LLVM::Instruction] The integer product of the two operands
|
|
304
337
|
# @LLVMinst mul
|
|
338
|
+
#: (Value, Value, ?String) -> Value
|
|
305
339
|
def mul(lhs, rhs, name = "")
|
|
306
340
|
Instruction.from_ptr(C.build_mul(self, lhs, rhs, name))
|
|
307
341
|
end
|
|
@@ -312,6 +346,7 @@ module LLVM
|
|
|
312
346
|
# @param [String] name Name of the result in LLVM IR
|
|
313
347
|
# @return [LLVM::Instruction] The integer product of the two operands
|
|
314
348
|
# @LLVMinst mul
|
|
349
|
+
#: (Value, Value, ?String) -> Value
|
|
315
350
|
def nsw_mul(lhs, rhs, name = "")
|
|
316
351
|
Instruction.from_ptr(C.build_nsw_mul(self, lhs, rhs, name))
|
|
317
352
|
end
|
|
@@ -322,6 +357,7 @@ module LLVM
|
|
|
322
357
|
# @param [String] name Name of the result in LLVM IR
|
|
323
358
|
# @return [LLVM::Instruction] The integer product of the two operands
|
|
324
359
|
# @LLVMinst mul
|
|
360
|
+
#: (Value, Value, ?String) -> Value
|
|
325
361
|
def nuw_mul(lhs, rhs, name = "")
|
|
326
362
|
Instruction.from_ptr(C.build_nuw_mul(self, lhs, rhs, name))
|
|
327
363
|
end
|
|
@@ -333,6 +369,7 @@ module LLVM
|
|
|
333
369
|
# @return [LLVM::Instruction] The floating point product of the two
|
|
334
370
|
# operands
|
|
335
371
|
# @LLVMinst fmul
|
|
372
|
+
#: (Value, Value, ?String) -> Value
|
|
336
373
|
def fmul(lhs, rhs, name = "")
|
|
337
374
|
Instruction.from_ptr(C.build_f_mul(self, lhs, rhs, name))
|
|
338
375
|
end
|
|
@@ -343,6 +380,7 @@ module LLVM
|
|
|
343
380
|
# @param [String] name Name of the result in LLVM IR
|
|
344
381
|
# @return [LLVM::Instruction] The integer quotient of the two operands
|
|
345
382
|
# @LLVMinst udiv
|
|
383
|
+
#: (Value, Value, ?String) -> Value
|
|
346
384
|
def udiv(lhs, rhs, name = "")
|
|
347
385
|
Instruction.from_ptr(C.build_u_div(self, lhs, rhs, name))
|
|
348
386
|
end
|
|
@@ -353,6 +391,7 @@ module LLVM
|
|
|
353
391
|
# @param [String] name Name of the result in LLVM IR
|
|
354
392
|
# @return [LLVM::Instruction] The integer quotient of the two operands
|
|
355
393
|
# @LLVMinst sdiv
|
|
394
|
+
#: (Value, Value, ?String) -> Value
|
|
356
395
|
def sdiv(lhs, rhs, name = "")
|
|
357
396
|
Instruction.from_ptr(C.build_s_div(self, lhs, rhs, name))
|
|
358
397
|
end
|
|
@@ -363,6 +402,7 @@ module LLVM
|
|
|
363
402
|
# @param [String] name Name of the result in LLVM IR
|
|
364
403
|
# @return [LLVM::Instruction] The integer quotient of the two operands
|
|
365
404
|
# @LLVMinst sdiv
|
|
405
|
+
#: (Value, Value, ?String) -> Value
|
|
366
406
|
def exact_sdiv(lhs, rhs, name = "")
|
|
367
407
|
Instruction.from_ptr(C.build_exact_s_div(self, lhs, rhs, name))
|
|
368
408
|
end
|
|
@@ -373,6 +413,7 @@ module LLVM
|
|
|
373
413
|
# @return [LLVM::Instruction] The floating point quotient of the two
|
|
374
414
|
# operands
|
|
375
415
|
# @LLVMinst fdiv
|
|
416
|
+
#: (Value, Value, ?String) -> Value
|
|
376
417
|
def fdiv(lhs, rhs, name = "")
|
|
377
418
|
Instruction.from_ptr(C.build_f_div(self, lhs, rhs, name))
|
|
378
419
|
end
|
|
@@ -383,6 +424,7 @@ module LLVM
|
|
|
383
424
|
# @param [String] name Name of the result in LLVM IR
|
|
384
425
|
# @return [LLVM::Instruction] The integer remainder
|
|
385
426
|
# @LLVMinst urem
|
|
427
|
+
#: (Value, Value, ?String) -> Value
|
|
386
428
|
def urem(lhs, rhs, name = "")
|
|
387
429
|
Instruction.from_ptr(C.build_u_rem(self, lhs, rhs, name))
|
|
388
430
|
end
|
|
@@ -393,6 +435,7 @@ module LLVM
|
|
|
393
435
|
# @param [String] name Name of the result in LLVM IR
|
|
394
436
|
# @return [LLVM::Instruction] The integer remainder
|
|
395
437
|
# @LLVMinst srem
|
|
438
|
+
#: (Value, Value, ?String) -> Value
|
|
396
439
|
def srem(lhs, rhs, name = "")
|
|
397
440
|
Instruction.from_ptr(C.build_s_rem(self, lhs, rhs, name))
|
|
398
441
|
end
|
|
@@ -402,6 +445,7 @@ module LLVM
|
|
|
402
445
|
# @param [String] name Name of the result in LLVM IR
|
|
403
446
|
# @return [LLVM::Instruction] The floating point remainder
|
|
404
447
|
# @LLVMinst frem
|
|
448
|
+
#: (Value, Value, ?String) -> Value
|
|
405
449
|
def frem(lhs, rhs, name = "")
|
|
406
450
|
Instruction.from_ptr(C.build_f_rem(self, lhs, rhs, name))
|
|
407
451
|
end
|
|
@@ -412,6 +456,7 @@ module LLVM
|
|
|
412
456
|
# @return [LLVM::Instruction] The floating point negation
|
|
413
457
|
# @LLVMinst fneg
|
|
414
458
|
# https://llvm.org/docs/LangRef.html#fneg-instruction
|
|
459
|
+
#: (Value, ?String) -> Value
|
|
415
460
|
def fneg(lhs, name = "")
|
|
416
461
|
Instruction.from_ptr(C.build_f_neg(self, lhs, name))
|
|
417
462
|
end
|
|
@@ -421,6 +466,7 @@ module LLVM
|
|
|
421
466
|
# @param [String] name Name of the result in LLVM IR
|
|
422
467
|
# @return [LLVM::Instruction] An integer instruction
|
|
423
468
|
# @LLVMinst shl
|
|
469
|
+
#: (Value, Value, ?String) -> Value
|
|
424
470
|
def shl(lhs, rhs, name = "")
|
|
425
471
|
Instruction.from_ptr(C.build_shl(self, lhs, rhs, name))
|
|
426
472
|
end
|
|
@@ -431,6 +477,7 @@ module LLVM
|
|
|
431
477
|
# @param [String] name Name of the result in LLVM IR
|
|
432
478
|
# @return [LLVM::Instruction] An integer instruction
|
|
433
479
|
# @LLVMinst lshr
|
|
480
|
+
#: (Value, Value, ?String) -> Value
|
|
434
481
|
def lshr(lhs, rhs, name = "")
|
|
435
482
|
Instruction.from_ptr(C.build_l_shr(self, lhs, rhs, name))
|
|
436
483
|
end
|
|
@@ -441,6 +488,7 @@ module LLVM
|
|
|
441
488
|
# @param [String] name Name of the result in LLVM IR
|
|
442
489
|
# @return [LLVM::Instruction] An integer instruction
|
|
443
490
|
# @LLVMinst ashr
|
|
491
|
+
#: (Value, Value, ?String) -> Value
|
|
444
492
|
def ashr(lhs, rhs, name = "")
|
|
445
493
|
Instruction.from_ptr(C.build_a_shr(self, lhs, rhs, name))
|
|
446
494
|
end
|
|
@@ -450,6 +498,7 @@ module LLVM
|
|
|
450
498
|
# @param [String] name Name of the result in LLVM IR
|
|
451
499
|
# @return [LLVM::Instruction] An integer instruction
|
|
452
500
|
# @LLVMinst and
|
|
501
|
+
#: (Value, Value, ?String) -> Value
|
|
453
502
|
def and(lhs, rhs, name = "")
|
|
454
503
|
Instruction.from_ptr(C.build_and(self, lhs, rhs, name))
|
|
455
504
|
end
|
|
@@ -459,6 +508,7 @@ module LLVM
|
|
|
459
508
|
# @param [String] name Name of the result in LLVM IR
|
|
460
509
|
# @return [LLVM::Instruction] An integer instruction
|
|
461
510
|
# @LLVMinst or
|
|
511
|
+
#: (Value, Value, ?String) -> Value
|
|
462
512
|
def or(lhs, rhs, name = "")
|
|
463
513
|
Instruction.from_ptr(C.build_or(self, lhs, rhs, name))
|
|
464
514
|
end
|
|
@@ -468,6 +518,7 @@ module LLVM
|
|
|
468
518
|
# @param [String] name Name of the result in LLVM IR
|
|
469
519
|
# @return [LLVM::Instruction] An integer instruction
|
|
470
520
|
# @LLVMinst xor
|
|
521
|
+
#: (Value, Value, ?String) -> Value
|
|
471
522
|
def xor(lhs, rhs, name = "")
|
|
472
523
|
Instruction.from_ptr(C.build_xor(self, lhs, rhs, name))
|
|
473
524
|
end
|
|
@@ -478,6 +529,7 @@ module LLVM
|
|
|
478
529
|
# @param [String] name Name of the result in LLVM IR
|
|
479
530
|
# @return [LLVM::Instruction] The negated operand
|
|
480
531
|
# @LLVMinst sub
|
|
532
|
+
#: (Value, ?String) -> Value
|
|
481
533
|
def neg(arg, name = "")
|
|
482
534
|
Instruction.from_ptr(C.build_neg(self, arg, name))
|
|
483
535
|
end
|
|
@@ -487,6 +539,7 @@ module LLVM
|
|
|
487
539
|
# @param [String] name Name of the result in LLVM IR
|
|
488
540
|
# @return [LLVM::Instruction] The negated operand
|
|
489
541
|
# @LLVMinst sub
|
|
542
|
+
#: (Value, ?String) -> Value
|
|
490
543
|
def nsw_neg(arg, name = "")
|
|
491
544
|
Instruction.from_ptr(C.build_nsw_neg(self, arg, name))
|
|
492
545
|
end
|
|
@@ -497,6 +550,7 @@ module LLVM
|
|
|
497
550
|
# @return [LLVM::Instruction] The negated operand
|
|
498
551
|
# @LLVMinst sub
|
|
499
552
|
# @deprecated
|
|
553
|
+
#: (Value, ?String) -> Value
|
|
500
554
|
def nuw_neg(arg, name = "")
|
|
501
555
|
Instruction.from_ptr(C.build_nuw_neg(self, arg, name))
|
|
502
556
|
end
|
|
@@ -506,6 +560,7 @@ module LLVM
|
|
|
506
560
|
# @param [LLVM::Value] arg Integer or vector of integers
|
|
507
561
|
# @param [String] name The name of the result in LLVM IR
|
|
508
562
|
# @return [LLVM::Instruction] The negated operand
|
|
563
|
+
#: (Value, ?String) -> Value
|
|
509
564
|
def not(arg, name = "")
|
|
510
565
|
Instruction.from_ptr(C.build_not(self, arg, name))
|
|
511
566
|
end
|
|
@@ -514,6 +569,7 @@ module LLVM
|
|
|
514
569
|
# should be malloced
|
|
515
570
|
# @param [String] name The name of the result in LLVM IR
|
|
516
571
|
# @return [LLVM::Instruction] A pointer to the malloced bytes
|
|
572
|
+
#: (Type, ?String) -> Value
|
|
517
573
|
def malloc(ty, name = "")
|
|
518
574
|
Instruction.from_ptr(C.build_malloc(self, LLVM::Type(ty), name))
|
|
519
575
|
end
|
|
@@ -523,6 +579,7 @@ module LLVM
|
|
|
523
579
|
# @param [LLVM::Value] sz Unsigned integer representing size of the array
|
|
524
580
|
# @param [String] name The name of the result in LLVM IR
|
|
525
581
|
# @return [LLVM::Instruction] A pointer to the malloced array
|
|
582
|
+
#: (Type, Integer, ?String) -> Value
|
|
526
583
|
def array_malloc(ty, sz, name = "")
|
|
527
584
|
size = case sz
|
|
528
585
|
when LLVM::Value
|
|
@@ -541,8 +598,9 @@ module LLVM
|
|
|
541
598
|
# @param [String] name The name of the result in LLVM IR
|
|
542
599
|
# @return [LLVM::Instruction] A pointer to the allocad bytes
|
|
543
600
|
# @LLVMinst alloca
|
|
601
|
+
#: (Type, ?String) -> Alloca
|
|
544
602
|
def alloca(ty, name = "")
|
|
545
|
-
|
|
603
|
+
Alloca.from_ptr(C.build_alloca(self, LLVM::Type(ty), name)) #: as Alloca
|
|
546
604
|
end
|
|
547
605
|
|
|
548
606
|
# Array stack allocation
|
|
@@ -552,12 +610,14 @@ module LLVM
|
|
|
552
610
|
# @param [String] name The name of the result in LLVM IR
|
|
553
611
|
# @return [LLVM::Instruction] A pointer to the allocad array
|
|
554
612
|
# @LLVMinst alloca
|
|
613
|
+
#: (Type, Integer, ?String) -> Alloca
|
|
555
614
|
def array_alloca(ty, sz, name = "")
|
|
556
|
-
|
|
615
|
+
Alloca.from_ptr(C.build_array_alloca(self, LLVM::Type(ty), sz, name)) #: as Alloca
|
|
557
616
|
end
|
|
558
617
|
|
|
559
618
|
# @param [LLVM::Value] ptr The pointer to be freed
|
|
560
619
|
# @return [LLVM::Instruction] The result of the free instruction
|
|
620
|
+
#: (Value) -> Value
|
|
561
621
|
def free(ptr)
|
|
562
622
|
Instruction.from_ptr(C.build_free(self, ptr))
|
|
563
623
|
end
|
|
@@ -568,10 +628,12 @@ module LLVM
|
|
|
568
628
|
# @return [LLVM::Instruction] The result of the load operation. Represents
|
|
569
629
|
# a value of the pointer's type.
|
|
570
630
|
# @LLVMinst load
|
|
631
|
+
#: (Value, ?String) -> Value
|
|
571
632
|
def load(ptr, name = "")
|
|
572
633
|
load2(nil, ptr, name)
|
|
573
634
|
end
|
|
574
635
|
|
|
636
|
+
#: (Type?, Value, ?String) -> Value
|
|
575
637
|
def load2(type, ptr, name = "")
|
|
576
638
|
must_be_value!(ptr)
|
|
577
639
|
|
|
@@ -587,8 +649,9 @@ module LLVM
|
|
|
587
649
|
# @param [LLVM::Value] ptr A pointer to the same type as val
|
|
588
650
|
# @return [LLVM::Instruction] The result of the store operation
|
|
589
651
|
# @LLVMinst store
|
|
652
|
+
#: (Value, Value) -> Value
|
|
590
653
|
def store(val, ptr)
|
|
591
|
-
raise "val must be a Value, got #{val.class.name}" unless Value
|
|
654
|
+
raise "val must be a Value, got #{val.class.name}" unless val.is_a?(Value)
|
|
592
655
|
Instruction.from_ptr(C.build_store(self, val, ptr))
|
|
593
656
|
end
|
|
594
657
|
|
|
@@ -601,6 +664,7 @@ module LLVM
|
|
|
601
664
|
# @LLVMinst gep
|
|
602
665
|
# @see http://llvm.org/docs/GetElementPtr.html
|
|
603
666
|
# may return Instruction or GlobalVariable
|
|
667
|
+
#: (Value, [Value], ?String) -> Value
|
|
604
668
|
def gep(ptr, indices, name = "")
|
|
605
669
|
gep2(nil, ptr, indices, name)
|
|
606
670
|
end
|
|
@@ -615,6 +679,7 @@ module LLVM
|
|
|
615
679
|
# @LLVMinst gep2
|
|
616
680
|
# @see http://llvm.org/docs/GetElementPtr.html
|
|
617
681
|
# may return Instruction or GlobalVariable
|
|
682
|
+
#: (Type?, Value, [Value], ?String) -> Value
|
|
618
683
|
def gep2(type, ptr, indices, name = '')
|
|
619
684
|
must_be_value!(ptr)
|
|
620
685
|
|
|
@@ -626,7 +691,7 @@ module LLVM
|
|
|
626
691
|
indices_ptr.write_array_of_pointer(indices)
|
|
627
692
|
ins = C.build_gep2(self, type, ptr, indices_ptr, indices.size, name)
|
|
628
693
|
return Instruction.from_ptr(ins)
|
|
629
|
-
end
|
|
694
|
+
end #: as Value
|
|
630
695
|
end
|
|
631
696
|
|
|
632
697
|
# Builds a inbounds getelementptr instruction. If the indices are outside
|
|
@@ -638,10 +703,12 @@ module LLVM
|
|
|
638
703
|
# @return [LLVM::Instruction] The resulting pointer
|
|
639
704
|
# @LLVMinst gep
|
|
640
705
|
# @see http://llvm.org/docs/GetElementPtr.html
|
|
706
|
+
#: (Value, [Value], ?String) -> Value
|
|
641
707
|
def inbounds_gep(ptr, indices, name = "")
|
|
642
708
|
inbounds_gep2(nil, ptr, indices, name)
|
|
643
709
|
end
|
|
644
710
|
|
|
711
|
+
#: (Type?, Value, [Value], ?String) -> Value
|
|
645
712
|
def inbounds_gep2(type, ptr, indices, name = "")
|
|
646
713
|
must_be_value!(ptr)
|
|
647
714
|
|
|
@@ -653,7 +720,7 @@ module LLVM
|
|
|
653
720
|
indices_ptr.write_array_of_pointer(indices)
|
|
654
721
|
ins = C.build_inbounds_gep2(self, type, ptr, indices_ptr, indices.size, name)
|
|
655
722
|
return Instruction.from_ptr(ins)
|
|
656
|
-
end
|
|
723
|
+
end #: as Value
|
|
657
724
|
end
|
|
658
725
|
|
|
659
726
|
# Builds a struct getelementptr Instruction.
|
|
@@ -665,10 +732,12 @@ module LLVM
|
|
|
665
732
|
# @return [LLVM::Instruction] The resulting pointer
|
|
666
733
|
# @LLVMinst gep
|
|
667
734
|
# @see http://llvm.org/docs/GetElementPtr.html
|
|
735
|
+
#: (Value, Value, ?String) -> Value
|
|
668
736
|
def struct_gep(ptr, idx, name = "")
|
|
669
737
|
struct_gep2(nil, ptr, idx, name)
|
|
670
738
|
end
|
|
671
739
|
|
|
740
|
+
#: (Type?, Value, Value, ?String) -> Value
|
|
672
741
|
def struct_gep2(type, ptr, idx, name = "")
|
|
673
742
|
must_be_value!(ptr)
|
|
674
743
|
|
|
@@ -683,6 +752,7 @@ module LLVM
|
|
|
683
752
|
# @param [String] string The string used by the initialize
|
|
684
753
|
# @param [Name] name Name of the result in LLVM IR
|
|
685
754
|
# @return [LLVM::Instruction] Reference to the global string
|
|
755
|
+
#: (String, ?String) -> Value
|
|
686
756
|
def global_string(string, name = "")
|
|
687
757
|
Instruction.from_ptr(C.build_global_string(self, string, name))
|
|
688
758
|
end
|
|
@@ -691,6 +761,7 @@ module LLVM
|
|
|
691
761
|
# @param [String] string The string used by the initializer
|
|
692
762
|
# @param [String] name The name of the result in LLVM IR
|
|
693
763
|
# @return [LLVM::Instruction] Reference to the global string pointer
|
|
764
|
+
#: (String, ?String) -> Value
|
|
694
765
|
def global_string_pointer(string, name = "")
|
|
695
766
|
Instruction.from_ptr(C.build_global_string_ptr(self, string, name))
|
|
696
767
|
end
|
|
@@ -703,6 +774,7 @@ module LLVM
|
|
|
703
774
|
# @param [String] name The name of the result in LLVM IR
|
|
704
775
|
# @return [LLVM::Instruction] The truncated value
|
|
705
776
|
# @LLVMinst trunc
|
|
777
|
+
#: (Value, Type, ?String) -> Value
|
|
706
778
|
def trunc(val, ty, name = "")
|
|
707
779
|
Instruction.from_ptr(C.build_trunc(self, val, LLVM::Type(ty), name))
|
|
708
780
|
end
|
|
@@ -715,6 +787,7 @@ module LLVM
|
|
|
715
787
|
# @param [String] name The name of the result in LLVM IR
|
|
716
788
|
# @return [LLVM::Instruction] The extended value
|
|
717
789
|
# @LLVMinst zext
|
|
790
|
+
#: (Value, Type, ?String) -> Value
|
|
718
791
|
def zext(val, ty, name = "")
|
|
719
792
|
Instruction.from_ptr(C.build_z_ext(self, val, LLVM::Type(ty), name))
|
|
720
793
|
end
|
|
@@ -727,6 +800,7 @@ module LLVM
|
|
|
727
800
|
# @param [String] name The name of the result in LLVM IR
|
|
728
801
|
# @return [LLVM::Instruction] The extended value
|
|
729
802
|
# @LLVMinst sext
|
|
803
|
+
#: (Value, Type, ?String) -> Value
|
|
730
804
|
def sext(val, ty, name = "")
|
|
731
805
|
Instruction.from_ptr(C.build_s_ext(self, val, LLVM::Type(ty), name))
|
|
732
806
|
end
|
|
@@ -738,6 +812,7 @@ module LLVM
|
|
|
738
812
|
# @param [String] name The name of the result in LLVM IR
|
|
739
813
|
# @return [LLVM::Instruction] The converted value
|
|
740
814
|
# @LLVMinst fptoui
|
|
815
|
+
#: (Value, Type, ?String) -> Value
|
|
741
816
|
def fp2ui(val, ty, name = "")
|
|
742
817
|
Instruction.from_ptr(C.build_fp_to_ui(self, val, LLVM::Type(ty), name))
|
|
743
818
|
end
|
|
@@ -749,6 +824,7 @@ module LLVM
|
|
|
749
824
|
# @param [String] name The name of the result in LLVM IR
|
|
750
825
|
# @return [LLVM::Instruction] The converted value
|
|
751
826
|
# @LLVMinst fptosi
|
|
827
|
+
#: (Value, Type, ?String) -> Value
|
|
752
828
|
def fp2si(val, ty, name = "")
|
|
753
829
|
Instruction.from_ptr(C.build_fp_to_si(self, val, LLVM::Type(ty), name))
|
|
754
830
|
end
|
|
@@ -761,6 +837,7 @@ module LLVM
|
|
|
761
837
|
# @param [String] name The name of the result in LLVM IR
|
|
762
838
|
# @return [LLVM::Instruction] The converted value
|
|
763
839
|
# @LLVMinst uitofp
|
|
840
|
+
#: (Value, Type, ?String) -> Value
|
|
764
841
|
def ui2fp(val, ty, name = "")
|
|
765
842
|
Instruction.from_ptr(C.build_ui_to_fp(self, val, LLVM::Type(ty), name))
|
|
766
843
|
end
|
|
@@ -773,6 +850,7 @@ module LLVM
|
|
|
773
850
|
# @param [String] name The name of the result in LLVM IR
|
|
774
851
|
# @return [LLVM::Instruction] The converted value
|
|
775
852
|
# @LLVMinst sitofp
|
|
853
|
+
#: (Value, Type, ?String) -> Value
|
|
776
854
|
def si2fp(val, ty, name = "")
|
|
777
855
|
Instruction.from_ptr(C.build_si_to_fp(self, val, LLVM::Type(ty), name))
|
|
778
856
|
end
|
|
@@ -784,6 +862,7 @@ module LLVM
|
|
|
784
862
|
# @param [String] name The name of the result in LLVM IR
|
|
785
863
|
# @return [LLVM::Instruction] The truncated value
|
|
786
864
|
# @LLVMinst fptrunc
|
|
865
|
+
#: (Value, Type, ?String) -> Value
|
|
787
866
|
def fp_trunc(val, ty, name = "")
|
|
788
867
|
Instruction.from_ptr(C.build_fp_trunc(self, val, LLVM::Type(ty), name))
|
|
789
868
|
end
|
|
@@ -795,6 +874,7 @@ module LLVM
|
|
|
795
874
|
# @param [String] name The name of the result in LLVM IR
|
|
796
875
|
# @return [LLVM::Instruction] The extended value
|
|
797
876
|
# @LLVMinst fpext
|
|
877
|
+
#: (Value, Type, ?String) -> Value
|
|
798
878
|
def fp_ext(val, ty, name = "")
|
|
799
879
|
Instruction.from_ptr(C.build_fp_ext(self, val, LLVM::Type(ty), name))
|
|
800
880
|
end
|
|
@@ -806,6 +886,7 @@ module LLVM
|
|
|
806
886
|
# @return [LLVM::Instruction] An integer of the given type representing
|
|
807
887
|
# the pointer's address
|
|
808
888
|
# @LLVMinst ptrtoint
|
|
889
|
+
#: (Value, Type, ?String) -> Value
|
|
809
890
|
def ptr2int(val, ty, name = "")
|
|
810
891
|
Instruction.from_ptr(C.build_ptr_to_int(self, val, LLVM::Type(ty), name))
|
|
811
892
|
end
|
|
@@ -817,6 +898,7 @@ module LLVM
|
|
|
817
898
|
# @return [LLVM::Instruction] A pointer of the given type and the address
|
|
818
899
|
# held in val
|
|
819
900
|
# @LLVMinst inttoptr
|
|
901
|
+
#: (Value, Type, ?String) -> Value
|
|
820
902
|
def int2ptr(val, ty, name = "")
|
|
821
903
|
Instruction.from_ptr(C.build_int_to_ptr(self, val, LLVM::Type(ty), name))
|
|
822
904
|
end
|
|
@@ -827,6 +909,7 @@ module LLVM
|
|
|
827
909
|
# @param [String] name The name of the result in LLVM IR
|
|
828
910
|
# @return [LLVM::Instruction] A value of the target type
|
|
829
911
|
# @LLVMinst bitcast
|
|
912
|
+
#: (Value, Type, ?String) -> Value
|
|
830
913
|
def bit_cast(val, ty, name = "")
|
|
831
914
|
Instruction.from_ptr(C.build_bit_cast(self, val, LLVM::Type(ty), name))
|
|
832
915
|
end
|
|
@@ -837,6 +920,7 @@ module LLVM
|
|
|
837
920
|
# @return [LLVM::Instruction]
|
|
838
921
|
# @LLVMinst zext
|
|
839
922
|
# @LLVMinst bitcast
|
|
923
|
+
#: (Value, Type, ?String) -> Value
|
|
840
924
|
def zext_or_bit_cast(val, ty, name = "")
|
|
841
925
|
Instruction.from_ptr(C.build_z_ext_or_bit_cast(self, val, LLVM::Type(ty), name))
|
|
842
926
|
end
|
|
@@ -847,6 +931,7 @@ module LLVM
|
|
|
847
931
|
# @return [LLVM::Instruction]
|
|
848
932
|
# @LLVMinst sext
|
|
849
933
|
# @LLVMinst bitcast
|
|
934
|
+
#: (Value, Type, ?String) -> Value
|
|
850
935
|
def sext_or_bit_cast(val, ty, name = "")
|
|
851
936
|
Instruction.from_ptr(C.build_s_ext_or_bit_cast(self, val, LLVM::Type(ty), name))
|
|
852
937
|
end
|
|
@@ -857,6 +942,7 @@ module LLVM
|
|
|
857
942
|
# @return [LLVM::Instruction]
|
|
858
943
|
# @LLVMinst trunc
|
|
859
944
|
# @LLVMinst bitcast
|
|
945
|
+
#: (Value, Type, ?String) -> Value
|
|
860
946
|
def trunc_or_bit_cast(val, ty, name = "")
|
|
861
947
|
Instruction.from_ptr(C.build_trunc_or_bit_cast(self, val, LLVM::Type(ty), name))
|
|
862
948
|
end
|
|
@@ -866,6 +952,7 @@ module LLVM
|
|
|
866
952
|
# @param [String] name The name of the result in LLVM IR
|
|
867
953
|
# @return [LLVM::Instruction]
|
|
868
954
|
# Cast pointer to other type
|
|
955
|
+
#: (Value, Type, ?String) -> Value
|
|
869
956
|
def pointer_cast(val, ty, name = "")
|
|
870
957
|
Instruction.from_ptr(C.build_pointer_cast(self, val, LLVM::Type(ty), name))
|
|
871
958
|
end
|
|
@@ -874,6 +961,7 @@ module LLVM
|
|
|
874
961
|
# @param [LLVM::Type, #ty] ty
|
|
875
962
|
# @param [String] name The name of the result in LLVM IR
|
|
876
963
|
# @return [LLVM::Instruction]
|
|
964
|
+
#: (Value, Type, ?String) -> Value
|
|
877
965
|
def int_cast(val, ty, name = "")
|
|
878
966
|
Instruction.from_ptr(C.build_int_cast(self, val, LLVM::Type(ty), name))
|
|
879
967
|
end
|
|
@@ -883,6 +971,7 @@ module LLVM
|
|
|
883
971
|
# @param [String] name The name of the result in LLVM IR
|
|
884
972
|
# @param [bool] signed whether to sign or zero extend
|
|
885
973
|
# @return [LLVM::Instruction]
|
|
974
|
+
#: (Value, Type, bool, ?String) -> Value
|
|
886
975
|
def int_cast2(val, ty, signed, name = "")
|
|
887
976
|
Instruction.from_ptr(C.build_int_cast2(self, val, LLVM::Type(ty), signed, name))
|
|
888
977
|
end
|
|
@@ -891,6 +980,7 @@ module LLVM
|
|
|
891
980
|
# @param [LLVM::Type, #ty] ty
|
|
892
981
|
# @param [String] name The name of the result in LLVM IR
|
|
893
982
|
# @return [LLVM::Instruction]
|
|
983
|
+
#: (Value, Type, ?String) -> Value
|
|
894
984
|
def fp_cast(val, ty, name = "")
|
|
895
985
|
Instruction.from_ptr(C.build_fp_cast(self, val, LLVM::Type(ty), name))
|
|
896
986
|
end
|
|
@@ -915,6 +1005,7 @@ module LLVM
|
|
|
915
1005
|
# @param [String] name The name of the result in LLVM IR
|
|
916
1006
|
# @return [LLVM::Instruction] A boolean represented as i1
|
|
917
1007
|
# @LLVMinst icmp
|
|
1008
|
+
#: (Symbol, Value, Value, ?String) -> Value
|
|
918
1009
|
def icmp(pred, lhs, rhs, name = "")
|
|
919
1010
|
Instruction.from_ptr(C.build_i_cmp(self, pred, lhs, rhs, name))
|
|
920
1011
|
end
|
|
@@ -945,6 +1036,7 @@ module LLVM
|
|
|
945
1036
|
# @param [String] name The name of the result in LLVM IR
|
|
946
1037
|
# @return [LLVM::Instruction] A boolean represented as i1
|
|
947
1038
|
# @LLVMinst fcmp
|
|
1039
|
+
#: (Symbol, Value, Value, ?String) -> Value
|
|
948
1040
|
def fcmp(pred, lhs, rhs, name = "")
|
|
949
1041
|
Instruction.from_ptr(C.build_f_cmp(self, pred, lhs, rhs, name))
|
|
950
1042
|
end
|
|
@@ -958,6 +1050,7 @@ module LLVM
|
|
|
958
1050
|
# @param [String] name The name of the result in LLVM IR
|
|
959
1051
|
# @return [LLVM::Instruction] The phi node
|
|
960
1052
|
# @LLVMinst phi
|
|
1053
|
+
#: (Type, Hash[BasicBlock, Value], ?String) -> Value
|
|
961
1054
|
def phi(ty, incoming, name = "")
|
|
962
1055
|
phi = Phi.from_ptr(C.build_phi(self, LLVM::Type(ty), name))
|
|
963
1056
|
phi.add_incoming(incoming)
|
|
@@ -971,10 +1064,17 @@ module LLVM
|
|
|
971
1064
|
# @param [Array<LLVM::Value>] args
|
|
972
1065
|
# @param [LLVM::Instruction]
|
|
973
1066
|
# @LLVMinst call
|
|
1067
|
+
#: (untyped, *Value) -> CallInst
|
|
974
1068
|
def call(fun, *args)
|
|
975
|
-
call2(
|
|
1069
|
+
call2(
|
|
1070
|
+
nil,
|
|
1071
|
+
fun,
|
|
1072
|
+
*args #: untyped
|
|
1073
|
+
)
|
|
976
1074
|
end
|
|
977
1075
|
|
|
1076
|
+
# TODO: (Type?, untyped) -> [Type, Function]
|
|
1077
|
+
#: (Type?, untyped) -> [untyped, untyped]
|
|
978
1078
|
private def call2_infer_function_and_type(type, fun)
|
|
979
1079
|
fun2 = fun.is_a?(LLVM::Value) ? fun : insert_block.parent.global_parent.functions[fun.to_s]
|
|
980
1080
|
|
|
@@ -990,10 +1090,11 @@ module LLVM
|
|
|
990
1090
|
[type, fun2]
|
|
991
1091
|
end
|
|
992
1092
|
|
|
1093
|
+
#: (Type, untyped, *Value) -> CallInst
|
|
993
1094
|
def call2(type, fun, *args)
|
|
994
1095
|
type, fun = call2_infer_function_and_type(type, fun)
|
|
995
1096
|
|
|
996
|
-
name = if args.last.
|
|
1097
|
+
name = if args.last.is_a? String
|
|
997
1098
|
args.pop
|
|
998
1099
|
else
|
|
999
1100
|
""
|
|
@@ -1003,7 +1104,7 @@ module LLVM
|
|
|
1003
1104
|
args_ptr.write_array_of_pointer(args)
|
|
1004
1105
|
ins = C.build_call2(self, type, fun, args_ptr, args.size, name)
|
|
1005
1106
|
|
|
1006
|
-
call_inst = CallInst.from_ptr(ins)
|
|
1107
|
+
call_inst = CallInst.from_ptr(ins) #: as CallInst
|
|
1007
1108
|
|
|
1008
1109
|
if fun.is_a?(Function)
|
|
1009
1110
|
call_inst.call_conv = fun.call_conv
|
|
@@ -1023,6 +1124,7 @@ module LLVM
|
|
|
1023
1124
|
# @return [LLVM::Instruction] An instruction representing either _then or
|
|
1024
1125
|
# _else
|
|
1025
1126
|
# @LLVMinst select
|
|
1127
|
+
#: (Value, Value, Value, ?String) -> Value
|
|
1026
1128
|
def select(_if, _then, _else, name = "")
|
|
1027
1129
|
Instruction.from_ptr(C.build_select(self, _if, _then, _else, name))
|
|
1028
1130
|
end
|
|
@@ -1034,6 +1136,7 @@ module LLVM
|
|
|
1034
1136
|
# @param [String] name The value of the result in LLVM IR
|
|
1035
1137
|
# @return [LLVM::Instruction] The extracted element
|
|
1036
1138
|
# @LLVMinst extractelement
|
|
1139
|
+
#: (Value, Value, ?String) -> Value
|
|
1037
1140
|
def extract_element(vector, idx, name = "")
|
|
1038
1141
|
must_be_value!(vector)
|
|
1039
1142
|
must_be_value!(idx)
|
|
@@ -1052,6 +1155,7 @@ module LLVM
|
|
|
1052
1155
|
# @param [String] name The name of the result in LLVM IR
|
|
1053
1156
|
# @return [LLVM::Instruction] A vector the same type as 'vector'
|
|
1054
1157
|
# @LLVMinst insertelement
|
|
1158
|
+
#: (Value, Value, Value, ?String) -> Value
|
|
1055
1159
|
def insert_element(vector, elem, idx, name = "")
|
|
1056
1160
|
must_be_value!(vector)
|
|
1057
1161
|
must_be_value!(elem)
|
|
@@ -1072,6 +1176,7 @@ module LLVM
|
|
|
1072
1176
|
# @param [String] name The name of the result in LLVM IR
|
|
1073
1177
|
# @return [LLVM::Instruction] The shuffled vector
|
|
1074
1178
|
# @LLVMinst shufflevector
|
|
1179
|
+
#: (Value, Value, Value, ?String) -> Value
|
|
1075
1180
|
def shuffle_vector(vec1, vec2, mask, name = "")
|
|
1076
1181
|
Instruction.from_ptr(C.build_shuffle_vector(self, vec1, vec2, mask, name))
|
|
1077
1182
|
end
|
|
@@ -1082,6 +1187,7 @@ module LLVM
|
|
|
1082
1187
|
# @param [String] name The name of the result in LLVM IR
|
|
1083
1188
|
# @return [LLVM::Instruction] The extracted value
|
|
1084
1189
|
# @LLVMinst extractvalue
|
|
1190
|
+
#: (Value, Integer, ?String) -> Value
|
|
1085
1191
|
def extract_value(aggregate, idx, name = "")
|
|
1086
1192
|
must_be_value!(aggregate)
|
|
1087
1193
|
error = value_error(aggregate, idx)
|
|
@@ -1099,6 +1205,7 @@ module LLVM
|
|
|
1099
1205
|
# @param [String] name The name of the result in LLVM IR
|
|
1100
1206
|
# @return [LLVM::Instruction] An aggregate value of the same type as 'aggregate'
|
|
1101
1207
|
# @LLVMinst insertvalue
|
|
1208
|
+
#: (Value, Value, Integer, ?String) -> Value
|
|
1102
1209
|
def insert_value(aggregate, elem, idx, name = "")
|
|
1103
1210
|
must_be_value!(aggregate)
|
|
1104
1211
|
must_be_value!(elem)
|
|
@@ -1115,6 +1222,7 @@ module LLVM
|
|
|
1115
1222
|
# @param [String] name The name of the result in LLVM IR
|
|
1116
1223
|
# @return [LLVM::Instruction] An i1
|
|
1117
1224
|
# rubocop:disable Naming/PredicatePrefix
|
|
1225
|
+
#: (Value, ?String) -> Value
|
|
1118
1226
|
def is_null(val, name = "")
|
|
1119
1227
|
Instruction.from_ptr(C.build_is_null(self, val, name))
|
|
1120
1228
|
end
|
|
@@ -1123,6 +1231,7 @@ module LLVM
|
|
|
1123
1231
|
# @param [LLVM::Value] val The value to check
|
|
1124
1232
|
# @param [String] name The name of the result in LLVM IR
|
|
1125
1233
|
# @return [LLVM::Instruction] An i1
|
|
1234
|
+
#: (Value, ?String) -> Value
|
|
1126
1235
|
def is_not_null(val, name = "") # rubocop:disable Naming/PredicatePrefix
|
|
1127
1236
|
Instruction.from_ptr(C.build_is_not_null(self, val, name))
|
|
1128
1237
|
end
|
|
@@ -1133,10 +1242,12 @@ module LLVM
|
|
|
1133
1242
|
# @param [String] name The name of the result in LLVM IR
|
|
1134
1243
|
# @return [LLVM::Instruction] The integer difference between the two
|
|
1135
1244
|
# pointers
|
|
1245
|
+
#: (Value, Value, ?String) -> Value
|
|
1136
1246
|
def ptr_diff(lhs, rhs, name = "")
|
|
1137
1247
|
ptr_diff2(nil, lhs, rhs, name)
|
|
1138
1248
|
end
|
|
1139
1249
|
|
|
1250
|
+
#: (Type?, Value, Value, ?String) -> Value
|
|
1140
1251
|
def ptr_diff2(type, lhs, rhs, name = "")
|
|
1141
1252
|
must_be_value!(lhs)
|
|
1142
1253
|
must_be_value!(rhs)
|
|
@@ -1155,19 +1266,23 @@ module LLVM
|
|
|
1155
1266
|
|
|
1156
1267
|
private
|
|
1157
1268
|
|
|
1269
|
+
#: (untyped) -> void
|
|
1158
1270
|
def must_be_value!(value)
|
|
1159
|
-
raise ArgumentError, "must be a Value, got #{value.class.name}" unless Value
|
|
1271
|
+
raise ArgumentError, "must be a Value, got #{value.class.name}" unless value.is_a?(Value)
|
|
1160
1272
|
end
|
|
1161
1273
|
|
|
1274
|
+
#: (untyped) -> void
|
|
1162
1275
|
def must_be_type!(type)
|
|
1163
1276
|
type2 = LLVM.Type(type)
|
|
1164
|
-
raise ArgumentError, "must be a Type (LLVMTypeRef), got #{type2.class.name}" unless Type
|
|
1277
|
+
raise ArgumentError, "must be a Type (LLVMTypeRef), got #{type2.class.name}" unless type2.is_a?(Type)
|
|
1165
1278
|
end
|
|
1166
1279
|
|
|
1280
|
+
#: (untyped) -> void
|
|
1167
1281
|
def must_infer_type!(value)
|
|
1168
1282
|
infer_type(value)
|
|
1169
1283
|
end
|
|
1170
1284
|
|
|
1285
|
+
#: (untyped) -> void
|
|
1171
1286
|
def infer_type(ptr)
|
|
1172
1287
|
case ptr
|
|
1173
1288
|
when GlobalVariable
|
|
@@ -1179,6 +1294,7 @@ module LLVM
|
|
|
1179
1294
|
end
|
|
1180
1295
|
end
|
|
1181
1296
|
|
|
1297
|
+
#: (untyped) -> void
|
|
1182
1298
|
def must_infer_instruction_type!(ptr)
|
|
1183
1299
|
case ptr.opcode
|
|
1184
1300
|
when :get_element_ptr
|
|
@@ -1192,6 +1308,7 @@ module LLVM
|
|
|
1192
1308
|
end
|
|
1193
1309
|
end
|
|
1194
1310
|
|
|
1311
|
+
#: (untyped) -> void
|
|
1195
1312
|
def must_infer_gep!(ptr)
|
|
1196
1313
|
source_type = Type.from_ptr(C.get_gep_source_element_type(ptr))
|
|
1197
1314
|
case source_type.kind
|
|
@@ -1206,6 +1323,7 @@ module LLVM
|
|
|
1206
1323
|
end
|
|
1207
1324
|
end
|
|
1208
1325
|
|
|
1326
|
+
#: (untyped, Value) -> String?
|
|
1209
1327
|
def element_error(vector, idx)
|
|
1210
1328
|
if !vector.is_a?(LLVM::Value)
|
|
1211
1329
|
# :nocov:
|
|
@@ -1222,6 +1340,7 @@ module LLVM
|
|
|
1222
1340
|
end
|
|
1223
1341
|
end
|
|
1224
1342
|
|
|
1343
|
+
#: (untyped, Integer) -> String?
|
|
1225
1344
|
def value_error(aggregate, idx)
|
|
1226
1345
|
if !aggregate.is_a?(LLVM::Value)
|
|
1227
1346
|
# :nocov:
|