[llvm-commits] CVS: llvm-gcc/gcc/llvm-expand.c
Chris Lattner
lattner at cs.uiuc.edu
Tue Jul 26 15:06:15 PDT 2005
Changes in directory llvm-gcc/gcc:
llvm-expand.c updated: 1.107 -> 1.108
---
Log message:
* Fix a whole bunch of random warnings compiling this file.
* The isConstructorAllZeros part of the patch fixes PR607: http://llvm.cs.uiuc.edu/PR607 .
---
Diffs of the changes: (+48 -16)
llvm-expand.c | 64 +++++++++++++++++++++++++++++++++++++++++++---------------
1 files changed, 48 insertions(+), 16 deletions(-)
Index: llvm-gcc/gcc/llvm-expand.c
diff -u llvm-gcc/gcc/llvm-expand.c:1.107 llvm-gcc/gcc/llvm-expand.c:1.108
--- llvm-gcc/gcc/llvm-expand.c:1.107 Fri Jul 22 13:50:31 2005
+++ llvm-gcc/gcc/llvm-expand.c Tue Jul 26 17:05:49 2005
@@ -725,7 +725,7 @@
/* Debug info */
llvm_value *dbg_global_memloc;
- int LastDebugLine, LastDebugCol;
+ unsigned LastDebugLine, LastDebugCol;
llvm_basicblock *LastDebugBB;
} llvm_expand_info;
@@ -3935,9 +3935,6 @@
unsigned FieldIndexVal = llvm_constant_get_integer_val(V2C(FieldIndex));
llvm_type *FieldType = GET_STRUCT_TYPE_ELEMENT(Ty, FieldIndexVal);
unsigned FieldOffset = GetFieldOffset(field);
- assert(TREE_CODE(DECL_FIELD_OFFSET(field)) == INTEGER_CST &&
- "Can't handle structures with variable sized objects in them");
-
/*
* Attempt to get the size of the field.
@@ -3946,6 +3943,9 @@
tree FieldSizeTree = DECL_SIZE(field);
llvm_value *ElVal;
+ assert(TREE_CODE(DECL_FIELD_OFFSET(field)) == INTEGER_CST &&
+ "Can't handle structures with variable sized objects in them");
+
/*
* TODO:
* Currently, we can skip the size checking code if we don't know the
@@ -4398,9 +4398,9 @@
tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
llvm_type *FnType = llvm_type_get_from_tree(TREE_TYPE(fndecl));
llvm_type *VAListTy = GET_FUNCTION_TYPE_ARGUMENT(FnType, 0);
- llvm_type *FnTy = llvm_type_create_function(1, VoidTy);
+ llvm_type *FnTy, *Ty = llvm_type_create_function(1, VoidTy);
FnTy->Elements[1] = VAListTy;
- llvm_type *Ty = llvm_type_get_cannonical_function(FnTy);
+ Ty = llvm_type_get_cannonical_function(FnTy);
llvm_va_start_fn = CreateIntrinsicFnWithType("llvm.va_start", Ty);
}
@@ -4469,6 +4469,10 @@
static llvm_function *llvm_va_copy_fn = 0;
llvm_type *VAListType;
+ tree SrcArg;
+ llvm_value *DestAddr;
+ llvm_instruction *I;
+
if (!llvm_va_copy_fn) {
llvm_type *VACopyTy = llvm_type_get_from_tree(TREE_TYPE(fndecl));
llvm_type *VAListTyPtr = GET_FUNCTION_TYPE_ARGUMENT(VACopyTy, 0);
@@ -4479,9 +4483,9 @@
llvm_va_copy_fn = CreateIntrinsicFnWithType("llvm.va_copy", FnTy);
}
- tree SrcArg = TREE_VALUE(TREE_CHAIN(TREE_OPERAND(exp, 1)));
- llvm_value *DestAddr = llvm_expand_expr(Fn, TREE_VALUE(TREE_OPERAND(exp, 1)), 0);
- llvm_instruction *I = llvm_instruction_new(VoidTy, "", O_Call, 3);
+ SrcArg = TREE_VALUE(TREE_CHAIN(TREE_OPERAND(exp, 1)));
+ DestAddr = llvm_expand_expr(Fn, TREE_VALUE(TREE_OPERAND(exp, 1)), 0);
+ I = llvm_instruction_new(VoidTy, "", O_Call, 3);
I->Operands[0] = G2V(llvm_va_copy_fn);
I->Operands[1] = DestAddr;
I->Operands[2] = llvm_expand_lvalue_expr(Fn, SrcArg, 0, 0);
@@ -4553,7 +4557,7 @@
struct UnaryBuiltinList *Next;
};
-llvm_function *GetUnaryBuiltin(const char *Name, llvm_type *ArgTy) {
+static llvm_function *GetUnaryBuiltin(const char *Name, llvm_type *ArgTy) {
llvm_type *FnTy;
static struct UnaryBuiltinList *UnaryBuiltins = 0;
@@ -4748,11 +4752,11 @@
case BUILT_IN_SQRT:
case BUILT_IN_SQRTF:
case BUILT_IN_SQRTL:
- // If errno math has been disabled, expand these to llvm.sqrt calls.
+ /* If errno math has been disabled, expand these to llvm.sqrt calls. */
if (!flag_errno_math) {
return llvm_expand_builtin_unaryop(Fn, DestTy, arglist, "llvm.sqrt");
} else {
- // Otherwise, expand as a call to sqrt*.
+ /* Otherwise, expand as a call to sqrt*. */
return llvm_expand_call (Fn, exp, DestLoc);
}
@@ -5184,6 +5188,29 @@
return V2C(llvm_constant_new(llvm_type_get_array(ElTy, Len), Buffer));
}
+/* isConstructorAllZeros - This little hack is used to tell if a constructor
+ * is all zeros, in which case we can use zeroinitializer.
+ */
+static bool isConstructorAllZeros(tree cst) {
+ tree elt;
+ if (TREE_CODE(cst) == INTEGER_CST)
+ return (unsigned HOST_WIDE_INT)TREE_INT_CST_HIGH(cst) == 0 &&
+ (unsigned HOST_WIDE_INT)TREE_INT_CST_LOW(cst) == 0;
+ else if (TREE_CODE(cst) == REAL_CST) {
+ long RealArr[2];
+ RealArr[0] = RealArr[1] = 0;
+ REAL_VALUE_TO_TARGET_DOUBLE(TREE_REAL_CST(cst), RealArr);
+ return RealArr[0] == 0 && RealArr[1] == 0;
+ } else if (TREE_CODE(cst) != CONSTRUCTOR)
+ return 0;
+
+ for (elt = CONSTRUCTOR_ELTS(cst); elt; elt = TREE_CHAIN(elt))
+ if (TREE_VALUE(elt)) /* Ignore missing fields. */
+ if (!isConstructorAllZeros(TREE_VALUE (elt)))
+ return 0;
+ return 1;
+}
+
/* llvm_expand_constant_expr - This function is responsible for translating a
* constant tree expression into a suitable LLVM constant value. This is
* separate from other expression evaluation code because it is used to compute
@@ -5335,7 +5362,11 @@
llvm_value **Elements = llvm_expand_constructor_elements(0, 0, exp, 0);
if (Elements[0]->Ty == ReqTy)
Val = Elements[0];
- else {
+ else if (isConstructorAllZeros(exp)) {
+ /* If we can use zeroinitializer, do so. */
+ Val = llvm_constant_get_null(ReqTy);
+ } else {
+ /* Cannot expand an aggregate constructor into a scalar context. */
assert(0 && "Couldn't expand constructor in this context!");
}
} else {
@@ -6668,9 +6699,10 @@
/* If the divisor is a power of two, we can do the xform. */
if (Divisor && (Divisor & (Divisor-1)) == 0) {
+ unsigned ShAmt;
Opcode = O_Shr; /* Perform a signed SHR */
- unsigned ShAmt = 0;
+ ShAmt = 0;
for (; Divisor > 1; Divisor >>= 1)
++ShAmt;
op1 = llvm_constant_new_integral(UByteTy, ShAmt);
@@ -8111,7 +8143,7 @@
append_inst(Fn, load_dbg_inst);
append_inst(Fn, stoppoint_inst);
- store_dbg_inst = create_store_inst(stoppoint_inst,
+ store_dbg_inst = create_store_inst(D2V(stoppoint_inst),
Fn->ExpandInfo->dbg_global_memloc, 0);
append_inst(Fn, store_dbg_inst);
@@ -8137,7 +8169,7 @@
/* see above for description of the 'alloca trick':*/
- store_dbg_inst = create_store_inst(dbg_call_reg_end_inst,
+ store_dbg_inst = create_store_inst(D2V(dbg_call_reg_end_inst),
Fn->ExpandInfo->dbg_global_memloc, 0);
llvm_ilist_push_front(llvm_instruction, last_block->Instructions,
More information about the llvm-commits
mailing list