ruby-llvm 15.0.2 → 15.0.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 79169ec6b39406ef0c395bee5bbc02578340808b2728ba61b5b89c1532e05c94
4
- data.tar.gz: 8fe97708a36b561acbd24433f1ddf5d940e6535a776d918eca463fd179a29aea
3
+ metadata.gz: a9606baaed260920d087cafdc03a4524875a11378d9e15792128ec7df9946c7b
4
+ data.tar.gz: 0fba76718a8f7dfd2ee63993eb9ceecb94d0feb75d286997a3dc651ac966ecf7
5
5
  SHA512:
6
- metadata.gz: 75303049be604101b44001f68264b0ba0e5902816cf8d001ed5302aa7b71067b1e8d4ac7f24cf3470e53f59aac5547391b31c5f1145dceb28661966e95c56928
7
- data.tar.gz: 9bad15b50111baf7dd2804d9bd6e61d8a2d05b892eacbbbc52df0194662f961eba8c7f9b81f5ebf1b5e9ce796e4aaeb4b4b47e858874d474ea39e54d3a6dd042
6
+ metadata.gz: 1c095bf095482f67ca94efc4e36c7d04fb5f82f65b9a483c79239e9bcb91fa4da0f6ed76b77259140a9d17e3a268d77fb05899b59a7469d5d664d808ff8be53a
7
+ data.tar.gz: 88b3dae5b535fdf9d7a6cd0225e3b809b7f54c2d072668516e53a18298953a9d4daa68669e7b01ddb0ddb03a044975828741eecf47b3683f66bfa229e44d3ead
data/lib/llvm/analysis.rb CHANGED
@@ -20,6 +20,10 @@ module LLVM
20
20
  do_verification(:abort_process)
21
21
  end
22
22
 
23
+ def valid?
24
+ verify.nil?
25
+ end
26
+
23
27
  private
24
28
 
25
29
  def do_verification(action)
@@ -42,10 +46,14 @@ module LLVM
42
46
  do_verification(:abort_process)
43
47
  end
44
48
 
49
+ def valid?
50
+ verify
51
+ end
52
+
45
53
  private
46
54
 
47
55
  def do_verification(action)
48
- C.verify_function(self, action) != 0
56
+ C.verify_function(self, action).zero?
49
57
  end
50
58
  end
51
59
  end
@@ -36,6 +36,28 @@ module LLVM
36
36
  end
37
37
  status == 0
38
38
  end
39
+
40
+ def self.parse_ir(path_or_memory_buffer, context = Context.global)
41
+ memory_buffer = case path_or_memory_buffer
42
+ when MemoryBuffer then path_or_memory_buffer
43
+ else MemoryBuffer.from_file(path_or_memory_buffer)
44
+ end
45
+ FFI::MemoryPointer.new(:pointer) do |mod_ref|
46
+ FFI::MemoryPointer.new(:pointer) do |msg_ref|
47
+ status = C.parse_ir_in_context(context, memory_buffer, mod_ref, msg_ref)
48
+ raise msg_ref.get_pointer(0).get_string(0) if status
49
+ return from_ptr(mod_ref.get_pointer(0))
50
+ end
51
+ end
52
+ end
53
+
54
+ def write_ir!(filename)
55
+ FFI::MemoryPointer.new(:pointer) do |msg_ref|
56
+ status = C.print_module_to_file(self, filename, msg_ref)
57
+ raise msg_ref.get_pointer(0).get_string(0) if status != 0
58
+ end
59
+ self
60
+ end
39
61
  end
40
62
 
41
63
  # @private
@@ -563,6 +563,7 @@ module LLVM
563
563
  # @return [LLVM::Instruction] The resulting pointer
564
564
  # @LLVMinst gep
565
565
  # @see http://llvm.org/docs/GetElementPtr.html
566
+ # may return Instruction or GlobalVariable
566
567
  def gep(ptr, indices, name = "")
567
568
  gep2(nil, ptr, indices, name)
568
569
  end
@@ -576,6 +577,7 @@ module LLVM
576
577
  # @return [LLVM::Instruction] The resulting pointer
577
578
  # @LLVMinst gep2
578
579
  # @see http://llvm.org/docs/GetElementPtr.html
580
+ # may return Instruction or GlobalVariable
579
581
  def gep2(type, ptr, indices, name)
580
582
  must_be_value!(ptr)
581
583
 
@@ -24,6 +24,16 @@ module LLVM
24
24
  @ptr = nil
25
25
  end
26
26
 
27
+ def inspect
28
+ {
29
+ triple: triple,
30
+ globals: globals.count,
31
+ functions: functions.count,
32
+ lines: to_s.lines.size,
33
+ valid: valid?,
34
+ }.to_s
35
+ end
36
+
27
37
  # Get module triple.
28
38
  #
29
39
  # @return [String]
@@ -1,5 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "llvm/transforms/ipo"
4
+ require "llvm/transforms/scalar"
5
+ require "llvm/transforms/utils"
6
+ require "llvm/transforms/vectorize"
7
+
3
8
  module LLVM
4
9
  # The PassManager runs a queue of passes on a module. See
5
10
  # http://llvm.org/docs/Passes.html for the list of available passes.
@@ -12,6 +12,26 @@ module LLVM
12
12
  val
13
13
  end
14
14
 
15
+ def self.from_ptr_kind(ptr)
16
+ return if ptr.null?
17
+
18
+ kind = C.get_value_kind(ptr)
19
+ case kind
20
+ when :instruction
21
+ Instruction.from_ptr(ptr)
22
+ when :const_int
23
+ Int.from_ptr(ptr)
24
+ when :const_fp
25
+ Float.from_ptr(ptr)
26
+ when :poison
27
+ Poison.from_ptr(ptr)
28
+ when :global_variable
29
+ GlobalValue.from_ptr(ptr)
30
+ else
31
+ raise "from_ptr_kind cannot handle: #{kind}"
32
+ end
33
+ end
34
+
15
35
  # Returns the Value type. This is abstract and is overidden by its subclasses.
16
36
  def self.type
17
37
  raise NotImplementedError, "#{name}.type() is abstract."
@@ -26,6 +46,11 @@ module LLVM
26
46
  Type.from_ptr(C.type_of(self), nil)
27
47
  end
28
48
 
49
+ # Returns the value's kind.
50
+ def kind
51
+ C.get_value_kind(self)
52
+ end
53
+
29
54
  def allocated_type
30
55
  Type.from_ptr(C.get_allocated_type(self), nil)
31
56
  end
@@ -412,22 +437,22 @@ module LLVM
412
437
 
413
438
  # Unsigned division.
414
439
  def udiv(rhs)
415
- self.class.from_ptr(C.const_u_div(self, rhs))
440
+ raise "constant udiv removed in LLVM 15"
416
441
  end
417
442
 
418
443
  # Signed division.
419
444
  def /(rhs)
420
- self.class.from_ptr(C.const_s_div(self, rhs))
445
+ raise "constant sdiv removed in LLVM 15"
421
446
  end
422
447
 
423
448
  # Unsigned remainder.
424
449
  def urem(rhs)
425
- self.class.from_ptr(C.const_u_rem(self, rhs))
450
+ raise "constant urem removed in LLVM 15"
426
451
  end
427
452
 
428
453
  # Signed remainder.
429
454
  def rem(rhs)
430
- self.class.from_ptr(C.const_s_rem(self, rhs))
455
+ raise "constant srem removed in LLVM 15"
431
456
  end
432
457
 
433
458
  # Boolean negation.
@@ -507,6 +532,17 @@ module LLVM
507
532
  def sext(type)
508
533
  self.class.from_ptr(C.const_s_ext(self, type))
509
534
  end
535
+ alias_method :ext, :sext
536
+
537
+ # constant trunc
538
+ def trunc(type)
539
+ self.class.from_ptr(C.const_trunc(self, type))
540
+ end
541
+
542
+ # LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
543
+ def to_f(type)
544
+ self.class.from_ptr(C.const_si_to_fp(self, type))
545
+ end
510
546
  end
511
547
 
512
548
  def self.const_missing(const)
@@ -564,22 +600,22 @@ module LLVM
564
600
 
565
601
  # Returns the result of adding this ConstantReal to rhs.
566
602
  def +(rhs)
567
- self.class.from_ptr(C.const_f_add(self, rhs))
603
+ raise "constant fadd removed in LLVM 15"
568
604
  end
569
605
 
570
606
  # Returns the result of multiplying this ConstantReal by rhs.
571
607
  def *(rhs)
572
- self.class.from_ptr(C.const_f_mul(self, rhs))
608
+ raise "constant fmul removed in LLVM 15"
573
609
  end
574
610
 
575
611
  # Returns the result of dividing this ConstantReal by rhs.
576
612
  def /(rhs)
577
- self.class.from_ptr(C.const_f_div(self, rhs))
613
+ raise "constant fdiv removed in LLVM 15"
578
614
  end
579
615
 
580
616
  # Remainder.
581
617
  def rem(rhs)
582
- self.class.from_ptr(C.const_f_rem(self, rhs))
618
+ raise "constant frem removed in LLVM 15"
583
619
  end
584
620
 
585
621
  # Floating point comparison using the predicate specified via the first
@@ -603,6 +639,24 @@ module LLVM
603
639
  def fcmp(pred, rhs)
604
640
  self.class.from_ptr(C.llmv_const_f_cmp(pred, self, rhs))
605
641
  end
642
+
643
+ # constant FPToSI
644
+ # LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
645
+ def to_i(type)
646
+ self.class.from_ptr(C.const_fp_to_si(self, type))
647
+ end
648
+
649
+ # Constant FPExt
650
+ # this is a signed extension
651
+ def ext(type)
652
+ self.class.from_ptr(C.const_fp_ext(self, type))
653
+ end
654
+ alias_method :sext, :ext
655
+
656
+ def trunc(type)
657
+ self.class.from_ptr(C.const_fp_trunc(self, type))
658
+ end
659
+
606
660
  end
607
661
 
608
662
  class Float < ConstantReal
@@ -939,6 +993,17 @@ module LLVM
939
993
  def gc
940
994
  C.get_gc(self)
941
995
  end
996
+
997
+ def inspect
998
+ {
999
+ signature: to_s.lines[attribute_count == 0 ? 0 : 1],
1000
+ type: type.to_s,
1001
+ attributes: attribute_count,
1002
+ valid: valid?,
1003
+ blocks: basic_blocks.size,
1004
+ lines: to_s.lines.size,
1005
+ }.to_s
1006
+ end
942
1007
  end
943
1008
 
944
1009
  class GlobalAlias < GlobalValue
@@ -966,6 +1031,12 @@ module LLVM
966
1031
  end
967
1032
 
968
1033
  class Instruction < User
1034
+
1035
+ def self.from_ptr(ptr)
1036
+ kind = C.get_value_kind(ptr)
1037
+ kind == :instruction ? super : LLVM::Value.from_ptr_kind(ptr)
1038
+ end
1039
+
969
1040
  # Returns the parent of the instruction (a BasicBlock).
970
1041
  def parent
971
1042
  ptr = C.get_instruction_parent(self)
@@ -987,6 +1058,14 @@ module LLVM
987
1058
  def opcode
988
1059
  C.get_instruction_opcode(self)
989
1060
  end
1061
+
1062
+ def inspect
1063
+ { self.class.name => { opcode: opcode, ptr: @ptr } }.to_s
1064
+ end
1065
+ end
1066
+
1067
+ class Poison < Value
1068
+
990
1069
  end
991
1070
 
992
1071
  class CallInst < Instruction
data/lib/llvm/core.rb CHANGED
@@ -134,6 +134,56 @@ module LLVM
134
134
  # @return [Bool]
135
135
  # @scope class
136
136
  attach_function :is_literal_struct, :LLVMIsLiteralStruct, [:pointer], :bool
137
+
138
+ # /**
139
+ # * Read LLVM IR from a memory buffer and convert it into an in-memory Module
140
+ # * object. Returns 0 on success.
141
+ # * Optionally returns a human-readable description of any errors that
142
+ # * occurred during parsing IR. OutMessage must be disposed with
143
+ # * LLVMDisposeMessage.
144
+ # *
145
+ # * @see llvm::ParseIR()
146
+ # */
147
+ # LLVMBool LLVMParseIRInContext(LLVMContextRef ContextRef,
148
+ # LLVMMemoryBufferRef MemBuf, LLVMModuleRef *OutM,
149
+ # char **OutMessage);
150
+ attach_function :parse_ir_in_context, :LLVMParseIRInContext, [:pointer, :pointer, :pointer, :pointer], :bool
151
+
152
+ enum :value_kind, [
153
+ :argument, 0,
154
+ :basic_block, 1,
155
+ :memory_use, 2,
156
+ :memory_def, 3,
157
+ :memory_phi, 4,
158
+ :function, 5,
159
+ :global_alias, 6,
160
+ :global_ifunc, 7,
161
+ :global_variable, 8,
162
+ :block_address, 9,
163
+ :const_expr, 10,
164
+ :const_array, 11,
165
+ :const_struct, 12,
166
+ :const_vector, 13,
167
+ :undef, 14,
168
+ :const_aggregregate_zero, 15,
169
+ :const_data_array, 16,
170
+ :const_data_vector, 17,
171
+ :const_int, 18,
172
+ :const_fp, 19,
173
+ :const_null, 20,
174
+ :const_none, 21,
175
+ :metadata, 22,
176
+ :inline_asm, 23,
177
+ :instruction, 24,
178
+ :poison, 25,
179
+ ]
180
+
181
+ # /**
182
+ # * Obtain the enumerated type of a Value instance.
183
+ # *
184
+ # * @see llvm::Value::getValueID()
185
+ # */
186
+ attach_function :get_value_kind, :LLVMGetValueKind, [:pointer], :value_kind
137
187
  end
138
188
 
139
189
  # Yields a pointer suitable for storing an LLVM output message.
@@ -9,72 +9,116 @@ module LLVM
9
9
  class PassManager
10
10
  # @LLVMpass arg_promotion
11
11
  def arg_promote!
12
- C.add_argument_promotion_pass(self)
12
+ warn('arg_promote! / LLVMAddArgumentPromotionPass was removed from LLVM')
13
13
  end
14
14
 
15
15
  # @LLVMpass const_merge
16
+ # /** See llvm::createConstantMergePass function. */
17
+ # void LLVMAddConstantMergePass(LLVMPassManagerRef PM);
16
18
  def const_merge!
17
19
  C.add_constant_merge_pass(self)
18
20
  end
19
21
 
22
+ # @LLVMpass mergefunc
23
+ # /** See llvm::createMergeFunctionsPass function. */
24
+ # void LLVMAddMergeFunctionsPass(LLVMPassManagerRef PM);
25
+ def mergefunc!
26
+ C.add_merge_functions_pass(self)
27
+ end
28
+
29
+ # @LLVMpass called-value-propagation
30
+ # /** See llvm::createCalledValuePropagationPass function. */
31
+ # void LLVMAddCalledValuePropagationPass(LLVMPassManagerRef PM);
32
+ def called_value_propagation!
33
+ C.add_called_value_propagation_pass(self)
34
+ end
35
+
20
36
  # @LLVMpass dae
37
+ # /** See llvm::createDeadArgEliminationPass function. */
38
+ # void LLVMAddDeadArgEliminationPass(LLVMPassManagerRef PM);
21
39
  def dae!
22
- C.add_dead_arg_elimination(self)
40
+ C.add_dead_arg_elimination_pass(self)
23
41
  end
24
42
 
25
43
  # @LLVMpass function_attrs
44
+ # /** See llvm::createFunctionAttrsPass function. */
45
+ # void LLVMAddFunctionAttrsPass(LLVMPassManagerRef PM);
26
46
  def fun_attrs!
27
47
  C.add_function_attrs_pass(self)
28
48
  end
29
49
 
30
50
  # @LLVMpass inline
51
+ # /** See llvm::createFunctionInliningPass function. */
52
+ # void LLVMAddFunctionInliningPass(LLVMPassManagerRef PM);
31
53
  def inline!
32
54
  C.add_function_inlining_pass(self)
33
55
  end
34
56
 
35
57
  # @LLVMpass always_inline
58
+ # /** See llvm::createAlwaysInlinerPass function. */
59
+ # void LLVMAddAlwaysInlinerPass(LLVMPassManagerRef PM);
36
60
  def always_inline!
37
61
  C.add_always_inliner_pass(self)
38
62
  end
39
63
 
40
64
  # @LLVMpass gdce
65
+ # /** See llvm::createGlobalDCEPass function. */
66
+ # void LLVMAddGlobalDCEPass(LLVMPassManagerRef PM);
41
67
  def gdce!
42
68
  C.add_global_dce_pass(self)
43
69
  end
44
70
 
45
71
  # @LLVMpass global_opt
72
+ # /** See llvm::createGlobalOptimizerPass function. */
73
+ # void LLVMAddGlobalOptimizerPass(LLVMPassManagerRef PM);
46
74
  def global_opt!
47
75
  C.add_global_optimizer_pass(self)
48
76
  end
49
77
 
50
78
  # @LLVMpass ipcp
51
79
  def ipcp!
52
- C.add_ip_constant_propagation_pass(self)
80
+ warn('ipcp! / LLVMAddIPConstantPropagationPass was removed from LLVM')
53
81
  end
54
82
 
55
83
  # @LLVMpass prune_eh
84
+ # /** See llvm::createPruneEHPass function. */
85
+ # void LLVMAddPruneEHPass(LLVMPassManagerRef PM);
56
86
  def prune_eh!
57
87
  C.add_prune_eh_pass(self)
58
88
  end
59
89
 
60
90
  # @LLVMpass ipsccp
91
+ # /** See llvm::createIPSCCPPass function. */
92
+ # void LLVMAddIPSCCPPass(LLVMPassManagerRef PM);
61
93
  def ipsccp!
62
94
  C.add_ipsccp_pass(self)
63
95
  end
64
96
 
65
97
  # @LLVMpass internalize
98
+ # /** See llvm::createInternalizePass function. */
99
+ # void LLVMAddInternalizePass(LLVMPassManagerRef, unsigned AllButMain);
66
100
  def internalize!(all_but_main = true)
67
- C.add_internalize_pass(self, all_but_main)
101
+ C.add_internalize_pass(self, all_but_main ? 1 : 0)
68
102
  end
69
103
 
70
104
  # @LLVMpass sdp
105
+ # /** See llvm::createStripDeadPrototypesPass function. */
106
+ # void LLVMAddStripDeadPrototypesPass(LLVMPassManagerRef PM);
71
107
  def sdp!
72
108
  C.add_strip_dead_prototypes_pass(self)
73
109
  end
74
110
 
75
111
  # @LLVMpass strip
112
+ # /** See llvm::createStripSymbolsPass function. */
113
+ # void LLVMAddStripSymbolsPass(LLVMPassManagerRef PM);
76
114
  def strip!
77
115
  C.add_strip_symbols_pass(self)
78
116
  end
117
+
118
+ end
119
+
120
+ module C
121
+ attach_function :add_merge_functions_pass, :LLVMAddMergeFunctionsPass, [:pointer], :void
122
+ attach_function :add_called_value_propagation_pass, :LLVMAddCalledValuePropagationPass, [:pointer], :void
79
123
  end
80
124
  end
@@ -12,14 +12,6 @@ module LLVM::C
12
12
  end
13
13
  end
14
14
 
15
- # See llvm::createArgumentPromotionPass function.
16
- #
17
- # @method add_argument_promotion_pass(pm)
18
- # @param [FFI::Pointer(PassManagerRef)] pm
19
- # @return [nil]
20
- # @scope class
21
- attach_function :add_argument_promotion_pass, :LLVMAddArgumentPromotionPass, [:pointer], :void
22
-
23
15
  # See llvm::createConstantMergePass function.
24
16
  #
25
17
  # @method add_constant_merge_pass(pm)
@@ -76,14 +68,6 @@ module LLVM::C
76
68
  # @scope class
77
69
  attach_function :add_global_optimizer_pass, :LLVMAddGlobalOptimizerPass, [:pointer], :void
78
70
 
79
- # See llvm::createIPConstantPropagationPass function.
80
- #
81
- # @method add_ip_constant_propagation_pass(pm)
82
- # @param [FFI::Pointer(PassManagerRef)] pm
83
- # @return [nil]
84
- # @scope class
85
- attach_function :add_ip_constant_propagation_pass, :LLVMAddIPConstantPropagationPass, [:pointer], :void
86
-
87
71
  # See llvm::createPruneEHPass function.
88
72
  #
89
73
  # @method add_prune_eh_pass(pm)
@@ -7,158 +7,320 @@ require 'llvm/transforms/scalar_ffi'
7
7
  module LLVM
8
8
  class PassManager
9
9
  # @LLVMpass adce
10
+ # /** See llvm::createAggressiveDCEPass function. */
11
+ # void LLVMAddAggressiveDCEPass(LLVMPassManagerRef PM);
10
12
  def adce!
11
13
  C.add_aggressive_dce_pass(self)
12
14
  end
13
15
 
16
+ # @LLVMpass dce
17
+ # /** See llvm::createDeadCodeEliminationPass function. */
18
+ # void LLVMAddDCEPass(LLVMPassManagerRef PM);
19
+ def dce!
20
+ C.add_dce_pass(self)
21
+ end
22
+
23
+ # @LLVMpass bdce
24
+ # /** See llvm::createBitTrackingDCEPass function. */
25
+ # void LLVMAddBitTrackingDCEPass(LLVMPassManagerRef PM);
26
+ def bdce!
27
+ C.add_bit_tracking_dce_pass(self)
28
+ end
29
+
30
+ # @LLVMpass alignment_from_assumptions
31
+ # /** See llvm::createAlignmentFromAssumptionsPass function. */
32
+ # void LLVMAddAlignmentFromAssumptionsPass(LLVMPassManagerRef PM);
33
+ def alignment_from_assumptions!
34
+ C.add_alignment_from_assumptions_pass(self)
35
+ end
36
+
14
37
  # @LLVMpass simplifycfg
38
+ # /** See llvm::createCFGSimplificationPass function. */
39
+ # void LLVMAddCFGSimplificationPass(LLVMPassManagerRef PM);
15
40
  def simplifycfg!
16
41
  C.add_cfg_simplification_pass(self)
17
42
  end
18
43
 
19
44
  # @LLVMpass dse
45
+ # /** See llvm::createDeadStoreEliminationPass function. */
46
+ # void LLVMAddDeadStoreEliminationPass(LLVMPassManagerRef PM);
20
47
  def dse!
21
48
  C.add_dead_store_elimination_pass(self)
22
49
  end
23
50
 
51
+ # @LLVMPass scalarizer
52
+ # /** See llvm::createScalarizerPass function. */
53
+ # void LLVMAddScalarizerPass(LLVMPassManagerRef PM);
54
+ def scalarizer!
55
+ C.add_scalarizer_pass(self)
56
+ end
57
+
58
+ # @LLVMpass mldst-motion
59
+ # /** See llvm::createMergedLoadStoreMotionPass function. */
60
+ # void LLVMAddMergedLoadStoreMotionPass(LLVMPassManagerRef PM);
61
+ def mldst_motion!
62
+ C.add_merged_load_store_motion_pass(self)
63
+ end
64
+
24
65
  # @LLVMpass gvn
66
+ # /** See llvm::createGVNPass function. */
67
+ # void LLVMAddGVNPass(LLVMPassManagerRef PM);
25
68
  def gvn!
26
69
  C.add_gvn_pass(self)
27
70
  end
28
71
 
72
+ # @LLVMpass newgvn
73
+ # /** See llvm::createGVNPass function. */
74
+ # void LLVMAddNewGVNPass(LLVMPassManagerRef PM);
75
+ def newgvn!
76
+ C.add_new_gvn_pass(self)
77
+ end
78
+
29
79
  # @LLVMpass indvars
80
+ # /** See llvm::createIndVarSimplifyPass function. */
81
+ # void LLVMAddIndVarSimplifyPass(LLVMPassManagerRef PM);
30
82
  def indvars!
31
83
  C.add_ind_var_simplify_pass(self)
32
84
  end
33
85
 
34
86
  # @LLVMpass instcombine
87
+ # /** See llvm::createInstructionCombiningPass function. */
88
+ # void LLVMAddInstructionCombiningPass(LLVMPassManagerRef PM);
35
89
  def instcombine!
36
90
  C.add_instruction_combining_pass(self)
37
91
  end
38
92
 
93
+ # @LLVMpass instsimplify
94
+ # /** See llvm::createInstSimplifyLegacyPass function. */
95
+ # void LLVMAddInstructionSimplifyPass(LLVMPassManagerRef PM);
96
+ def instsimplify!
97
+ C.add_instruction_simplify_pass(self)
98
+ end
99
+
39
100
  # @LLVMpass jump-threading
101
+ # /** See llvm::createJumpThreadingPass function. */
102
+ # void LLVMAddJumpThreadingPass(LLVMPassManagerRef PM);
40
103
  def jump_threading!
41
104
  C.add_jump_threading_pass(self)
42
105
  end
43
106
 
44
107
  # @LLVMpass licm
108
+ # /** See llvm::createLICMPass function. */
109
+ # void LLVMAddLICMPass(LLVMPassManagerRef PM);
45
110
  def licm!
46
111
  C.add_licm_pass(self)
47
112
  end
48
113
 
49
114
  # @LLVMpass loop-deletion
115
+ # /** See llvm::createLoopDeletionPass function. */
116
+ # void LLVMAddLoopDeletionPass(LLVMPassManagerRef PM);
50
117
  def loop_deletion!
51
118
  C.add_loop_deletion_pass(self)
52
119
  end
53
120
 
54
121
  # @LLVMpass loop-idiom
122
+ # /** See llvm::createLoopIdiomPass function */
123
+ # void LLVMAddLoopIdiomPass(LLVMPassManagerRef PM);
55
124
  def loop_idiom!
56
125
  C.add_loop_idiom_pass(self)
57
126
  end
58
127
 
59
128
  # @LLVMpass loop-rotate
129
+ # /** See llvm::createLoopRotatePass function. */
130
+ # void LLVMAddLoopRotatePass(LLVMPassManagerRef PM);
60
131
  def loop_rotate!
61
132
  C.add_loop_rotate_pass(self)
62
133
  end
63
134
 
135
+ # @LLVMpass loop-reroll
136
+ # /** See llvm::createLoopRerollPass function. */
137
+ # void LLVMAddLoopRerollPass(LLVMPassManagerRef PM);
138
+ def loop_reroll!
139
+ C.add_loop_reroll_pass(self)
140
+ end
141
+
64
142
  # @LLVMpass loop-unroll
143
+ # /** See llvm::createLoopUnrollPass function. */
144
+ # void LLVMAddLoopUnrollPass(LLVMPassManagerRef PM);
65
145
  def loop_unroll!
66
146
  C.add_loop_unroll_pass(self)
67
147
  end
68
148
 
149
+ # @LLVMpass loop-unroll-and-jam
150
+ # /** See llvm::createLoopUnrollAndJamPass function. */
151
+ # void LLVMAddLoopUnrollAndJamPass(LLVMPassManagerRef PM);
152
+ def loop_unroll_and_jam!
153
+ C.add_loop_unroll_and_jam_pass(self)
154
+ end
155
+
69
156
  # @LLVMpass loop-unswitch
70
157
  def loop_unswitch!
71
- C.add_loop_unswitch_pass(self)
158
+ warn('loop_unswitch! / LLVMAddLoopUnswitchPass was removed in LLVM 15')
159
+ end
160
+
161
+ # @LLVMpass loweratomic
162
+ # /** See llvm::createLowerAtomicPass function. */
163
+ # void LLVMAddLowerAtomicPass(LLVMPassManagerRef PM);
164
+ def loweratomic!
165
+ C.add_lower_atomic_pass(self)
72
166
  end
73
167
 
74
168
  # @LLVMpass memcpyopt
169
+ # /** See llvm::createMemCpyOptPass function. */
170
+ # void LLVMAddMemCpyOptPass(LLVMPassManagerRef PM);
75
171
  def memcpyopt!
76
172
  C.add_mem_cpy_opt_pass(self)
77
173
  end
78
174
 
79
- # @LLVMpass mem2reg
80
- def mem2reg!
81
- C.add_promote_memory_to_register_pass(self)
175
+ # @LLVMpass partially-inline-libcalls
176
+ # /** See llvm::createPartiallyInlineLibCallsPass function. */
177
+ # void LLVMAddPartiallyInlineLibCallsPass(LLVMPassManagerRef PM);
178
+ def partially_inline_libcalls!
179
+ C.add_partially_inline_lib_calls_pass(self)
82
180
  end
83
181
 
84
182
  # @LLVMpass reassociate
183
+ # /** See llvm::createReassociatePass function. */
184
+ # void LLVMAddReassociatePass(LLVMPassManagerRef PM);
85
185
  def reassociate!
86
186
  C.add_reassociate_pass(self)
87
187
  end
88
188
 
89
189
  # @LLVMpass sccp
190
+ # /** See llvm::createSCCPPass function. */
191
+ # void LLVMAddSCCPPass(LLVMPassManagerRef PM);
90
192
  def sccp!
91
193
  C.add_sccp_pass(self)
92
194
  end
93
195
 
94
- # @LLVMpass scalarrepl
196
+ # @LLVMpass sroa
197
+ # /** See llvm::createSROAPass function. */
198
+ # void LLVMAddScalarReplAggregatesPass(LLVMPassManagerRef PM);
95
199
  def scalarrepl!
96
200
  C.add_scalar_repl_aggregates_pass(self)
97
201
  end
98
202
 
99
- # @LLVMpass scalarrepl
203
+ # @LLVMpass sroa
204
+ # /** See llvm::createSROAPass function. */
205
+ # void LLVMAddScalarReplAggregatesPassSSA(LLVMPassManagerRef PM);
100
206
  def scalarrepl_ssa!
101
207
  C.add_scalar_repl_aggregates_pass_ssa(self)
102
208
  end
103
209
 
104
- # @LLVMpass scalarrepl
105
- def scalarrepl_threshold!(threshold)
106
- C.add_scalar_repl_aggregates_pass(self, threshold)
210
+ # @LLVMpass sroa
211
+ # /** See llvm::createSROAPass function. */
212
+ # void LLVMAddScalarReplAggregatesPassWithThreshold(LLVMPassManagerRef PM,
213
+ # int Threshold);
214
+ # threshold appears unused: https://llvm.org/doxygen/Scalar_8cpp_source.html#l00211
215
+ def scalarrepl_threshold!(threshold = 0)
216
+ C.add_scalar_repl_aggregates_pass_with_threshold(self, threshold)
107
217
  end
108
218
 
109
219
  # @LLVMpass simplify-libcalls
220
+ # /** See llvm::createSimplifyLibCallsPass function. */
221
+ # void LLVMAddSimplifyLibCallsPass(LLVMPassManagerRef PM);
222
+ # removed: https://llvm.org/doxygen/Scalar_8cpp_source.html#l00211
110
223
  def simplify_libcalls!
111
- C.add_simplify_lib_calls_pass(self)
224
+ warn('simplify_libcalls! / LLVMAddSimplifyLibCallsPass was removed from LLVM')
112
225
  end
113
226
 
114
227
  # @LLVMpass tailcallelim
228
+ # /** See llvm::createTailCallEliminationPass function. */
229
+ # void LLVMAddTailCallEliminationPass(LLVMPassManagerRef PM);
115
230
  def tailcallelim!
116
231
  C.add_tail_call_elimination_pass(self)
117
232
  end
118
233
 
119
234
  # @LLVMpass constprop
120
235
  def constprop!
121
- C.add_constant_propagation_pass(self)
236
+ warn('constprop! / LLVMAddConstantPropagationPass was removed from LLVM')
122
237
  end
123
238
 
124
239
  # @LLVMpass reg2mem
240
+ # /** See llvm::demotePromoteMemoryToRegisterPass function. */
241
+ # void LLVMAddDemoteMemoryToRegisterPass(LLVMPassManagerRef PM);
125
242
  def reg2mem!
126
243
  C.add_demote_memory_to_register_pass(self)
127
244
  end
128
245
 
246
+ # @LLVMpass verify
247
+ # /** See llvm::createVerifierPass function. */
248
+ # void LLVMAddVerifierPass(LLVMPassManagerRef PM);
249
+ def verify!
250
+ C.add_verifier_pass(self)
251
+ end
252
+
129
253
  # @LLVMpass cvprop
254
+ # /** See llvm::createCorrelatedValuePropagationPass function */
255
+ # void LLVMAddCorrelatedValuePropagationPass(LLVMPassManagerRef PM);
130
256
  def cvprop!
131
257
  C.add_correlated_value_propagation_pass(self)
132
258
  end
133
259
 
134
260
  # @LLVMpass early-cse
261
+ # /** See llvm::createEarlyCSEPass function */
262
+ # void LLVMAddEarlyCSEPass(LLVMPassManagerRef PM);
135
263
  def early_cse!
136
264
  C.add_early_cse_pass(self)
137
265
  end
138
266
 
267
+ # @LLVMpass early-cse-memssa
268
+ # /** See llvm::createEarlyCSEPass function */
269
+ # void LLVMAddEarlyCSEMemSSAPass(LLVMPassManagerRef PM);
270
+ def early_cse_memssa!
271
+ C.add_early_cse_mem_ssa_pass(self)
272
+ end
273
+
139
274
  # @LLVMpass lower-expect
275
+ # /** See llvm::createLowerExpectIntrinsicPass function */
276
+ # void LLVMAddLowerExpectIntrinsicPass(LLVMPassManagerRef PM);
140
277
  def lower_expect!
141
278
  C.add_lower_expect_intrinsic_pass(self)
142
279
  end
143
280
 
281
+ # @LLVMPass lower-constant-intrinsics
282
+ # /** See llvm::createLowerConstantIntrinsicsPass function */
283
+ # void LLVMAddLowerConstantIntrinsicsPass(LLVMPassManagerRef PM);
284
+ def lower_constant_intrinsics!
285
+ C.add_lower_constant_intrinsics_pass(self)
286
+ end
287
+
144
288
  # @LLVMpass tbaa
289
+ # /** See llvm::createTypeBasedAliasAnalysisPass function */
290
+ # void LLVMAddTypeBasedAliasAnalysisPass(LLVMPassManagerRef PM);
145
291
  def tbaa!
146
292
  C.add_type_based_alias_analysis_pass(self)
147
293
  end
148
294
 
295
+ # @ LLVMPass scoped-noalias-aa
296
+ # /** See llvm::createScopedNoAliasAAPass function */
297
+ # void LLVMAddScopedNoAliasAAPass(LLVMPassManagerRef PM);
298
+ def scoped_noalias_aa!
299
+ C.add_scoped_no_alias_aa_pass(self)
300
+ end
301
+
149
302
  # @LLVMpass basicaa
303
+ # /** See llvm::createBasicAliasAnalysisPass function */
304
+ # void LLVMAddBasicAliasAnalysisPass(LLVMPassManagerRef PM);
150
305
  def basicaa!
151
306
  C.add_basic_alias_analysis_pass(self)
152
307
  end
153
308
 
154
- # @LLVMpass mergefunc
155
- def mergefunc!
156
- C.add_merge_functions_pass(self)
309
+ # @LLVMpass mergereturn
310
+ # /** See llvm::createUnifyFunctionExitNodesPass function */
311
+ # void LLVMAddUnifyFunctionExitNodesPass(LLVMPassManagerRef PM);
312
+ def mergereturn!
313
+ C.add_unify_function_exit_nodes_pass(self)
157
314
  end
158
315
 
159
316
  end
160
317
 
161
318
  module C
162
- attach_function :add_merge_functions_pass, :LLVMAddMergeFunctionsPass, [:pointer], :void
319
+ attach_function :add_dce_pass, :LLVMAddDCEPass, [:pointer], :void
320
+ attach_function :add_instruction_simplify_pass, :LLVMAddInstructionSimplifyPass, [:pointer], :void
321
+ attach_function :add_loop_unroll_and_jam_pass, :LLVMAddLoopUnrollAndJamPass, [:pointer], :void
322
+ attach_function :add_lower_atomic_pass, :LLVMAddLowerAtomicPass, [:pointer], :void
323
+ attach_function :add_lower_constant_intrinsics_pass, :LLVMAddLowerConstantIntrinsicsPass, [:pointer], :void
324
+ attach_function :add_unify_function_exit_nodes_pass, :LLVMAddUnifyFunctionExitNodesPass, [:pointer], :void
163
325
  end
164
326
  end
@@ -164,14 +164,6 @@ module LLVM::C
164
164
  # @scope class
165
165
  attach_function :add_loop_unroll_pass, :LLVMAddLoopUnrollPass, [:pointer], :void
166
166
 
167
- # See llvm::createLoopUnswitchPass function.
168
- #
169
- # @method add_loop_unswitch_pass(pm)
170
- # @param [FFI::Pointer(PassManagerRef)] pm
171
- # @return [nil]
172
- # @scope class
173
- attach_function :add_loop_unswitch_pass, :LLVMAddLoopUnswitchPass, [:pointer], :void
174
-
175
167
  # See llvm::createMemCpyOptPass function.
176
168
  #
177
169
  # @method add_mem_cpy_opt_pass(pm)
@@ -245,14 +237,6 @@ module LLVM::C
245
237
  # @scope class
246
238
  attach_function :add_scalar_repl_aggregates_pass_with_threshold, :LLVMAddScalarReplAggregatesPassWithThreshold, [:pointer, :int], :void
247
239
 
248
- # See llvm::createSimplifyLibCallsPass function.
249
- #
250
- # @method add_simplify_lib_calls_pass(pm)
251
- # @param [FFI::Pointer(PassManagerRef)] pm
252
- # @return [nil]
253
- # @scope class
254
- attach_function :add_simplify_lib_calls_pass, :LLVMAddSimplifyLibCallsPass, [:pointer], :void
255
-
256
240
  # See llvm::createTailCallEliminationPass function.
257
241
  #
258
242
  # @method add_tail_call_elimination_pass(pm)
@@ -261,14 +245,6 @@ module LLVM::C
261
245
  # @scope class
262
246
  attach_function :add_tail_call_elimination_pass, :LLVMAddTailCallEliminationPass, [:pointer], :void
263
247
 
264
- # See llvm::createConstantPropagationPass function.
265
- #
266
- # @method add_constant_propagation_pass(pm)
267
- # @param [FFI::Pointer(PassManagerRef)] pm
268
- # @return [nil]
269
- # @scope class
270
- attach_function :add_constant_propagation_pass, :LLVMAddConstantPropagationPass, [:pointer], :void
271
-
272
248
  # See llvm::demotePromoteMemoryToRegisterPass function.
273
249
  #
274
250
  # @method add_demote_memory_to_register_pass(pm)
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'llvm'
4
+ require 'llvm/core'
5
+
6
+ module LLVM
7
+ class PassManager
8
+
9
+ # @LLVMpass lowerswitch
10
+ # /** See llvm::createLowerSwitchPass function. */
11
+ # void LLVMAddLowerSwitchPass(LLVMPassManagerRef PM);
12
+ def lowerswitch!
13
+ C.add_lower_switch_pass(self)
14
+ end
15
+
16
+ # @LLVMpass mem2reg
17
+ # /** See llvm::createPromoteMemoryToRegisterPass function. */
18
+ # void LLVMAddPromoteMemoryToRegisterPass(LLVMPassManagerRef PM);
19
+ def mem2reg!
20
+ C.add_promote_memory_to_register_pass(self)
21
+ end
22
+
23
+ # @LLVMpass add-discriminators
24
+ # /** See llvm::createAddDiscriminatorsPass function. */
25
+ # void LLVMAddAddDiscriminatorsPass(LLVMPassManagerRef PM);
26
+ def add_discriminators!
27
+ C.add_add_discriminators_pass(self)
28
+ end
29
+ end
30
+
31
+ module C
32
+ attach_function :add_add_discriminators_pass, :LLVMAddAddDiscriminatorsPass, [:pointer], :void
33
+ end
34
+ end
@@ -8,15 +8,20 @@ module LLVM
8
8
  class PassManager
9
9
  # @LLVMpass bb_vectorize
10
10
  def bb_vectorize!
11
- C.add_bb_vectorize_pass(self)
11
+ warn('bb_vectorize! / LLVMAddBBVectorizePass was removed from LLVM - replace with slp_vectorize!')
12
+ slp_vectorize!
12
13
  end
13
14
 
14
15
  # @LLVMpass loop_vectorize
16
+ # /** See llvm::createLoopVectorizePass function. */
17
+ # void LLVMAddLoopVectorizePass(LLVMPassManagerRef PM);
15
18
  def loop_vectorize!
16
19
  C.add_loop_vectorize_pass(self)
17
20
  end
18
21
 
19
22
  # @LLVMpass slp_vectorize
23
+ # /** See llvm::createSLPVectorizerPass function. */
24
+ # void LLVMAddSLPVectorizePass(LLVMPassManagerRef PM);
20
25
  def slp_vectorize!
21
26
  C.add_slp_vectorize_pass(self)
22
27
  end
data/lib/llvm/version.rb CHANGED
@@ -3,5 +3,5 @@
3
3
  module LLVM
4
4
  LLVM_VERSION = "15"
5
5
  LLVM_REQUIRED_VERSION = "15.0"
6
- RUBY_LLVM_VERSION = "15.0.2"
6
+ RUBY_LLVM_VERSION = "15.0.4"
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-llvm
3
3
  version: !ruby/object:Gem::Version
4
- version: 15.0.2
4
+ version: 15.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jesse Johnson
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2023-01-31 00:00:00.000000000 Z
12
+ date: 2023-05-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ffi
@@ -197,7 +197,6 @@ files:
197
197
  - lib/llvm/core/builder.rb
198
198
  - lib/llvm/core/context.rb
199
199
  - lib/llvm/core/module.rb
200
- - lib/llvm/core/opaque_pointer_builder.rb
201
200
  - lib/llvm/core/pass_manager.rb
202
201
  - lib/llvm/core/type.rb
203
202
  - lib/llvm/core/value.rb
@@ -215,6 +214,7 @@ files:
215
214
  - lib/llvm/transforms/ipo_ffi.rb
216
215
  - lib/llvm/transforms/scalar.rb
217
216
  - lib/llvm/transforms/scalar_ffi.rb
217
+ - lib/llvm/transforms/utils.rb
218
218
  - lib/llvm/transforms/vectorize.rb
219
219
  - lib/llvm/transforms/vectorize_ffi.rb
220
220
  - lib/llvm/version.rb
@@ -1,26 +0,0 @@
1
- # frozen_string_literal: true
2
- # module LLVM
3
- # module OpaquePointerBuilder
4
- # # Builds a struct getelementptr Instruction.
5
- # #
6
- # # @param [LLVM::Value] pointer A pointer to a structure
7
- # # @param [LLVM::Value] idx Unsigned integer representing the index of a
8
- # # structure member
9
- # # @param [String] name The name of the result in LLVM IR
10
- # # @return [LLVM::Instruction] The resulting pointer
11
- # # @LLVMinst gep
12
- # # @see http://llvm.org/docs/GetElementPtr.html
13
- # def struct_gep1(pointer, idx, name = "")
14
- # Instruction.from_ptr(C.build_struct_gep(self, pointer, idx, name))
15
- # end
16
- #
17
- # private def struct_gep2(type, pointer, idx, name)
18
- # Instruction.from_ptr(C.build_struct_gep2(self, type, pointer, idx, name))
19
- # end
20
- #
21
- # def struct_gep(pointer, idx, name = "", type = nil)
22
- # type2 = type || must_infer_type(pointer)
23
- # struct_gep2(types2, pointer, idx, name)
24
- # end
25
- # end
26
- # end