[llvm-commits] CVS: gcc-3.4/gcc/llvm-representation.c
Chris Lattner
lattner at cs.uiuc.edu
Sat Feb 14 20:20:01 PST 2004
Changes in directory gcc-3.4/gcc:
llvm-representation.c updated: 1.1 -> 1.2
---
Log message:
Implement PR205: [llvmgcc] C front-end does not emit 'zeroinitializer' when possible
---
Diffs of the changes: (+27 -0)
Index: gcc-3.4/gcc/llvm-representation.c
diff -u gcc-3.4/gcc/llvm-representation.c:1.1 gcc-3.4/gcc/llvm-representation.c:1.2
--- gcc-3.4/gcc/llvm-representation.c:1.1 Thu Jan 8 16:35:32 2004
+++ gcc-3.4/gcc/llvm-representation.c Sat Feb 14 20:19:44 2004
@@ -442,11 +442,38 @@
llvm_constant_aggregate_print(CA, stderr);
}
+static int isNullConstant(llvm_value *V) {
+ switch (V->VTy) {
+ case ConstantAggregate: {
+ llvm_constant_aggregate *CA = (llvm_constant_aggregate*)V;
+ unsigned i, e;
+ if (V->Ty->ID == StructTyID) {
+ e = V->Ty->NumElements;
+ } else {
+ assert(V->Ty->ID == ArrayTyID && "Invalid aggregate type!");
+ e = V->Ty->x.Array.Size;
+ }
+ for (i = 0; i != e; ++i)
+ if (!isNullConstant(CA->Initializers[i])) return 0;
+ return 1;
+ }
+ default: return 0;
+ case Constant:
+ return !strcmp("0", V2C(V)->Repr);
+ }
+}
+
void llvm_constant_aggregate_print(llvm_constant_aggregate *CE, FILE *F) {
unsigned i;
llvm_type *Ty = G2V(CE)->Ty;
llvm_value **Elements = CE->Initializers;
+
+ if (isNullConstant((llvm_value*)CE)) {
+ fprintf(F, "zeroinitializer");
+ return;
+ }
+
if (Ty->ID == StructTyID) {
fprintf(F, "{ ");
for (i = 0; i != Ty->NumElements; ++i) {
More information about the llvm-commits
mailing list