summaryrefslogtreecommitdiff
blob: bbfd922149eb1e2fae4aad827d393991ac4ff737 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
https://bugs.gentoo.org/630634
diff --git a/.gitignore b/.gitignore
index 9a883edfd..5f852d930 100644
--- a/.gitignore
+++ b/.gitignore
@@ -12,5 +12,6 @@ all_spec
 /tmp
 /doc/
 /src/llvm/ext/llvm_ext.o
+/src/llvm/ext/llvm_ext.dwo
 /src/ext/*.o
 /src/ext/libcrystal.a
diff --git a/Makefile b/Makefile
index a5dc0d7e3..14a21bb86 100644
--- a/Makefile
+++ b/Makefile
@@ -37,8 +37,6 @@ LLVM_CONFIG_FINDER := \
     (command -v llvm-config > /dev/null && (case "$(llvm-config --version)" in 3.9*) command -v llvm-config;; *) false;; esac)) || \
   command -v llvm-config-3.8 || command -v llvm-config38 || \
     (command -v llvm-config > /dev/null && (case "$(llvm-config --version)" in 3.8*) command -v llvm-config;; *) false;; esac)) || \
-  command -v llvm-config-3.6 || command -v llvm-config36 || \
-  command -v llvm-config-3.5 || command -v llvm-config35 || \
   command -v llvm-config
 LLVM_CONFIG := $(shell $(LLVM_CONFIG_FINDER))
 LLVM_EXT_DIR = src/llvm/ext
diff --git a/src/compiler/crystal/compiler.cr b/src/compiler/crystal/compiler.cr
index a2bed9a95..afc7976e3 100644
--- a/src/compiler/crystal/compiler.cr
+++ b/src/compiler/crystal/compiler.cr
@@ -447,9 +447,6 @@ module Crystal

     protected def optimize(llvm_mod)
       fun_pass_manager = llvm_mod.new_function_pass_manager
-      {% if LibLLVM::IS_35 || LibLLVM::IS_36 %}
-        fun_pass_manager.add_target_data target_machine.data_layout
-      {% end %}
       pass_manager_builder.populate fun_pass_manager
       fun_pass_manager.run llvm_mod
       module_pass_manager.run llvm_mod
@@ -460,9 +457,6 @@ module Crystal
     private def module_pass_manager
       @module_pass_manager ||= begin
         mod_pass_manager = LLVM::ModulePassManager.new
-        {% if LibLLVM::IS_35 || LibLLVM::IS_36 %}
-          mod_pass_manager.add_target_data target_machine.data_layout
-        {% end %}
         pass_manager_builder.populate mod_pass_manager
         mod_pass_manager
       end
@@ -554,54 +548,29 @@ module Crystal
         can_reuse_previous_compilation =
           !compiler.emit && !@bc_flags_changed && File.exists?(bc_name) && File.exists?(object_name)

-        {% if LibLLVM::IS_35 %}
-          # In LLVM 3.5 we can't write a bitcode to memory,
-          # so instead we write it to another file
-          bc_name_new = self.bc_name_new
-          llvm_mod.write_bitcode_to_file(bc_name_new)
-
-          if can_reuse_previous_compilation
-            if FileUtils.cmp(bc_name, bc_name_new)
-              # If the user cancelled a previous compilation it might be that
-              # the .o file is empty
-              if File.size(object_name) > 0
-                File.delete bc_name_new
-                must_compile = false
-              end
-            end
-          end
+        memory_buffer = llvm_mod.write_bitcode_to_memory_buffer

-          if must_compile
-            # Create/overwrite the .bc file (for next compilations)
-            File.rename(bc_name_new, bc_name)
-            compiler.optimize llvm_mod if compiler.release?
-            compiler.target_machine.emit_obj_to_file llvm_mod, object_name
-          end
-        {% else %}
-          memory_buffer = llvm_mod.write_bitcode_to_memory_buffer
-
-          if can_reuse_previous_compilation
-            memory_io = IO::Memory.new(memory_buffer.to_slice)
-            changed = File.open(bc_name) { |bc_file| !FileUtils.cmp(bc_file, memory_io) }
-
-            # If the user cancelled a previous compilation
-            # it might be that the .o file is empty
-            if !changed && File.size(object_name) > 0
-              must_compile = false
-              memory_buffer.dispose
-              memory_buffer = nil
-            else
-              # We need to compile, so we'll write the memory buffer to file
-            end
-          end
+        if can_reuse_previous_compilation
+          memory_io = IO::Memory.new(memory_buffer.to_slice)
+          changed = File.open(bc_name) { |bc_file| !FileUtils.cmp(bc_file, memory_io) }

-          # If there's a memory buffer, it means we must create a .o from it
-          if memory_buffer
-            # Create the .bc file (for next compilations)
-            File.write(bc_name, memory_buffer.to_slice)
+          # If the user cancelled a previous compilation
+          # it might be that the .o file is empty
+          if !changed && File.size(object_name) > 0
+            must_compile = false
             memory_buffer.dispose
+            memory_buffer = nil
+          else
+            # We need to compile, so we'll write the memory buffer to file
           end
-        {% end %}
+        end
+
+        # If there's a memory buffer, it means we must create a .o from it
+        if memory_buffer
+          # Create the .bc file (for next compilations)
+          File.write(bc_name, memory_buffer.to_slice)
+          memory_buffer.dispose
+        end

         if must_compile
           compiler.optimize llvm_mod if compiler.release?
diff --git a/src/llvm.cr b/src/llvm.cr
index 44a03c272..f9b31cf4b 100644
--- a/src/llvm.cr
+++ b/src/llvm.cr
@@ -94,11 +94,5 @@ module LLVM
     string
   end

-  {% if LibLLVM::IS_35 %}
-    DEBUG_METADATA_VERSION = 1
-  {% elsif LibLLVM::IS_36 %}
-    DEBUG_METADATA_VERSION = 2
-  {% else %}
-    DEBUG_METADATA_VERSION = 3
-  {% end %}
+  DEBUG_METADATA_VERSION = 3
 end
diff --git a/src/llvm/context.cr b/src/llvm/context.cr
index 8485eedf1..7d66a4365 100644
--- a/src/llvm/context.cr
+++ b/src/llvm/context.cr
@@ -9,9 +9,9 @@ class LLVM::Context
   end

   def new_module(name : String) : Module
-    {% if LibLLVM::IS_38 || LibLLVM::IS_36 || LibLLVM::IS_35 %}
+    {% if LibLLVM::IS_38 %}
       Module.new(LibLLVM.module_create_with_name_in_context(name, self), name, self)
-    {% else %}
+    {% else %} # LLVM >= 3.9
       Module.new(LibLLVM.module_create_with_name_in_context(name, self), self)
     {% end %}
   end
@@ -104,9 +104,9 @@ class LLVM::Context
     if ret != 0 && msg
       raise LLVM.string_and_dispose(msg)
     end
-    {% if LibLLVM::IS_38 || LibLLVM::IS_36 || LibLLVM::IS_35 %}
+    {% if LibLLVM::IS_38 %}
       Module.new(mod, "unknown", self)
-    {% else %}
+    {% else %} # LLVM >= 3.9
       Module.new(mod, self)
     {% end %}
   end
diff --git a/src/llvm/di_builder.cr b/src/llvm/di_builder.cr
index b8c0fd628..79571d2c0 100644
--- a/src/llvm/di_builder.cr
+++ b/src/llvm/di_builder.cr
@@ -31,16 +31,8 @@ struct LLVM::DIBuilder

   def create_function(scope, name, linkage_name, file, line, composite_type, is_local_to_unit, is_definition,
                       scope_line, flags, is_optimized, func)
-    {% if LibLLVM::IS_36 || LibLLVM::IS_35 %}
-      LibLLVMExt.di_builder_create_function(self, scope, name, linkage_name, file, line, composite_type,
-                                            is_local_to_unit ? 1 : 0,
-                                            is_definition ? 1 : 0,
-                                            scope_line, flags,
-                                            is_optimized ? 1 : 0, func)
-    {% else %}
-      LibLLVMExt.di_builder_create_function(self, scope, name, linkage_name, file, line, composite_type,
-                                            is_local_to_unit, is_definition, scope_line, flags, is_optimized, func)
-    {% end %}
+    LibLLVMExt.di_builder_create_function(self, scope, name, linkage_name, file, line, composite_type,
+      is_local_to_unit, is_definition, scope_line, flags, is_optimized, func)
   end

   def create_auto_variable(scope, name, file, line, type, align_in_bits)
@@ -87,19 +79,11 @@ struct LLVM::DIBuilder
   end

   def create_replaceable_composite_type(scope, name, file, line, context : Context)
-    {% if LibLLVM::IS_35 || LibLLVM::IS_36 %}
-      LibLLVMExt.temporary_md_node(context, nil, 0).as(LibLLVMExt::Metadata)
-    {% else %}
-      LibLLVMExt.di_builder_create_replaceable_composite_type(self, scope, name, file, line)
-    {% end %}
+    LibLLVMExt.di_builder_create_replaceable_composite_type(self, scope, name, file, line)
   end

   def replace_temporary(from, to)
-    {% if LibLLVM::IS_35 || LibLLVM::IS_36 %}
-      LibLLVMExt.metadata_replace_all_uses_with(from, to)
-    {% else %}
-      LibLLVMExt.di_builder_replace_temporary(self, from, to)
-    {% end %}
+    LibLLVMExt.di_builder_replace_temporary(self, from, to)
   end

   def end
diff --git a/src/llvm/ext/llvm_ext.cc b/src/llvm/ext/llvm_ext.cc
index d13446160..3dbdd4220 100644
--- a/src/llvm/ext/llvm_ext.cc
+++ b/src/llvm/ext/llvm_ext.cc
@@ -18,35 +18,22 @@ using namespace llvm;
 #define LLVM_VERSION_LE(major, minor) \
   (LLVM_VERSION_MAJOR < (major) || LLVM_VERSION_MAJOR == (major) && LLVM_VERSION_MINOR <= (minor))

+#if LLVM_VERSION_LE(4, 0)
 typedef struct LLVMOpaqueDIBuilder *LLVMDIBuilderRef;
 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(DIBuilder, LLVMDIBuilderRef)

-#if LLVM_VERSION_EQ(3, 5)
-typedef LLVMValueRef LLVMMetadataRef;
-typedef Value Metadata;
-#define DIBuilderRef LLVMDIBuilderRef
-
-#else /* LLVM != 3.5 */
 typedef struct LLVMOpaqueMetadata *LLVMMetadataRef;
 DEFINE_ISA_CONVERSION_FUNCTIONS(Metadata, LLVMMetadataRef)
 inline Metadata **unwrap(LLVMMetadataRef *Vals) {
   return reinterpret_cast<Metadata **>(Vals);
 }
-#endif /* LLVM == 3.5 */
-
-#if LLVM_VERSION_LE(3, 6)
-template <typename T> T unwrapDIptr(LLVMMetadataRef v) {
-  return v ? T(unwrap<MDNode>(v)) : T();
-}
-#define DIBuilderRef LLVMDIBuilderRef
+#endif

-#else /* LLVM > 3.6 */
 typedef DIBuilder *DIBuilderRef;
 #define DIArray DINodeArray
 template <typename T> T *unwrapDIptr(LLVMMetadataRef v) {
   return (T *)(v ? unwrap<MDNode>(v) : NULL);
 }
-#endif /* LLVM <= 3.6 */

 #if LLVM_VERSION_LE(3, 6)
 #define OperandBundleDef void
@@ -66,13 +53,7 @@ void LLVMDIBuilderFinalize(LLVMDIBuilderRef dref) { unwrap(dref)->finalize(); }

 LLVMMetadataRef LLVMDIBuilderCreateFile(DIBuilderRef Dref, const char *File,
                                         const char *Dir) {
-#if LLVM_VERSION_LE(3, 6)
-  DIBuilder *D = unwrap(Dref);
-  DIFile F = D->createFile(File, Dir);
-  return wrap(F);
-#else
   return wrap(Dref->createFile(File, Dir));
-#endif
 }

 LLVMMetadataRef LLVMDIBuilderCreateCompileUnit(DIBuilderRef Dref, unsigned Lang,
@@ -82,20 +63,13 @@ LLVMMetadataRef LLVMDIBuilderCreateCompileUnit(DIBuilderRef Dref, unsigned Lang,
                                                int Optimized,
                                                const char *Flags,
                                                unsigned RuntimeVersion) {
-#if LLVM_VERSION_LE(3, 6)
-  DIBuilder *D = unwrap(Dref);
-  DICompileUnit CU = D->createCompileUnit(Lang, File, Dir, Producer, Optimized,
-                                          Flags, RuntimeVersion);
-  return wrap(CU);
-#else
-# if LLVM_VERSION_LE(3, 9)
+#if LLVM_VERSION_LE(3, 9)
   return wrap(Dref->createCompileUnit(Lang, File, Dir, Producer, Optimized,
                                       Flags, RuntimeVersion));
-# else
+#else
   DIFile *F = Dref->createFile(File, Dir);
   return wrap(Dref->createCompileUnit(Lang, F, Producer, Optimized,
                                       Flags, RuntimeVersion));
-# endif
 #endif
 }

@@ -111,19 +85,11 @@ LLVMMetadataRef LLVMDIBuilderCreateFunction(
 #endif
     bool IsOptimized,
     LLVMValueRef Func) {
-#if LLVM_VERSION_LE(3, 6)
-  DIBuilder *D = unwrap(Dref);
-  DISubprogram Sub = D->createFunction(
-      unwrapDI<DIDescriptor>(Scope), Name, LinkageName, unwrapDI<DIFile>(File),
-      Line, unwrapDI<DICompositeType>(CompositeType), IsLocalToUnit,
-      IsDefinition, ScopeLine, Flags, IsOptimized, unwrap<Function>(Func));
-#else
   DISubprogram *Sub = Dref->createFunction(
       unwrapDI<DIScope>(Scope), Name, LinkageName, unwrapDI<DIFile>(File), Line,
       unwrapDI<DISubroutineType>(CompositeType), IsLocalToUnit, IsDefinition,
       ScopeLine, Flags, IsOptimized);
   unwrap<Function>(Func)->setSubprogram(Sub);
-#endif
   return wrap(Sub);
 }

@@ -132,18 +98,8 @@ LLVMMetadataRef LLVMDIBuilderCreateLexicalBlock(DIBuilderRef Dref,
                                                 LLVMMetadataRef File,
                                                 unsigned Line,
                                                 unsigned Column) {
-#if LLVM_VERSION_LE(3, 6)
-  DIBuilder *D = unwrap(Dref);
-# if LLVM_VERSION_EQ(3, 5)
-  DILexicalBlock LB = D->createLexicalBlock(unwrapDI<DIDescriptor>(Scope), unwrapDI<DIFile>(File), Line, Column, 0);
-# else /* LLVM <= 3.6 && LLVM != 3.5 */
-  DILexicalBlock LB = D->createLexicalBlock(unwrapDI<DIDescriptor>(Scope), unwrapDI<DIFile>(File), Line, Column);
-# endif
-  return wrap(LB);
-#else /* LLVM > 3.6 */
   return wrap(Dref->createLexicalBlock(unwrapDI<DIDescriptor>(Scope),
                                        unwrapDI<DIFile>(File), Line, Column));
-#endif /* LLVM <= 3.6 */
 }

 LLVMMetadataRef LLVMDIBuilderCreateBasicType(DIBuilderRef Dref,
@@ -151,71 +107,34 @@ LLVMMetadataRef LLVMDIBuilderCreateBasicType(DIBuilderRef Dref,
                                              uint64_t SizeInBits,
                                              uint64_t AlignInBits,
                                              unsigned Encoding) {
-#if LLVM_VERSION_LE(3, 6)
-  DIBuilder *D = unwrap(Dref);
-  DIBasicType T = D->createBasicType(Name, SizeInBits, AlignInBits, Encoding);
-  return wrap(T);
-#else
-# if LLVM_VERSION_LE(3, 9)
+#if LLVM_VERSION_LE(3, 9)
   return wrap(Dref->createBasicType(Name, SizeInBits, AlignInBits, Encoding));
-# else
+#else
   return wrap(Dref->createBasicType(Name, SizeInBits, Encoding));
-# endif
 #endif
 }

 LLVMMetadataRef LLVMDIBuilderGetOrCreateTypeArray(DIBuilderRef Dref,
                                                   LLVMMetadataRef *Data,
                                                   unsigned Length) {
-#if LLVM_VERSION_LE(3, 6)
-  DIBuilder *D = unwrap(Dref);
-# if LLVM_VERSION_EQ(3, 5)
-  Value **DataValue = unwrap(Data);
-  ArrayRef<Value *> Elements(DataValue, Length);
-  DIArray A = D->getOrCreateArray(Elements);
-# else /* LLVM <= 3.6 && LLVM != 3.5 */
-  Metadata **DataValue = unwrap(Data);
-  ArrayRef<Metadata *> Elements(DataValue, Length);
-  DITypeArray A = D->getOrCreateTypeArray(Elements);
-# endif
-  return wrap(A);
-#else /* LLVM > 3.6 */
   Metadata **DataValue = unwrap(Data);
   return wrap(
       Dref->getOrCreateTypeArray(ArrayRef<Metadata *>(DataValue, Length))
           .get());
-#endif /* LLVM <= 3.6 */
 }

 LLVMMetadataRef LLVMDIBuilderGetOrCreateArray(DIBuilderRef Dref,
                                               LLVMMetadataRef *Data,
                                               unsigned Length) {
-#if LLVM_VERSION_LE(3, 6)
-  DIBuilder *D = unwrap(Dref);
-  ArrayRef<Metadata *> elements(unwrap(Data), Length);
-  DIArray a = D->getOrCreateArray(elements);
-
-  return wrap(a);
-#else
   Metadata **DataValue = unwrap(Data);
   return wrap(
       Dref->getOrCreateArray(ArrayRef<Metadata *>(DataValue, Length)).get());
-#endif
 }

 LLVMMetadataRef
 LLVMDIBuilderCreateSubroutineType(DIBuilderRef Dref, LLVMMetadataRef File,
                                   LLVMMetadataRef ParameterTypes) {
-#if LLVM_VERSION_LE(3, 6)
-  DIBuilder *D = unwrap(Dref);
-# if LLVM_VERSION_EQ(3, 5)
-  DICompositeType CT = D->createSubroutineType(unwrapDI<DIFile>(File), unwrapDI<DIArray>(ParameterTypes));
-# else /* LLVM <= 3.6 && LLVM != 3.5 */
-  DICompositeType CT = D->createSubroutineType(unwrapDI<DIFile>(File), unwrapDI<DITypeArray>(ParameterTypes));
-# endif
-#else /* LLVM > 3.6 */
   DISubroutineType *CT = Dref->createSubroutineType(DITypeRefArray(unwrap<MDTuple>(ParameterTypes)));
-#endif /* LLVM <= 3.6 */
   return wrap(CT);
 }

@@ -229,21 +148,14 @@ LLVMMetadataRef LLVMDIBuilderCreateAutoVariable(
     DINode::DIFlags Flags,
 #endif
     uint32_t AlignInBits) {
-#if LLVM_VERSION_LE(3, 6)
-  DIBuilder *D = unwrap(Dref);
-  DIVariable V = D->createLocalVariable(
-      llvm::dwarf::DW_TAG_auto_variable, unwrapDI<DIDescriptor>(Scope), Name, unwrapDI<DIFile>(File), Line,
-      unwrapDI<DIType>(Ty), AlwaysPreserve, Flags, 0);
-#else
-# if LLVM_VERSION_LE(3, 9)
+#if LLVM_VERSION_LE(3, 9)
   DILocalVariable *V = Dref->createAutoVariable(
       unwrapDI<DIDescriptor>(Scope), Name, unwrapDI<DIFile>(File), Line,
       unwrapDI<DIType>(Ty), AlwaysPreserve, Flags);
-# else
+#else
   DILocalVariable *V = Dref->createAutoVariable(
       unwrapDI<DIDescriptor>(Scope), Name, unwrapDI<DIFile>(File), Line,
       unwrapDI<DIType>(Ty), AlwaysPreserve, Flags, AlignInBits);
-# endif
 #endif
   return wrap(V);
 }
@@ -258,18 +170,10 @@ LLVMMetadataRef LLVMDIBuilderCreateParameterVariable(
     DINode::DIFlags Flags
 #endif
     ) {
-#if LLVM_VERSION_LE(3, 6)
-  DIBuilder *D = unwrap(Dref);
-  DIVariable V = D->createLocalVariable(
-       llvm::dwarf::DW_TAG_arg_variable, unwrapDI<DIDescriptor>(Scope), Name, unwrapDI<DIFile>(File), Line,
-       unwrapDI<DIType>(Ty), AlwaysPreserve, Flags, ArgNo);
-  return wrap(V);
-#else
   DILocalVariable *V = Dref->createParameterVariable
     (unwrapDI<DIDescriptor>(Scope), Name, ArgNo, unwrapDI<DIFile>(File), Line,
      unwrapDI<DIType>(Ty), AlwaysPreserve, Flags);
   return wrap(V);
-#endif
 }

 LLVMValueRef LLVMDIBuilderInsertDeclareAtEnd(DIBuilderRef Dref,
@@ -278,46 +182,17 @@ LLVMValueRef LLVMDIBuilderInsertDeclareAtEnd(DIBuilderRef Dref,
                                              LLVMMetadataRef Expr,
                                              LLVMValueRef DL,
                                              LLVMBasicBlockRef Block) {
-#if LLVM_VERSION_EQ(3, 5)
-  DIBuilder *D = unwrap(Dref);
-  Instruction *Instr =
-    D->insertDeclare(unwrap(Storage), unwrapDI<DIVariable>(VarInfo),
-                     unwrap(Block));
-  Instr->setDebugLoc(DebugLoc::getFromDILocation(cast<MDNode>(DL)));
-#endif
-
-#if LLVM_VERSION_EQ(3, 6)
-  DIBuilder *D = unwrap(Dref);
-  Instruction *Instr =
-    D->insertDeclare(unwrap(Storage), unwrapDI<DIVariable>(VarInfo),
-                     unwrapDI<DIExpression>(Expr), unwrap(Block));
-  Instr->setDebugLoc(DebugLoc::getFromDILocation(cast<MDNode>(unwrap<MetadataAsValue>(DL)->getMetadata())));
-#endif
-
-#if LLVM_VERSION_GE(3, 7)
   Instruction *Instr =
     Dref->insertDeclare(unwrap(Storage), unwrap<DILocalVariable>(VarInfo),
                         unwrapDI<DIExpression>(Expr),
                         DebugLoc(cast<MDNode>(unwrap<MetadataAsValue>(DL)->getMetadata())),
                         unwrap(Block));
-#endif
-
   return wrap(Instr);
 }

 LLVMMetadataRef LLVMDIBuilderCreateExpression(DIBuilderRef Dref, int64_t *Addr,
                                               size_t Length) {
-#if LLVM_VERSION_LE(3, 6)
-# if LLVM_VERSION_EQ(3, 5)
-  return nullptr;
-# else /* LLVM <= 3.6 && LLVM != 3.5 */
-  DIBuilder *D = unwrap(Dref);
-  DIExpression Expr = D->createExpression(ArrayRef<int64_t>(Addr, Length));
-  return wrap(Expr);
-# endif
-#else /* LLVM > 3.6 */
   return wrap(Dref->createExpression(ArrayRef<int64_t>(Addr, Length)));
-#endif
 }

 LLVMMetadataRef LLVMDIBuilderCreateEnumerationType(
@@ -325,30 +200,16 @@ LLVMMetadataRef LLVMDIBuilderCreateEnumerationType(
     LLVMMetadataRef File, unsigned LineNumber, uint64_t SizeInBits,
     uint64_t AlignInBits, LLVMMetadataRef Elements,
     LLVMMetadataRef UnderlyingType) {
-#if LLVM_VERSION_LE(3, 6)
-  DIBuilder *D = unwrap(Dref);
-  DICompositeType enumType = D->createEnumerationType(
-      unwrapDI<DIDescriptor>(Scope), Name, unwrapDI<DIFile>(File), LineNumber,
-      SizeInBits, AlignInBits, unwrapDI<DIArray>(Elements),
-      unwrapDI<DIType>(UnderlyingType));
-#else
   DICompositeType *enumType = Dref->createEnumerationType(
       unwrapDI<DIDescriptor>(Scope), Name, unwrapDI<DIFile>(File), LineNumber,
       SizeInBits, AlignInBits, DINodeArray(unwrapDI<MDTuple>(Elements)),
       unwrapDI<DIType>(UnderlyingType));
-#endif
   return wrap(enumType);
 }

 LLVMMetadataRef LLVMDIBuilderCreateEnumerator(DIBuilderRef Dref,
                                               const char *Name, int64_t Value) {
-#if LLVM_VERSION_LE(3, 6)
-  DIBuilder *D = unwrap(Dref);
-  DIEnumerator e = D->createEnumerator(Name, Value);
-  return wrap(e);
-#else
   DIEnumerator *e = Dref->createEnumerator(Name, Value);
-#endif
   return wrap(e);
 }

@@ -367,22 +228,13 @@ LLVMDIBuilderCreateStructType(DIBuilderRef Dref,
 #endif
                               LLVMMetadataRef DerivedFrom,
                               LLVMMetadataRef Elements) {
-#if LLVM_VERSION_LE(3, 6)
-  DIBuilder *D = unwrap(Dref);
-  DICompositeType CT = D->createStructType(
-      unwrapDI<DIDescriptor>(Scope), Name, unwrapDI<DIFile>(File), Line,
-      SizeInBits, AlignInBits, Flags, unwrapDI<DIType>(DerivedFrom),
-      unwrapDI<DIArray>(Elements));
-#else
   DICompositeType *CT = Dref->createStructType(
       unwrapDI<DIDescriptor>(Scope), Name, unwrapDI<DIFile>(File), Line,
       SizeInBits, AlignInBits, Flags, unwrapDI<DIType>(DerivedFrom),
       DINodeArray(unwrapDI<MDTuple>(Elements)));
-#endif
   return wrap(CT);
 }

-#if LLVM_VERSION_GE(3, 8)
 LLVMMetadataRef
 LLVMDIBuilderCreateReplaceableCompositeType(DIBuilderRef Dref,
                                             LLVMMetadataRef Scope,
@@ -409,7 +261,6 @@ LLVMDIBuilderReplaceTemporary(DIBuilderRef Dref,
   llvm::TempMDNode fwd_decl(Node);
   Dref->replaceTemporary(std::move(fwd_decl), Type);
 }
-#endif

 LLVMMetadataRef
 LLVMDIBuilderCreateMemberType(DIBuilderRef Dref, LLVMMetadataRef Scope,
@@ -422,16 +273,9 @@ LLVMDIBuilderCreateMemberType(DIBuilderRef Dref, LLVMMetadataRef Scope,
                               DINode::DIFlags Flags,
 #endif
                               LLVMMetadataRef Ty) {
-#if LLVM_VERSION_LE(3, 6)
-  DIBuilder *D = unwrap(Dref);
-  DIDerivedType DT = D->createMemberType(
-      unwrapDI<DIDescriptor>(Scope), Name, unwrapDI<DIFile>(File), Line,
-      SizeInBits, AlignInBits, OffsetInBits, Flags, unwrapDI<DIType>(Ty));
-#else
   DIDerivedType *DT = Dref->createMemberType(
       unwrapDI<DIDescriptor>(Scope), Name, unwrapDI<DIFile>(File), Line,
       SizeInBits, AlignInBits, OffsetInBits, Flags, unwrapDI<DIType>(Ty));
-#endif
   return wrap(DT);
 }

@@ -440,39 +284,24 @@ LLVMMetadataRef LLVMDIBuilderCreatePointerType(DIBuilderRef Dref,
                                                uint64_t SizeInBits,
                                                uint64_t AlignInBits,
                                                const char *Name) {
-#if LLVM_VERSION_LE(3, 6)
-  DIBuilder *D = unwrap(Dref);
-  DIDerivedType T = D->createPointerType(unwrapDI<DIType>(PointeeType),
-                                         SizeInBits, AlignInBits, Name);
-#else
   DIDerivedType *T = Dref->createPointerType(unwrapDI<DIType>(PointeeType),
-                                             SizeInBits, AlignInBits, Name);
+                                             SizeInBits, AlignInBits,
+#if LLVM_VERSION_GE(5, 0)
+                                             None,
 #endif
+                                             Name);
   return wrap(T);
 }

 LLVMMetadataRef LLVMTemporaryMDNode(LLVMContextRef C, LLVMMetadataRef *MDs,
                                     unsigned Count) {
-#if LLVM_VERSION_LE(3, 6)
-  return wrap(MDNode::getTemporary(*unwrap(C),
-                                   ArrayRef<Metadata *>(unwrap(MDs), Count)));
-#else
   return wrap(MDTuple::getTemporary(*unwrap(C),
                                     ArrayRef<Metadata *>(unwrap(MDs), Count))
                   .release());
-#endif
 }

 void LLVMMetadataReplaceAllUsesWith(LLVMMetadataRef MD, LLVMMetadataRef New) {
-#if LLVM_VERSION_LE(3, 6)
-# if LLVM_VERSION_EQ(3, 5)
   auto *Node = unwrap<MDNode>(MD);
-# else /* LLVM <= 3.6 && LLVM != 3.5 */
-  auto *Node = unwrap<MDNodeFwdDecl>(MD);
-# endif
-#else /* LLVM > 3.6 */
-  auto *Node = unwrap<MDNode>(MD);
-#endif
   Node->replaceAllUsesWith(unwrap<MDNode>(New));
   MDNode::deleteTemporary(Node);
 }
diff --git a/src/llvm/function_pass_manager.cr b/src/llvm/function_pass_manager.cr
index 979cb9c97..834d72a20 100644
--- a/src/llvm/function_pass_manager.cr
+++ b/src/llvm/function_pass_manager.cr
@@ -2,12 +2,6 @@ class LLVM::FunctionPassManager
   def initialize(@unwrap : LibLLVM::PassManagerRef)
   end

-  {% if LibLLVM::IS_35 || LibLLVM::IS_36 %}
-    def add_target_data(target_data)
-      LibLLVM.add_target_data target_data, self
-    end
-  {% end %}
-
   def run(mod : Module)
     changed = false
     run do |runner|
diff --git a/src/llvm/lib_llvm.cr b/src/llvm/lib_llvm.cr
index e2c7a9445..5a0b67cdd 100644
--- a/src/llvm/lib_llvm.cr
+++ b/src/llvm/lib_llvm.cr
@@ -6,8 +6,6 @@ lib LibLLVM
                    (command -v llvm-config > /dev/null && (case "$(llvm-config --version)" in 3.9*) command -v llvm-config;; *) false;; esac)) || \
                    command -v llvm-config-3.8 || command -v llvm-config38 || \
                    (command -v llvm-config > /dev/null && (case "$(llvm-config --version)" in 3.8*) command -v llvm-config;; *) false;; esac)) || \
-                   command -v llvm-config-3.6 || command -v llvm-config36 || \
-                   command -v llvm-config-3.5 || command -v llvm-config35 || \
                    command -v llvm-config
                   `.chomp.stringify
                 }}
@@ -32,8 +30,6 @@ end
     IS_40 = {{LibLLVM::VERSION.starts_with?("4.0")}}
     IS_39 = {{LibLLVM::VERSION.starts_with?("3.9")}}
     IS_38 = {{LibLLVM::VERSION.starts_with?("3.8")}}
-    IS_36 = {{LibLLVM::VERSION.starts_with?("3.6")}}
-    IS_35 = {{LibLLVM::VERSION.starts_with?("3.5")}}
   end
 {% end %}

@@ -283,9 +279,7 @@ lib LibLLVM
   fun set_alignment = LLVMSetAlignment(value : ValueRef, bytes : UInt32)
   fun get_return_type = LLVMGetReturnType(TypeRef) : TypeRef

-  {% unless LibLLVM::IS_35 %}
-    fun write_bitcode_to_memory_buffer = LLVMWriteBitcodeToMemoryBuffer(mod : ModuleRef) : MemoryBufferRef
-  {% end %}
+  fun write_bitcode_to_memory_buffer = LLVMWriteBitcodeToMemoryBuffer(mod : ModuleRef) : MemoryBufferRef

   fun dispose_memory_buffer = LLVMDisposeMemoryBuffer(buf : MemoryBufferRef) : Void
   fun get_buffer_start = LLVMGetBufferStart(buf : MemoryBufferRef) : UInt8*
@@ -293,26 +287,22 @@ lib LibLLVM

   fun write_bitcode_to_fd = LLVMWriteBitcodeToFD(mod : ModuleRef, fd : LibC::Int, should_close : LibC::Int, unbuffered : LibC::Int) : LibC::Int

-  {% if LibLLVM::IS_36 || LibLLVM::IS_35 %}
-    fun add_target_data = LLVMAddTargetData(td : TargetDataRef, pm : PassManagerRef)
-  {% end %}
-
-  {% if LibLLVM::IS_38 || LibLLVM::IS_36 || LibLLVM::IS_35 %}
+  {% if LibLLVM::IS_38 %}
     fun copy_string_rep_of_target_data = LLVMCopyStringRepOfTargetData(data : TargetDataRef) : UInt8*
     fun get_target_machine_data = LLVMGetTargetMachineData(t : TargetMachineRef) : TargetDataRef
     fun set_data_layout = LLVMSetDataLayout(mod : ModuleRef, data : UInt8*)
-  {% else %}
+  {% else %} # LLVM >= 3.9
     fun create_target_data_layout = LLVMCreateTargetDataLayout(t : TargetMachineRef) : TargetDataRef
     fun set_module_data_layout = LLVMSetModuleDataLayout(mod : ModuleRef, data : TargetDataRef)
   {% end %}

-  {% if LibLLVM::IS_38 || LibLLVM::IS_36 || LibLLVM::IS_35 %}
+  {% if LibLLVM::IS_38 %}
     fun add_attribute = LLVMAddAttribute(arg : ValueRef, attr : LLVM::Attribute)
     fun add_instr_attribute = LLVMAddInstrAttribute(instr : ValueRef, index : UInt32, attr : LLVM::Attribute)
     fun add_function_attr = LLVMAddFunctionAttr(fn : ValueRef, pa : LLVM::Attribute)
     fun get_function_attr = LLVMGetFunctionAttr(fn : ValueRef) : LLVM::Attribute
     fun get_attribute = LLVMGetAttribute(arg : ValueRef) : LLVM::Attribute
-  {% else %}
+  {% else %} # LLVM >= 3.9
     type AttributeRef = Void*
     alias AttributeIndex = UInt

diff --git a/src/llvm/lib_llvm_ext.cr b/src/llvm/lib_llvm_ext.cr
index 84c65cccb..953567eb8 100644
--- a/src/llvm/lib_llvm_ext.cr
+++ b/src/llvm/lib_llvm_ext.cr
@@ -13,19 +13,11 @@ lib LibLLVMExt
   fun create_di_builder = LLVMNewDIBuilder(LibLLVM::ModuleRef) : DIBuilder
   fun di_builder_finalize = LLVMDIBuilderFinalize(DIBuilder)

-  {% if LibLLVM::IS_36 || LibLLVM::IS_35 %}
-    fun di_builder_create_function = LLVMDIBuilderCreateFunction(
-                                                                 builder : DIBuilder, scope : Metadata, name : Char*,
-                                                                 linkage_name : Char*, file : Metadata, line : UInt,
-                                                                 composite_type : Metadata, is_local_to_unit : Int, is_definition : Int,
-                                                                 scope_line : UInt, flags : LLVM::DIFlags, is_optimized : Int, func : LibLLVM::ValueRef) : Metadata
-  {% else %}
-    fun di_builder_create_function = LLVMDIBuilderCreateFunction(
-                                                                 builder : DIBuilder, scope : Metadata, name : Char*,
-                                                                 linkage_name : Char*, file : Metadata, line : UInt,
-                                                                 composite_type : Metadata, is_local_to_unit : Bool, is_definition : Bool,
-                                                                 scope_line : UInt, flags : LLVM::DIFlags, is_optimized : Bool, func : LibLLVM::ValueRef) : Metadata
-  {% end %}
+  fun di_builder_create_function = LLVMDIBuilderCreateFunction(
+                                                               builder : DIBuilder, scope : Metadata, name : Char*,
+                                                               linkage_name : Char*, file : Metadata, line : UInt,
+                                                               composite_type : Metadata, is_local_to_unit : Bool, is_definition : Bool,
+                                                               scope_line : UInt, flags : LLVM::DIFlags, is_optimized : Bool, func : LibLLVM::ValueRef) : Metadata

   fun di_builder_create_file = LLVMDIBuilderCreateFile(builder : DIBuilder, file : Char*, dir : Char*) : Metadata
   fun di_builder_create_compile_unit = LLVMDIBuilderCreateCompileUnit(builder : DIBuilder,
@@ -94,17 +86,12 @@ lib LibLLVMExt
                                                                       align_in_bits : UInt64,
                                                                       name : Char*) : Metadata

-  {% if LibLLVM::IS_35 || LibLLVM::IS_36 %}
-    fun temporary_md_node = LLVMTemporaryMDNode(context : LibLLVM::ContextRef, mds : Metadata*, count : UInt) : Metadata
-    fun metadata_replace_all_uses_with = LLVMMetadataReplaceAllUsesWith(Metadata, Metadata)
-  {% else %}
-    fun di_builder_create_replaceable_composite_type = LLVMDIBuilderCreateReplaceableCompositeType(builder : DIBuilder,
-                                                                                                   scope : Metadata,
-                                                                                                   name : Char*,
-                                                                                                                    file : Metadata,
-                                                                                                   line : UInt) : Metadata
-    fun di_builder_replace_temporary = LLVMDIBuilderReplaceTemporary(builder : DIBuilder, from : Metadata, to : Metadata)
-  {% end %}
+  fun di_builder_create_replaceable_composite_type = LLVMDIBuilderCreateReplaceableCompositeType(builder : DIBuilder,
+                                                                                                 scope : Metadata,
+                                                                                                 name : Char*,
+                                                                                                 file : Metadata,
+                                                                                                 line : UInt) : Metadata
+  fun di_builder_replace_temporary = LLVMDIBuilderReplaceTemporary(builder : DIBuilder, from : Metadata, to : Metadata)

   fun set_current_debug_location = LLVMSetCurrentDebugLocation2(LibLLVM::BuilderRef, Int, Int, Metadata, Metadata)

diff --git a/src/llvm/module.cr b/src/llvm/module.cr
index cb71e3b21..c15a56e77 100644
--- a/src/llvm/module.cr
+++ b/src/llvm/module.cr
@@ -6,7 +6,7 @@ class LLVM::Module

   getter context : Context

-  {% if LibLLVM::IS_38 || LibLLVM::IS_36 || LibLLVM::IS_35 %}
+  {% if LibLLVM::IS_38 %}
     def initialize(@unwrap : LibLLVM::ModuleRef, @name : String, @context : Context)
       @owned = false
     end
@@ -14,7 +14,7 @@ class LLVM::Module
     def name : String
       @name
     end
-  {% else %}
+  {% else %} # LLVM >= 3.9
     def initialize(@unwrap : LibLLVM::ModuleRef, @context : Context)
       @owned = false
     end
@@ -34,9 +34,9 @@ class LLVM::Module
   end

   def data_layout=(data : TargetData)
-    {% if LibLLVM::IS_38 || LibLLVM::IS_36 || LibLLVM::IS_35 %}
+    {% if LibLLVM::IS_38 %}
       LibLLVM.set_data_layout(self, data.to_data_layout_string)
-    {% else %}
+    {% else %} # LLVM >= 3.9
       LibLLVM.set_module_data_layout(self, data)
     {% end %}
   end
@@ -57,11 +57,9 @@ class LLVM::Module
     LibLLVM.write_bitcode_to_file self, filename
   end

-  {% unless LibLLVM::IS_35 %}
-    def write_bitcode_to_memory_buffer
-      MemoryBuffer.new(LibLLVM.write_bitcode_to_memory_buffer self)
-    end
-  {% end %}
+  def write_bitcode_to_memory_buffer
+    MemoryBuffer.new(LibLLVM.write_bitcode_to_memory_buffer self)
+  end

   def write_bitcode_to_fd(fd : Int, should_close = false, buffered = false)
     LibLLVM.write_bitcode_to_fd(self, fd, should_close ? 1 : 0, buffered ? 1 : 0)
diff --git a/src/llvm/module_pass_manager.cr b/src/llvm/module_pass_manager.cr
index 10bfa60bd..519227809 100644
--- a/src/llvm/module_pass_manager.cr
+++ b/src/llvm/module_pass_manager.cr
@@ -3,12 +3,6 @@ class LLVM::ModulePassManager
     @unwrap = LibLLVM.pass_manager_create
   end

-  {% if LibLLVM::IS_35 || LibLLVM::IS_36 %}
-    def add_target_data(target_data)
-      LibLLVM.add_target_data target_data, self
-    end
-  {% end %}
-
   def run(mod)
     LibLLVM.run_pass_manager(self, mod) != 0
   end
diff --git a/src/llvm/target_machine.cr b/src/llvm/target_machine.cr
index e4bb081e9..42e44abe2 100644
--- a/src/llvm/target_machine.cr
+++ b/src/llvm/target_machine.cr
@@ -9,9 +9,9 @@ class LLVM::TargetMachine

   def data_layout
     @layout ||= begin
-      layout = {% if LibLLVM::IS_38 || LibLLVM::IS_36 || LibLLVM::IS_35 %}
+      layout = {% if LibLLVM::IS_38 %}
                  LibLLVM.get_target_machine_data(self)
-               {% else %}
+               {% else %} # LLVM >= 3.9
                  LibLLVM.create_target_data_layout(self)
                {% end %}
       layout ? TargetData.new(layout) : raise "Missing layout for #{self}"
--
2.14.1