[llvm] r308758 - [mips] Support -membedded-data and fix a related bug

Simon Dardis via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 21 10:19:00 PDT 2017


Author: sdardis
Date: Fri Jul 21 10:19:00 2017
New Revision: 308758

URL: http://llvm.org/viewvc/llvm-project?rev=308758&view=rev
Log:
[mips] Support -membedded-data and fix a related bug

-membedded-data changes the location of constant data from the .sdata to
the .rodata section. Previously it was (incorrectly) always located in the
.rodata section.

Reviewers: atanasyan

Differential Revision: https://reviews.llvm.org/D35686

Modified:
    llvm/trunk/lib/Target/Mips/MipsTargetObjectFile.cpp
    llvm/trunk/test/CodeGen/Mips/2008-07-15-SmallSection.ll

Modified: llvm/trunk/lib/Target/Mips/MipsTargetObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/MipsTargetObjectFile.cpp?rev=308758&r1=308757&r2=308758&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Mips/MipsTargetObjectFile.cpp (original)
+++ llvm/trunk/lib/Target/Mips/MipsTargetObjectFile.cpp Fri Jul 21 10:19:00 2017
@@ -36,6 +36,12 @@ ExternSData("mextern-sdata", cl::Hidden,
                      "current object."),
             cl::init(true));
 
+static cl::opt<bool>
+EmbeddedData("membedded-data", cl::Hidden,
+             cl::desc("MIPS: Try to allocate variables in the following"
+                      " sections if possible: .rodata, .sdata, .data ."),
+             cl::init(false));
+
 void MipsTargetObjectFile::Initialize(MCContext &Ctx, const TargetMachine &TM){
   TargetLoweringObjectFileELF::Initialize(Ctx, TM);
   InitializeELF(TM.Options.UseInitArray);
@@ -77,8 +83,9 @@ bool MipsTargetObjectFile::IsGlobalInSma
 bool MipsTargetObjectFile::
 IsGlobalInSmallSection(const GlobalObject *GO, const TargetMachine &TM,
                        SectionKind Kind) const {
-  return (IsGlobalInSmallSectionImpl(GO, TM) &&
-          (Kind.isData() || Kind.isBSS() || Kind.isCommon()));
+  return IsGlobalInSmallSectionImpl(GO, TM) &&
+         (Kind.isData() || Kind.isBSS() || Kind.isCommon() ||
+          Kind.isReadOnly());
 }
 
 /// Return true if this global address should be placed into small data/bss
@@ -108,6 +115,10 @@ IsGlobalInSmallSectionImpl(const GlobalO
                        GVA->hasCommonLinkage()))
     return false;
 
+  // Enforce -membedded-data.
+  if (EmbeddedData && GVA->isConstant())
+    return false;
+
   Type *Ty = GVA->getValueType();
   return IsInSmallSection(
       GVA->getParent()->getDataLayout().getTypeAllocSize(Ty));
@@ -123,6 +134,8 @@ MCSection *MipsTargetObjectFile::SelectS
     return SmallBSSSection;
   if (Kind.isData() && IsGlobalInSmallSection(GO, TM, Kind))
     return SmallDataSection;
+  if (Kind.isReadOnly() && IsGlobalInSmallSection(GO, TM, Kind))
+    return SmallDataSection;
 
   // Otherwise, we work the same as ELF.
   return TargetLoweringObjectFileELF::SelectSectionForGlobal(GO, Kind, TM);

Modified: llvm/trunk/test/CodeGen/Mips/2008-07-15-SmallSection.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/Mips/2008-07-15-SmallSection.ll?rev=308758&r1=308757&r2=308758&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/Mips/2008-07-15-SmallSection.ll (original)
+++ llvm/trunk/test/CodeGen/Mips/2008-07-15-SmallSection.ll Fri Jul 21 10:19:00 2017
@@ -1,16 +1,32 @@
-; RUN: llc < %s -march=mips -mcpu=mips32 -mips-ssection-threshold=8 -relocation-model=static -mattr=+noabicalls -mgpopt | FileCheck %s
+; RUN: llc < %s -march=mips -mcpu=mips32 -mips-ssection-threshold=8 \
+; RUN:     -relocation-model=static -mattr=+noabicalls -mgpopt \
+; RUN:   | FileCheck %s --check-prefixes=BASIC,COMMON
+; RUN: llc < %s -march=mips -mcpu=mips32 -mips-ssection-threshold=8 \
+; RUN:     -relocation-model=static -mattr=+noabicalls -mgpopt -membedded-data \
+; RUN:   | FileCheck %s --check-prefixes=EMBDATA,COMMON
+
+; Test the layout of objects when compiling for static, noabicalls environment.
 
 %struct.anon = type { i32, i32 }
 
+; BASIC: .type  s0, at object
+; BASIC-NEXT: .section .sdata,"aw", at progbits
+
+; EMDATA: .type  s0, at object
+; EMDATA-NEXT: .section .rodata,"a", at progbits
+
 @s0 = constant [8 x i8] c"AAAAAAA\00", align 4
 
-; CHECK: .type  foo, at object
-; CHECK-NEXT: .section .sdata,"aw", at progbits
+; BASIC: .type  foo, at object
+; BASIC-NOT:  .section
+
+; EMBDATA: .type  foo, at object
+; EMBDATA-NEXT:  .section .sdata,"aw", at progbits
 @foo = global %struct.anon { i32 2, i32 3 }
 
-; CHECK:  .type bar, at object
-; CHECK-NEXT:  .section  .sbss,"aw", at nobits
- at bar = global %struct.anon zeroinitializer 
+; COMMON:  .type bar, at object
+; COMMON-NEXT:  .section  .sbss,"aw", at nobits
+ at bar = global %struct.anon zeroinitializer
 
 define i8* @A0() nounwind {
 entry:




More information about the llvm-commits mailing list