llvm.org GIT mirror llvm / 516286f
Use function attribute "trap-func-name" and remove TargetOptions::TrapFuncName. This commit changes normal isel and fast isel to read the user-defined trap function name from function attribute "trap-func-name" attached to llvm.trap or llvm.debugtrap instead of from TargetOptions::TrapFuncName. This is needed to use clang's command line option "-ftrap-function" for LTO and enable changing the trap function name on a per-call-site basis. Out-of-tree projects currently using TargetOptions::TrapFuncName to specify the trap function name should attach attribute "trap-func-name" to the call sites of llvm.trap and llvm.debugtrap instead. rdar://problem/21225723 Differential Revision: http://reviews.llvm.org/D10832 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241305 91177308-0d34-0410-b5e6-96231b3b80d8 Akira Hatanaka 5 years ago
6 changed file(s) with 58 addition(s) and 18 deletion(s). Raw diff Collapse all Expand all
1616 #define LLVM_CODEGEN_COMMANDFLAGS_H
1717
1818 #include "llvm/ADT/StringExtras.h"
19 #include "llvm/IR/Instructions.h"
20 #include "llvm/IR/Intrinsics.h"
1921 #include "llvm/IR/Module.h"
2022 #include "llvm/MC/MCTargetOptionsCommandFlags.h"
2123 #include "llvm//MC/SubtargetFeature.h"
248250 Options.NoZerosInBSS = DontPlaceZerosInBSS;
249251 Options.GuaranteedTailCallOpt = EnableGuaranteedTailCallOpt;
250252 Options.StackAlignmentOverride = OverrideStackAlignment;
251 Options.TrapFuncName = TrapFuncName;
252253 Options.PositionIndependentExecutable = EnablePIE;
253254 Options.UseInitArray = !UseCtors;
254255 Options.DataSections = DataSections;
319320 "disable-tail-calls",
320321 toStringRef(DisableTailCalls));
321322
323 if (TrapFuncName.getNumOccurrences() > 0)
324 for (auto &B : F)
325 for (auto &I : B)
326 if (auto *Call = dyn_cast(&I))
327 if (const auto *F = Call->getCalledFunction())
328 if (F->getIntrinsicID() == Intrinsic::debugtrap ||
329 F->getIntrinsicID() == Intrinsic::trap)
330 Call->addAttribute(llvm::AttributeSet::FunctionIndex,
331 "trap-func-name", TrapFuncName);
332
322333 // Let NewAttrs override Attrs.
323334 NewAttrs = Attrs.addAttributes(Ctx, AttributeSet::FunctionIndex, NewAttrs);
324335 F.setAttributes(NewAttrs);
7171 UseInitArray(false), DisableIntegratedAS(false),
7272 CompressDebugSections(false), FunctionSections(false),
7373 DataSections(false), UniqueSectionNames(true), TrapUnreachable(false),
74 TrapFuncName(), FloatABIType(FloatABI::Default),
74 FloatABIType(FloatABI::Default),
7575 AllowFPOpFusion(FPOpFusion::Standard), Reciprocals(TargetRecip()),
7676 JTType(JumpTable::Single),
7777 ThreadModel(ThreadModel::POSIX) {}
170170
171171 /// Emit target-specific trap instruction for 'unreachable' IR instructions.
172172 unsigned TrapUnreachable : 1;
173
174 /// getTrapFunctionName - If this returns a non-empty string, this means
175 /// isel should lower Intrinsic::trap to a call to the specified function
176 /// name instead of an ISD::TRAP node.
177 std::string TrapFuncName;
178 StringRef getTrapFunctionName() const;
179173
180174 /// FloatABIType - This setting is set by -float-abi=xxx option is specfied
181175 /// on the command line. This setting may either be Default, Soft, or Hard.
236230 ARE_EQUAL(PositionIndependentExecutable) &&
237231 ARE_EQUAL(UseInitArray) &&
238232 ARE_EQUAL(TrapUnreachable) &&
239 ARE_EQUAL(TrapFuncName) &&
240233 ARE_EQUAL(FloatABIType) &&
241234 ARE_EQUAL(AllowFPOpFusion) &&
242235 ARE_EQUAL(Reciprocals) &&
13491349
13501350 // Don't handle Intrinsic::trap if a trap funciton is specified.
13511351 if (F && F->getIntrinsicID() == Intrinsic::trap &&
1352 !TM.Options.getTrapFunctionName().empty())
1352 Call->hasFnAttr("trap-func-name"))
13531353 return false;
13541354 }
13551355
47794779
47804780 case Intrinsic::debugtrap:
47814781 case Intrinsic::trap: {
4782 StringRef TrapFuncName = TM.Options.getTrapFunctionName();
4782 StringRef TrapFuncName =
4783 I.getAttributes()
4784 .getAttribute(AttributeSet::FunctionIndex, "trap-func-name")
4785 .getValueAsString();
47834786 if (TrapFuncName.empty()) {
47844787 ISD::NodeType Op = (Intrinsic == Intrinsic::trap) ?
47854788 ISD::TRAP : ISD::DEBUGTRAP;
4646 bool TargetOptions::HonorSignDependentRoundingFPMath() const {
4747 return !UnsafeFPMath && HonorSignDependentRoundingFPMathOption;
4848 }
49
50 /// getTrapFunctionName - If this returns a non-empty string, this means isel
51 /// should lower Intrinsic::trap to a call to the specified function name
52 /// instead of an ISD::TRAP node.
53 StringRef TargetOptions::getTrapFunctionName() const {
54 return TrapFuncName;
55 }
0 ; RUN: llc < %s -march arm | FileCheck %s -check-prefix=NOOPTION
1 ; RUN: llc < %s -march arm -trap-func=trap_llc | FileCheck %s -check-prefix=TRAP
2
3 ; NOOPTION-LABEL: {{\_?}}foo0:
4 ; NOOPTION: trap{{$}}
5
6 ; TRAP-LABEL: {{\_?}}foo0:
7 ; TRAP: bl {{\_?}}trap_llc
8
9 define void @foo0() {
10 call void @llvm.trap()
11 unreachable
12 }
13
14 ; NOOPTION-LABEL: {{\_?}}foo1:
15 ; NOOPTION: bl {{\_?}}trap_func_attr0
16
17 ; TRAP-LABEL: {{\_?}}foo1:
18 ; TRAP: bl {{\_?}}trap_llc
19
20 define void @foo1() {
21 call void @llvm.trap() #0
22 unreachable
23 }
24
25 ; NOOPTION-LABEL: {{\_?}}foo2:
26 ; NOOPTION: bl {{\_?}}trap_func_attr1
27
28 ; TRAP-LABEL: {{\_?}}foo2:
29 ; TRAP: bl {{\_?}}trap_llc
30
31 define void @foo2() {
32 call void @llvm.trap() #1
33 unreachable
34 }
35
36 declare void @llvm.trap() nounwind
37
38 attributes #0 = { "trap-func-name"="trap_func_attr0" }
39 attributes #1 = { "trap-func-name"="trap_func_attr1" }