From e3932eeea4d10d6835fef10e13b15144fedec6fb Mon Sep 17 00:00:00 2001 From: Jessica Paquette Date: Mon, 29 Oct 2018 20:27:07 +0000 Subject: [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. llvm-svn: 345535 --- llvm/lib/CodeGen/MachineOutliner.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'llvm/lib/CodeGen/MachineOutliner.cpp') diff --git a/llvm/lib/CodeGen/MachineOutliner.cpp b/llvm/lib/CodeGen/MachineOutliner.cpp index 4b65d97..0085636 100644 --- a/llvm/lib/CodeGen/MachineOutliner.cpp +++ b/llvm/lib/CodeGen/MachineOutliner.cpp @@ -1202,6 +1202,14 @@ MachineOutliner::createOutlinedFunction(Module &M, const OutlinedFunction &OF, 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(); -- cgit v1.1