summaryrefslogtreecommitdiff
path: root/backend/kernels
diff options
context:
space:
mode:
authorBenjamin Segovia <segovia.benjamin@gmail.com>2012-02-29 18:09:08 +0000
committerKeith Packard <keithp@keithp.com>2012-08-10 16:15:30 -0700
commited6ae6a4408e2faa1349f105cd4967737e693de2 (patch)
tree01ae6f584e99999dfd9846045f22deba1d8f90b0 /backend/kernels
parent9564e88c263551304ab037f2ef489ae215eae463 (diff)
downloadbeignet-ed6ae6a4408e2faa1349f105cd4967737e693de2.tar.gz
Finished a first very very limited LLVM to Gen-IR translation. It should be just enough to write a first very simple kernel
Diffstat (limited to 'backend/kernels')
-rw-r--r--backend/kernels/load_store.cbe.c161
-rw-r--r--backend/kernels/load_store.cl5
-rw-r--r--backend/kernels/load_store.ll17
-rw-r--r--backend/kernels/load_store.obin0 -> 508 bytes
4 files changed, 183 insertions, 0 deletions
diff --git a/backend/kernels/load_store.cbe.c b/backend/kernels/load_store.cbe.c
new file mode 100644
index 00000000..18768f93
--- /dev/null
+++ b/backend/kernels/load_store.cbe.c
@@ -0,0 +1,161 @@
+/*
+ * Copyright © 2012 Intel Corporation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Benjamin Segovia <benjamin.segovia@intel.com>
+ */
+
+/* Provide Declarations */
+#include <stdarg.h>
+#include <setjmp.h>
+#include <limits.h>
+/* get a declaration for alloca */
+#if defined(__CYGWIN__) || defined(__MINGW32__)
+#define alloca(x) __builtin_alloca((x))
+#define _alloca(x) __builtin_alloca((x))
+#elif defined(__APPLE__)
+extern void *__builtin_alloca(unsigned long);
+#define alloca(x) __builtin_alloca(x)
+#define longjmp _longjmp
+#define setjmp _setjmp
+#elif defined(__sun__)
+#if defined(__sparcv9)
+extern void *__builtin_alloca(unsigned long);
+#else
+extern void *__builtin_alloca(unsigned int);
+#endif
+#define alloca(x) __builtin_alloca(x)
+#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(__arm__)
+#define alloca(x) __builtin_alloca(x)
+#elif defined(_MSC_VER)
+#define inline _inline
+#define alloca(x) _alloca(x)
+#else
+#include <alloca.h>
+#endif
+
+#ifndef __GNUC__ /* Can only support "linkonce" vars with GCC */
+#define __attribute__(X)
+#endif
+
+#if defined(__GNUC__) && defined(__APPLE_CC__)
+#define __EXTERNAL_WEAK__ __attribute__((weak_import))
+#elif defined(__GNUC__)
+#define __EXTERNAL_WEAK__ __attribute__((weak))
+#else
+#define __EXTERNAL_WEAK__
+#endif
+
+#if defined(__GNUC__) && defined(__APPLE_CC__)
+#define __ATTRIBUTE_WEAK__
+#elif defined(__GNUC__)
+#define __ATTRIBUTE_WEAK__ __attribute__((weak))
+#else
+#define __ATTRIBUTE_WEAK__
+#endif
+
+#if defined(__GNUC__)
+#define __HIDDEN__ __attribute__((visibility("hidden")))
+#endif
+
+#ifdef __GNUC__
+#define LLVM_NAN(NanStr) __builtin_nan(NanStr) /* Double */
+#define LLVM_NANF(NanStr) __builtin_nanf(NanStr) /* Float */
+#define LLVM_NANS(NanStr) __builtin_nans(NanStr) /* Double */
+#define LLVM_NANSF(NanStr) __builtin_nansf(NanStr) /* Float */
+#define LLVM_INF __builtin_inf() /* Double */
+#define LLVM_INFF __builtin_inff() /* Float */
+#define LLVM_PREFETCH(addr,rw,locality) __builtin_prefetch(addr,rw,locality)
+#define __ATTRIBUTE_CTOR__ __attribute__((constructor))
+#define __ATTRIBUTE_DTOR__ __attribute__((destructor))
+#define LLVM_ASM __asm__
+#else
+#define LLVM_NAN(NanStr) ((double)0.0) /* Double */
+#define LLVM_NANF(NanStr) 0.0F /* Float */
+#define LLVM_NANS(NanStr) ((double)0.0) /* Double */
+#define LLVM_NANSF(NanStr) 0.0F /* Float */
+#define LLVM_INF ((double)0.0) /* Double */
+#define LLVM_INFF 0.0F /* Float */
+#define LLVM_PREFETCH(addr,rw,locality) /* PREFETCH */
+#define __ATTRIBUTE_CTOR__
+#define __ATTRIBUTE_DTOR__
+#define LLVM_ASM(X)
+#endif
+
+#if __GNUC__ < 4 /* Old GCC's, or compilers not GCC */
+#define __builtin_stack_save() 0 /* not implemented */
+#define __builtin_stack_restore(X) /* noop */
+#endif
+
+#if __GNUC__ && __LP64__ /* 128-bit integer types */
+typedef int __attribute__((mode(TI))) llvmInt128;
+typedef unsigned __attribute__((mode(TI))) llvmUInt128;
+#endif
+
+#define CODE_FOR_MAIN() /* Any target-specific code for main()*/
+
+#ifndef __cplusplus
+typedef unsigned char bool;
+#endif
+
+
+/* Support for floating point constants */
+typedef unsigned long long ConstantDoubleTy;
+typedef unsigned int ConstantFloatTy;
+typedef struct { unsigned long long f1; unsigned short f2; unsigned short pad[3]; } ConstantFP80Ty;
+typedef struct { unsigned long long f1; unsigned long long f2; } ConstantFP128Ty;
+
+
+/* Global Declarations */
+/* Helper union for bitcasts */
+typedef union {
+ unsigned int Int32;
+ unsigned long long Int64;
+ float Float;
+ double Double;
+} llvmBitCastUnion;
+
+/* Function Declarations */
+double fmod(double, double);
+float fmodf(float, float);
+long double fmodl(long double, long double);
+void load_store(unsigned int *llvm_cbe_dst, unsigned int *llvm_cbe_src);
+void abort(void);
+
+
+/* Function Bodies */
+static inline int llvm_fcmp_ord(double X, double Y) { return X == X && Y == Y; }
+static inline int llvm_fcmp_uno(double X, double Y) { return X != X || Y != Y; }
+static inline int llvm_fcmp_ueq(double X, double Y) { return X == Y || llvm_fcmp_uno(X, Y); }
+static inline int llvm_fcmp_une(double X, double Y) { return X != Y; }
+static inline int llvm_fcmp_ult(double X, double Y) { return X < Y || llvm_fcmp_uno(X, Y); }
+static inline int llvm_fcmp_ugt(double X, double Y) { return X > Y || llvm_fcmp_uno(X, Y); }
+static inline int llvm_fcmp_ule(double X, double Y) { return X <= Y || llvm_fcmp_uno(X, Y); }
+static inline int llvm_fcmp_uge(double X, double Y) { return X >= Y || llvm_fcmp_uno(X, Y); }
+static inline int llvm_fcmp_oeq(double X, double Y) { return X == Y ; }
+static inline int llvm_fcmp_one(double X, double Y) { return X != Y && llvm_fcmp_ord(X, Y); }
+static inline int llvm_fcmp_olt(double X, double Y) { return X < Y ; }
+static inline int llvm_fcmp_ogt(double X, double Y) { return X > Y ; }
+static inline int llvm_fcmp_ole(double X, double Y) { return X <= Y ; }
+static inline int llvm_fcmp_oge(double X, double Y) { return X >= Y ; }
+
+void load_store(unsigned int *llvm_cbe_dst, unsigned int *llvm_cbe_src) {
+ unsigned int llvm_cbe_tmp__1;
+
+ llvm_cbe_tmp__1 = *llvm_cbe_src;
+ *llvm_cbe_dst = llvm_cbe_tmp__1;
+ return;
+}
+
diff --git a/backend/kernels/load_store.cl b/backend/kernels/load_store.cl
new file mode 100644
index 00000000..f88e4ccb
--- /dev/null
+++ b/backend/kernels/load_store.cl
@@ -0,0 +1,5 @@
+__kernel void load_store(__local int *dst, __local int *src)
+{
+ dst[0] = src[0];
+}
+
diff --git a/backend/kernels/load_store.ll b/backend/kernels/load_store.ll
new file mode 100644
index 00000000..53296872
--- /dev/null
+++ b/backend/kernels/load_store.ll
@@ -0,0 +1,17 @@
+; ModuleID = 'load_store.o'
+target datalayout = "e-p:32:32-i64:64:64-f64:64:64-n1:8:16:32:64"
+target triple = "ptx32--"
+
+define ptx_kernel void @load_store(i32 addrspace(4)* nocapture %dst, i32 addrspace(4)* nocapture %src) nounwind noinline {
+entry:
+ %0 = load i32 addrspace(4)* %src, align 4, !tbaa !1
+ store i32 %0, i32 addrspace(4)* %dst, align 4, !tbaa !1
+ ret void
+}
+
+!opencl.kernels = !{!0}
+
+!0 = metadata !{void (i32 addrspace(4)*, i32 addrspace(4)*)* @load_store}
+!1 = metadata !{metadata !"int", metadata !2}
+!2 = metadata !{metadata !"omnipotent char", metadata !3}
+!3 = metadata !{metadata !"Simple C/C++ TBAA", null}
diff --git a/backend/kernels/load_store.o b/backend/kernels/load_store.o
new file mode 100644
index 00000000..1ac59885
--- /dev/null
+++ b/backend/kernels/load_store.o
Binary files differ