ruby-llvm 3.4.2 → 13.0.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.
Files changed (47) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +21 -4
  3. data/ext/ruby-llvm-support/Rakefile +15 -6
  4. data/ext/ruby-llvm-support/support.cpp +0 -12
  5. data/lib/llvm/analysis_ffi.rb +30 -28
  6. data/lib/llvm/config.rb +4 -4
  7. data/lib/llvm/core/bitcode.rb +10 -10
  8. data/lib/llvm/core/bitcode_ffi.rb +92 -70
  9. data/lib/llvm/core/builder.rb +2 -3
  10. data/lib/llvm/core/context.rb +1 -1
  11. data/lib/llvm/core/pass_manager.rb +4 -2
  12. data/lib/llvm/core/type.rb +2 -2
  13. data/lib/llvm/core/value.rb +148 -26
  14. data/lib/llvm/core.rb +45 -2
  15. data/lib/llvm/core_ffi.rb +4038 -3716
  16. data/lib/llvm/execution_engine.rb +45 -36
  17. data/lib/llvm/execution_engine_ffi.rb +245 -272
  18. data/lib/llvm/linker.rb +2 -19
  19. data/lib/llvm/linker_ffi.rb +24 -25
  20. data/lib/llvm/support.rb +0 -8
  21. data/lib/llvm/target.rb +9 -15
  22. data/lib/llvm/target_ffi.rb +336 -362
  23. data/lib/llvm/transforms/builder.rb +1 -1
  24. data/lib/llvm/transforms/builder_ffi.rb +57 -58
  25. data/lib/llvm/transforms/ipo.rb +1 -1
  26. data/lib/llvm/transforms/ipo_ffi.rb +60 -61
  27. data/lib/llvm/transforms/scalar_ffi.rb +208 -136
  28. data/lib/llvm/transforms/vectorize_ffi.rb +15 -16
  29. data/lib/llvm/version.rb +3 -2
  30. data/lib/llvm.rb +0 -6
  31. data/test/basic_block_test.rb +0 -1
  32. data/test/bitcode_test.rb +1 -2
  33. data/test/call_test.rb +1 -1
  34. data/test/double_test.rb +8 -7
  35. data/test/equality_test.rb +2 -4
  36. data/test/function_test.rb +27 -0
  37. data/test/generic_value_test.rb +1 -1
  38. data/test/instruction_test.rb +0 -2
  39. data/test/ipo_test.rb +1 -1
  40. data/test/linker_test.rb +0 -9
  41. data/test/mcjit_test.rb +14 -1
  42. data/test/module_test.rb +20 -1
  43. data/test/pass_manager_builder_test.rb +1 -2
  44. data/test/target_test.rb +8 -24
  45. data/test/test_helper.rb +4 -1
  46. metadata +103 -41
  47. data/lib/llvm/support_ffi.rb +0 -23
@@ -25,8 +25,8 @@ module LLVM
25
25
  @ptr = ptr.read_pointer
26
26
  else
27
27
  C.dispose_message(error)
28
- error.autorelease=false
29
- raise RuntimeError, "Error creating JIT compiler: #{message}"
28
+ error.autorelease = false
29
+ raise "Error creating JIT compiler: #{message}"
30
30
  end
31
31
  end
32
32
  end
@@ -49,6 +49,13 @@ module LLVM
49
49
  TargetDataLayout.from_ptr(C.get_execution_engine_target_data(self))
50
50
  end
51
51
 
52
+ # Get the associated target machine.
53
+ #
54
+ # @return [TargetMachine]
55
+ def target_machine
56
+ TargetMachine.from_ptr(C.get_execution_engine_target_machine(self))
57
+ end
58
+
52
59
  # Execute the given LLVM::Function with the supplied args (as
53
60
  # GenericValues).
54
61
  # Important: Call #dispose on the returned GenericValue to
@@ -56,7 +63,7 @@ module LLVM
56
63
  def run_function(fun, *args)
57
64
  FFI::MemoryPointer.new(FFI.type_size(:pointer) * args.size) do |args_ptr|
58
65
  new_values = []
59
- args_ptr.write_array_of_pointer fun.params.zip(args).map { |p, a|
66
+ args_ptr.write_array_of_pointer(fun.params.zip(args).map do |p, a|
60
67
  if a.kind_of?(GenericValue)
61
68
  a
62
69
  else
@@ -64,7 +71,7 @@ module LLVM
64
71
  new_values << value
65
72
  value
66
73
  end
67
- }
74
+ end)
68
75
  result = LLVM::GenericValue.from_ptr(
69
76
  C.run_function(self, fun, args.size, args_ptr))
70
77
  new_values.each(&:dispose)
@@ -77,6 +84,10 @@ module LLVM
77
84
  C.get_pointer_to_global(self, global)
78
85
  end
79
86
 
87
+ def function_address(name)
88
+ C.get_function_address(self, name)
89
+ end
90
+
80
91
  # Returns a ModuleCollection of all the Modules in the engine.
81
92
  # @return [ModuleCollection]
82
93
  def modules
@@ -116,7 +127,7 @@ module LLVM
116
127
  message = errorp.read_string unless errorp.null?
117
128
 
118
129
  C.dispose_message(error)
119
- error.autorelease=false
130
+ error.autorelease = false
120
131
 
121
132
  raise "Error removing module: #{message}"
122
133
  end
@@ -159,35 +170,6 @@ module LLVM
159
170
  end
160
171
  end
161
172
 
162
- class JITCompiler < ExecutionEngine
163
- # Create a JIT execution engine.
164
- #
165
- # @note You should call `LLVM.init_jit` before creating an execution engine.
166
- #
167
- # @param [LLVM::Module] mod module
168
- # @param [Hash{Symbol => Object}] options options
169
- # @option options [Integer] :opt_level (3) Optimization level
170
- # @return [ExecutionEngine] Execution engine
171
- def initialize(mod, options = {})
172
- # Prior to ruby-llvm 3.4.0, signature is initialize(mod, opt_level = 3)
173
- if options.kind_of?(Integer)
174
- options = { :opt_level => options }
175
- end
176
-
177
- options = {
178
- :opt_level => 3,
179
- }.merge(options)
180
-
181
- super
182
- end
183
-
184
- protected
185
-
186
- def create_execution_engine_for_module(out_ee, mod, out_error, options)
187
- C.create_jit_compiler_for_module(out_ee, mod, options[:opt_level], out_error)
188
- end
189
- end
190
-
191
173
  class MCJITCompiler < ExecutionEngine
192
174
  # Create a MCJIT execution engine.
193
175
  #
@@ -196,7 +178,7 @@ module LLVM
196
178
  #
197
179
  # @param [LLVM::Module] mod module
198
180
  # @param [Hash{Symbol => Object}] options options
199
- # @option options [Integer] :opt_level (2) Optimization level
181
+ # @option options [Integer] :opt_level (2) Optimization level
200
182
  # @option options [Integer] :code_model (0) Code model types
201
183
  # @option options [Boolean] :no_frame_pointer_elim (false) Disable frame pointer elimination optimization
202
184
  # @option options [Boolean] :enable_fast_i_sel (false) Enables fast-path instruction selection
@@ -204,7 +186,7 @@ module LLVM
204
186
  def initialize(mod, options = {})
205
187
  options = {
206
188
  :opt_level => 2, # LLVMCodeGenLevelDefault
207
- :code_model => 0, # LLVMCodeModelDefault
189
+ :code_model => 0,
208
190
  :no_frame_pointer_elim => false,
209
191
  :enable_fast_i_sel => false,
210
192
  # TODO
@@ -214,6 +196,31 @@ module LLVM
214
196
  super
215
197
  end
216
198
 
199
+ def convert_type(type)
200
+ case type.kind
201
+ when :integer
202
+ if type.width <= 8
203
+ :int8
204
+ else
205
+ "int#{type.width}".to_sym
206
+ end
207
+ else
208
+ type.kind
209
+ end
210
+ end
211
+
212
+ def run_function(fun, *args)
213
+ args2 = fun.params.map {|e| convert_type(e.type)}
214
+ ptr = FFI::Pointer.new(function_address(fun.name))
215
+ raise "Couldn't find function" if ptr.null?
216
+
217
+ return_type = convert_type(fun.function_type.return_type)
218
+ f = FFI::Function.new(return_type, args2, ptr)
219
+ ret1 = f.call(*args)
220
+ ret2 = LLVM.make_generic_value(fun.function_type.return_type, ret1)
221
+ ret2
222
+ end
223
+
217
224
  protected
218
225
 
219
226
  def create_execution_engine_for_module(out_ee, mod, out_error, options)
@@ -230,6 +237,8 @@ module LLVM
230
237
  end
231
238
  end
232
239
 
240
+ JITCompiler = MCJITCompiler
241
+
233
242
  class GenericValue
234
243
  # @private
235
244
  def to_ptr