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
@@ -5,14 +5,74 @@ require 'llvm/transforms/ipo_ffi'
5
5
 
6
6
  module LLVM
7
7
  class PassManager
8
- # @LLVMpass gdce
9
- def gdce!
10
- C.add_global_dce_pass(self)
8
+ # @LLVMpass arg_promotion
9
+ def arg_promote!
10
+ C.add_argument_promotion_pass(self)
11
+ end
12
+
13
+ # @LLVMpass const_merge
14
+ def const_merge!
15
+ C.add_constant_merge_pass(self)
16
+ end
17
+
18
+ # @LLVMpass dae
19
+ def dae!
20
+ C.add_dead_arg_elimination(self)
21
+ end
22
+
23
+ # @LLVMpass function_attrs
24
+ def fun_attrs!
25
+ C.add_function_attrs_pass(self)
11
26
  end
12
-
27
+
13
28
  # @LLVMpass inline
14
29
  def inline!
15
30
  C.add_function_inlining_pass(self)
16
31
  end
32
+
33
+ # @LLVMpass always_inline
34
+ def always_inline!
35
+ C.add_always_inliner_pass(self)
36
+ end
37
+
38
+ # @LLVMpass gdce
39
+ def gdce!
40
+ C.add_global_dce_pass(self)
41
+ end
42
+
43
+ # @LLVMpass global_opt
44
+ def global_opt!
45
+ C.add_global_optimizer_pass(self)
46
+ end
47
+
48
+ # @LLVMpass ipcp
49
+ def ipcp!
50
+ C.add_ip_constant_propagation_pass(self)
51
+ end
52
+
53
+ # @LLVMpass prune_eh
54
+ def prune_eh!
55
+ C.add_prune_eh_pass(self)
56
+ end
57
+
58
+ # @LLVMpass ipsccp
59
+ def ipsccp!
60
+ C.add_ipsccp_pass(self)
61
+ end
62
+
63
+ # @LLVMpass internalize
64
+ def internalize!(all_but_main=true)
65
+ C.add_internalize_pass(self, all_but_main)
66
+ end
67
+
68
+ # @LLVMpass sdp
69
+ def sdp!
70
+ C.add_strip_dead_prototypes_pass(self)
71
+ end
72
+
73
+ # @LLVMpass strip
74
+ def strip!
75
+ C.add_strip_symbols_pass(self)
76
+ end
17
77
  end
18
78
  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
@@ -8,105 +8,145 @@ module LLVM
8
8
  def adce!
9
9
  C.add_aggressive_dce_pass(self)
10
10
  end
11
-
11
+
12
12
  # @LLVMpass simplifycfg
13
13
  def simplifycfg!
14
14
  C.add_cfg_simplification_pass(self)
15
15
  end
16
-
16
+
17
17
  # @LLVMpass dse
18
18
  def dse!
19
19
  C.add_dead_store_elimination_pass(self)
20
20
  end
21
-
21
+
22
22
  # @LLVMpass gvn
23
23
  def gvn!
24
24
  C.add_gvn_pass(self)
25
25
  end
26
-
26
+
27
27
  # @LLVMpass indvars
28
28
  def indvars!
29
29
  C.add_ind_var_simplify_pass(self)
30
30
  end
31
-
31
+
32
32
  # @LLVMpass instcombine
33
33
  def instcombine!
34
34
  C.add_instruction_combining_pass(self)
35
35
  end
36
-
36
+
37
37
  # @LLVMpass jump-threading
38
38
  def jump_threading!
39
39
  C.add_jump_threading_pass(self)
40
40
  end
41
-
41
+
42
42
  # @LLVMpass licm
43
43
  def licm!
44
44
  C.add_licm_pass(self)
45
45
  end
46
-
46
+
47
47
  # @LLVMpass loop-deletion
48
48
  def loop_deletion!
49
49
  C.add_loop_deletion_pass(self)
50
50
  end
51
-
51
+
52
+ # @LLVMpass loop-idiom
53
+ def loop_idiom!
54
+ C.add_loop_idiom_pass(self)
55
+ end
56
+
52
57
  # @LLVMpass loop-rotate
53
58
  def loop_rotate!
54
59
  C.add_loop_rotate_pass(self)
55
60
  end
56
-
61
+
57
62
  # @LLVMpass loop-unroll
58
63
  def loop_unroll!
59
64
  C.add_loop_unroll_pass(self)
60
65
  end
61
-
66
+
62
67
  # @LLVMpass loop-unswitch
63
68
  def loop_unswitch!
64
69
  C.add_loop_unswitch_pass(self)
65
70
  end
66
-
71
+
67
72
  # @LLVMpass memcpyopt
68
73
  def memcpyopt!
69
74
  C.add_mem_cpy_opt_pass(self)
70
75
  end
71
-
76
+
72
77
  # @LLVMpass mem2reg
73
78
  def mem2reg!
74
79
  C.add_promote_memory_to_register_pass(self)
75
80
  end
76
-
81
+
77
82
  # @LLVMpass reassociate
78
83
  def reassociate!
79
84
  C.add_reassociate_pass(self)
80
85
  end
81
-
86
+
82
87
  # @LLVMpass sccp
83
88
  def sccp!
84
89
  C.add_sccp_pass(self)
85
90
  end
86
-
91
+
87
92
  # @LLVMpass scalarrepl
88
93
  def scalarrepl!
89
94
  C.add_scalar_repl_aggregates_pass(self)
90
95
  end
91
-
96
+
97
+ # @LLVMpass scalarrepl
98
+ def scalarrepl_ssa!
99
+ C.add_scalar_repl_aggregates_pass_ssa(self)
100
+ end
101
+
102
+ # @LLVMpass scalarrepl
103
+ def scalarrepl_threshold!(threshold)
104
+ C.add_scalar_repl_aggregates_pass(self, threshold)
105
+ end
106
+
92
107
  # @LLVMpass simplify-libcalls
93
108
  def simplify_libcalls!
94
109
  C.add_simplify_lib_calls_pass(self)
95
110
  end
96
-
111
+
97
112
  # @LLVMpass tailcallelim
98
113
  def tailcallelim!
99
114
  C.add_tail_call_elimination_pass(self)
100
115
  end
101
-
116
+
102
117
  # @LLVMpass constprop
103
118
  def constprop!
104
119
  C.add_constant_propagation_pass(self)
105
120
  end
106
-
121
+
107
122
  # @LLVMpass reg2mem
108
123
  def reg2mem!
109
124
  C.add_demote_memory_to_register_pass(self)
110
125
  end
126
+
127
+ # @LLVMpass cvprop
128
+ def cvprop!
129
+ C.add_correlated_value_propagation_pass(self)
130
+ end
131
+
132
+ # @LLVMpass early-cse
133
+ def early_cse!
134
+ C.add_early_cse_pass(self)
135
+ end
136
+
137
+ # @LLVMpass lower-expect
138
+ def lower_expect!
139
+ C.add_lower_expect_intrinsic_pass(self)
140
+ end
141
+
142
+ # @LLVMpass tbaa
143
+ def tbaa!
144
+ C.add_type_based_alias_analysis_pass(self)
145
+ end
146
+
147
+ # @LLVMpass basicaa
148
+ def basicaa!
149
+ C.add_basic_alias_analysis_pass(self)
150
+ end
111
151
  end
112
152
  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
@@ -13,5 +13,10 @@ module LLVM
13
13
  def loop_vectorize!
14
14
  C.add_loop_vectorize_pass(self)
15
15
  end
16
+
17
+ # @LLVMpass slp_vectorize
18
+ def slp_vectorize!
19
+ C.add_slp_vectorize_pass(self)
20
+ end
16
21
  end
17
22
  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
@@ -28,4 +28,12 @@ module LLVM::C
28
28
  # @scope class
29
29
  attach_function :add_loop_vectorize_pass, :LLVMAddLoopVectorizePass, [:pointer], :void
30
30
 
31
+ # See llvm::createSLPVectorizerPass function.
32
+ #
33
+ # @method add_slp_vectorize_pass(pm)
34
+ # @param [FFI::Pointer(PassManagerRef)] pm
35
+ # @return [nil]
36
+ # @scope class
37
+ attach_function :add_slp_vectorize_pass, :LLVMAddSLPVectorizePass, [:pointer], :void
38
+
31
39
  end
@@ -1,23 +1,4 @@
1
- require 'find'
2
-
3
1
  module LLVM
4
- LLVM_VERSION = "3.2"
5
- RUBY_LLVM_VERSION = "3.2.0.beta.1"
6
- LLVM_CONFIG = begin
7
- variants = %W(llvm-config-#{LLVM_VERSION} llvm-config)
8
- llvm_config = nil
9
- catch :done do
10
- paths = ENV['PATH'].split(File::PATH_SEPARATOR).select(&File.method(:directory?))
11
- Find.find(*paths) do |path|
12
- if variants.include?(File.basename(path))
13
- actual_version = `#{path} --version`.chomp
14
- if LLVM_VERSION == actual_version
15
- llvm_config = path
16
- throw(:done)
17
- end
18
- end
19
- end
20
- end
21
- llvm_config
22
- end
2
+ LLVM_VERSION = "3.3"
3
+ RUBY_LLVM_VERSION = "3.3.0"
23
4
  end
@@ -1,6 +1,6 @@
1
1
  require "test_helper"
2
2
 
3
- class ArrayTestCase < Test::Unit::TestCase
3
+ class ArrayTestCase < Minitest::Test
4
4
 
5
5
  def setup
6
6
  LLVM.init_jit
@@ -1,6 +1,6 @@
1
1
  require "test_helper"
2
2
 
3
- class BasicBlockTestCase < Test::Unit::TestCase
3
+ class BasicBlockTestCase < Minitest::Test
4
4
 
5
5
  def setup
6
6
  LLVM.init_jit
@@ -1,6 +1,6 @@
1
1
  require "test_helper"
2
2
 
3
- class BasicOperationsTestCase < Test::Unit::TestCase
3
+ class BasicOperationsTestCase < Minitest::Test
4
4
 
5
5
  def setup
6
6
  LLVM.init_jit
@@ -1,7 +1,7 @@
1
1
  require "test_helper"
2
2
  require "tempfile"
3
3
 
4
- class BitcodeTestCase < Test::Unit::TestCase
4
+ class BitcodeTestCase < Minitest::Test
5
5
  def setup
6
6
  LLVM.init_jit
7
7
  end
@@ -1,6 +1,6 @@
1
1
  require "test_helper"
2
2
 
3
- class BranchTestCase < Test::Unit::TestCase
3
+ class BranchTestCase < Minitest::Test
4
4
 
5
5
  def setup
6
6
  LLVM.init_jit
@@ -1,6 +1,6 @@
1
1
  require "test_helper"
2
2
 
3
- class CallTestCase < Test::Unit::TestCase
3
+ class CallTestCase < Minitest::Test
4
4
 
5
5
  def setup
6
6
  LLVM.init_jit
@@ -1,6 +1,6 @@
1
1
  require "test_helper"
2
2
 
3
- class ComparisonsTestCase < Test::Unit::TestCase
3
+ class ComparisonsTestCase < Minitest::Test
4
4
 
5
5
  def setup
6
6
  LLVM.init_jit
@@ -1,6 +1,6 @@
1
1
  require "test_helper"
2
2
 
3
- class ConversionsTestCase < Test::Unit::TestCase
3
+ class ConversionsTestCase < Minitest::Test
4
4
 
5
5
  def setup
6
6
  LLVM.init_jit
@@ -1,6 +1,6 @@
1
1
  require "test_helper"
2
2
 
3
- class DoubleTestCase < Test::Unit::TestCase
3
+ class DoubleTestCase < Minitest::Test
4
4
  def setup
5
5
  LLVM.init_jit
6
6
  end
@@ -1,7 +1,7 @@
1
1
  require "test_helper"
2
2
  require "llvm/core"
3
3
 
4
- class EqualityTestCase < Test::Unit::TestCase
4
+ class EqualityTestCase < Minitest::Test
5
5
  def setup
6
6
  LLVM.init_jit
7
7
  end
@@ -14,10 +14,10 @@ class EqualityTestCase < Test::Unit::TestCase
14
14
  def assert_equalities(options)
15
15
  map = {
16
16
  :equal => method(:assert_equal),
17
- :not_equal => method(:assert_not_equal),
17
+ :not_equal => lambda {|n, m, name| assert n != m, name },
18
18
  :same => method(:assert_same),
19
- :not_same => method(:assert_not_same),
20
- :eql => lambda {|n, m, name| assert n.eql?(m), name },
19
+ :not_same => lambda {|n, m, name| assert !n.equal?(m), name },
20
+ :eql => lambda {|n, m, name| assert n.eql?(m), name },
21
21
  :not_eql => lambda {|n, m, name| assert !n.eql?(m), name },
22
22
  }
23
23
 
@@ -0,0 +1,73 @@
1
+ require "test_helper"
2
+ require "llvm/core"
3
+
4
+
5
+ def with_function(arguments, retty, &block)
6
+ mod = LLVM::Module.new('test')
7
+ fun = mod.functions.add('fun', arguments, retty)
8
+ block.yield(fun)
9
+ mod.dispose
10
+ end
11
+
12
+ class FunctionTest < Minitest::Test
13
+
14
+ def test_type
15
+ with_function [], LLVM.Void do |fun|
16
+ type = fun.type
17
+
18
+ assert_instance_of LLVM::Type, type
19
+ assert_equal :pointer, type.kind
20
+ assert_equal :function, type.element_type.kind
21
+ end
22
+ end
23
+
24
+ def test_function_type
25
+ with_function [], LLVM.Void do |fun|
26
+ type = fun.function_type
27
+
28
+ assert_instance_of LLVM::FunctionType, type
29
+ assert_equal :function, type.kind
30
+ end
31
+ end
32
+
33
+ end
34
+
35
+ class FunctionTypeTest < Minitest::Test
36
+
37
+ def test_return_type
38
+ with_function [], LLVM.Void do |fun|
39
+ type = fun.function_type
40
+ assert_equal LLVM.Void, type.return_type
41
+ end
42
+
43
+ with_function [], LLVM::Int32 do |fun|
44
+ retty = fun.function_type.return_type
45
+
46
+ assert_kind_of LLVM::IntType, retty
47
+ assert_equal 32, retty.width
48
+ end
49
+ end
50
+
51
+ def test_argument_types
52
+ with_function [], LLVM.Void do |fun|
53
+ types = fun.function_type.argument_types
54
+ assert_equal [], types
55
+ end
56
+
57
+ with_function [LLVM::Int32], LLVM.Void do |fun|
58
+ types = fun.function_type.argument_types
59
+ assert_equal 1, types.size
60
+ a1 = types[0]
61
+ assert_kind_of LLVM::IntType, a1
62
+ assert_equal 32, a1.width
63
+ end
64
+ end
65
+
66
+ def test_vararg
67
+ with_function [], LLVM.Void do |fun|
68
+ type = fun.function_type
69
+ assert !type.vararg?, 'should be false'
70
+ end
71
+ end
72
+
73
+ end