[llvm] r197711 - Implement the .ltorg directive for ARM assembly

David Peixotto dpeixott at codeaurora.org
Thu Dec 19 10:26:07 PST 2013


Author: dpeixott
Date: Thu Dec 19 12:26:07 2013
New Revision: 197711

URL: http://llvm.org/viewvc/llvm-project?rev=197711&view=rev
Log:
Implement the .ltorg directive for ARM assembly

This directive will write out the assembler-maintained constant
pool for the current section. These constant pools are created to
support the ldr-pseudo instruction (e.g. ldr r0, =val).

The directive can be used by the programmer to place the constant
pool in a location that can be reached by a pc-relative offset in
the ldr instruction.

Added:
    llvm/trunk/test/MC/ARM/ltorg-darwin.s
    llvm/trunk/test/MC/ARM/ltorg.s
Modified:
    llvm/trunk/lib/Target/ARM/AsmParser/ARMAsmParser.cpp

Modified: llvm/trunk/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/AsmParser/ARMAsmParser.cpp?rev=197711&r1=197710&r2=197711&view=diff
==============================================================================
--- llvm/trunk/lib/Target/ARM/AsmParser/ARMAsmParser.cpp (original)
+++ llvm/trunk/lib/Target/ARM/AsmParser/ARMAsmParser.cpp Thu Dec 19 12:26:07 2013
@@ -115,6 +115,10 @@ class ARMAsmParser : public MCTargetAsmP
     return ConstantPools[Section];
   }
 
+  void destroyConstantPool(const MCSection *Section) {
+    ConstantPools.erase(Section);
+  }
+
   ARMTargetStreamer &getTargetStreamer() {
     MCTargetStreamer &TS = getParser().getStreamer().getTargetStreamer();
     return static_cast<ARMTargetStreamer &>(TS);
@@ -211,6 +215,7 @@ class ARMAsmParser : public MCTargetAsmP
   bool parseDirectivePad(SMLoc L);
   bool parseDirectiveRegSave(SMLoc L, bool IsVector);
   bool parseDirectiveInst(SMLoc L, char Suffix = '\0');
+  bool parseDirectiveLtorg(SMLoc L);
 
   StringRef splitMnemonic(StringRef Mnemonic, unsigned &PredicationCode,
                           bool &CarrySetting, unsigned &ProcessorIMod,
@@ -7894,6 +7899,8 @@ bool ARMAsmParser::ParseDirective(AsmTok
     return parseDirectiveInst(DirectiveID.getLoc(), 'n');
   else if (IDVal == ".inst.w")
     return parseDirectiveInst(DirectiveID.getLoc(), 'w');
+  else if (IDVal == ".ltorg")
+    return parseDirectiveLtorg(DirectiveID.getLoc());
   return true;
 }
 
@@ -8445,6 +8452,20 @@ bool ARMAsmParser::parseDirectiveInst(SM
   return false;
 }
 
+/// parseDirectiveLtorg
+///  ::= .ltorg
+bool ARMAsmParser::parseDirectiveLtorg(SMLoc L) {
+  MCStreamer &Streamer = getParser().getStreamer();
+  const MCSection *Section = Streamer.getCurrentSection().first;
+
+  if (ConstantPool *CP = getConstantPool(Section)) {
+    CP->emitEntries(Streamer);
+    CP = 0;
+    destroyConstantPool(Section);
+  }
+  return false;
+}
+
 /// Force static initialization.
 extern "C" void LLVMInitializeARMAsmParser() {
   RegisterMCAsmParser<ARMAsmParser> X(TheARMTarget);

Added: llvm/trunk/test/MC/ARM/ltorg-darwin.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ARM/ltorg-darwin.s?rev=197711&view=auto
==============================================================================
--- llvm/trunk/test/MC/ARM/ltorg-darwin.s (added)
+++ llvm/trunk/test/MC/ARM/ltorg-darwin.s Thu Dec 19 12:26:07 2013
@@ -0,0 +1,151 @@
+@ This test has a partner (ltorg.s) that contains matching
+@ tests for the .ltorg on linux targets. We need separate files
+@ because the syntax for switching sections and temporary labels differs
+@ between darwin and linux. Any tests added here should have a matching
+@ test added there.
+
+ at RUN: llvm-mc -triple   armv7-apple-darwin %s | FileCheck %s
+ at RUN: llvm-mc -triple thumbv5-apple-darwin %s | FileCheck %s
+ at RUN: llvm-mc -triple thumbv7-apple-darwin %s | FileCheck %s
+
+@ check that ltorg dumps the constant pool at the current location
+.section __TEXT,a,regular,pure_instructions
+@ CHECK-LABEL: f2:
+f2:
+  ldr r0, =0x10001
+@ CHECK: ldr r0, Ltmp0
+  adds r0, r0, #1
+  adds r0, r0, #1
+  b f3
+.ltorg
+@ constant pool
+@ CHECK: .align 2
+@ CHECK: .data_region
+@ CHECK-LABEL: Ltmp0:
+@ CHECK: .long 65537
+@ CHECK: .end_data_region
+
+@ CHECK-LABEL: f3:
+f3:
+  adds r0, r0, #1
+  adds r0, r0, #1
+
+@ check that ltorg clears the constant pool after dumping it
+.section __TEXT,b,regular,pure_instructions
+@ CHECK-LABEL: f4:
+f4:
+  ldr r0, =0x10002
+@ CHECK: ldr r0, Ltmp1
+  adds r0, r0, #1
+  adds r0, r0, #1
+  b f5
+.ltorg
+@ constant pool
+@ CHECK: .align 2
+@ CHECK: .data_region
+@ CHECK-LABEL: Ltmp1:
+@ CHECK: .long 65538
+@ CHECK: .end_data_region
+
+@ CHECK-LABEL: f5:
+f5:
+  adds r0, r0, #1
+  adds r0, r0, #1
+  ldr r0, =0x10003
+@ CHECK: ldr r0, Ltmp2
+  adds r0, r0, #1
+  b f6
+.ltorg
+@ constant pool
+@ CHECK: .align 2
+@ CHECK: .data_region
+@ CHECK-LABEL: Ltmp2:
+@ CHECK: .long 65539
+@ CHECK: .end_data_region
+
+@ CHECK-LABEL: f6:
+f6:
+  adds r0, r0, #1
+  adds r0, r0, #1
+
+@ check that ltorg does not issue an error if there is no constant pool
+.section __TEXT,c,regular,pure_instructions
+@ CHECK-LABEL: f7:
+f7:
+  adds r0, r0, #1
+  b f8
+  .ltorg
+f8:
+  adds r0, r0, #1
+
+@ check that ltorg works for labels
+.section __TEXT,d,regular,pure_instructions
+@ CHECK-LABEL: f9:
+f9:
+  adds r0, r0, #1
+  adds r0, r0, #1
+  ldr r0, =bar
+@ CHECK: ldr r0, Ltmp3
+  adds r0, r0, #1
+  adds r0, r0, #1
+  adds r0, r0, #1
+  b f10
+.ltorg
+@ constant pool
+@ CHECK: .align 2
+@ CHECK: .data_region
+@ CHECK-LABEL: Ltmp3:
+@ CHECK: .long bar
+@ CHECK: .end_data_region
+
+@ CHECK-LABEL: f10:
+f10:
+  adds r0, r0, #1
+  adds r0, r0, #1
+
+@ check that use of ltorg does not prevent dumping non-empty constant pools at end of section
+.section __TEXT,e,regular,pure_instructions
+@ CHECK-LABEL: f11:
+f11:
+  adds r0, r0, #1
+  adds r0, r0, #1
+  ldr r0, =0x10004
+@ CHECK: ldr r0, Ltmp4
+  b f12
+  .ltorg
+@ constant pool
+@ CHECK: .align 2
+@ CHECK: .data_region
+@ CHECK-LABEL: Ltmp4:
+@ CHECK: .long 65540
+@ CHECK: .end_data_region
+
+@ CHECK-LABEL: f12:
+f12:
+  adds r0, r0, #1
+  ldr r0, =0x10005
+@ CHECK: ldr r0, Ltmp5
+
+.section __TEXT,f,regular,pure_instructions
+@ CHECK-LABEL: f13
+f13:
+  adds r0, r0, #1
+  adds r0, r0, #1
+
+@ should not have a constant pool at end of section with empty constant pools
+@ CHECK-NOT: .section __TEXT,a,regular,pure_instructions
+@ CHECK-NOT: .section __TEXT,b,regular,pure_instructions
+@ CHECK-NOT: .section __TEXT,c,regular,pure_instructions
+@ CHECK-NOT: .section __TEXT,d,regular,pure_instructions
+
+@ should have a non-empty constant pool at end of this section
+@ CHECK: .section __TEXT,e,regular,pure_instructions
+@ constant pool
+@ CHECK: .align 2
+@ CHECK: .data_region
+@ CHECK-LABEL: Ltmp5:
+@ CHECK: .long 65541
+@ CHECK: .end_data_region
+
+@ should not have a constant pool at end of section with empty constant pools
+@ CHECK-NOT: .section __TEXT,f,regular,pure_instructions

Added: llvm/trunk/test/MC/ARM/ltorg.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ARM/ltorg.s?rev=197711&view=auto
==============================================================================
--- llvm/trunk/test/MC/ARM/ltorg.s (added)
+++ llvm/trunk/test/MC/ARM/ltorg.s Thu Dec 19 12:26:07 2013
@@ -0,0 +1,138 @@
+@ This test has a partner (ltorg-darwin.s) that contains matching
+@ tests for the .ltorg on darwin targets. We need separate files
+@ because the syntax for switching sections and temporary labels differs
+@ between darwin and linux. Any tests added here should have a matching
+@ test added there.
+
+ at RUN: llvm-mc -triple   armv7-unknown-linux-gnueabi %s | FileCheck %s
+ at RUN: llvm-mc -triple thumbv5-unknown-linux-gnueabi %s | FileCheck %s
+ at RUN: llvm-mc -triple thumbv7-unknown-linux-gnueabi %s | FileCheck %s
+
+@ check that ltorg dumps the constant pool at the current location
+.section a,"ax",%progbits
+@ CHECK-LABEL: f2:
+f2:
+  ldr r0, =0x10001
+@ CHECK: ldr r0, .Ltmp0
+  adds r0, r0, #1
+  adds r0, r0, #1
+  b f3
+.ltorg
+@ constant pool
+@ CHECK: .align 2
+@ CHECK-LABEL: .Ltmp0:
+@ CHECK: .long 65537
+
+@ CHECK-LABEL: f3:
+f3:
+  adds r0, r0, #1
+  adds r0, r0, #1
+
+@ check that ltorg clears the constant pool after dumping it
+.section b,"ax",%progbits
+@ CHECK-LABEL: f4:
+f4:
+  ldr r0, =0x10002
+@ CHECK: ldr r0, .Ltmp1
+  adds r0, r0, #1
+  adds r0, r0, #1
+  b f5
+.ltorg
+@ constant pool
+@ CHECK: .align 2
+@ CHECK-LABEL: .Ltmp1:
+@ CHECK: .long 65538
+
+@ CHECK-LABEL: f5:
+f5:
+  adds r0, r0, #1
+  adds r0, r0, #1
+  ldr r0, =0x10003
+@ CHECK: ldr r0, .Ltmp2
+  adds r0, r0, #1
+  b f6
+.ltorg
+@ constant pool
+@ CHECK: .align 2
+@ CHECK-LABEL: .Ltmp2:
+@ CHECK: .long 65539
+
+@ CHECK-LABEL: f6:
+f6:
+  adds r0, r0, #1
+  adds r0, r0, #1
+
+@ check that ltorg does not issue an error if there is no constant pool
+.section c,"ax",%progbits
+@ CHECK-LABEL: f7:
+f7:
+  adds r0, r0, #1
+  b f8
+  .ltorg
+f8:
+  adds r0, r0, #1
+
+@ check that ltorg works for labels
+.section d,"ax",%progbits
+@ CHECK-LABEL: f9:
+f9:
+  adds r0, r0, #1
+  adds r0, r0, #1
+  ldr r0, =bar
+@ CHECK: ldr r0, .Ltmp3
+  adds r0, r0, #1
+  adds r0, r0, #1
+  adds r0, r0, #1
+  b f10
+.ltorg
+@ constant pool
+@ CHECK: .align 2
+@ CHECK-LABEL: .Ltmp3:
+@ CHECK: .long bar
+
+@ CHECK-LABEL: f10:
+f10:
+  adds r0, r0, #1
+  adds r0, r0, #1
+
+@ check that use of ltorg does not prevent dumping non-empty constant pools at end of section
+.section e,"ax",%progbits
+@ CHECK-LABEL: f11:
+f11:
+  adds r0, r0, #1
+  adds r0, r0, #1
+  ldr r0, =0x10004
+@ CHECK: ldr r0, .Ltmp4
+  b f12
+  .ltorg
+@ constant pool
+@ CHECK: .align 2
+@ CHECK-LABEL: .Ltmp4:
+@ CHECK: .long 65540
+@ CHECK-LABEL: f12:
+f12:
+  adds r0, r0, #1
+  ldr r0, =0x10005
+@ CHECK: ldr r0, .Ltmp5
+
+.section f,"ax",%progbits
+@ CHECK-LABEL: f13
+f13:
+  adds r0, r0, #1
+  adds r0, r0, #1
+
+@ should not have a constant pool at end of section with empty constant pools
+@ CHECK-NOT: .section a,"ax",%progbits
+@ CHECK-NOT: .section b,"ax",%progbits
+@ CHECK-NOT: .section c,"ax",%progbits
+@ CHECK-NOT: .section d,"ax",%progbits
+
+@ should have a non-empty constant pool at end of this section
+@ CHECK: .section e,"ax",%progbits
+@ constant pool
+@ CHECK: .align 2
+@ CHECK-LABEL: .Ltmp5:
+@ CHECK: .long 65541
+
+@ should not have a constant pool at end of section with empty constant pools
+@ CHECK-NOT: .section f,"ax",%progbits





More information about the llvm-commits mailing list