[llvm-commits] CVS: llvm-gcc/gcc/llvm-expand.c
Chris Lattner
lattner at cs.uiuc.edu
Thu Mar 10 22:12:43 PST 2005
Changes in directory llvm-gcc/gcc:
llvm-expand.c updated: 1.89 -> 1.90
---
Log message:
Correctly transform __builtin_prefetch into llvm.prefetch.
---
Diffs of the changes: (+66 -4)
llvm-expand.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++----
1 files changed, 66 insertions(+), 4 deletions(-)
Index: llvm-gcc/gcc/llvm-expand.c
diff -u llvm-gcc/gcc/llvm-expand.c:1.89 llvm-gcc/gcc/llvm-expand.c:1.90
--- llvm-gcc/gcc/llvm-expand.c:1.89 Sun Feb 27 13:28:51 2005
+++ llvm-gcc/gcc/llvm-expand.c Fri Mar 11 00:12:27 2005
@@ -4525,6 +4525,70 @@
return D2V(TheCall);
}
+static void llvm_expand_builtin_prefetch(llvm_function *Fn, tree arglist) {
+ llvm_value *Ptr;
+ llvm_value *arg1 = llvm_constant_uint_0, *arg2 = llvm_constant_uint_0;
+ static llvm_function *llvm_prefetch = 0;
+ llvm_instruction *Call;
+
+ if (llvm_prefetch == 0) {
+ llvm_type *FnTy = llvm_type_create_function(3, VoidTy);
+ FnTy->Elements[1] = VoidPtrTy;
+ FnTy->Elements[2] = UIntTy;
+ FnTy->Elements[3] = UIntTy;
+ FnTy = llvm_type_get_cannonical_function(FnTy);
+ llvm_prefetch = CreateIntrinsicFnWithType("llvm.prefetch", FnTy);
+ }
+
+ arglist = TREE_OPERAND(arglist, 1);
+
+ /* Check and expand the pointer argument. */
+ if (TREE_CODE(TREE_TYPE(TREE_VALUE(arglist))) != POINTER_TYPE) {
+ error("invalid first argument to `__builtin_prefetch'");
+ return;
+ }
+ Ptr = llvm_expand_expr(Fn, TREE_VALUE(arglist), 0);
+ Ptr = cast_if_type_not_equal(Fn, Ptr, VoidPtrTy);
+
+ /* Arguments 1 and 2 are optional; argument 1 (read/write) defaults to zero
+ * (read) and argument 2 (locality) defaults to 3 (high degree of locality).
+ */
+ arglist = TREE_CHAIN(arglist);
+ if (arglist) {
+ tree tmp = TREE_VALUE(arglist);
+ if (TREE_CODE(tmp) != INTEGER_CST) {
+ error ("second arg to `__builtin_prefetch' must be a constant");
+ return;
+ } else if ((unsigned)TREE_INT_CST_LOW(tmp) > 1) {
+ /* Argument 1 must be either zero or one. */
+ warning("invalid second arg to __builtin_prefetch; using zero");
+ } else {
+ arg1 = llvm_expand_expr(Fn, tmp, 0);
+ arg1 = cast_if_type_not_equal(Fn, arg1, UIntTy);
+ }
+ arglist = TREE_CHAIN(arglist);
+ if (arglist) {
+ tmp = TREE_VALUE(arglist);
+ if (TREE_CODE(tmp) != INTEGER_CST) {
+ error ("third arg to `__builtin_prefetch' must be a constant");
+ return;
+ } else if ((unsigned)TREE_INT_CST_LOW(tmp) > 3) {
+ /* Argument 2 must be 0, 1, 2, or 3. */
+ warning ("invalid third arg to __builtin_prefetch; using zero");
+ } else {
+ arg2 = llvm_expand_expr(Fn, tmp, 0);
+ arg2 = cast_if_type_not_equal(Fn, arg2, UIntTy);
+ }
+ }
+ }
+
+ Call = llvm_instruction_new(VoidTy, "", O_Call, 4);
+ Call->Operands[0] = G2V(llvm_prefetch);
+ Call->Operands[1] = Ptr;
+ Call->Operands[2] = arg1;
+ Call->Operands[3] = arg2;
+ append_inst(Fn, Call);
+}
/* llvm_expand_builtin - This is patterned off of expand_builtin. */
static llvm_value *llvm_expand_builtin(llvm_function *Fn, tree exp,
@@ -4995,11 +5059,9 @@
if (arglist == NULL_TREE || TREE_CHAIN (arglist) == NULL_TREE)
return 0;
return llvm_expand_expr(Fn, TREE_VALUE (arglist), DestLoc);
-#if 0
case BUILT_IN_PREFETCH:
- expand_builtin_prefetch (arglist);
- return const0_rtx;
-#endif
+ llvm_expand_builtin_prefetch(Fn, exp);
+ return 0;
default: /* just do library call, if unknown builtin */
if (!DECL_ASSEMBLER_NAME_SET_P (fndecl))
error ("built-in function `%s' not currently supported",
More information about the llvm-commits
mailing list