[llvm-commits] [llvm-gcc-4.0] r40686 - in /llvm-gcc-4.0/trunk/gcc: llvm-convert.cpp llvm-internal.h tree.c
Lauro Ramos Venancio
lauro.venancio at gmail.com
Wed Aug 1 13:06:17 PDT 2007
Author: laurov
Date: Wed Aug 1 15:06:15 2007
New Revision: 40686
URL: http://llvm.org/viewvc/llvm-project?rev=40686&view=rev
Log:
Set the alignment of loads and stores. (PR1548)
Modified:
llvm-gcc-4.0/trunk/gcc/llvm-convert.cpp
llvm-gcc-4.0/trunk/gcc/llvm-internal.h
llvm-gcc-4.0/trunk/gcc/tree.c
Modified: llvm-gcc-4.0/trunk/gcc/llvm-convert.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.0/trunk/gcc/llvm-convert.cpp?rev=40686&r1=40685&r2=40686&view=diff
==============================================================================
--- llvm-gcc-4.0/trunk/gcc/llvm-convert.cpp (original)
+++ llvm-gcc-4.0/trunk/gcc/llvm-convert.cpp Wed Aug 1 15:06:15 2007
@@ -1135,13 +1135,19 @@
/// ptrs, copying all of the elements.
static void CopyAggregate(Value *DestPtr, Value *SrcPtr,
bool isDstVolatile, bool isSrcVolatile,
- LLVMBuilder &Builder) {
+ unsigned Alignment, LLVMBuilder &Builder) {
assert(DestPtr->getType() == SrcPtr->getType() &&
"Cannot copy between two pointers of different type!");
const Type *ElTy = cast<PointerType>(DestPtr->getType())->getElementType();
+
+ unsigned TypeAlign = getTargetData().getABITypeAlignment(ElTy);
+ Alignment = MIN(Alignment, TypeAlign);
+
if (ElTy->isFirstClassType()) {
LoadInst *V = Builder.CreateLoad(SrcPtr, isSrcVolatile, "tmp");
- Builder.CreateStore(V, DestPtr, isDstVolatile);
+ StoreInst *S = Builder.CreateStore(V, DestPtr, isDstVolatile);
+ V->setAlignment(Alignment);
+ S->setAlignment(Alignment);
} else if (const StructType *STy = dyn_cast<StructType>(ElTy)) {
Constant *Zero = ConstantInt::get(Type::Int32Ty, 0);
for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) {
@@ -1150,7 +1156,8 @@
Constant *Idx = ConstantInt::get(Type::Int32Ty, i);
Value *DElPtr = Builder.CreateGEP(DestPtr, Zero, Idx, "tmp");
Value *SElPtr = Builder.CreateGEP(SrcPtr, Zero, Idx, "tmp");
- CopyAggregate(DElPtr, SElPtr, isDstVolatile, isSrcVolatile, Builder);
+ CopyAggregate(DElPtr, SElPtr, isDstVolatile, isSrcVolatile, Alignment,
+ Builder);
}
} else {
const ArrayType *ATy = cast<ArrayType>(ElTy);
@@ -1159,7 +1166,8 @@
Constant *Idx = ConstantInt::get(Type::Int32Ty, i);
Value *DElPtr = Builder.CreateGEP(DestPtr, Zero, Idx, "tmp");
Value *SElPtr = Builder.CreateGEP(SrcPtr, Zero, Idx, "tmp");
- CopyAggregate(DElPtr, SElPtr, isDstVolatile, isSrcVolatile, Builder);
+ CopyAggregate(DElPtr, SElPtr, isDstVolatile, isSrcVolatile, Alignment,
+ Builder);
}
}
}
@@ -1187,7 +1195,8 @@
/// EmitAggregateCopy - Copy the elements from SrcPtr to DestPtr, using the
/// GCC type specified by GCCType to know which elements to copy.
void TreeToLLVM::EmitAggregateCopy(Value *DestPtr, Value *SrcPtr, tree type,
- bool isDstVolatile, bool isSrcVolatile) {
+ bool isDstVolatile, bool isSrcVolatile,
+ unsigned Alignment) {
if (DestPtr == SrcPtr && !isDstVolatile && !isSrcVolatile)
return; // noop copy.
@@ -1206,12 +1215,12 @@
PointerType::get(LLVMTy));
SrcPtr = CastToType(Instruction::BitCast, SrcPtr,
PointerType::get(LLVMTy));
- CopyAggregate(DestPtr, SrcPtr, isDstVolatile, isSrcVolatile, Builder);
+ CopyAggregate(DestPtr, SrcPtr, isDstVolatile, isSrcVolatile, Alignment,
+ Builder);
return;
}
}
- unsigned Alignment = TYPE_ALIGN_OK(type) ? (TYPE_ALIGN_UNIT(type) & ~0U) : 0;
Value *TypeSize = Emit(TYPE_SIZE_UNIT(type), 0);
EmitMemCpy(DestPtr, SrcPtr, TypeSize, Alignment);
}
@@ -2460,14 +2469,17 @@
const Type *Ty = ConvertType(TREE_TYPE(exp));
if (!LV.isBitfield()) {
-
+ unsigned Alignment = expr_align(exp) / 8;
if (!DestLoc) {
// Scalar value: emit a load.
Value *Ptr = CastToType(Instruction::BitCast, LV.Ptr,
PointerType::get(Ty));
- return Builder.CreateLoad(Ptr, isVolatile, "tmp");
+ LoadInst *LI = Builder.CreateLoad(Ptr, isVolatile, "tmp");
+ LI->setAlignment(Alignment);
+ return LI;
} else {
- EmitAggregateCopy(DestLoc, LV.Ptr, TREE_TYPE(exp), false, isVolatile);
+ EmitAggregateCopy(DestLoc, LV.Ptr, TREE_TYPE(exp), false, isVolatile,
+ Alignment);
return 0;
}
} else {
@@ -2903,6 +2915,7 @@
LValue LV = EmitLV(TREE_OPERAND(exp, 0));
bool isVolatile = TREE_THIS_VOLATILE(TREE_OPERAND(exp, 0));
+ unsigned Alignment = expr_align(TREE_OPERAND(exp, 0)) / 8;
if (!LV.isBitfield()) {
const Type *ValTy = ConvertType(TREE_TYPE(TREE_OPERAND(exp, 1)));
@@ -2915,14 +2928,16 @@
RHS = CastToAnyType(RHS, Op1Signed, PT->getElementType(), Op0Signed);
else
LV.Ptr = BitCastToType(LV.Ptr, PointerType::get(RHS->getType()));
- Builder.CreateStore(RHS, LV.Ptr, isVolatile);
+ StoreInst *SI = Builder.CreateStore(RHS, LV.Ptr, isVolatile);
+ SI->setAlignment(Alignment);
return RHS;
}
// Non-bitfield aggregate value.
if (DestLoc) {
Emit(TREE_OPERAND(exp, 1), LV.Ptr);
- EmitAggregateCopy(DestLoc, LV.Ptr, TREE_TYPE(exp), isVolatile, false);
+ EmitAggregateCopy(DestLoc, LV.Ptr, TREE_TYPE(exp), isVolatile, false,
+ Alignment);
} else if (!isVolatile) {
Emit(TREE_OPERAND(exp, 1), LV.Ptr);
} else {
@@ -2935,7 +2950,7 @@
Value *Tmp = CreateTemporary(ConvertType(TREE_TYPE(TREE_OPERAND(exp,1))));
Emit(TREE_OPERAND(exp, 1), Tmp);
EmitAggregateCopy(LV.Ptr, Tmp, TREE_TYPE(TREE_OPERAND(exp,1)),
- isVolatile, false);
+ isVolatile, false, Alignment);
}
return 0;
}
@@ -3049,8 +3064,10 @@
LValue LV = EmitLV(Op);
assert(!LV.isBitfield() && "Expected an aggregate operand!");
bool isVolatile = TREE_THIS_VOLATILE(Op);
+ unsigned Alignment = expr_align(Op) / 8;
- EmitAggregateCopy(Target, LV.Ptr, TREE_TYPE(exp), false, isVolatile);
+ EmitAggregateCopy(Target, LV.Ptr, TREE_TYPE(exp), false, isVolatile,
+ Alignment);
break;
}
Modified: llvm-gcc-4.0/trunk/gcc/llvm-internal.h
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.0/trunk/gcc/llvm-internal.h?rev=40686&r1=40685&r2=40686&view=diff
==============================================================================
--- llvm-gcc-4.0/trunk/gcc/llvm-internal.h (original)
+++ llvm-gcc-4.0/trunk/gcc/llvm-internal.h Wed Aug 1 15:06:15 2007
@@ -439,7 +439,8 @@
/// EmitAggregateCopy - Copy the elements from SrcPtr to DestPtr, using the
/// GCC type specified by GCCType to know which elements to copy.
void EmitAggregateCopy(Value *DestPtr, Value *SrcPtr, tree_node *GCCType,
- bool isDstVolatile, bool isSrcVolatile);
+ bool isDstVolatile, bool isSrcVolatile,
+ unsigned Alignment);
/// EmitAggregateZero - Zero the elements of DestPtr.
///
void EmitAggregateZero(Value *DestPtr, tree_node *GCCType);
Modified: llvm-gcc-4.0/trunk/gcc/tree.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.0/trunk/gcc/tree.c?rev=40686&r1=40685&r2=40686&view=diff
==============================================================================
--- llvm-gcc-4.0/trunk/gcc/tree.c (original)
+++ llvm-gcc-4.0/trunk/gcc/tree.c Wed Aug 1 15:06:15 2007
@@ -1565,6 +1565,10 @@
case SAVE_EXPR: case COMPOUND_EXPR: case MODIFY_EXPR:
case INIT_EXPR: case TARGET_EXPR: case WITH_CLEANUP_EXPR:
case CLEANUP_POINT_EXPR:
+ /* LLVM local begin */
+ /* return correctly the alignment of packed structs */
+ case COMPONENT_REF:
+ /* LLVM local end */
/* These don't change the alignment of an object. */
return expr_align (TREE_OPERAND (t, 0));
More information about the llvm-commits
mailing list