[llvm] ca4c1ad - [Outliner] Set nounwind for outlined functions

David Green via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 1 09:18:49 PDT 2020


Author: David Green
Date: 2020-07-01T17:18:34+01:00
New Revision: ca4c1ad854ab9baf510e489d81625cace991beb1

URL: https://github.com/llvm/llvm-project/commit/ca4c1ad854ab9baf510e489d81625cace991beb1
DIFF: https://github.com/llvm/llvm-project/commit/ca4c1ad854ab9baf510e489d81625cace991beb1.diff

LOG: [Outliner] Set nounwind for outlined functions

This prevents the outlined functions from pulling in a lot of unnecessary code
in our downstream libraries/linker. Which stops outlining making codesize
worse in c++ code with no-exceptions.

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

Added: 
    llvm/test/CodeGen/AArch64/machine-outliner-throw.ll
    llvm/test/CodeGen/AArch64/machine-outliner-throw2.ll

Modified: 
    llvm/lib/CodeGen/MachineOutliner.cpp
    llvm/test/CodeGen/AArch64/machine-outliner-retaddr-sign-cfi.ll
    llvm/test/CodeGen/AArch64/machine-outliner-retaddr-sign-same-scope-same-key-b.ll
    llvm/test/CodeGen/AArch64/machine-outliner-retaddr-sign-v8-3.ll
    llvm/test/CodeGen/AArch64/machine-outliner.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/MachineOutliner.cpp b/llvm/lib/CodeGen/MachineOutliner.cpp
index d70638bd3840..f9d099e02995 100644
--- a/llvm/lib/CodeGen/MachineOutliner.cpp
+++ b/llvm/lib/CodeGen/MachineOutliner.cpp
@@ -618,9 +618,6 @@ MachineFunction *MachineOutliner::createOutlinedFunction(
   F->setLinkage(GlobalValue::InternalLinkage);
   F->setUnnamedAddr(GlobalValue::UnnamedAddr::Global);
 
-  // FIXME: Set nounwind, so we don't generate eh_frame? Haven't verified it's
-  // necessary.
-
   // Set optsize/minsize, so we don't insert padding between outlined
   // functions.
   F->addFnAttr(Attribute::OptimizeForSize);
@@ -635,6 +632,12 @@ MachineFunction *MachineOutliner::createOutlinedFunction(
   if (ParentFn.hasFnAttribute("target-features"))
     F->addFnAttr(ParentFn.getFnAttribute("target-features"));
 
+  // Set nounwind, so we don't generate eh_frame.
+  if (llvm::all_of(OF.Candidates, [](const outliner::Candidate &C) {
+        return C.getMF()->getFunction().hasFnAttribute(Attribute::NoUnwind);
+      }))
+    F->addFnAttr(Attribute::NoUnwind);
+
   BasicBlock *EntryBB = BasicBlock::Create(C, "entry", F);
   IRBuilder<> Builder(EntryBB);
   Builder.CreateRetVoid();

diff  --git a/llvm/test/CodeGen/AArch64/machine-outliner-retaddr-sign-cfi.ll b/llvm/test/CodeGen/AArch64/machine-outliner-retaddr-sign-cfi.ll
index 49e538bce172..3b61588f41ed 100644
--- a/llvm/test/CodeGen/AArch64/machine-outliner-retaddr-sign-cfi.ll
+++ b/llvm/test/CodeGen/AArch64/machine-outliner-retaddr-sign-cfi.ll
@@ -82,10 +82,8 @@ define void @c() "sign-return-address"="all" "sign-return-address-key"="b_key" n
 
 ; CHECK:            [[OUTLINED_FUNC]]
 ; CHECK:            // %bb.0:
-; CHECK-NEXT:           .cfi_b_key_frame
 ; V8A-NEXT:             hint #27
 ; V83A-NEXT:            pacibsp
-; CHECK-NEXT:           .cfi_negate_ra_state
 ; V8A:                  hint #31
 ; V83A:                 autibsp
 ; V8A-NEXT, V83A-NEXT:  ret

diff  --git a/llvm/test/CodeGen/AArch64/machine-outliner-retaddr-sign-same-scope-same-key-b.ll b/llvm/test/CodeGen/AArch64/machine-outliner-retaddr-sign-same-scope-same-key-b.ll
index de32f059b807..128ac6dc4b45 100644
--- a/llvm/test/CodeGen/AArch64/machine-outliner-retaddr-sign-same-scope-same-key-b.ll
+++ b/llvm/test/CodeGen/AArch64/machine-outliner-retaddr-sign-same-scope-same-key-b.ll
@@ -72,10 +72,8 @@ define void @c() "sign-return-address"="all" "sign-return-address-key"="b_key" n
 
 ; CHECK-LABEL:      OUTLINED_FUNCTION_0:
 ; CHECK:            // %bb.0:
-; CHECK-NEXT:           .cfi_b_key_frame
 ; V8A-NEXT:             hint #27
 ; V83A-NEXT:            pacibsp
-; CHECK-NEXT:           .cfi_negate_ra_state
 ; V8A:                  hint #31
 ; V83A:                 autibsp
 ; CHECK-NEXT:           ret

diff  --git a/llvm/test/CodeGen/AArch64/machine-outliner-retaddr-sign-v8-3.ll b/llvm/test/CodeGen/AArch64/machine-outliner-retaddr-sign-v8-3.ll
index 5d728aa378f8..2c66bcb6f4e0 100644
--- a/llvm/test/CodeGen/AArch64/machine-outliner-retaddr-sign-v8-3.ll
+++ b/llvm/test/CodeGen/AArch64/machine-outliner-retaddr-sign-v8-3.ll
@@ -77,7 +77,6 @@ attributes #0 = { "sign-return-address"="all"
 
 ; CHECK:            OUTLINED_FUNC
 ; CHECK:            // %bb.0:
-; CHECK-NEXT:               .cfi_b_key_frame
 ; CHECK-NEXT:               pacibsp
 ; CHECK:                    retab
 ; CHECK-NOT:                auti[a,b]sp

diff  --git a/llvm/test/CodeGen/AArch64/machine-outliner-throw.ll b/llvm/test/CodeGen/AArch64/machine-outliner-throw.ll
new file mode 100644
index 000000000000..52d05aa900e3
--- /dev/null
+++ b/llvm/test/CodeGen/AArch64/machine-outliner-throw.ll
@@ -0,0 +1,71 @@
+; RUN: llc -verify-machineinstrs -enable-machine-outliner -mtriple=aarch64-arm-none-eabi < %s | FileCheck %s
+; RUN: llc -verify-machineinstrs -enable-machine-outliner -mtriple=aarch64-arm-none-eabi -stop-after=machine-outliner < %s | FileCheck %s -check-prefix=TARGET_FEATURES
+
+; Make sure that we haven't added nouwind.
+; TARGET_FEATURES: define internal void @OUTLINED_FUNCTION_0()
+; TARGET_FEATURES-SAME: #[[ATTR_NUM:[0-9]+]]
+; TARGET_FEATURES: attributes #[[ATTR_NUM]] = { minsize optsize }
+
+define dso_local i32 @_Z5func1i(i32 %x) #0 {
+; CHECK-LABEL: _Z5func1i:
+; CHECK:       // %bb.0: // %entry
+; CHECK-NEXT:    stp x30, x19, [sp, #-16]! // 16-byte Folded Spill
+; CHECK-NEXT:    .cfi_def_cfa_offset 16
+; CHECK-NEXT:    .cfi_offset w19, -8
+; CHECK-NEXT:    .cfi_offset w30, -16
+; CHECK-NEXT:    orr w8, wzr, #0x1
+; CHECK-NEXT:    madd w19, w0, w0, w8
+; CHECK-NEXT:    mov w0, #4
+; CHECK-NEXT:    bl __cxa_allocate_exception
+; CHECK-NEXT:    bl OUTLINED_FUNCTION_0
+entry:
+  %mul = mul nsw i32 %x, %x
+  %add = add nuw nsw i32 %mul, 1
+  %exception = tail call i8* @__cxa_allocate_exception(i64 4) #1
+  %0 = bitcast i8* %exception to i32*
+  store i32 %add, i32* %0, align 16
+  tail call void @__cxa_throw(i8* %exception, i8* bitcast (i8** @_ZTIi to i8*), i8* null) #2
+  unreachable
+}
+
+define dso_local i32 @_Z5func2c(i8 %x) #0 {
+; CHECK-LABEL: _Z5func2c:
+; CHECK:       // %bb.0: // %entry
+; CHECK-NEXT:    stp x30, x19, [sp, #-16]! // 16-byte Folded Spill
+; CHECK-NEXT:    .cfi_def_cfa_offset 16
+; CHECK-NEXT:    .cfi_offset w19, -8
+; CHECK-NEXT:    .cfi_offset w30, -16
+; CHECK-NEXT:    and w8, w0, #0xff
+; CHECK-NEXT:    orr w9, wzr, #0x1
+; CHECK-NEXT:    mov w0, #4
+; CHECK-NEXT:    madd w19, w8, w8, w9
+; CHECK-NEXT:    bl __cxa_allocate_exception
+; CHECK-NEXT:    bl OUTLINED_FUNCTION_0
+entry:
+  %conv = zext i8 %x to i32
+  %mul = mul nuw nsw i32 %conv, %conv
+  %add = add nuw nsw i32 %mul, 1
+  %exception = tail call i8* @__cxa_allocate_exception(i64 4) #1
+  %0 = bitcast i8* %exception to i32*
+  store i32 %add, i32* %0, align 16
+  tail call void @__cxa_throw(i8* %exception, i8* bitcast (i8** @_ZTIi to i8*), i8* null) #2
+  unreachable
+}
+
+; CHECK-LABEL: OUTLINED_FUNCTION_0:
+; CHECK:      .cfi_startproc
+; CHECK:        adrp    x1, _ZTIi
+; CHECK-NEXT:   add     x1, x1, :lo12:_ZTIi
+; CHECK-NEXT:   mov     x2, xzr
+; CHECK-NEXT:   str     w19, [x0]
+; CHECK-NEXT:   b       __cxa_throw
+; CHECK:      .cfi_endproc
+
+
+ at _ZTIi = external dso_local constant i8*
+declare dso_local i8* @__cxa_allocate_exception(i64) local_unnamed_addr
+declare dso_local void @__cxa_throw(i8*, i8*, i8*) local_unnamed_addr
+
+attributes #0 = { minsize noreturn optsize }
+attributes #1 = { nounwind }
+attributes #2 = { noreturn }

diff  --git a/llvm/test/CodeGen/AArch64/machine-outliner-throw2.ll b/llvm/test/CodeGen/AArch64/machine-outliner-throw2.ll
new file mode 100644
index 000000000000..2ea906fa47ba
--- /dev/null
+++ b/llvm/test/CodeGen/AArch64/machine-outliner-throw2.ll
@@ -0,0 +1,101 @@
+; RUN: llc -verify-machineinstrs -enable-machine-outliner -mtriple=aarch64-arm-none-eabi -frame-pointer=non-leaf < %s | FileCheck %s --check-prefix=NOOMIT
+; RUN: llc -verify-machineinstrs -enable-machine-outliner -mtriple=aarch64-arm-none-eabi -frame-pointer=none < %s | FileCheck %s --check-prefix=OMITFP
+
+define void @_Z1giii(i32 %x, i32 %y, i32 %z) minsize {
+; NOOMIT-LABEL: _Z1giii:
+; NOOMIT:       // %bb.0: // %entry
+; NOOMIT-NEXT:    b _Z1hiii
+;
+; OMITFP-LABEL: _Z1giii:
+; OMITFP:       // %bb.0: // %entry
+; OMITFP-NEXT:    b _Z1hiii
+entry:
+  tail call void @_Z1hiii(i32 %x, i32 %y, i32 %z)
+  ret void
+}
+
+declare void @_Z1hiii(i32, i32, i32) minsize
+
+define void @_Z2f1v() minsize {
+; NOOMIT-LABEL: _Z2f1v:
+; NOOMIT:       // %bb.0: // %entry
+; NOOMIT-NEXT:    stp x29, x30, [sp, #-16]! // 16-byte Folded Spill
+; NOOMIT-NEXT:    mov x29, sp
+; NOOMIT-NEXT:    .cfi_def_cfa w29, 16
+; NOOMIT-NEXT:    .cfi_offset w30, -8
+; NOOMIT-NEXT:    .cfi_offset w29, -16
+; NOOMIT-NEXT:    bl OUTLINED_FUNCTION_0
+; NOOMIT-NEXT:    ldp x29, x30, [sp], #16 // 16-byte Folded Reload
+; NOOMIT-NEXT:    b _Z1giii
+;
+; OMITFP-LABEL: _Z2f1v:
+; OMITFP:       // %bb.0: // %entry
+; OMITFP-NEXT:    str x30, [sp, #-16]! // 8-byte Folded Spill
+; OMITFP-NEXT:    .cfi_def_cfa_offset 16
+; OMITFP-NEXT:    .cfi_offset w30, -16
+; OMITFP-NEXT:    bl OUTLINED_FUNCTION_0
+; OMITFP-NEXT:    ldr x30, [sp], #16 // 8-byte Folded Reload
+; OMITFP-NEXT:    b _Z1giii
+entry:
+  tail call void @_Z1giii(i32 1, i32 2, i32 3)
+  tail call void @_Z1giii(i32 1, i32 2, i32 3)
+  ret void
+}
+
+define void @_Z2f2v() minsize {
+; NOOMIT-LABEL: _Z2f2v:
+; NOOMIT:       // %bb.0: // %entry
+; NOOMIT-NEXT:    stp x29, x30, [sp, #-16]! // 16-byte Folded Spill
+; NOOMIT-NEXT:    mov x29, sp
+; NOOMIT-NEXT:    .cfi_def_cfa w29, 16
+; NOOMIT-NEXT:    .cfi_offset w30, -8
+; NOOMIT-NEXT:    .cfi_offset w29, -16
+; NOOMIT-NEXT:    bl OUTLINED_FUNCTION_0
+; NOOMIT-NEXT:    ldp x29, x30, [sp], #16 // 16-byte Folded Reload
+; NOOMIT-NEXT:    b _Z1giii
+;
+; OMITFP-LABEL: _Z2f2v:
+; OMITFP:       // %bb.0: // %entry
+; OMITFP-NEXT:    str x30, [sp, #-16]! // 8-byte Folded Spill
+; OMITFP-NEXT:    .cfi_def_cfa_offset 16
+; OMITFP-NEXT:    .cfi_offset w30, -16
+; OMITFP-NEXT:    bl OUTLINED_FUNCTION_0
+; OMITFP-NEXT:    ldr x30, [sp], #16 // 8-byte Folded Reload
+; OMITFP-NEXT:    b _Z1giii
+entry:
+  tail call void @_Z1giii(i32 1, i32 2, i32 3)
+  tail call void @_Z1giii(i32 1, i32 2, i32 3)
+  ret void
+}
+
+; OMITFP-LABEL: OUTLINED_FUNCTION_0:
+; OMITFP:              .cfi_startproc
+; OMITFP-NEXT: // %bb.0:
+; OMITFP-NEXT:         .cfi_def_cfa_offset 16
+; OMITFP-NEXT:         .cfi_offset w30, -16
+; OMITFP-NEXT:         str     x30, [sp, #-16]!
+; OMITFP-NEXT:         mov     w0, #1
+; OMITFP-NEXT:         mov     w1, #2
+; OMITFP-NEXT:         mov     w2, #3
+; OMITFP-NEXT:         bl      _Z1giii
+; OMITFP-NEXT:         mov     w0, #1
+; OMITFP-NEXT:         mov     w1, #2
+; OMITFP-NEXT:         mov     w2, #3
+; OMITFP-NEXT:         ldr     x30, [sp], #16
+; OMITFP-NEXT:         ret
+
+; NOOMIT-LABEL: OUTLINED_FUNCTION_0:
+; NOOMIT:              .cfi_startproc
+; NOOMIT-NEXT: // %bb.0:
+; NOOMIT-NEXT:         .cfi_def_cfa_offset 16
+; NOOMIT-NEXT:         .cfi_offset w30, -16
+; NOOMIT-NEXT:         str     x30, [sp, #-16]!
+; NOOMIT-NEXT:         mov     w0, #1
+; NOOMIT-NEXT:         mov     w1, #2
+; NOOMIT-NEXT:         mov     w2, #3
+; NOOMIT-NEXT:         bl      _Z1giii
+; NOOMIT-NEXT:         mov     w0, #1
+; NOOMIT-NEXT:         mov     w1, #2
+; NOOMIT-NEXT:         mov     w2, #3
+; NOOMIT-NEXT:         ldr     x30, [sp], #16
+; NOOMIT-NEXT:         ret

diff  --git a/llvm/test/CodeGen/AArch64/machine-outliner.ll b/llvm/test/CodeGen/AArch64/machine-outliner.ll
index 6c76f894c856..3d1c7357b967 100644
--- a/llvm/test/CodeGen/AArch64/machine-outliner.ll
+++ b/llvm/test/CodeGen/AArch64/machine-outliner.ll
@@ -9,6 +9,7 @@
 ; TARGET_FEATURES-SAME: #[[ATTR_NUM:[0-9]+]]
 ; TARGET_FEATURES-DAG: attributes #[[ATTR_NUM]] = {
 ; TARGET_FEATURES-SAME: minsize
+; TARGET_FEATURES-SAME: nounwind
 ; TARGET_FEATURES-SAME: optsize
 ; TARGET_FEATURES-SAME: "target-features"="+sse"
 
@@ -103,4 +104,4 @@ define void @dog() #0 {
 ; CHECK-DAG: add     sp, sp, #32
 ; CHECK-DAG: ret
 
-attributes #0 = { noredzone "target-cpu"="cyclone" "target-features"="+sse" }
+attributes #0 = { nounwind noredzone "target-cpu"="cyclone" "target-features"="+sse" }


        


More information about the llvm-commits mailing list