From 8077d0ff5c662dacbc69831a2c5acff10b759c48 Mon Sep 17 00:00:00 2001 From: Snehasish Kumar Date: Wed, 21 Apr 2021 14:41:12 -0700 Subject: [PATCH] [CodeGen] Do not split functions with attr "implicit-section-name". The #pragma clang section can be used at a coarse granularity to specify the section used for bss/data/text/rodata for global objects. When split functions is enabled, the function may be split into two parts violating user expectations. Reference: https://clang.llvm.org/docs/LanguageExtensions.html#specifying-section-names-for-global-objects-pragma-clang-section Differential Revision: https://reviews.llvm.org/D101004 --- llvm/lib/CodeGen/MachineFunctionSplitter.cpp | 3 ++- llvm/test/CodeGen/X86/machine-function-splitter.ll | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/llvm/lib/CodeGen/MachineFunctionSplitter.cpp b/llvm/lib/CodeGen/MachineFunctionSplitter.cpp index 294e3c2..2bb69e0 100644 --- a/llvm/lib/CodeGen/MachineFunctionSplitter.cpp +++ b/llvm/lib/CodeGen/MachineFunctionSplitter.cpp @@ -101,7 +101,8 @@ bool MachineFunctionSplitter::runOnMachineFunction(MachineFunction &MF) { // since the split part may not be placed in a contiguous region. It may also // be more beneficial to augment the linker to ensure contiguous layout of // split functions within the same section as specified by the attribute. - if (!MF.getFunction().getSection().empty()) + if (!MF.getFunction().getSection().empty() || + MF.getFunction().hasFnAttribute("implicit-section-name")) return false; // We don't want to proceed further for cold functions diff --git a/llvm/test/CodeGen/X86/machine-function-splitter.ll b/llvm/test/CodeGen/X86/machine-function-splitter.ll index b4721ac..dfdf69b 100644 --- a/llvm/test/CodeGen/X86/machine-function-splitter.ll +++ b/llvm/test/CodeGen/X86/machine-function-splitter.ll @@ -223,6 +223,26 @@ exit: ret i32 %5 } +define void @foo9(i1 zeroext %0) nounwind #0 !prof !14 { +;; Check that function with section attribute is not split. +; MFS-DEFAULTS-LABEL: foo9 +; MFS-DEFAULTS-NOT: foo9.cold: + br i1 %0, label %2, label %4, !prof !17 + +2: ; preds = %1 + %3 = call i32 @bar() + br label %6 + +4: ; preds = %1 + %5 = call i32 @baz() + br label %6 + +6: ; preds = %4, %2 + %7 = tail call i32 @qux() + ret void +} + + declare i32 @bar() declare i32 @baz() declare i32 @bam() @@ -232,6 +252,8 @@ declare i32 @__gxx_personality_v0(...) @_ZTIi = external constant i8* +attributes #0 = { "implicit-section-name"="nosplit" } + !llvm.module.flags = !{!0} !0 = !{i32 1, !"ProfileSummary", !1} !1 = !{!2, !3, !4, !5, !6, !7, !8, !9} -- 2.7.4