ruby-llvm 3.2.0.beta.1 → 3.3.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 (57) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +6 -3
  3. data/ext/ruby-llvm-support/Rakefile +80 -24
  4. data/ext/ruby-llvm-support/support.cpp +4 -3
  5. data/lib/llvm.rb +2 -2
  6. data/lib/llvm/analysis_ffi.rb +1 -1
  7. data/lib/llvm/config.rb +10 -0
  8. data/lib/llvm/core.rb +7 -5
  9. data/lib/llvm/core/bitcode_ffi.rb +1 -1
  10. data/lib/llvm/core/builder.rb +88 -6
  11. data/lib/llvm/core/module.rb +1 -0
  12. data/lib/llvm/core/type.rb +4 -4
  13. data/lib/llvm/core/value.rb +111 -25
  14. data/lib/llvm/core_ffi.rb +248 -1
  15. data/lib/llvm/execution_engine_ffi.rb +61 -1
  16. data/lib/llvm/linker.rb +0 -2
  17. data/lib/llvm/linker_ffi.rb +1 -1
  18. data/lib/llvm/support.rb +1 -1
  19. data/lib/llvm/target.rb +1 -1
  20. data/lib/llvm/target_ffi.rb +30 -25
  21. data/lib/llvm/transforms/builder.rb +102 -0
  22. data/lib/llvm/transforms/builder_ffi.rb +118 -0
  23. data/lib/llvm/transforms/ipo.rb +64 -4
  24. data/lib/llvm/transforms/ipo_ffi.rb +1 -1
  25. data/lib/llvm/transforms/scalar.rb +60 -20
  26. data/lib/llvm/transforms/scalar_ffi.rb +1 -1
  27. data/lib/llvm/transforms/vectorize.rb +5 -0
  28. data/lib/llvm/transforms/vectorize_ffi.rb +9 -1
  29. data/lib/llvm/version.rb +2 -21
  30. data/test/array_test.rb +1 -1
  31. data/test/basic_block_test.rb +1 -1
  32. data/test/binary_operations_test.rb +1 -1
  33. data/test/bitcode_test.rb +1 -1
  34. data/test/branch_test.rb +1 -1
  35. data/test/call_test.rb +1 -1
  36. data/test/comparisons_test.rb +1 -1
  37. data/test/conversions_test.rb +1 -1
  38. data/test/double_test.rb +1 -1
  39. data/test/equality_test.rb +4 -4
  40. data/test/function_test.rb +73 -0
  41. data/test/generic_value_test.rb +1 -1
  42. data/test/instruction_test.rb +1 -1
  43. data/test/ipo_test.rb +1 -1
  44. data/test/linker_test.rb +2 -2
  45. data/test/memory_access_test.rb +1 -1
  46. data/test/module_test.rb +6 -6
  47. data/test/parameter_collection_test.rb +1 -1
  48. data/test/pass_manager_builder_test.rb +33 -0
  49. data/test/phi_test.rb +1 -1
  50. data/test/select_test.rb +1 -1
  51. data/test/struct_test.rb +9 -1
  52. data/test/target_test.rb +19 -13
  53. data/test/test_helper.rb +2 -2
  54. data/test/type_test.rb +1 -1
  55. data/test/vector_test.rb +2 -2
  56. metadata +117 -85
  57. data/test/basic_test.rb +0 -11
@@ -219,6 +219,9 @@ module LLVM
219
219
  ConstantExpr.from_ptr(C.const_bit_cast(self, type))
220
220
  end
221
221
 
222
+ # @deprecated
223
+ alias bit_cast bitcast_to
224
+
222
225
  # Returns the element pointer at the given indices of the constant.
223
226
  # For more information on gep go to: http://llvm.org/docs/GetElementPtr.html
224
227
  def gep(*indices)
@@ -230,8 +233,9 @@ module LLVM
230
233
  end
231
234
  end
232
235
 
233
- def bit_cast(type)
234
- return ConstantExpr.from_ptr(C.const_bit_cast(self, type))
236
+ # Conversion to integer.
237
+ def ptr_to_int(type)
238
+ ConstantInt.from_ptr(C.const_ptr_to_int(self, type))
235
239
  end
236
240
  end
237
241
 
@@ -290,29 +294,69 @@ module LLVM
290
294
  self.class.from_ptr(C.const_neg(self))
291
295
  end
292
296
 
293
- # Boolean negation.
294
- def ~@
295
- self.class.from_ptr(C.const_not(self))
297
+ alias neg -@
298
+
299
+ # "No signed wrap" negation.
300
+ def nsw_neg
301
+ self.class.from_ptr(C.const_nsw_neg(self))
296
302
  end
297
303
 
298
- alias not ~
304
+ # "No unsigned wrap" negation.
305
+ def nuw_neg
306
+ self.class.from_ptr(C.const_nuw_neg(self))
307
+ end
299
308
 
300
309
  # Addition.
301
310
  def +(rhs)
302
311
  self.class.from_ptr(C.const_add(self, rhs))
303
312
  end
304
313
 
305
- # "No signed wrap" addition. See
306
- # http://llvm.org/docs/LangRef.html#i_add for discusison.
314
+ alias add +
315
+
316
+ # "No signed wrap" addition.
307
317
  def nsw_add(rhs)
308
318
  self.class.from_ptr(C.const_nsw_add(self, rhs))
309
319
  end
310
320
 
321
+ # "No unsigned wrap" addition.
322
+ def nuw_add(rhs)
323
+ self.class.from_ptr(C.const_nuw_add(self, rhs))
324
+ end
325
+
326
+ # Subtraction.
327
+ def -(rhs)
328
+ self.class.from_ptr(C.const_sub(self, rhs))
329
+ end
330
+
331
+ alias sub -
332
+
333
+ # "No signed wrap" subtraction.
334
+ def nsw_sub(rhs)
335
+ self.class.from_ptr(C.const_nsw_sub(self, rhs))
336
+ end
337
+
338
+ # "No unsigned wrap" subtraction.
339
+ def nuw_sub(rhs)
340
+ self.class.from_ptr(C.const_nuw_sub(self, rhs))
341
+ end
342
+
311
343
  # Multiplication.
312
344
  def *(rhs)
313
345
  self.class.from_ptr(C.const_mul(self, rhs))
314
346
  end
315
347
 
348
+ alias mul *
349
+
350
+ # "No signed wrap" multiplication.
351
+ def nsw_mul(rhs)
352
+ self.class.from_ptr(C.const_nsw_mul(self, rhs))
353
+ end
354
+
355
+ # "No unsigned wrap" multiplication.
356
+ def nuw_mul(rhs)
357
+ self.class.from_ptr(C.const_nuw_mul(self, rhs))
358
+ end
359
+
316
360
  # Unsigned division.
317
361
  def udiv(rhs)
318
362
  self.class.from_ptr(C.const_u_div(self, rhs))
@@ -333,21 +377,53 @@ module LLVM
333
377
  self.class.from_ptr(C.const_s_rem(self, rhs))
334
378
  end
335
379
 
380
+ # Boolean negation.
381
+ def ~@
382
+ self.class.from_ptr(C.const_not(self))
383
+ end
384
+
385
+ alias not ~
386
+
336
387
  # Integer AND.
337
- def and(rhs)
388
+ def &(rhs)
338
389
  self.class.from_ptr(C.const_and(self, rhs))
339
390
  end
340
391
 
392
+ alias and &
393
+
341
394
  # Integer OR.
342
- def or(rhs)
395
+ def |(rhs)
343
396
  self.class.from_ptr(C.const_or(self, rhs))
344
397
  end
345
398
 
399
+ alias or |
400
+
346
401
  # Integer XOR.
347
- def xor(rhs)
402
+ def ^(rhs)
348
403
  self.class.from_ptr(C.const_xor(self, rhs))
349
404
  end
350
405
 
406
+ alias xor ^
407
+
408
+ # Shift left.
409
+ def <<(bits)
410
+ self.class.from_ptr(C.const_shl(self, bits))
411
+ end
412
+
413
+ alias shl <<
414
+
415
+ # Shift right.
416
+ def >>(bits)
417
+ self.class.from_ptr(C.const_l_shr(self, bits))
418
+ end
419
+
420
+ alias shr >>
421
+
422
+ # Arithmatic shift right.
423
+ def ashr(bits)
424
+ self.class.from_ptr(C.const_a_shr(self, bits))
425
+ end
426
+
351
427
  # Integer comparison using the predicate specified via the first parameter.
352
428
  # Predicate can be any of:
353
429
  # :eq - equal to
@@ -364,19 +440,9 @@ module LLVM
364
440
  self.class.from_ptr(C.const_i_cmp(pred, self, rhs))
365
441
  end
366
442
 
367
- # Shift left.
368
- def <<(bits)
369
- self.class.from_ptr(C.const_shl(self, bits))
370
- end
371
-
372
- # Shift right.
373
- def >>(bits)
374
- self.class.from_ptr(C.const_l_shr(self, bits))
375
- end
376
-
377
- # Arithmatic shift right.
378
- def ashr(bits)
379
- self.class.from_ptr(C.const_a_shr(self, bits))
443
+ # Conversion to pointer.
444
+ def int_to_ptr(type)
445
+ ConstantExpr.from_ptr(C.const_int_to_ptr(self, type))
380
446
  end
381
447
  end
382
448
 
@@ -505,6 +571,11 @@ module LLVM
505
571
  vals = LLVM::Support.allocate_pointers(size_or_values, &block)
506
572
  from_ptr C.const_struct(vals, vals.size / vals.type_size, packed ? 1 : 0)
507
573
  end
574
+
575
+ def self.named_const(type, size_or_values, &block)
576
+ vals = LLVM::Support.allocate_pointers(size_or_values, &block)
577
+ from_ptr C.const_named_struct(type, vals, vals.size / vals.type_size)
578
+ end
508
579
  end
509
580
 
510
581
  class ConstantVector < Constant
@@ -607,7 +678,11 @@ module LLVM
607
678
  end
608
679
 
609
680
  def type
610
- Type.from_ptr(C.type_of(self), :function)
681
+ Type.from_ptr(C.type_of(self), :pointer)
682
+ end
683
+
684
+ def function_type
685
+ type.element_type
611
686
  end
612
687
 
613
688
  # @private
@@ -789,4 +864,15 @@ module LLVM
789
864
  C.add_case(self, val, block)
790
865
  end
791
866
  end
867
+
868
+
869
+ # @private
870
+ class IndirectBr < Instruction
871
+ # Adds a basic block reference as a destination for this indirect branch.
872
+ def add_dest(dest)
873
+ C.add_destination(self, dest)
874
+ end
875
+
876
+ alias :<< :add_dest
877
+ end
792
878
  end
@@ -4,7 +4,7 @@ require 'ffi'
4
4
 
5
5
  module LLVM::C
6
6
  extend FFI::Library
7
- ffi_lib 'LLVM-3.2'
7
+ ffi_lib 'LLVM-3.3'
8
8
 
9
9
  def self.attach_function(name, *_)
10
10
  begin; super; rescue FFI::NotFoundError => e
@@ -651,6 +651,121 @@ module LLVM::C
651
651
  :filter, 1
652
652
  ]
653
653
 
654
+ # (Not documented)
655
+ #
656
+ # <em>This entry is only for documentation and no real method. The FFI::Enum can be accessed via #enum_type(:thread_local_mode).</em>
657
+ #
658
+ # === Options:
659
+ # :not_thread_local ::
660
+ #
661
+ # :general_dynamic_tls_model ::
662
+ #
663
+ # :local_dynamic_tls_model ::
664
+ #
665
+ # :initial_exec_tls_model ::
666
+ #
667
+ # :local_exec_tls_model ::
668
+ #
669
+ #
670
+ # @method _enum_thread_local_mode_
671
+ # @return [Symbol]
672
+ # @scope class
673
+ enum :thread_local_mode, [
674
+ :not_thread_local, 0,
675
+ :general_dynamic_tls_model, 1,
676
+ :local_dynamic_tls_model, 2,
677
+ :initial_exec_tls_model, 3,
678
+ :local_exec_tls_model, 4
679
+ ]
680
+
681
+ # (Not documented)
682
+ #
683
+ # <em>This entry is only for documentation and no real method. The FFI::Enum can be accessed via #enum_type(:atomic_ordering).</em>
684
+ #
685
+ # === Options:
686
+ # :not_atomic ::
687
+ #
688
+ # :unordered ::
689
+ # < A load or store which is not atomic
690
+ # :monotonic ::
691
+ # < Lowest level of atomicity, guarantees
692
+ # somewhat sane results, lock free.
693
+ # :acquire ::
694
+ # < guarantees that if you take all the
695
+ # operations affecting a specific address,
696
+ # a consistent ordering exists
697
+ # :release ::
698
+ # < Acquire provides a barrier of the sort
699
+ # necessary to acquire a lock to access other
700
+ # memory with normal loads and stores.
701
+ # :acquire_release ::
702
+ # < Release is similar to Acquire, but with
703
+ # a barrier of the sort necessary to release
704
+ # a lock.
705
+ #
706
+ # @method _enum_atomic_ordering_
707
+ # @return [Symbol]
708
+ # @scope class
709
+ enum :atomic_ordering, [
710
+ :not_atomic, 0,
711
+ :unordered, 1,
712
+ :monotonic, 2,
713
+ :acquire, 4,
714
+ :release, 5,
715
+ :acquire_release, 6
716
+ ]
717
+
718
+ # (Not documented)
719
+ #
720
+ # <em>This entry is only for documentation and no real method. The FFI::Enum can be accessed via #enum_type(:atomic_rmw_bin_op).</em>
721
+ #
722
+ # === Options:
723
+ # :xchg ::
724
+ #
725
+ # :add ::
726
+ # < Set the new value and return the one old
727
+ # :sub ::
728
+ # < Add a value and return the old one
729
+ # :and_ ::
730
+ # < Subtract a value and return the old one
731
+ # :nand ::
732
+ # < And a value and return the old one
733
+ # :or_ ::
734
+ # < Not-And a value and return the old one
735
+ # :xor ::
736
+ # < OR a value and return the old one
737
+ # :max ::
738
+ # < Xor a value and return the old one
739
+ # :min ::
740
+ # < Sets the value if it's greater than the
741
+ # original using a signed comparison and return
742
+ # the old one
743
+ # :u_max ::
744
+ # < Sets the value if it's Smaller than the
745
+ # original using a signed comparison and return
746
+ # the old one
747
+ # :u_min ::
748
+ # < Sets the value if it's greater than the
749
+ # original using an unsigned comparison and return
750
+ # the old one
751
+ #
752
+ # @method _enum_atomic_rmw_bin_op_
753
+ # @return [Symbol]
754
+ # @scope class
755
+ enum :atomic_rmw_bin_op, [
756
+ :xchg, 0,
757
+ :add, 1,
758
+ :sub, 2,
759
+ :and_, 3,
760
+ :nand, 4,
761
+ :or_, 5,
762
+ :xor, 6,
763
+ :max, 7,
764
+ :min, 8,
765
+ :u_max, 9,
766
+ :u_min, 10
767
+ ]
768
+
654
769
  # @}
655
770
  #
656
771
  # @method initialize_core(r)
@@ -659,6 +774,15 @@ module LLVM::C
659
774
  # @scope class
660
775
  attach_function :initialize_core, :LLVMInitializeCore, [OpaquePassRegistry], :void
661
776
 
777
+ # Deallocate and destroy all ManagedStatic variables.
778
+ # @see llvm::llvm_shutdown
779
+ # @see ManagedStatic
780
+ #
781
+ # @method shutdown()
782
+ # @return [nil]
783
+ # @scope class
784
+ attach_function :shutdown, :LLVMShutdown, [], :void
785
+
662
786
  # ===-- Error handling ----------------------------------------------------===
663
787
  #
664
788
  # @method dispose_message(message)
@@ -3234,6 +3358,40 @@ module LLVM::C
3234
3358
  # @scope class
3235
3359
  attach_function :set_global_constant, :LLVMSetGlobalConstant, [OpaqueValue, :int], :void
3236
3360
 
3361
+ # (Not documented)
3362
+ #
3363
+ # @method get_thread_local_mode(global_var)
3364
+ # @param [OpaqueValue] global_var
3365
+ # @return [Symbol from _enum_thread_local_mode_]
3366
+ # @scope class
3367
+ attach_function :get_thread_local_mode, :LLVMGetThreadLocalMode, [OpaqueValue], :thread_local_mode
3368
+
3369
+ # (Not documented)
3370
+ #
3371
+ # @method set_thread_local_mode(global_var, mode)
3372
+ # @param [OpaqueValue] global_var
3373
+ # @param [Symbol from _enum_thread_local_mode_] mode
3374
+ # @return [nil]
3375
+ # @scope class
3376
+ attach_function :set_thread_local_mode, :LLVMSetThreadLocalMode, [OpaqueValue, :thread_local_mode], :void
3377
+
3378
+ # (Not documented)
3379
+ #
3380
+ # @method is_externally_initialized(global_var)
3381
+ # @param [OpaqueValue] global_var
3382
+ # @return [Integer]
3383
+ # @scope class
3384
+ attach_function :is_externally_initialized, :LLVMIsExternallyInitialized, [OpaqueValue], :int
3385
+
3386
+ # (Not documented)
3387
+ #
3388
+ # @method set_externally_initialized(global_var, is_ext_init)
3389
+ # @param [OpaqueValue] global_var
3390
+ # @param [Integer] is_ext_init
3391
+ # @return [nil]
3392
+ # @scope class
3393
+ attach_function :set_externally_initialized, :LLVMSetExternallyInitialized, [OpaqueValue, :int], :void
3394
+
3237
3395
  # @defgroup LLVMCoreValueConstantGlobalAlias Global Aliases
3238
3396
  #
3239
3397
  # This group contains function that operate on global alias values.
@@ -3330,6 +3488,17 @@ module LLVM::C
3330
3488
  # @scope class
3331
3489
  attach_function :add_function_attr, :LLVMAddFunctionAttr, [OpaqueValue, :attribute], :void
3332
3490
 
3491
+ # Add a target-dependent attribute to a fuction
3492
+ # @see llvm::AttrBuilder::addAttribute()
3493
+ #
3494
+ # @method add_target_dependent_function_attr(fn, a, v)
3495
+ # @param [OpaqueValue] fn
3496
+ # @param [String] a
3497
+ # @param [String] v
3498
+ # @return [nil]
3499
+ # @scope class
3500
+ attach_function :add_target_dependent_function_attr, :LLVMAddTargetDependentFunctionAttr, [OpaqueValue, :string, :string], :void
3501
+
3333
3502
  # Obtain an attribute from a function.
3334
3503
  #
3335
3504
  # @see llvm::Function::getAttributes()
@@ -5158,6 +5327,19 @@ module LLVM::C
5158
5327
  # @scope class
5159
5328
  attach_function :build_ptr_diff, :LLVMBuildPtrDiff, [OpaqueBuilder, OpaqueValue, OpaqueValue, :string], OpaqueValue
5160
5329
 
5330
+ # (Not documented)
5331
+ #
5332
+ # @method build_atomic_rmw(b, op, ptr, val, ordering, single_thread)
5333
+ # @param [OpaqueBuilder] b
5334
+ # @param [Symbol from _enum_atomic_rmw_bin_op_] op
5335
+ # @param [OpaqueValue] ptr
5336
+ # @param [OpaqueValue] val
5337
+ # @param [Symbol from _enum_atomic_ordering_] ordering
5338
+ # @param [Integer] single_thread
5339
+ # @return [OpaqueValue]
5340
+ # @scope class
5341
+ attach_function :build_atomic_rmw, :LLVMBuildAtomicRMW, [OpaqueBuilder, :atomic_rmw_bin_op, OpaqueValue, OpaqueValue, :atomic_ordering, :int], OpaqueValue
5342
+
5161
5343
  # Changes the type of M so it can be passed to FunctionPassManagers and the
5162
5344
  # JIT. They take ModuleProviders for historical reasons.
5163
5345
  #
@@ -5196,6 +5378,43 @@ module LLVM::C
5196
5378
  # @scope class
5197
5379
  attach_function :create_memory_buffer_with_stdin, :LLVMCreateMemoryBufferWithSTDIN, [:pointer, :pointer], :int
5198
5380
 
5381
+ # (Not documented)
5382
+ #
5383
+ # @method create_memory_buffer_with_memory_range(input_data, input_data_length, buffer_name, requires_null_terminator)
5384
+ # @param [String] input_data
5385
+ # @param [Integer] input_data_length
5386
+ # @param [String] buffer_name
5387
+ # @param [Integer] requires_null_terminator
5388
+ # @return [OpaqueMemoryBuffer]
5389
+ # @scope class
5390
+ attach_function :create_memory_buffer_with_memory_range, :LLVMCreateMemoryBufferWithMemoryRange, [:string, :ulong, :string, :int], OpaqueMemoryBuffer
5391
+
5392
+ # (Not documented)
5393
+ #
5394
+ # @method create_memory_buffer_with_memory_range_copy(input_data, input_data_length, buffer_name)
5395
+ # @param [String] input_data
5396
+ # @param [Integer] input_data_length
5397
+ # @param [String] buffer_name
5398
+ # @return [OpaqueMemoryBuffer]
5399
+ # @scope class
5400
+ attach_function :create_memory_buffer_with_memory_range_copy, :LLVMCreateMemoryBufferWithMemoryRangeCopy, [:string, :ulong, :string], OpaqueMemoryBuffer
5401
+
5402
+ # (Not documented)
5403
+ #
5404
+ # @method get_buffer_start(mem_buf)
5405
+ # @param [OpaqueMemoryBuffer] mem_buf
5406
+ # @return [String]
5407
+ # @scope class
5408
+ attach_function :get_buffer_start, :LLVMGetBufferStart, [OpaqueMemoryBuffer], :string
5409
+
5410
+ # (Not documented)
5411
+ #
5412
+ # @method get_buffer_size(mem_buf)
5413
+ # @param [OpaqueMemoryBuffer] mem_buf
5414
+ # @return [Integer]
5415
+ # @scope class
5416
+ attach_function :get_buffer_size, :LLVMGetBufferSize, [OpaqueMemoryBuffer], :ulong
5417
+
5199
5418
  # (Not documented)
5200
5419
  #
5201
5420
  # @method dispose_memory_buffer(mem_buf)
@@ -5294,4 +5513,32 @@ module LLVM::C
5294
5513
  # @scope class
5295
5514
  attach_function :dispose_pass_manager, :LLVMDisposePassManager, [OpaquePassManager], :void
5296
5515
 
5516
+ # Allocate and initialize structures needed to make LLVM safe for
5517
+ # multithreading. The return value indicates whether multithreaded
5518
+ # initialization succeeded. Must be executed in isolation from all
5519
+ # other LLVM api calls.
5520
+ # @see llvm::llvm_start_multithreaded
5521
+ #
5522
+ # @method start_multithreaded()
5523
+ # @return [Integer]
5524
+ # @scope class
5525
+ attach_function :start_multithreaded, :LLVMStartMultithreaded, [], :int
5526
+
5527
+ # Deallocate structures necessary to make LLVM safe for multithreading.
5528
+ # Must be executed in isolation from all other LLVM api calls.
5529
+ # @see llvm::llvm_stop_multithreaded
5530
+ #
5531
+ # @method stop_multithreaded()
5532
+ # @return [nil]
5533
+ # @scope class
5534
+ attach_function :stop_multithreaded, :LLVMStopMultithreaded, [], :void
5535
+
5536
+ # Check whether LLVM is executing in thread-safe mode or not.
5537
+ # @see llvm::llvm_is_multithreaded
5538
+ #
5539
+ # @method is_multithreaded()
5540
+ # @return [Integer]
5541
+ # @scope class
5542
+ attach_function :is_multithreaded, :LLVMIsMultithreaded, [], :int
5543
+
5297
5544
  end