[Hexagon] Place globals with explicit .sdata section in small data
authorKrzysztof Parzyszek <kparzysz@codeaurora.org>
Fri, 9 Nov 2018 17:31:22 +0000 (17:31 +0000)
committerKrzysztof Parzyszek <kparzysz@codeaurora.org>
Fri, 9 Nov 2018 17:31:22 +0000 (17:31 +0000)
Both -fPIC and -G0 disable placement of globals in small data section,
but if a global has an explicit section assigmnent placing it in small
data, it should go there anyway.

llvm-svn: 346523

llvm/lib/Target/Hexagon/HexagonTargetObjectFile.cpp
llvm/test/CodeGen/Hexagon/sdata-explicit-section.ll [new file with mode: 0644]

index 386cd14c827beaf3e6cb7e03dd8b332f5162a3cf..2185bf8eebc66d0fab86786a6e68bd5ae9748e7c 100644 (file)
@@ -199,11 +199,10 @@ MCSection *HexagonTargetObjectFile::getExplicitSectionGlobal(
 /// section.
 bool HexagonTargetObjectFile::isGlobalInSmallSection(const GlobalObject *GO,
       const TargetMachine &TM) const {
-  if (!isSmallDataEnabled(TM)) {
-    LLVM_DEBUG(dbgs() << "Small data is not available.\n");
-    return false;
-  }
-
+  bool HaveSData = isSmallDataEnabled(TM);
+  if (!HaveSData)
+    LLVM_DEBUG(dbgs() << "Small-data allocation is disabled, but symbols "
+                         "may have explicit section assignments...\n");
   // Only global variables, not functions.
   LLVM_DEBUG(dbgs() << "Checking if value is in small-data, -G"
                     << SmallDataThreshold << ": \"" << GO->getName() << "\": ");
@@ -223,6 +222,12 @@ bool HexagonTargetObjectFile::isGlobalInSmallSection(const GlobalObject *GO,
     return IsSmall;
   }
 
+  // If sdata is disabled, stop the checks here.
+  if (!HaveSData) {
+    LLVM_DEBUG(dbgs() << "no, small-data allocation is disabled\n");
+    return false;
+  }
+
   if (GVar->isConstant()) {
     LLVM_DEBUG(dbgs() << "no, is a constant\n");
     return false;
diff --git a/llvm/test/CodeGen/Hexagon/sdata-explicit-section.ll b/llvm/test/CodeGen/Hexagon/sdata-explicit-section.ll
new file mode 100644 (file)
index 0000000..807474f
--- /dev/null
@@ -0,0 +1,6 @@
+; RUN: llc -march=hexagon -hexagon-small-data-threshold=0 < %s | FileCheck %s
+; RUN: llc -march=hexagon -relocation-model=pic < %s | FileCheck %s
+
+; CHECK: .section .sdata.4,"aws",@progbits
+@g0 = global i32 zeroinitializer, section ".sdata"
+