[llvm] r345535 - [MachineOutliner] Inherit target features from parent function
Jessica Paquette via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 29 13:27:07 PDT 2018
Author: paquette
Date: Mon Oct 29 13:27:07 2018
New Revision: 345535
URL: http://llvm.org/viewvc/llvm-project?rev=345535&view=rev
Log:
[MachineOutliner] Inherit target features from parent function
If a function has target features, it may contain instructions that aren't
represented in the default set of instructions. If the outliner pulls out one
of these instructions, and the function doesn't have the right attributes
attached, we'll run into an LLVM error explaining that the target doesn't
support the necessary feature for the instruction.
This makes outlined functions inherit target features from their parents.
It also updates the machine-outliner.ll test to check that we're properly
inheriting target features.
Modified:
llvm/trunk/lib/CodeGen/MachineOutliner.cpp
llvm/trunk/test/CodeGen/AArch64/machine-outliner.ll
Modified: llvm/trunk/lib/CodeGen/MachineOutliner.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineOutliner.cpp?rev=345535&r1=345534&r2=345535&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MachineOutliner.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachineOutliner.cpp Mon Oct 29 13:27:07 2018
@@ -1202,6 +1202,14 @@ MachineOutliner::createOutlinedFunction(
F->addFnAttr(Attribute::OptimizeForSize);
F->addFnAttr(Attribute::MinSize);
+ // Include target features from an arbitrary candidate for the outlined
+ // function. This makes sure the outlined function knows what kinds of
+ // instructions are going into it. This is fine, since all parent functions
+ // must necessarily support the instructions that are in the outlined region.
+ const Function &ParentFn = OF.Candidates.front()->getMF()->getFunction();
+ if (ParentFn.hasFnAttribute("target-features"))
+ F->addFnAttr(ParentFn.getFnAttribute("target-features"));
+
BasicBlock *EntryBB = BasicBlock::Create(C, "entry", F);
IRBuilder<> Builder(EntryBB);
Builder.CreateRetVoid();
Modified: llvm/trunk/test/CodeGen/AArch64/machine-outliner.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/AArch64/machine-outliner.ll?rev=345535&r1=345534&r2=345535&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/AArch64/machine-outliner.ll (original)
+++ llvm/trunk/test/CodeGen/AArch64/machine-outliner.ll Mon Oct 29 13:27:07 2018
@@ -1,6 +1,16 @@
; RUN: llc -verify-machineinstrs -enable-machine-outliner -mtriple=aarch64-apple-darwin < %s | FileCheck %s
; RUN: llc -verify-machineinstrs -enable-machine-outliner -mtriple=aarch64-apple-darwin -mcpu=cortex-a53 -enable-misched=false < %s | FileCheck %s
; RUN: llc -verify-machineinstrs -enable-machine-outliner -enable-linkonceodr-outlining -mtriple=aarch64-apple-darwin < %s | FileCheck %s -check-prefix=ODR
+; RUN: llc -verify-machineinstrs -enable-machine-outliner -mtriple=aarch64-apple-darwin -stop-after=machine-outliner < %s | FileCheck %s -check-prefix=TARGET_FEATURES
+
+; Make sure that we inherit target features from functions and make sure we have
+; the right function attributes.
+; TARGET_FEATURES: define internal void @OUTLINED_FUNCTION_{{[0-9]+}}()
+; TARGET_FEATURES-SAME: #[[ATTR_NUM:[0-9]+]]
+; TARGET_FEATURES-DAG: attributes #[[ATTR_NUM]] = {
+; TARGET_FEATURES-SAME: minsize
+; TARGET_FEATURES-SAME: optsize
+; TARGET_FEATURES-SAME: "target-features"="+sse"
define linkonce_odr void @fish() #0 {
; CHECK-LABEL: _fish:
@@ -95,4 +105,4 @@ define void @dog() #0 {
; CHECK-NEXT: str w8, [sp, #8]
; CHECK-NEXT: ret
-attributes #0 = { noredzone "target-cpu"="cyclone" }
+attributes #0 = { noredzone "target-cpu"="cyclone" "target-features"="+sse" }
More information about the llvm-commits
mailing list