Move lowerGlobal() from target-specific code to emitGlobal() in generic code.

Emitting the global initializers is mostly the same across
each architecture (same filling, alignment, etc.). The only difference
is in assembler-directive quirks. E.g., on ARM for ".align N" N is
the exponent for a power of 2, while on x86 N is the actual number
of bytes. To avoid target-specific directives, use .p2align which
is always a power of 2. Similarly, use % instead of @. Either one
may be a comment character for *some* architecture, but for the
architectures we care about % is not a comment character while @
is sometimes (ARM).

Usually MIPS uses ".space N" for ".zero", but the assembler seems
to accept ".zero" so don't change that for now.

May need to adjust .long in the future too.
.word for AArch64 and .4byte for MIPS?

Potentially we can refactor the lowerGlobals() dispatcher
(ELF vs ASM vs IASM). The only thing target-specific about that
is *probably* just the relocation type.

BUG= https://code.google.com/p/nativeclient/issues/detail?id=4076
R=stichnot@chromium.org

Review URL: https://codereview.chromium.org/1188603002.
diff --git a/tests_lit/llvm2ice_tests/globalinit.pnacl.ll b/tests_lit/llvm2ice_tests/globalinit.pnacl.ll
index fcefe6a..e22d292 100644
--- a/tests_lit/llvm2ice_tests/globalinit.pnacl.ll
+++ b/tests_lit/llvm2ice_tests/globalinit.pnacl.ll
@@ -2,16 +2,35 @@
 
 ; REQUIRES: allow_dump
 
-; Test -filetype=asm to test the lea "hack" until we are fully confident
-; in -filetype=iasm .
-; RUN: %p2i -i %s --filetype=asm --args --verbose none | FileCheck %s
+; Test initializers with -filetype=asm.
+; RUN: %if --need=target_X8632 --command %p2i --filetype=asm --target x8632 \
+; RUN:   -i %s --args -O2 | %if --need=target_X8632 --command FileCheck %s
 
-; Test -filetype=iasm and try to cross reference instructions w/ the
-; symbol table.
-; RUN: %p2i --assemble --disassemble -i %s --args --verbose none \
-; RUN:   | FileCheck --check-prefix=IAS %s
-; RUN: %p2i --assemble --disassemble --dis-flags=-t -i %s --args \
-; RUN:   --verbose none | FileCheck --check-prefix=SYMTAB %s
+; RUN: %if --need=target_ARM32 --command %p2i --filetype=asm --target arm32 \
+; RUN:   -i %s --args -O2 --skip-unimplemented \
+; RUN:   | %if --need=target_ARM32 --command FileCheck %s
+
+; Test instructions for materializing addresses.
+; RUN: %if --need=target_X8632 --command %p2i --filetype=asm --target x8632 \
+; RUN:   -i %s --args -O2 \
+; RUN: | %if --need=target_X8632 --command FileCheck %s --check-prefix=X8632
+
+; Test instructions with -filetype=obj and try to cross reference instructions
+; w/ the symbol table.
+; RUN: %if --need=target_X8632 --command %p2i --assemble --disassemble \
+; RUN:   --target x8632 -i %s --args --verbose none \
+; RUN:   | %if --need=target_X8632 --command FileCheck --check-prefix=IAS %s
+
+; RUN: %if --need=target_X8632 --command %p2i --assemble --disassemble \
+; RUN:   --dis-flags=-t --target x8632 -i %s --args --verbose none \
+; RUN:   | %if --need=target_X8632 --command FileCheck --check-prefix=SYMTAB %s
+
+; Only checking symtab for ARM for now. TODO(jvoung): Need to lower
+; arguments at callsite.
+; RUN: %if --need=target_ARM32 --command %p2i --filetype=asm --assemble \
+; RUN:   --disassemble --dis-flags=-t --target arm32 -i %s \
+; RUN:   --args --verbose none --skip-unimplemented \
+; RUN:   | %if --need=target_ARM32 --command FileCheck --check-prefix=SYMTAB %s
 
 define internal i32 @main(i32 %argc, i32 %argv) {
 entry:
@@ -31,14 +50,14 @@
   call void @use(i32 %expanded13)
   ret i32 0
 }
-; CHECK-LABEL: main
-; CHECK: movl $PrimitiveInit,
-; CHECK: movl $PrimitiveInitConst,
-; CHECK: movl $PrimitiveInitStatic,
-; CHECK: movl $PrimitiveUninit,
-; CHECK: movl $ArrayInit,
-; CHECK: movl $ArrayInitPartial,
-; CHECK: movl $ArrayUninit,
+; X8632-LABEL: main
+; X8632: movl $PrimitiveInit,
+; X8632: movl $PrimitiveInitConst,
+; X8632: movl $PrimitiveInitStatic,
+; X8632: movl $PrimitiveUninit,
+; X8632: movl $ArrayInit,
+; X8632: movl $ArrayInitPartial,
+; X8632: movl $ArrayUninit,
 
 ; objdump does not indicate what symbol the mov/relocation applies to
 ; so we grep for "mov {{.*}}, OFFSET, sec", along with
@@ -91,73 +110,73 @@
 
 
 @PrimitiveInit = internal global [4 x i8] c"\1B\00\00\00", align 4
-; CHECK: .type PrimitiveInit,@object
-; CHECK-NEXT: .section .data,"aw",@progbits
-; CHECK-NEXT: .align 4
+; CHECK: .type PrimitiveInit,%object
+; CHECK-NEXT: .section .data,"aw",%progbits
+; CHECK-NEXT: .p2align 2
 ; CHECK-NEXT: PrimitiveInit:
 ; CHECK-NEXT: .byte
 ; CHECK: .size PrimitiveInit, 4
 
 @PrimitiveInitConst = internal constant [4 x i8] c"\0D\00\00\00", align 4
-; CHECK: .type PrimitiveInitConst,@object
-; CHECK-NEXT: .section .rodata,"a",@progbits
-; CHECK-NEXT: .align 4
+; CHECK: .type PrimitiveInitConst,%object
+; CHECK-NEXT: .section .rodata,"a",%progbits
+; CHECK-NEXT: .p2align 2
 ; CHECK-NEXT: PrimitiveInitConst:
 ; CHECK-NEXT: .byte
 ; CHECK: .size PrimitiveInitConst, 4
 
 @ArrayInit = internal global [20 x i8] c"\0A\00\00\00\14\00\00\00\1E\00\00\00(\00\00\002\00\00\00", align 4
-; CHECK: .type ArrayInit,@object
-; CHECK-NEXT: .section .data,"aw",@progbits
-; CHECK-NEXT: .align 4
+; CHECK: .type ArrayInit,%object
+; CHECK-NEXT: .section .data,"aw",%progbits
+; CHECK-NEXT: .p2align 2
 ; CHECK-NEXT: ArrayInit:
 ; CHECK-NEXT: .byte
 ; CHECK: .size ArrayInit, 20
 
 @ArrayInitPartial = internal global [40 x i8] c"<\00\00\00F\00\00\00P\00\00\00Z\00\00\00d\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00", align 4
-; CHECK: .type ArrayInitPartial,@object
-; CHECK-NEXT: .section .data,"aw",@progbits
-; CHECK-NEXT: .align 4
+; CHECK: .type ArrayInitPartial,%object
+; CHECK-NEXT: .section .data,"aw",%progbits
+; CHECK-NEXT: .p2align 2
 ; CHECK-NEXT: ArrayInitPartial:
 ; CHECK-NEXT: .byte
 ; CHECK: .size ArrayInitPartial, 40
 
 @PrimitiveInitStatic = internal global [4 x i8] zeroinitializer, align 4
-; CHECK: .type PrimitiveInitStatic,@object
-; CHECK-NEXT: .section .bss,"aw",@nobits
-; CHECK-NEXT: .align 4
+; CHECK: .type PrimitiveInitStatic,%object
+; CHECK-NEXT: .section .bss,"aw",%nobits
+; CHECK-NEXT: .p2align 2
 ; CHECK-NEXT: PrimitiveInitStatic:
 ; CHECK-NEXT: .zero 4
 ; CHECK-NEXT: .size PrimitiveInitStatic, 4
 
 @PrimitiveUninit = internal global [4 x i8] zeroinitializer, align 4
-; CHECK: .type PrimitiveUninit,@object
-; CHECK-NEXT: .section .bss,"aw",@nobits
-; CHECK-NEXT: .align 4
+; CHECK: .type PrimitiveUninit,%object
+; CHECK-NEXT: .section .bss,"aw",%nobits
+; CHECK-NEXT: .p2align 2
 ; CHECK-NEXT: PrimitiveUninit:
 ; CHECK-NEXT: .zero 4
 ; CHECK-NEXT: .size PrimitiveUninit, 4
 
 @ArrayUninit = internal global [20 x i8] zeroinitializer, align 4
-; CHECK: .type ArrayUninit,@object
-; CHECK-NEXT: .section .bss,"aw",@nobits
-; CHECK-NEXT: .align 4
+; CHECK: .type ArrayUninit,%object
+; CHECK-NEXT: .section .bss,"aw",%nobits
+; CHECK-NEXT: .p2align 2
 ; CHECK-NEXT: ArrayUninit:
 ; CHECK-NEXT: .zero 20
 ; CHECK-NEXT: .size ArrayUninit, 20
 
 @ArrayUninitConstDouble = internal constant [200 x i8] zeroinitializer, align 8
-; CHECK: .type ArrayUninitConstDouble,@object
-; CHECK-NEXT: .section .rodata,"a",@progbits
-; CHECK-NEXT: .align 8
+; CHECK: .type ArrayUninitConstDouble,%object
+; CHECK-NEXT: .section .rodata,"a",%progbits
+; CHECK-NEXT: .p2align 3
 ; CHECK-NEXT: ArrayUninitConstDouble:
 ; CHECK-NEXT: .zero 200
 ; CHECK-NEXT: .size ArrayUninitConstDouble, 200
 
 @ArrayUninitConstInt = internal constant [20 x i8] zeroinitializer, align 4
-; CHECK: .type ArrayUninitConstInt,@object
-; CHECK: .section .rodata,"a",@progbits
-; CHECK-NEXT: .align 4
+; CHECK: .type ArrayUninitConstInt,%object
+; CHECK: .section .rodata,"a",%progbits
+; CHECK-NEXT: .p2align 2
 ; CHECK-NEXT: ArrayUninitConstInt:
 ; CHECK-NEXT: .zero 20
 ; CHECK-NEXT: .size ArrayUninitConstInt, 20