]> granicus.if.org Git - llvm/commitdiff
[COFF] Use comdat shared constants for MinGW as well
authorMartin Storsjo <martin@martin.st>
Wed, 25 Jul 2018 18:35:42 +0000 (18:35 +0000)
committerMartin Storsjo <martin@martin.st>
Wed, 25 Jul 2018 18:35:42 +0000 (18:35 +0000)
GNU binutils tools have no problems with this kind of shared constants,
provided that we actually hook it up completely in AsmPrinter and
produce a global symbol.

This effectively reverts SVN r335918 by hooking the rest of it up
properly.

This feature was implemented originally in SVN r213006, with no reason
for why it can't be used for MinGW other than the fact that GCC doesn't
do it while MSVC does.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@337951 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/MC/MCAsmInfo.h
lib/CodeGen/AsmPrinter/AsmPrinter.cpp
lib/CodeGen/TargetLoweringObjectFileImpl.cpp
lib/MC/MCAsmInfoCOFF.cpp
test/CodeGen/AArch64/win_cst_pool.ll
test/CodeGen/X86/win_cst_pool.ll

index 120fb8fa74921f3ef65851f49be14ac66d8a5474..0a0f37966fc5296a603ee9cd2910d10aaf3a3c69 100644 (file)
@@ -89,10 +89,6 @@ protected:
   /// them.
   bool HasCOFFAssociativeComdats = false;
 
-  /// True if this is a non-GNU COFF target. For GNU targets, we don't generate
-  /// constants into comdat sections.
-  bool HasCOFFComdatConstants = false;
-
   /// This is the maximum possible length of an instruction, which is needed to
   /// compute the size of an inline asm.  Defaults to 4.
   unsigned MaxInstLength = 4;
@@ -473,7 +469,6 @@ public:
   bool hasMachoZeroFillDirective() const { return HasMachoZeroFillDirective; }
   bool hasMachoTBSSDirective() const { return HasMachoTBSSDirective; }
   bool hasCOFFAssociativeComdats() const { return HasCOFFAssociativeComdats; }
-  bool hasCOFFComdatConstants() const { return HasCOFFComdatConstants; }
   unsigned getMaxInstLength() const { return MaxInstLength; }
   unsigned getMinInstAlignment() const { return MinInstAlignment; }
   bool getDollarIsPC() const { return DollarIsPC; }
index 9bbc77b3056bcfbc162a3f3ef5b1a556e0df12f6..f659282ac27c4adba85963bfc679494cf1ab0c9a 100644 (file)
@@ -2664,7 +2664,7 @@ MCSymbol *AsmPrinter::GetBlockAddressSymbol(const BasicBlock *BB) const {
 
 /// GetCPISymbol - Return the symbol for the specified constant pool entry.
 MCSymbol *AsmPrinter::GetCPISymbol(unsigned CPID) const {
-  if (getSubtargetInfo().getTargetTriple().isKnownWindowsMSVCEnvironment()) {
+  if (getSubtargetInfo().getTargetTriple().isOSWindows()) {
     const MachineConstantPoolEntry &CPE =
         MF->getConstantPool()->getConstants()[CPID];
     if (!CPE.isMachineConstantPoolEntry()) {
index b5dd2d4cca8922d8ab9e8e2f7793e5ca4d57870e..149cec2641189da91415578f6601168c18658d58 100644 (file)
@@ -1396,12 +1396,7 @@ static std::string scalarConstantToHexString(const Constant *C) {
 MCSection *TargetLoweringObjectFileCOFF::getSectionForConstant(
     const DataLayout &DL, SectionKind Kind, const Constant *C,
     unsigned &Align) const {
-  if (Kind.isMergeableConst() && C &&
-      getContext().getAsmInfo()->hasCOFFComdatConstants()) {
-    // This creates comdat sections with the given symbol name, but unless
-    // AsmPrinter::GetCPISymbol actually makes the symbol global, the symbol
-    // will be created with a null storage class, which makes GNU binutils
-    // error out.
+  if (Kind.isMergeableConst() && C) {
     const unsigned Characteristics = COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
                                      COFF::IMAGE_SCN_MEM_READ |
                                      COFF::IMAGE_SCN_LNK_COMDAT;
index d8fb875b67c6a6c0a1a157901f0a957373380459..8bb02c3f649c599c13b181fb182505ec5027605f 100644 (file)
@@ -45,11 +45,6 @@ MCAsmInfoCOFF::MCAsmInfoCOFF() {
   // If this is a COFF target, assume that it supports associative comdats. It's
   // part of the spec.
   HasCOFFAssociativeComdats = true;
-
-  // We can generate constants in comdat sections that can be shared,
-  // but in order not to create null typed symbols, we actually need to
-  // make them global symbols as well.
-  HasCOFFComdatConstants = true;
 }
 
 void MCAsmInfoMicrosoft::anchor() {}
@@ -63,7 +58,4 @@ MCAsmInfoGNUCOFF::MCAsmInfoGNUCOFF() {
   // comdats for jump tables, unwind information, and other data associated with
   // a function.
   HasCOFFAssociativeComdats = false;
-
-  // We don't create constants in comdat sections for MinGW.
-  HasCOFFComdatConstants = false;
 }
index 5bcc9194c7962fe423b1695b3faf1cb4a94d7eaf..9e78702980c9bcc689912cb9df05c500bb4b3064 100644 (file)
@@ -1,5 +1,5 @@
 ; RUN: llc < %s -mtriple=aarch64-win32-msvc | FileCheck %s
-; RUN: llc < %s -mtriple=aarch64-win32-gnu | FileCheck -check-prefix=MINGW %s
+; RUN: llc < %s -mtriple=aarch64-win32-gnu | FileCheck %s
 
 define double @double() {
   ret double 0x0000000000800000
@@ -13,12 +13,3 @@ define double @double() {
 ; CHECK:               adrp    x8, __real@0000000000800000
 ; CHECK-NEXT:          ldr     d0, [x8, __real@0000000000800000]
 ; CHECK-NEXT:          ret
-
-; MINGW:              .section        .rdata,"dr"
-; MINGW-NEXT:         .p2align  3
-; MINGW-NEXT: [[LABEL:\.LC.*]]:
-; MINGW-NEXT:         .xword   8388608
-; MINGW:      double:
-; MINGW:               adrp    x8, [[LABEL]]
-; MINGW-NEXT:          ldr     d0, [x8, [[LABEL]]]
-; MINGW-NEXT:          ret
index cf0aa9bccd935e598e89183afc4ea1caf22c1854..30762e9621d4be52c5199beb25efebab0ecef036 100644 (file)
@@ -1,5 +1,5 @@
 ; RUN: llc < %s -mtriple=x86_64-win32 -mattr=sse2 -mattr=avx | FileCheck %s
-; RUN: llc < %s -mtriple=x86_64-win32-gnu -mattr=sse2 -mattr=avx | FileCheck -check-prefix=MINGW %s
+; RUN: llc < %s -mtriple=x86_64-win32-gnu -mattr=sse2 -mattr=avx | FileCheck %s
 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
 target triple = "x86_64-pc-windows-msvc"
 
@@ -15,14 +15,6 @@ define double @double() {
 ; CHECK:               movsd   __real@0000000000800000(%rip), %xmm0
 ; CHECK-NEXT:          ret
 
-; MINGW:              .section        .rdata,"dr"
-; MINGW-NEXT:         .p2align  3
-; MINGW-NEXT: [[LABEL:\.LC.*]]:
-; MINGW-NEXT:         .quad   8388608
-; MINGW:      double:
-; MINGW:               movsd   [[LABEL]](%rip), %xmm0
-; MINGW-NEXT:          ret
-
 define <4 x i32> @vec1() {
   ret <4 x i32> <i32 3, i32 2, i32 1, i32 0>
 }