[llvm] r322425 - [MachineOutliner] Move hasAddressTaken check to MachineOutliner.cpp

Jessica Paquette via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 12 16:42:28 PST 2018


Author: paquette
Date: Fri Jan 12 16:42:28 2018
New Revision: 322425

URL: http://llvm.org/viewvc/llvm-project?rev=322425&view=rev
Log:
[MachineOutliner] Move hasAddressTaken check to MachineOutliner.cpp

*Mostly* NFC. Still updating the test though just for completeness.

This moves the hasAddressTaken check to MachineOutliner.cpp and replaces it
with a per-basic block test rather than a per-function test. The old test was
too conservative and was preventing functions in C programs from being
outlined even though they were safe to outline.

This was mostly a problem in C sources.


Modified:
    llvm/trunk/lib/CodeGen/MachineOutliner.cpp
    llvm/trunk/lib/Target/AArch64/AArch64InstrInfo.cpp
    llvm/trunk/test/CodeGen/AArch64/machine-outliner.mir

Modified: llvm/trunk/lib/CodeGen/MachineOutliner.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineOutliner.cpp?rev=322425&r1=322424&r2=322425&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MachineOutliner.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachineOutliner.cpp Fri Jan 12 16:42:28 2018
@@ -1357,8 +1357,8 @@ bool MachineOutliner::runOnModule(Module
     // If it is, look at each MachineBasicBlock in the function.
     for (MachineBasicBlock &MBB : MF) {
 
-      // Is there anything in MBB?
-      if (MBB.empty())
+      // Is there anything in MBB? And is it the target of an indirect branch?
+      if (MBB.empty() || MBB.hasAddressTaken())
         continue;
 
       // If yes, map it.

Modified: llvm/trunk/lib/Target/AArch64/AArch64InstrInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AArch64/AArch64InstrInfo.cpp?rev=322425&r1=322424&r2=322425&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AArch64/AArch64InstrInfo.cpp (original)
+++ llvm/trunk/lib/Target/AArch64/AArch64InstrInfo.cpp Fri Jan 12 16:42:28 2018
@@ -4779,10 +4779,6 @@ bool AArch64InstrInfo::isFunctionSafeToO
   if (!F.hasFnAttribute(Attribute::NoRedZone))
     return false;
 
-  // If anyone is using the address of this function, don't outline from it.
-  if (F.hasAddressTaken())
-    return false;
-
   // Can F be deduplicated by the linker? If it can, don't outline from it.
   if (!OutlineFromLinkOnceODRs && F.hasLinkOnceODRLinkage())
     return false;

Modified: llvm/trunk/test/CodeGen/AArch64/machine-outliner.mir
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/AArch64/machine-outliner.mir?rev=322425&r1=322424&r2=322425&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/AArch64/machine-outliner.mir (original)
+++ llvm/trunk/test/CodeGen/AArch64/machine-outliner.mir Fri Jan 12 16:42:28 2018
@@ -23,6 +23,7 @@
 # - Don't outline anything to do with LR or W30
 # - Save LR when it's not available
 # - Don't outline stack instructions when we might need to save + restore
+# - Functions whose addresses are taken can still be outlined
 #
 # CHECK-LABEL: name: main
 
@@ -48,6 +49,7 @@ tracksRegLiveness: true
 body:             |
   bb.0:
     %sp = frame-setup SUBXri %sp, 16, 0
+    renamable %x9 = ADRP target-flags(aarch64-page) @bar
     %x9 = ORRXri %xzr, 1
     %w16 = ORRWri %wzr, 1
     %w30 = ORRWri %wzr, 1




More information about the llvm-commits mailing list