[llvm] 11f47b7 - [OpenMP] Make offloading sections have the SHF_EXCLUDE flag
Joseph Huber via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 14 07:51:05 PDT 2022
Author: Joseph Huber
Date: 2022-04-14T10:50:49-04:00
New Revision: 11f47b791f96ca04b4cf9233d72febc704606dcf
URL: https://github.com/llvm/llvm-project/commit/11f47b791f96ca04b4cf9233d72febc704606dcf
DIFF: https://github.com/llvm/llvm-project/commit/11f47b791f96ca04b4cf9233d72febc704606dcf.diff
LOG: [OpenMP] Make offloading sections have the SHF_EXCLUDE flag
Offloading sections can be embedded in the host during codegen via a
section. This section was originally marked as metadata to prevent it
from being loaded, but these sections are completely unused at runtime
so the linker should automatically drop them from the final executable
or shard library. This flag adds support for the SHF_EXCLUDE flag in
target lowering and uses it.
Reviewed By: JonChesterfield, MaskRay
Differential Revision: https://reviews.llvm.org/D122987
Added:
Modified:
llvm/include/llvm/MC/SectionKind.h
llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
llvm/test/CodeGen/X86/offload_sections.ll
Removed:
################################################################################
diff --git a/llvm/include/llvm/MC/SectionKind.h b/llvm/include/llvm/MC/SectionKind.h
index 0fd86cc457deb..61e400fe9edee 100644
--- a/llvm/include/llvm/MC/SectionKind.h
+++ b/llvm/include/llvm/MC/SectionKind.h
@@ -24,6 +24,10 @@ class SectionKind {
/// Metadata - Debug info sections or other metadata.
Metadata,
+ /// Exclude - This section will be excluded from the final executable or
+ /// shared library. Only valid for ELF / COFF targets.
+ Exclude,
+
/// Text - Text section, used for functions and other executable code.
Text,
@@ -118,6 +122,8 @@ class SectionKind {
bool isMetadata() const { return K == Metadata; }
+ bool isExclude() const { return K == Exclude; }
+
bool isText() const { return K == Text || K == ExecuteOnly; }
bool isExecuteOnly() const { return K == ExecuteOnly; }
@@ -180,6 +186,7 @@ class SectionKind {
public:
static SectionKind getMetadata() { return get(Metadata); }
+ static SectionKind getExclude() { return get(Exclude); }
static SectionKind getText() { return get(Text); }
static SectionKind getExecuteOnly() { return get(ExecuteOnly); }
static SectionKind getReadOnly() { return get(ReadOnly); }
diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
index 3b21e945d8def..3246d77f59c13 100644
--- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -446,10 +446,12 @@ static SectionKind getELFKindForNamedSection(StringRef Name, SectionKind K) {
/*AddSegmentInfo=*/false) ||
Name == getInstrProfSectionName(IPSK_covfun, Triple::ELF,
/*AddSegmentInfo=*/false) ||
- Name == ".llvmbc" || Name == ".llvmcmd" ||
- Name.startswith(".llvm.offloading."))
+ Name == ".llvmbc" || Name == ".llvmcmd")
return SectionKind::getMetadata();
+ if (Name.startswith(".llvm.offloading"))
+ return SectionKind::getExclude();
+
if (Name.empty() || Name[0] != '.') return K;
// Default implementation based on some magic section names.
@@ -508,9 +510,12 @@ static unsigned getELFSectionType(StringRef Name, SectionKind K) {
static unsigned getELFSectionFlags(SectionKind K) {
unsigned Flags = 0;
- if (!K.isMetadata())
+ if (!K.isMetadata() && !K.isExclude())
Flags |= ELF::SHF_ALLOC;
+ if (K.isExclude())
+ Flags |= ELF::SHF_EXCLUDE;
+
if (K.isText())
Flags |= ELF::SHF_EXECINSTR;
@@ -1534,6 +1539,9 @@ getCOFFSectionFlags(SectionKind K, const TargetMachine &TM) {
if (K.isMetadata())
Flags |=
COFF::IMAGE_SCN_MEM_DISCARDABLE;
+ else if (K.isExclude())
+ Flags |=
+ COFF::IMAGE_SCN_LNK_REMOVE | COFF::IMAGE_SCN_MEM_DISCARDABLE;
else if (K.isText())
Flags |=
COFF::IMAGE_SCN_MEM_EXECUTE |
diff --git a/llvm/test/CodeGen/X86/offload_sections.ll b/llvm/test/CodeGen/X86/offload_sections.ll
index dcd6dcb7cf3fc..5c98824992093 100644
--- a/llvm/test/CodeGen/X86/offload_sections.ll
+++ b/llvm/test/CodeGen/X86/offload_sections.ll
@@ -1,6 +1,8 @@
-; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu | FileCheck %s
+; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu | FileCheck %s --check-prefix=CHECK-ELF
+; RUN: llc < %s -mtriple=x86_64-win32-gnu | FileCheck %s --check-prefix=CHECK-COFF
- at llvm.embedded.object = hidden constant [1 x i8] c"\00", section ".llvm.offloading.dummy"
+ at llvm.embedded.object = private constant [1 x i8] c"\00", section ".llvm.offloading"
@llvm.compiler.used = appending global [1 x i8*] [i8* getelementptr inbounds ([1 x i8], [1 x i8]* @llvm.embedded.object, i32 0, i32 0)], section "llvm.metadata"
-; CHECK-DAG: .section .llvm.offloading.dummy,""
+; CHECK-ELF: .section .llvm.offloading,"e"
+; CHECK-COFF: .section .llvm.offloading,"dr"
More information about the llvm-commits
mailing list