From: Simon Dardis Date: Fri, 21 Jul 2017 17:19:00 +0000 (+0000) Subject: [mips] Support -membedded-data and fix a related bug X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=abccd7d6bca2260f90ad5a9d8c1470377969d9ba;p=llvm [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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@308758 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Target/Mips/MipsTargetObjectFile.cpp b/lib/Target/Mips/MipsTargetObjectFile.cpp index 4d73c399103..3bf32e81d57 100644 --- a/lib/Target/Mips/MipsTargetObjectFile.cpp +++ b/lib/Target/Mips/MipsTargetObjectFile.cpp @@ -36,6 +36,12 @@ ExternSData("mextern-sdata", cl::Hidden, "current object."), cl::init(true)); +static cl::opt +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( 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 GlobalObject *GO, 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::SelectSectionForGlobal( 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); diff --git a/test/CodeGen/Mips/2008-07-15-SmallSection.ll b/test/CodeGen/Mips/2008-07-15-SmallSection.ll index 79f4d7970e6..21495423200 100644 --- a/test/CodeGen/Mips/2008-07-15-SmallSection.ll +++ b/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,@object +; BASIC-NEXT: .section .sdata,"aw",@progbits + +; EMDATA: .type s0,@object +; EMDATA-NEXT: .section .rodata,"a",@progbits + @s0 = constant [8 x i8] c"AAAAAAA\00", align 4 -; CHECK: .type foo,@object -; CHECK-NEXT: .section .sdata,"aw",@progbits +; BASIC: .type foo,@object +; BASIC-NOT: .section + +; EMBDATA: .type foo,@object +; EMBDATA-NEXT: .section .sdata,"aw",@progbits @foo = global %struct.anon { i32 2, i32 3 } -; CHECK: .type bar,@object -; CHECK-NEXT: .section .sbss,"aw",@nobits -@bar = global %struct.anon zeroinitializer +; COMMON: .type bar,@object +; COMMON-NEXT: .section .sbss,"aw",@nobits +@bar = global %struct.anon zeroinitializer define i8* @A0() nounwind { entry: