Paste: patch to attempt to use llvm intrinsics for memcpy/memmove
Author: | j |
Mode: | text |
Date: | Thu, 25 Nov 2010 09:09:00 |
Plain Text |
diff -r 232679786d1b lib-clay/operators/pod/pod.clay
--- a/lib-clay/operators/pod/pod.clay Tue Nov 23 21:21:00 2010 +0530
+++ b/lib-clay/operators/pod/pod.clay Tue Nov 23 21:46:50 2010 +0530
@@ -2,12 +2,58 @@
//
// bindings to llvm intrinsics
//
-// XXX couldn't get intrinsic calls to work, so we just bind to libc memcpy/memmove
-private external memcpy(dest: RawPointer, src: RawPointer, size: SizeT) RawPointer;
-private external memmove(dest: RawPointer, src: RawPointer, size: SizeT) RawPointer;
-[P] private inline _memcpy(dest: Pointer[P], src: Pointer[P], len: SizeT) { memcpy(RawPointer(dest), RawPointer(src), len); }
-[P] private inline _memmove(dest: Pointer[P], src: Pointer[P], len: SizeT) { memmove(RawPointer(dest), RawPointer(src), len); }
+__llvm__{
+declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i32, i1) nounwind
+declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture, i8* nocapture, i32, i32, i1) nounwind
+declare void @llvm.memmove.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i32, i1) nounwind
+declare void @llvm.memmove.p0i8.p0i8.i32(i8* nocapture, i8* nocapture, i32, i32, i1) nounwind
+}
+
+[align, volatile?]
+llvm_memcpy(dest: RawPointer, src: RawPointer, len: SizeT, static align, static volatile?)
+__llvm__ {
+ %destv = load i8** %dest
+ %srcv = load i8** %src
+ %lenv = load $SizeT* %len
+
+ call void @llvm.memcpy.p0i8.p0i8.$SizeT (i8* %destv, i8* %srcv, $SizeT %lenv, i32 $align, i1 $volatile?);
+ ret i32 0
+}
+
+[len, align, volatile?]
+overload llvm_memcpy(dest: RawPointer, src: RawPointer, static len, static align, static volatile?)
+__llvm__ {
+ %destv = load i8** %dest
+ %srcv = load i8** %src
+
+ call void @llvm.memcpy.p0i8.p0i8.$SizeT (i8* %destv, i8* %srcv, $SizeT $len, i32 $align, i1 $volatile?);
+ ret i32 0
+}
+
+[align, volatile?]
+llvm_memmove(dest: RawPointer, src: RawPointer, len: SizeT, static align, static volatile?)
+__llvm__ {
+ %destv = load i8** %dest
+ %srcv = load i8** %src
+ %lenv = load $SizeT* %len
+
+ call void @llvm.memmove.p0i8.p0i8.$SizeT (i8* %destv, i8* %srcv, $SizeT %lenv, i32 $align, i1 $volatile?);
+ ret i32 0
+}
+
+[len, align, volatile?]
+overload llvm_memmove(dest: RawPointer, src: RawPointer, static len, static align, static volatile?)
+__llvm__ {
+ %destv = load i8** %dest
+ %srcv = load i8** %src
+
+ call void @llvm.memmove.p0i8.p0i8.$SizeT (i8* %destv, i8* %srcv, $SizeT $len, i32 $align, i1 $volatile?);
+ ret i32 0
+}
+
+[P] private inline _memcpy(dest: Pointer[P], src: Pointer[P], len) { llvm_memcpy(RawPointer(dest), RawPointer(src), len, static TypeAlignment(P), static 0); }
+[P] private inline _memmove(dest: Pointer[P], src: Pointer[P], len) { memmove(RawPointer(dest), RawPointer(src), len, static TypeAlignment(P), static 0); }
//
@@ -89,7 +135,7 @@
//
[P | PODType?(P)]
-inline copyPOD(x: P) returned: P { _memcpy(&returned, &x, TypeSize(P)); }
+inline copyPOD(x: P) returned: P { _memcpy(&returned, &x, static TypeSize(P)); }
inline overload copyPOD(x: Bool) returned: Bool { primitiveCopy(returned, x); }
[N | Numeric?(N)]
inline overload copyPOD(x: N) returned: N { primitiveCopy(returned, x); }
Author: | j |
Mode: | text |
Date: | Thu, 25 Nov 2010 09:10:11 |
Plain Text |
diff -r 232679786d1b lib-clay/operators/pod/pod.clay
--- a/lib-clay/operators/pod/pod.clay Tue Nov 23 21:21:00 2010 +0530
+++ b/lib-clay/operators/pod/pod.clay Tue Nov 23 21:46:50 2010 +0530
@@ -2,12 +2,58 @@
//
// bindings to llvm intrinsics
//
-// XXX couldn't get intrinsic calls to work, so we just bind to libc memcpy/memmove
-private external memcpy(dest: RawPointer, src: RawPointer, size: SizeT) RawPointer;
-private external memmove(dest: RawPointer, src: RawPointer, size: SizeT) RawPointer;
-[P] private inline _memcpy(dest: Pointer[P], src: Pointer[P], len: SizeT) { memcpy(RawPointer(dest), RawPointer(src), len); }
-[P] private inline _memmove(dest: Pointer[P], src: Pointer[P], len: SizeT) { memmove(RawPointer(dest), RawPointer(src), len); }
+__llvm__{
+declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i32, i1) nounwind
+declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture, i8* nocapture, i32, i32, i1) nounwind
+declare void @llvm.memmove.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i32, i1) nounwind
+declare void @llvm.memmove.p0i8.p0i8.i32(i8* nocapture, i8* nocapture, i32, i32, i1) nounwind
+}
+
+[align, volatile?]
+llvm_memcpy(dest: RawPointer, src: RawPointer, len: SizeT, static align, static volatile?)
+__llvm__ {
+ %destv = load i8** %dest
+ %srcv = load i8** %src
+ %lenv = load $SizeT* %len
+
+ call void @llvm.memcpy.p0i8.p0i8.$SizeT (i8* %destv, i8* %srcv, $SizeT %lenv, i32 $align, i1 $volatile?);
+ ret i32 0
+}
+
+[len, align, volatile?]
+overload llvm_memcpy(dest: RawPointer, src: RawPointer, static len, static align, static volatile?)
+__llvm__ {
+ %destv = load i8** %dest
+ %srcv = load i8** %src
+
+ call void @llvm.memcpy.p0i8.p0i8.$SizeT (i8* %destv, i8* %srcv, $SizeT $len, i32 $align, i1 $volatile?);
+ ret i32 0
+}
+
+[align, volatile?]
+llvm_memmove(dest: RawPointer, src: RawPointer, len: SizeT, static align, static volatile?)
+__llvm__ {
+ %destv = load i8** %dest
+ %srcv = load i8** %src
+ %lenv = load $SizeT* %len
+
+ call void @llvm.memmove.p0i8.p0i8.$SizeT (i8* %destv, i8* %srcv, $SizeT %lenv, i32 $align, i1 $volatile?);
+ ret i32 0
+}
+
+[len, align, volatile?]
+overload llvm_memmove(dest: RawPointer, src: RawPointer, static len, static align, static volatile?)
+__llvm__ {
+ %destv = load i8** %dest
+ %srcv = load i8** %src
+
+ call void @llvm.memmove.p0i8.p0i8.$SizeT (i8* %destv, i8* %srcv, $SizeT $len, i32 $align, i1 $volatile?);
+ ret i32 0
+}
+
+[P] private inline _memcpy(dest: Pointer[P], src: Pointer[P], len) { llvm_memcpy(RawPointer(dest), RawPointer(src), len, static TypeAlignment(P), static 0); }
+[P] private inline _memmove(dest: Pointer[P], src: Pointer[P], len) { llvm_memmove(RawPointer(dest), RawPointer(src), len, static TypeAlignment(P), static 0); }
//
@@ -89,7 +135,7 @@
//
[P | PODType?(P)]
-inline copyPOD(x: P) returned: P { _memcpy(&returned, &x, TypeSize(P)); }
+inline copyPOD(x: P) returned: P { _memcpy(&returned, &x, static TypeSize(P)); }
inline overload copyPOD(x: Bool) returned: Bool { primitiveCopy(returned, x); }
[N | Numeric?(N)]
inline overload copyPOD(x: N) returned: N { primitiveCopy(returned, x); }
New Annotation