[cfe-dev] alignment of local variables

Akira Hatanaka ahatanak at gmail.com
Mon Mar 28 09:58:29 PDT 2011


Is it possible to set a maximum alignment for local variables, either by
passing a command line option or using target-specific hooks?
For example, in the code shown below, if the maximum alignment is 8, the
alignment attribute in the source code (__aligned__(16)) will be ignored,
and local variable a will be aligned on an 8-byte boundary.

# align2.c
#define N 16

int main1 (int n, int *a);

int main (void)
{
  int a[N+1] __attribute__ ((__aligned__(16)));

  main1 (N, a+1);

  return 0;
}

# .ll
# clang  -O3 -S -o - -emit-llvm align2.c
; ModuleID = 'align2.c'
target datalayout =
"e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32"
target triple = "i386-pc-linux-gnu"

define i32 @main() nounwind {
entry:
  %a = alloca [17 x i32], align 16;
  %add.ptr = getelementptr inbounds [17 x i32]* %a, i32 0, i32 1
  %call = call i32 @main1(i32 16, i32* %add.ptr) nounwind
  ret i32 0
}

declare i32 @main1(i32, i32*)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20110328/ecbf549e/attachment.html>


More information about the cfe-dev mailing list