[Libclc-dev] [PATCH 1/5] Restore support for llvm-3.9

Jan Vesely via Libclc-dev libclc-dev at lists.llvm.org
Wed Sep 20 21:06:52 PDT 2017


Signed-off-by: Jan Vesely <jan.vesely at rutgers.edu>
---
I haven't bothered fixing amdgcn-amdhsa beyond successful build,
it produces invalid calls to workitem postiion similar to bug #99856.

Please do consider this. there are still plenty of people running
llvm-3.9.

Jan

 amdgcn-amdhsa/lib/OVERRIDES               |  3 +++
 amdgcn/lib/OVERRIDES_3.9                  |  3 +++
 amdgcn/lib/SOURCES_3.9                    |  3 +++
 amdgcn/lib/workitem/get_global_size.39.ll | 18 ++++++++++++++++++
 amdgcn/lib/workitem/get_local_size.39.ll  | 18 ++++++++++++++++++
 amdgcn/lib/workitem/get_num_groups.39.ll  | 18 ++++++++++++++++++
 amdgpu/lib/SOURCES_3.9                    |  2 ++
 configure.py                              | 22 +++++++++++++++++-----
 utils/prepare-builtins.cpp                |  9 +++++++++
 9 files changed, 91 insertions(+), 5 deletions(-)
 create mode 100644 amdgcn/lib/OVERRIDES_3.9
 create mode 100644 amdgcn/lib/SOURCES_3.9
 create mode 100644 amdgcn/lib/workitem/get_global_size.39.ll
 create mode 100644 amdgcn/lib/workitem/get_local_size.39.ll
 create mode 100644 amdgcn/lib/workitem/get_num_groups.39.ll
 create mode 100644 amdgpu/lib/SOURCES_3.9

diff --git a/amdgcn-amdhsa/lib/OVERRIDES b/amdgcn-amdhsa/lib/OVERRIDES
index c9bd69b..e4dfca1 100644
--- a/amdgcn-amdhsa/lib/OVERRIDES
+++ b/amdgcn-amdhsa/lib/OVERRIDES
@@ -1 +1,4 @@
 workitem/get_num_groups.ll
+workitem/get_global_size.39.ll
+workitem/get_local_size.39.ll
+workitem/get_num_groups.39.ll
diff --git a/amdgcn/lib/OVERRIDES_3.9 b/amdgcn/lib/OVERRIDES_3.9
new file mode 100644
index 0000000..f26fbbe
--- /dev/null
+++ b/amdgcn/lib/OVERRIDES_3.9
@@ -0,0 +1,3 @@
+workitem/get_global_size.ll
+workitem/get_local_size.ll
+workitem/get_num_groups.ll
diff --git a/amdgcn/lib/SOURCES_3.9 b/amdgcn/lib/SOURCES_3.9
new file mode 100644
index 0000000..6ee7cb8
--- /dev/null
+++ b/amdgcn/lib/SOURCES_3.9
@@ -0,0 +1,3 @@
+workitem/get_global_size.39.ll
+workitem/get_local_size.39.ll
+workitem/get_num_groups.39.ll
diff --git a/amdgcn/lib/workitem/get_global_size.39.ll b/amdgcn/lib/workitem/get_global_size.39.ll
new file mode 100644
index 0000000..d51def3
--- /dev/null
+++ b/amdgcn/lib/workitem/get_global_size.39.ll
@@ -0,0 +1,18 @@
+declare i32 @llvm.r600.read.global.size.x() nounwind readnone
+declare i32 @llvm.r600.read.global.size.y() nounwind readnone
+declare i32 @llvm.r600.read.global.size.z() nounwind readnone
+
+define i32 @get_global_size(i32 %dim) nounwind readnone alwaysinline {
+  switch i32 %dim, label %default [i32 0, label %x_dim i32 1, label %y_dim i32 2, label %z_dim]
+x_dim:
+  %x = call i32 @llvm.r600.read.global.size.x()
+  ret i32 %x
+y_dim:
+  %y = call i32 @llvm.r600.read.global.size.y()
+  ret i32 %y
+z_dim:
+  %z = call i32 @llvm.r600.read.global.size.z()
+  ret i32 %z
+default:
+  ret i32 1
+}
diff --git a/amdgcn/lib/workitem/get_local_size.39.ll b/amdgcn/lib/workitem/get_local_size.39.ll
new file mode 100644
index 0000000..92c6d26
--- /dev/null
+++ b/amdgcn/lib/workitem/get_local_size.39.ll
@@ -0,0 +1,18 @@
+declare i32 @llvm.r600.read.local.size.x() nounwind readnone
+declare i32 @llvm.r600.read.local.size.y() nounwind readnone
+declare i32 @llvm.r600.read.local.size.z() nounwind readnone
+
+define i32 @get_local_size(i32 %dim) nounwind readnone alwaysinline {
+  switch i32 %dim, label %default [i32 0, label %x_dim i32 1, label %y_dim i32 2, label %z_dim]
+x_dim:
+  %x = call i32 @llvm.r600.read.local.size.x()
+  ret i32 %x
+y_dim:
+  %y = call i32 @llvm.r600.read.local.size.y()
+  ret i32 %y
+z_dim:
+  %z = call i32 @llvm.r600.read.local.size.z()
+  ret i32 %z
+default:
+  ret i32 1
+}
diff --git a/amdgcn/lib/workitem/get_num_groups.39.ll b/amdgcn/lib/workitem/get_num_groups.39.ll
new file mode 100644
index 0000000..fd5c17c
--- /dev/null
+++ b/amdgcn/lib/workitem/get_num_groups.39.ll
@@ -0,0 +1,18 @@
+declare i32 @llvm.r600.read.ngroups.x() nounwind readnone
+declare i32 @llvm.r600.read.ngroups.y() nounwind readnone
+declare i32 @llvm.r600.read.ngroups.z() nounwind readnone
+
+define i32 @get_num_groups(i32 %dim) nounwind readnone alwaysinline {
+  switch i32 %dim, label %default [i32 0, label %x_dim i32 1, label %y_dim i32 2, label %z_dim]
+x_dim:
+  %x = call i32 @llvm.r600.read.ngroups.x()
+  ret i32 %x
+y_dim:
+  %y = call i32 @llvm.r600.read.ngroups.y()
+  ret i32 %y
+z_dim:
+  %z = call i32 @llvm.r600.read.ngroups.z()
+  ret i32 %z
+default:
+  ret i32 1
+}
diff --git a/amdgpu/lib/SOURCES_3.9 b/amdgpu/lib/SOURCES_3.9
new file mode 100644
index 0000000..69c5e5c
--- /dev/null
+++ b/amdgpu/lib/SOURCES_3.9
@@ -0,0 +1,2 @@
+shared/vload_half_helpers.ll
+shared/vstore_half_helpers.ll
diff --git a/configure.py b/configure.py
index cc4c84b..bcdc6d0 100755
--- a/configure.py
+++ b/configure.py
@@ -72,8 +72,8 @@ llvm_version = llvm_config(['--version']).replace('svn', '').split('.')
 llvm_int_version = int(llvm_version[0]) * 100 + int(llvm_version[1]) * 10
 llvm_string_version = llvm_version[0] + '.' + llvm_version[1]
 
-if llvm_int_version < 400:
-    print("libclc requires LLVM >= 4.0")
+if llvm_int_version < 390:
+    print("libclc requires LLVM >= 3.9")
     sys.exit(1)
 
 llvm_system_libs = llvm_config(['--system-libs'])
@@ -81,7 +81,7 @@ llvm_bindir = llvm_config(['--bindir'])
 llvm_core_libs = llvm_config(['--libs', 'core', 'bitreader', 'bitwriter']) + ' ' + \
                  llvm_system_libs + ' ' + \
                  llvm_config(['--ldflags'])
-llvm_cxxflags = llvm_config(['--cxxflags']) + ' -fno-exceptions -fno-rtti'
+llvm_cxxflags = llvm_config(['--cxxflags']) + ' -fno-exceptions -fno-rtti -DHAVE_LLVM=0x' + str(llvm_int_version)
 llvm_libdir = llvm_config(['--libdir'])
 
 llvm_clang = os.path.join(llvm_bindir, 'clang')
@@ -108,9 +108,13 @@ available_targets = {
   'nvptx64--nvidiacl' : { 'devices' : [{'gpu' : '', 'aliases' : []} ]},
 }
 
-available_targets['amdgcn-mesa-mesa3d'] = available_targets['amdgcn--']
 
-default_targets = ['nvptx--nvidiacl', 'nvptx64--nvidiacl', 'r600--', 'amdgcn--', 'amdgcn--amdhsa', 'amdgcn-mesa-mesa3d']
+default_targets = ['nvptx--nvidiacl', 'nvptx64--nvidiacl', 'r600--', 'amdgcn--', 'amdgcn--amdhsa']
+
+#mesa is using amdgcn-mesa-mesa3d since llvm-4.0
+if llvm_int_version > 390:
+    available_targets['amdgcn-mesa-mesa3d'] = available_targets['amdgcn--']
+    default_targets.append('amdgcn-mesa-mesa3d')
 
 targets = args
 if not targets:
@@ -217,6 +221,8 @@ for target in targets:
       override_list_file = os.path.join(libdir, 'OVERRIDES')
       compat_list_file = os.path.join(libdir,
         'SOURCES_' + llvm_string_version)
+      compat_list_override = os.path.join(libdir,
+        'OVERRIDES_' + llvm_string_version)
 
       # Build compat list
       if os.path.exists(compat_list_file):
@@ -224,6 +230,12 @@ for target in targets:
           compat = compat.rstrip()
           compats.append(compat)
 
+      # Add target compat overrides
+      if os.path.exists(compat_list_override):
+        for override in open(compat_list_override).readlines():
+          override = override.rstrip()
+          sources_seen.add(override)
+
       # Add target overrides
       if os.path.exists(override_list_file):
         for override in open(override_list_file).readlines():
diff --git a/utils/prepare-builtins.cpp b/utils/prepare-builtins.cpp
index 882dadd..8022e85 100644
--- a/utils/prepare-builtins.cpp
+++ b/utils/prepare-builtins.cpp
@@ -1,5 +1,10 @@
+#if HAVE_LLVM > 0x0390
 #include "llvm/Bitcode/BitcodeReader.h"
 #include "llvm/Bitcode/BitcodeWriter.h"
+#else
+#include "llvm/Bitcode/ReaderWriter.h"
+#endif
+
 #include "llvm/IR/Function.h"
 #include "llvm/IR/GlobalVariable.h"
 #include "llvm/IR/LLVMContext.h"
@@ -41,8 +46,12 @@ int main(int argc, char **argv) {
     } else {
       std::unique_ptr<MemoryBuffer> &BufferPtr = BufferOrErr.get();
       ErrorOr<std::unique_ptr<Module>> ModuleOrErr =
+#if HAVE_LLVM > 0x0390
           expectedToErrorOrAndEmitErrors(Context,
           parseBitcodeFile(BufferPtr.get()->getMemBufferRef(), Context));
+#else
+          parseBitcodeFile(BufferPtr.get()->getMemBufferRef(), Context);
+#endif
       if (std::error_code ec = ModuleOrErr.getError())
         ErrorMessage = ec.message();
 
-- 
2.13.5



More information about the Libclc-dev mailing list