[PATCH] D35686: [mips] Support -membedded-data and fix a related bug
Simon Dardis via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 21 10:19:36 PDT 2017
This revision was automatically updated to reflect the committed changes.
Closed by commit rL308758: [mips] Support -membedded-data and fix a related bug (authored by sdardis).
Repository:
rL LLVM
https://reviews.llvm.org/D35686
Files:
llvm/trunk/lib/Target/Mips/MipsTargetObjectFile.cpp
llvm/trunk/test/CodeGen/Mips/2008-07-15-SmallSection.ll
Index: llvm/trunk/lib/Target/Mips/MipsTargetObjectFile.cpp
===================================================================
--- llvm/trunk/lib/Target/Mips/MipsTargetObjectFile.cpp
+++ llvm/trunk/lib/Target/Mips/MipsTargetObjectFile.cpp
@@ -36,6 +36,12 @@
"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::
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 @@
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 @@
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);
Index: llvm/trunk/test/CodeGen/Mips/2008-07-15-SmallSection.ll
===================================================================
--- llvm/trunk/test/CodeGen/Mips/2008-07-15-SmallSection.ll
+++ llvm/trunk/test/CodeGen/Mips/2008-07-15-SmallSection.ll
@@ -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:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D35686.107687.patch
Type: text/x-patch
Size: 3603 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170721/1186bbca/attachment.bin>
More information about the llvm-commits
mailing list