[llvm-commits] CVS: llvm-gcc/gcc/llvm-expand.c
Chris Lattner
lattner at cs.uiuc.edu
Tue Jul 6 22:35:02 PDT 2004
Changes in directory llvm-gcc/gcc:
llvm-expand.c updated: 1.47 -> 1.48
---
Log message:
Fix PR394: http://llvm.cs.uiuc.edu/PR394 . This makes the CFE emit int indices for sequential gep
instructions on 32-bit targets. While I'm at it, use uint constants instead
of ubyte constants for indexing into structure fields.
---
Diffs of the changes: (+62 -62)
Index: llvm-gcc/gcc/llvm-expand.c
diff -u llvm-gcc/gcc/llvm-expand.c:1.47 llvm-gcc/gcc/llvm-expand.c:1.48
--- llvm-gcc/gcc/llvm-expand.c:1.47 Tue Jul 6 21:22:24 2004
+++ llvm-gcc/gcc/llvm-expand.c Tue Jul 6 22:34:17 2004
@@ -181,14 +181,14 @@
llvm_instruction *GEP = llvm_instruction_new(Ty, "tmp", O_GetElementPtr,
2+Depth);
GEP->Operands[0] = V;
- GEP->Operands[1] = llvm_constant_long_0;
+ GEP->Operands[1] = llvm_constant_intptr_0;
STy = GET_POINTER_TYPE_ELEMENT(V->Ty);
for (Depth = 2; STy != DTy; STy = STy->Elements[0])
if (STy->ID == StructTyID)
- GEP->Operands[Depth++] = llvm_constant_ubyte_0;
+ GEP->Operands[Depth++] = llvm_constant_uint_0;
else
- GEP->Operands[Depth++] = llvm_constant_long_0;
+ GEP->Operands[Depth++] = llvm_constant_intptr_0;
return append_inst(Fn, GEP);
}
}
@@ -225,8 +225,8 @@
} else if (ElTy->ID == StructTyID) {
unsigned i;
for (i = 0; i != ElTy->NumElements; ++i) {
- llvm_instruction *OffsetInst = create_gep3(Dest, llvm_constant_long_0,
- llvm_constant_new_integral(UByteTy, i));
+ llvm_instruction *OffsetInst = create_gep3(Dest, llvm_constant_intptr_0,
+ llvm_constant_new_integral(UIntTy, i));
llvm_zero_initialize(Fn, append_inst(Fn, OffsetInst));
}
@@ -234,8 +234,8 @@
unsigned i;
for (i = 0; i != GET_ARRAY_TYPE_SIZE(ElTy); ++i) {
llvm_instruction *OffsetInst =
- create_gep3(Dest, llvm_constant_long_0,
- llvm_constant_new_integral(LongTy, i));
+ create_gep3(Dest, llvm_constant_intptr_0,
+ llvm_constant_new_integral(IntPtrTy, i));
llvm_zero_initialize(Fn, append_inst(Fn, OffsetInst));
}
@@ -297,8 +297,8 @@
unsigned i;
for (i = 0; i != ElTy->NumElements; ++i) {
llvm_instruction *OffsetInst =
- create_gep3(Dest, llvm_constant_long_0,
- llvm_constant_new_integral(UByteTy, i));
+ create_gep3(Dest, llvm_constant_intptr_0,
+ llvm_constant_new_integral(UIntTy, i));
llvm_get_composite_vararg(Fn, VAList, append_inst(Fn, OffsetInst));
}
@@ -306,8 +306,8 @@
unsigned i;
for (i = 0; i != GET_ARRAY_TYPE_SIZE(ElTy); ++i) {
llvm_instruction *OffsetInst =
- create_gep3(Dest, llvm_constant_long_0,
- llvm_constant_new_integral(LongTy, i));
+ create_gep3(Dest, llvm_constant_intptr_0,
+ llvm_constant_new_integral(IntPtrTy, i));
llvm_get_composite_vararg(Fn, VAList, append_inst(Fn, OffsetInst));
}
@@ -466,7 +466,7 @@
*/
if (llvm_type_get_size(ObjTy) > 128) {
EmitMemCpyMove(Fn, DestPtr, SrcPtr,
- llvm_constant_new_integral(LongTy,llvm_type_get_size(ObjTy)),
+ llvm_constant_new_integral(IntPtrTy,llvm_type_get_size(ObjTy)),
Alignment, 0);
return;
}
@@ -475,11 +475,11 @@
switch (ObjTy->ID) {
case StructTyID:
for (i = 0; i < ObjTy->NumElements; ++i) {
- llvm_value *FieldNo = llvm_constant_new_integral(UByteTy, i);
+ llvm_value *FieldNo = llvm_constant_new_integral(UIntTy, i);
llvm_value *DestElPtr = append_inst(Fn, create_gep3(DestPtr,
- llvm_constant_long_0, FieldNo));
+ llvm_constant_intptr_0, FieldNo));
llvm_value *SrcElPtr = append_inst(Fn, create_gep3(SrcPtr,
- llvm_constant_long_0, FieldNo));
+ llvm_constant_intptr_0, FieldNo));
llvm_copy_aggregate(Fn, DestElPtr, SrcElPtr,
isSourceVolatile, isDestVolatile, 1);
@@ -488,11 +488,11 @@
case ArrayTyID: {
for (i = 0; i < GET_ARRAY_TYPE_SIZE(ObjTy); ++i) {
- llvm_value *FieldNo = llvm_constant_new_integral(LongTy, i);
+ llvm_value *FieldNo = llvm_constant_new_integral(IntPtrTy, i);
llvm_value *DestElPtr = append_inst(Fn, create_gep3(DestPtr,
- llvm_constant_long_0, FieldNo));
+ llvm_constant_intptr_0, FieldNo));
llvm_value *SrcElPtr = append_inst(Fn, create_gep3(SrcPtr,
- llvm_constant_long_0, FieldNo));
+ llvm_constant_intptr_0, FieldNo));
llvm_copy_aggregate(Fn, DestElPtr, SrcElPtr,
isSourceVolatile, isDestVolatile, 1);
}
@@ -2746,8 +2746,7 @@
if (BitSize == 0) return Src; /* Not a bitfield reference */
if (BitStart+BitSize != ValSize) {
- Idx = llvm_constant_new_integral(UByteTy,
- ValSize-(BitStart+BitSize));
+ Idx = llvm_constant_new_integral(UByteTy, ValSize-(BitStart+BitSize));
Src = append_inst(Fn, create_binary_inst("tmp", O_Shl, Src, Idx));
}
@@ -2880,9 +2879,9 @@
unsigned i, e;
for (i = 0, e = llvm_type_get_composite_num_elements(ValTy); i != e; ++i) {
llvm_value *Element = llvm_constant_new_integral(ValTy->ID == StructTyID ?
- UByteTy : LongTy, i);
+ UIntTy : IntPtrTy, i);
llvm_value *Addr = append_inst(Fn, create_gep3(ArgAddr,
- llvm_constant_long_0, Element));
+ llvm_constant_intptr_0, Element));
NumArgs = PassStructureByValue(Fn, Addr, Call, CalledFuncType,
ArgOffset, NumArgs);
}
@@ -3167,10 +3166,9 @@
I = llvm_instruction_new(Op->Ty, isIncrement ? "inc" : "dec",
O_GetElementPtr, 2);
I->Operands[0] = Op;
- I->Operands[1] = llvm_constant_new_integral(LongTy, isIncrement ? 1 : -1);
+ I->Operands[1] = llvm_constant_new_integral(IntPtrTy, isIncrement ? 1 : -1);
IV = append_inst(Fn, I);
} else {
- llvm_type *IntPtrTy = llvm_type_get_size(VoidPtrTy) == 4 ? IntTy : LongTy;
llvm_value *OpTmp = cast_if_type_not_equal(Fn, Op, IntPtrTy);
llvm_value *Inc = llvm_expand_expr(Fn, TREE_OPERAND(exp, 1), 0);
@@ -3272,7 +3270,7 @@
unsigned Depth = 0;
llvm_type *CTy, *OTy;
- /*return 0; // Used to disabled addsub transformation */
+ /*return 0; // Used to disable the addsub transformation */
assert(DestTy->ID == PointerTyID && op0->Ty->ID == PointerTyID);
@@ -3293,11 +3291,13 @@
llvm_instruction *I = llvm_instruction_new(DestTy, "tmp",
O_GetElementPtr, 2);
I->Operands[0] = op0;
- I->Operands[1] = cast_if_type_not_equal(Fn, op1, LongTy);
+ I->Operands[1] = cast_if_type_not_equal(Fn, op1, IntPtrTy);
if (!isAdd) {
/* If this is a subtract, negate the index! */
+ llvm_value *Zero =
+ cast_if_type_not_equal(0, llvm_constant_uint_0, IntPtrTy);
I->Operands[1] = append_inst(Fn, create_binary_inst("tmp", O_Sub,
- llvm_constant_long_0, I->Operands[1]));
+ Zero, I->Operands[1]));
}
return append_inst(Fn, I);
@@ -3320,7 +3320,7 @@
if (!isAdd) GEPIdx *= -1;
I->Operands[0] = op0;
- I->Operands[1] = llvm_constant_new_integral(LongTy, GEPIdx);
+ I->Operands[1] = llvm_constant_new_integral(IntPtrTy, GEPIdx);
return append_inst(Fn, I);
}
}
@@ -3375,13 +3375,13 @@
1+Depth);
Depth = 0;
GEP->Operands[Depth++] = op0;
- GEP->Operands[Depth++] = llvm_constant_new_integral(LongTy, Value / Size);
+ GEP->Operands[Depth++] = llvm_constant_new_integral(IntPtrTy, Value / Size);
Value %= Size;
CTy = OTy;
while (Value && llvm_type_is_composite(CTy))
if (CTy->ID == ArrayTyID) {
unsigned ElSize = llvm_type_get_size(CTy->Elements[0]);
- GEP->Operands[Depth++]=llvm_constant_new_integral(LongTy, Value/ElSize);
+ GEP->Operands[Depth++]=llvm_constant_new_integral(IntPtrTy, Value/ElSize);
Value %= ElSize;
CTy = CTy->Elements[0];
} else {
@@ -3392,7 +3392,7 @@
assert(i < CTy->NumElements && CTy->x.Struct.MemberOffsets[i] <= Value);
Value -= CTy->x.Struct.MemberOffsets[i];
CTy = CTy->Elements[i];
- GEP->Operands[Depth++] = llvm_constant_new_integral(UByteTy, i);
+ GEP->Operands[Depth++] = llvm_constant_new_integral(UIntTy, i);
}
/* Now that the pointer has been adjusted by the appropriate amount, convert
@@ -3423,8 +3423,8 @@
--Idx;
Offset -= ElTy->x.Struct.MemberOffsets[Idx];
*ResOffset += ElTy->x.Struct.MemberOffsets[Idx];
- Ptr = append_inst(Fn, create_gep3(Ptr, llvm_constant_long_0,
- llvm_constant_new_integral(UByteTy,Idx)));
+ Ptr = append_inst(Fn, create_gep3(Ptr, llvm_constant_intptr_0,
+ llvm_constant_new_integral(UIntTy, Idx)));
return IndexIntoCompositeToByteOffset(Fn, Ptr, Offset, ResOffset);
} else if (ElTy->ID == ArrayTyID) {
llvm_type *ArrEl = GET_ARRAY_TYPE_ELEMENT(ElTy);
@@ -3433,8 +3433,8 @@
assert(Idx < ElTy->x.Array.Size && "Array idx out of range!");
Offset -= ElSize*Idx;
*ResOffset += ElSize*Idx;
- Ptr = append_inst(Fn, create_gep3(Ptr, llvm_constant_long_0,
- llvm_constant_new_integral(LongTy,Idx)));
+ Ptr = append_inst(Fn, create_gep3(Ptr, llvm_constant_intptr_0,
+ llvm_constant_new_integral(IntPtrTy, Idx)));
return IndexIntoCompositeToByteOffset(Fn, Ptr, Offset, ResOffset);
} else {
assert(0 && "Unknown composite type!");
@@ -3585,7 +3585,7 @@
*/
if (llvm_type_is_composite(ElTy) && Target) {
llvm_instruction *OffsetInst
- = create_gep3(Target, llvm_constant_long_0, IdxExpr);
+ = create_gep3(Target, llvm_constant_intptr_0, IdxExpr);
llvm_value *Offset = append_inst(Fn, OffsetInst);
@@ -3863,7 +3863,7 @@
if (Result[i] == 0) {
llvm_type *FieldType = Ty->Elements[i];
Result[i] = llvm_expand_constructor_element(Fn, target, 0, FieldType,
- llvm_constant_new_integral(UByteTy, i),
+ llvm_constant_new_integral(UIntTy, i),
isVolatile);
}
@@ -3996,7 +3996,7 @@
Result[FieldOffset] =
llvm_expand_constructor_element(Fn, target, value, FieldType,
- llvm_constant_new_integral(LongTy, FieldOffset),
+ llvm_constant_new_integral(IntPtrTy, FieldOffset),
isVolatile);
}
}
@@ -4008,7 +4008,7 @@
for (i = 0; i != Size; ++i)
if (Result[i] == 0)
Result[i] = llvm_expand_constructor_element(Fn, target, 0, FieldType,
- llvm_constant_new_integral(LongTy, i),
+ llvm_constant_new_integral(IntPtrTy, i),
isVolatile);
} else
@@ -4063,8 +4063,8 @@
/* Composite elements handled already */
if (!llvm_type_is_composite(Ty->Elements[i])) {
/* Make a getelementptr instruction that addresses the field */
- OffsetInst = create_gep3(target, llvm_constant_long_0,
- llvm_constant_new_integral(UByteTy, i));
+ OffsetInst = create_gep3(target, llvm_constant_intptr_0,
+ llvm_constant_new_integral(UIntTy, i));
Offset = append_inst(Fn, OffsetInst); /* Add it to the program */
append_inst(Fn, create_store_inst(Elements[i], Offset, isVolatile));
}
@@ -4122,8 +4122,8 @@
for (i = 0; i != Size; ++i) {
/* Make a getelementptr instruction that addresses the field */
- OffsetInst = create_gep3(target, llvm_constant_long_0,
- llvm_constant_new_integral(LongTy, i));
+ OffsetInst = create_gep3(target, llvm_constant_intptr_0,
+ llvm_constant_new_integral(IntPtrTy, i));
Offset = append_inst(Fn, OffsetInst); /* Add it to the program */
append_inst(Fn, create_store_inst(Elements[i], Offset, isVolatile));
}
@@ -4980,7 +4980,7 @@
if (llvm_type_is_integral(ReqTy))
return V2C(llvm_constant_new_integral(ReqTy, IntValue));
else if (ReqTy->ID == PointerTyID) {
- Val = llvm_constant_new_integral(LongTy, IntValue);
+ Val = llvm_constant_new_integral(IntPtrTy, IntValue);
return V2C(cast_if_type_not_equal(0, Val, ReqTy));
} else {
char Buffer[50];
@@ -5096,8 +5096,8 @@
op1 = cast_if_type_not_equal(0, op1, op0->Ty);
if (op0->Ty->ID == PointerTyID && op1->Ty->ID == PointerTyID) {
- op0 = cast_if_type_not_equal(0, op0, LongTy);
- op1 = cast_if_type_not_equal(0, op1, LongTy);
+ op0 = cast_if_type_not_equal(0, op0, IntPtrTy);
+ op1 = cast_if_type_not_equal(0, op1, IntPtrTy);
}
Inst = create_binary_inst("tmp", isPlus ? O_Add : O_Sub, op0, op1);
@@ -5272,7 +5272,7 @@
llvm_value *Op0 = llvm_expand_lvalue_expr(Fn, tOp0, 0, 0);
llvm_value *Op1 = llvm_expand_expr(Fn, tOp1, 0);
Op1 = cast_if_type_not_equal(Fn, Op1, IntPtrTy);
- Result = append_inst(Fn, create_gep3(Op0, llvm_constant_long_0, Op1));
+ Result = append_inst(Fn, create_gep3(Op0, llvm_constant_intptr_0, Op1));
} else {
llvm_instruction *I;
/* As a "special extension" we have perverted ARRAY_REF's so that they can
@@ -5348,7 +5348,7 @@
unsigned ActualSize;
llvm_value *FieldNo = DECL_LLVM(FieldDecl);
llvm_type *ResultElTy;
- I = create_gep3(Op0, llvm_constant_long_0, FieldNo);
+ I = create_gep3(Op0, llvm_constant_intptr_0, FieldNo);
Result = append_inst(Fn, I);
ResultElTy = GET_POINTER_TYPE_ELEMENT(Result->Ty);
@@ -5390,7 +5390,7 @@
llvm_instruction *GEP = llvm_instruction_new(SBPtr, "tmp",
O_GetElementPtr, 2);
GEP->Operands[0] = Ptr;
- GEP->Operands[1] = llvm_constant_new_integral(LongTy, Offset/8);
+ GEP->Operands[1] = llvm_constant_new_integral(IntPtrTy, Offset/8);
Ptr = append_inst(Fn, GEP);
}
Result = cast_if_type_not_equal(Fn, Ptr, Result->Ty);
@@ -5518,8 +5518,8 @@
/* Get the address of the complex */
Result = llvm_expand_lvalue_expr(Fn, TREE_OPERAND(exp, 0), 0, 0);
/* Get a pointer to the 0th or 1st element */
- Result = append_inst(Fn, create_gep3(Result, llvm_constant_long_0,
- llvm_constant_new_integral(UByteTy, TREE_CODE(exp) == IMAGPART_EXPR)));
+ Result = append_inst(Fn, create_gep3(Result, llvm_constant_intptr_0,
+ llvm_constant_new_integral(UIntTy, TREE_CODE(exp) == IMAGPART_EXPR)));
break;
case CONSTRUCTOR:
@@ -5639,12 +5639,12 @@
llvm_value *Real, llvm_value *Imag,
int isVolatile) {
llvm_instruction *I;
- I = create_gep3(DestLoc, llvm_constant_long_0,
- llvm_constant_new_integral(UByteTy, 0));
+ I = create_gep3(DestLoc, llvm_constant_intptr_0,
+ llvm_constant_new_integral(UIntTy, 0));
append_inst(Fn, create_store_inst(Real, append_inst(Fn, I), isVolatile));
- I = create_gep3(DestLoc, llvm_constant_long_0,
- llvm_constant_new_integral(UByteTy, 1));
+ I = create_gep3(DestLoc, llvm_constant_intptr_0,
+ llvm_constant_new_integral(UIntTy, 1));
append_inst(Fn, create_store_inst(Imag, append_inst(Fn, I), isVolatile));
}
@@ -5655,8 +5655,8 @@
llvm_value *Complex,
int ImagPart, int isVolatile) {
llvm_value *Addr =
- append_inst(Fn, create_gep3(Complex, llvm_constant_long_0,
- llvm_constant_new_integral(UByteTy, ImagPart)));
+ append_inst(Fn, create_gep3(Complex, llvm_constant_intptr_0,
+ llvm_constant_new_integral(UIntTy, ImagPart)));
return append_inst(Fn, create_load_inst("tmp", Addr, isVolatile));
}
@@ -6192,7 +6192,7 @@
case RSHIFT_EXPR: /* Shift amount -> ubyte */
op1 = cast_if_type_not_equal(Fn, op1, UByteTy);
if (op0->Ty->ID == PointerTyID)
- op0 = cast_if_type_not_equal(Fn, op0, LongTy);
+ op0 = cast_if_type_not_equal(Fn, op0, IntPtrTy);
break;
case NE_EXPR:
@@ -6227,8 +6227,8 @@
if (Opcode < O_SetEQ && (op0->Ty->ID == PointerTyID ||
op1->Ty->ID == PointerTyID)) {
/* Disallow pointer arithmetic. */
- op0 = cast_if_type_not_equal(Fn, op0, LongTy);
- op1 = cast_if_type_not_equal(Fn, op1, LongTy);
+ op0 = cast_if_type_not_equal(Fn, op0, IntPtrTy);
+ op1 = cast_if_type_not_equal(Fn, op1, IntPtrTy);
break;
}
@@ -6553,7 +6553,7 @@
*/
unsigned i, NameLen = strlen(Name);
char *SubName = (char*)xmalloc(NameLen+6); /* Should use alloca, oh well */
- llvm_type *ElIdxTy = Ty->ID == StructTyID ? UByteTy : LongTy;
+ llvm_type *ElIdxTy = Ty->ID == StructTyID ? UIntTy : IntPtrTy;
strcpy(SubName, Name);
for (i = 0; i != llvm_type_get_composite_num_elements(Ty); ++i) {
llvm_type *ElTy = llvm_type_get_composite_element(Ty, i);
@@ -6564,7 +6564,7 @@
if (Address) {
llvm_instruction *GEP = 0;
sprintf(SubName+NameLen, ".%d", i);
- GEP = create_gep3(Address, llvm_constant_long_0,
+ GEP = create_gep3(Address, llvm_constant_intptr_0,
llvm_constant_new(ElIdxTy, SubName+NameLen+1));
Offset = append_inst(Fn, GEP); /* Add the inst to the stream */
}
More information about the llvm-commits
mailing list