[llvm-commits] [dragonegg] r164936 - in /dragonegg/trunk/src: Backend.cpp Convert.cpp
Duncan Sands
baldrick at free.fr
Mon Oct 1 05:04:14 PDT 2012
Author: baldrick
Date: Mon Oct 1 07:04:14 2012
New Revision: 164936
URL: http://llvm.org/viewvc/llvm-project?rev=164936&view=rev
Log:
Give variables the alignment that GCC says they should have rather than trying
to second guess GCC: remove some strange DECL_USER_ALIGN logic inherited from
llvm-gcc that I never understood the point of.
Modified:
dragonegg/trunk/src/Backend.cpp
dragonegg/trunk/src/Convert.cpp
Modified: dragonegg/trunk/src/Backend.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/src/Backend.cpp?rev=164936&r1=164935&r2=164936&view=diff
==============================================================================
--- dragonegg/trunk/src/Backend.cpp (original)
+++ dragonegg/trunk/src/Backend.cpp Mon Oct 1 07:04:14 2012
@@ -975,7 +975,6 @@
/// emit_global - Emit the specified VAR_DECL or aggregate CONST_DECL to LLVM as
/// a global variable. This function implements the end of assemble_variable.
static void emit_global(tree decl) {
- // FIXME: Support alignment on globals: DECL_ALIGN.
// FIXME: DECL_PRESERVE_P indicates the var is marked with attribute 'used'.
// Global register variables don't turn into LLVM GlobalVariables.
@@ -1119,23 +1118,18 @@
#endif
}
- // Set the alignment for the global if one of the following condition is met
- // 1) DECL_ALIGN is better than the alignment as per ABI specification
- // 2) DECL_ALIGN is set by user.
- if (DECL_ALIGN(decl)) {
- unsigned TargetAlign =
- getTargetData().getABITypeAlignment(GV->getType()->getElementType());
- if (DECL_USER_ALIGN(decl) ||
- 8 * TargetAlign < (unsigned)DECL_ALIGN(decl)) {
- GV->setAlignment(DECL_ALIGN(decl) / 8);
- }
+ GV->setAlignment(DECL_ALIGN(decl) / 8);
#ifdef TARGET_ADJUST_CSTRING_ALIGN
- else if (DECL_INITIAL(decl) != error_mark_node && // uninitialized?
- DECL_INITIAL(decl) && isa<STRING_CST>(DECL_INITIAL(decl))) {
- TARGET_ADJUST_CSTRING_ALIGN(GV);
- }
+ if (DECL_INITIAL(decl) != error_mark_node && // uninitialized?
+ DECL_INITIAL(decl) && isa<STRING_CST>(DECL_INITIAL(decl)))
+ TARGET_ADJUST_CSTRING_ALIGN(GV);
#endif
- }
+
+ // If this is the alignment we would have given the variable anyway then don't
+ // use an explicit alignment, making the IR look more portable.
+ if (GV->getAlignment() ==
+ getTargetData().getABITypeAlignment(GV->getType()->getElementType()))
+ GV->setAlignment(0);
// Handle used decls
if (DECL_PRESERVE_P (decl)) {
Modified: dragonegg/trunk/src/Convert.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/src/Convert.cpp?rev=164936&r1=164935&r2=164936&view=diff
==============================================================================
--- dragonegg/trunk/src/Convert.cpp (original)
+++ dragonegg/trunk/src/Convert.cpp Mon Oct 1 07:04:14 2012
@@ -1015,8 +1015,8 @@
register_ctor_dtor(Fn, DECL_FINI_PRIORITY(FnDecl), false);
// Handle attribute "aligned".
- if (DECL_ALIGN (FnDecl) != FUNCTION_BOUNDARY)
- Fn->setAlignment(DECL_ALIGN (FnDecl) / 8);
+ if (DECL_ALIGN(FnDecl) != FUNCTION_BOUNDARY)
+ Fn->setAlignment(DECL_ALIGN(FnDecl) / 8);
// Handle functions in specified sections.
if (DECL_SECTION_NAME(FnDecl))
@@ -2364,16 +2364,12 @@
Ty = Type::getInt8Ty(Context);
}
- unsigned Alignment = 0; // Alignment in bytes.
+ unsigned Alignment = DECL_ALIGN(decl) / 8; // Alignment in octets.
- // Set the alignment for the local if one of the following condition is met
- // 1) DECL_ALIGN is better than the alignment as per ABI specification
- // 2) DECL_ALIGN is set by user.
- if (DECL_ALIGN(decl)) {
- unsigned TargetAlign = getTargetData().getABITypeAlignment(Ty);
- if (DECL_USER_ALIGN(decl) || 8 * TargetAlign < (unsigned)DECL_ALIGN(decl))
- Alignment = DECL_ALIGN(decl) / 8;
- }
+ // If this is the alignment we would have given the variable anyway then don't
+ // use an explicit alignment, making the IR look more portable.
+ if (Alignment == getTargetData().getABITypeAlignment(Ty))
+ Alignment = 0;
// Insert an alloca for this variable.
AllocaInst *AI;
@@ -6208,12 +6204,9 @@
// type void.
if (Ty->isVoidTy()) Ty = StructType::get(Context);
PointerType *PTy = Ty->getPointerTo();
- // FIXME: If gcc wants less alignment, we should probably use that.
- unsigned Alignment = Ty->isSized() ? TD.getABITypeAlignment(Ty) : 1;
- if (DECL_ALIGN(exp)) {
- if (DECL_USER_ALIGN(exp) || 8 * Alignment < (unsigned)DECL_ALIGN(exp))
- Alignment = DECL_ALIGN(exp) / 8;
- }
+ unsigned Alignment = DECL_ALIGN(exp) / 8;
+ if (!Alignment)
+ Alignment = 1;
return LValue(Builder.CreateBitCast(Decl, PTy), Alignment);
}
More information about the llvm-commits
mailing list