[Beignet] [PATCH 15/18] Add the barrier functions by add barrier.ll

junyan.he at inbox.com junyan.he at inbox.com
Tue Aug 12 00:32:51 PDT 2014


From: Junyan He <junyan.he at linux.intel.com>

Signed-off-by: Junyan He <junyan.he at linux.intel.com>
---
 backend/src/libocl/Makefile.in        |  5 ++++-
 backend/src/libocl/lib/ocl_barrier.ll | 39 +++++++++++++++++++++++++++++++++++
 2 files changed, 43 insertions(+), 1 deletion(-)
 create mode 100644 backend/src/libocl/lib/ocl_barrier.ll

diff --git a/backend/src/libocl/Makefile.in b/backend/src/libocl/Makefile.in
index 93d4c2b..2b9de51 100644
--- a/backend/src/libocl/Makefile.in
+++ b/backend/src/libocl/Makefile.in
@@ -8,7 +8,7 @@ GENERATED_HEADERS=ocl_defines.h ocl_as.h ocl_convert.h ocl_common.h ocl_relation
 GENERATED_CL_SRCS=$(addprefix lib/, $(GENERATED_FILES))
 GENERATED_CL_HEADERS=$(addprefix include/, $(GENERATED_HEADERS))
 CL_FILE_NAMES=ocl_workitem.cl ocl_atom.cl ocl_async.cl ocl_sync.cl ocl_misc.cl ocl_vload.cl ocl_geometric.cl ocl_image.cl $(GENERATED_FILES)
-LL_FILE_NAMES=
+LL_FILE_NAMES=ocl_barrier.ll
 CL_SRCS=$(addprefix lib/, $(CL_FILE_NAMES))
 LL_SRCS=$(addprefix lib/, $(LL_FILE_NAMES))
 CL_BITCODES=$(patsubst %.cl, %.bc, $(CL_SRCS))
@@ -45,6 +45,9 @@ include/ocl_defines.h:include/ocl_defines.inh
 	@cat $< > $@
 	@cat ../ocl_common_defines.h >> $@
 
+%.bc:%.ll
+	llvm-as -o $@ $<
+
 %.h:%.inh
 	@echo "Generate the header:  $@"
 	@rm -f $@
diff --git a/backend/src/libocl/lib/ocl_barrier.ll b/backend/src/libocl/lib/ocl_barrier.ll
new file mode 100644
index 0000000..4e55fcb
--- /dev/null
+++ b/backend/src/libocl/lib/ocl_barrier.ll
@@ -0,0 +1,39 @@
+;XXX FIXME as llvm can't use macros, we hardcoded 3, 1, 2
+;here, we may need to use a more grace way to handle this type
+;of values latter.
+;#define CLK_LOCAL_MEM_FENCE  (1 << 0)
+;#define CLK_GLOBAL_MEM_FENCE (1 << 1)
+
+declare i32 @_get_local_mem_fence() nounwind alwaysinline
+declare i32 @_get_global_mem_fence() nounwind alwaysinline
+declare void @__gen_ocl_barrier_local() nounwind alwaysinline noduplicate
+declare void @__gen_ocl_barrier_global() nounwind alwaysinline noduplicate
+declare void @__gen_ocl_barrier_local_and_global() nounwind alwaysinline noduplicate
+
+define void @barrier(i32 %flags) nounwind noduplicate alwaysinline {
+  %1 = icmp eq i32 %flags, 3
+  br i1 %1, label %barrier_local_global, label %barrier_local_check
+
+barrier_local_global:
+  call void @__gen_ocl_barrier_local_and_global()
+  br label %done
+
+barrier_local_check:
+  %2 = icmp eq i32 %flags, 1
+  br i1 %2, label %barrier_local, label %barrier_global_check
+
+barrier_local:
+  call void @__gen_ocl_barrier_local()
+  br label %done
+
+barrier_global_check:
+  %3 = icmp eq i32 %flags, 2
+  br i1 %3, label %barrier_global, label %done
+
+barrier_global:
+  call void @__gen_ocl_barrier_global()
+  br label %done
+
+done:
+  ret void
+}
-- 
1.8.3.2



More information about the Beignet mailing list