llvm.org GIT mirror llvm / 1114aa2
Move EH-specific helper functions to a more appropriate place No functionality change is intended. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@254562 91177308-0d34-0410-b5e6-96231b3b80d8 David Majnemer 4 years ago
20 changed file(s) with 100 addition(s) and 147 deletion(s). Raw diff Collapse all Expand all
0 //===- EHPersonalities.h - Compute EH-related information -----------------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LLVM_ANALYSIS_LIBCALLSEMANTICS_H
10 #define LLVM_ANALYSIS_LIBCALLSEMANTICS_H
11
12 #include "llvm/Support/ErrorHandling.h"
13
14 namespace llvm {
15 class Function;
16 class Value;
17
18 enum class EHPersonality {
19 Unknown,
20 GNU_Ada,
21 GNU_C,
22 GNU_CXX,
23 GNU_ObjC,
24 MSVC_X86SEH,
25 MSVC_Win64SEH,
26 MSVC_CXX,
27 CoreCLR
28 };
29
30 /// \brief See if the given exception handling personality function is one
31 /// that we understand. If so, return a description of it; otherwise return
32 /// Unknown.
33 EHPersonality classifyEHPersonality(const Value *Pers);
34
35 /// \brief Returns true if this personality function catches asynchronous
36 /// exceptions.
37 inline bool isAsynchronousEHPersonality(EHPersonality Pers) {
38 // The two SEH personality functions can catch asynch exceptions. We assume
39 // unknown personalities don't catch asynch exceptions.
40 switch (Pers) {
41 case EHPersonality::MSVC_X86SEH:
42 case EHPersonality::MSVC_Win64SEH:
43 return true;
44 default:
45 return false;
46 }
47 llvm_unreachable("invalid enum");
48 }
49
50 /// \brief Returns true if this is a personality function that invokes
51 /// handler funclets (which must return to it).
52 inline bool isFuncletEHPersonality(EHPersonality Pers) {
53 switch (Pers) {
54 case EHPersonality::MSVC_CXX:
55 case EHPersonality::MSVC_X86SEH:
56 case EHPersonality::MSVC_Win64SEH:
57 case EHPersonality::CoreCLR:
58 return true;
59 default:
60 return false;
61 }
62 llvm_unreachable("invalid enum");
63 }
64
65 /// \brief Return true if this personality may be safely removed if there
66 /// are no invoke instructions remaining in the current function.
67 inline bool isNoOpWithoutInvoke(EHPersonality Pers) {
68 switch (Pers) {
69 case EHPersonality::Unknown:
70 return false;
71 // All known personalities currently have this behavior
72 default:
73 return true;
74 }
75 llvm_unreachable("invalid enum");
76 }
77
78 bool canSimplifyInvokeNoUnwind(const Function *F);
79
80 } // end namespace llvm
81
82 #endif
+0
-84
include/llvm/Analysis/LibCallSemantics.h less more
None //===- LibCallSemantics.h - Describe library semantics --------------------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines interfaces that can be used to describe language specific
10 // runtime library interfaces (e.g. libc, libm, etc) to LLVM optimizers.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_ANALYSIS_LIBCALLSEMANTICS_H
15 #define LLVM_ANALYSIS_LIBCALLSEMANTICS_H
16
17 #include "llvm/Analysis/AliasAnalysis.h"
18
19 namespace llvm {
20 class InvokeInst;
21
22 enum class EHPersonality {
23 Unknown,
24 GNU_Ada,
25 GNU_C,
26 GNU_CXX,
27 GNU_ObjC,
28 MSVC_X86SEH,
29 MSVC_Win64SEH,
30 MSVC_CXX,
31 CoreCLR
32 };
33
34 /// \brief See if the given exception handling personality function is one
35 /// that we understand. If so, return a description of it; otherwise return
36 /// Unknown.
37 EHPersonality classifyEHPersonality(const Value *Pers);
38
39 /// \brief Returns true if this personality function catches asynchronous
40 /// exceptions.
41 inline bool isAsynchronousEHPersonality(EHPersonality Pers) {
42 // The two SEH personality functions can catch asynch exceptions. We assume
43 // unknown personalities don't catch asynch exceptions.
44 switch (Pers) {
45 case EHPersonality::MSVC_X86SEH:
46 case EHPersonality::MSVC_Win64SEH:
47 return true;
48 default: return false;
49 }
50 llvm_unreachable("invalid enum");
51 }
52
53 /// \brief Returns true if this is a personality function that invokes
54 /// handler funclets (which must return to it).
55 inline bool isFuncletEHPersonality(EHPersonality Pers) {
56 switch (Pers) {
57 case EHPersonality::MSVC_CXX:
58 case EHPersonality::MSVC_X86SEH:
59 case EHPersonality::MSVC_Win64SEH:
60 case EHPersonality::CoreCLR:
61 return true;
62 default: return false;
63 }
64 llvm_unreachable("invalid enum");
65 }
66
67 /// \brief Return true if this personality may be safely removed if there
68 /// are no invoke instructions remaining in the current function.
69 inline bool isNoOpWithoutInvoke(EHPersonality Pers) {
70 switch (Pers) {
71 case EHPersonality::Unknown:
72 return false;
73 // All known personalities currently have this behavior
74 default: return true;
75 }
76 llvm_unreachable("invalid enum");
77 }
78
79 bool canSimplifyInvokeNoUnwind(const Function *F);
80
81 } // end namespace llvm
82
83 #endif
3434 #include "llvm/ADT/PointerIntPair.h"
3535 #include "llvm/ADT/SmallPtrSet.h"
3636 #include "llvm/ADT/SmallVector.h"
37 #include "llvm/Analysis/LibCallSemantics.h"
37 #include "llvm/Analysis/EHPersonalities.h"
3838 #include "llvm/IR/DebugLoc.h"
3939 #include "llvm/IR/Metadata.h"
4040 #include "llvm/IR/ValueHandle.h"
2121 namespace llvm {
2222 class AllocaInst;
2323 class BasicBlock;
24 class CatchReturnInst;
2425 class Constant;
2526 class Function;
2627 class GlobalVariable;
2424 DivergenceAnalysis.cpp
2525 DomPrinter.cpp
2626 DominanceFrontier.cpp
27 EHPersonalities.cpp
2728 GlobalsModRef.cpp
2829 IVUsers.cpp
2930 InlineCost.cpp
3435 IteratedDominanceFrontier.cpp
3536 LazyCallGraph.cpp
3637 LazyValueInfo.cpp
37 LibCallSemantics.cpp
3838 Lint.cpp
3939 Loads.cpp
4040 LoopAccessAnalysis.cpp
+0
-47
lib/Analysis/LibCallSemantics.cpp less more
None //===- LibCallSemantics.cpp - Describe library semantics ------------------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements interfaces that can be used to describe language
10 // specific runtime library interfaces (e.g. libc, libm, etc) to LLVM
11 // optimizers.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #include "llvm/Analysis/LibCallSemantics.h"
16 #include "llvm/ADT/StringSwitch.h"
17 #include "llvm/IR/Function.h"
18 using namespace llvm;
19
20 /// See if the given exception handling personality function is one that we
21 /// understand. If so, return a description of it; otherwise return Unknown.
22 EHPersonality llvm::classifyEHPersonality(const Value *Pers) {
23 const Function *F =
24 Pers ? dyn_cast(Pers->stripPointerCasts()) : nullptr;
25 if (!F)
26 return EHPersonality::Unknown;
27 return StringSwitch(F->getName())
28 .Case("__gnat_eh_personality", EHPersonality::GNU_Ada)
29 .Case("__gxx_personality_v0", EHPersonality::GNU_CXX)
30 .Case("__gcc_personality_v0", EHPersonality::GNU_C)
31 .Case("__objc_personality_v0", EHPersonality::GNU_ObjC)
32 .Case("_except_handler3", EHPersonality::MSVC_X86SEH)
33 .Case("_except_handler4", EHPersonality::MSVC_X86SEH)
34 .Case("__C_specific_handler", EHPersonality::MSVC_Win64SEH)
35 .Case("__CxxFrameHandler3", EHPersonality::MSVC_CXX)
36 .Case("ProcessCLRException", EHPersonality::CoreCLR)
37 .Default(EHPersonality::Unknown);
38 }
39
40 bool llvm::canSimplifyInvokeNoUnwind(const Function *F) {
41 EHPersonality Personality = classifyEHPersonality(F->getPersonalityFn());
42 // We can't simplify any invokes to nounwind functions if the personality
43 // function wants to catch asynch exceptions. The nounwind attribute only
44 // implies that the function does not throw synchronous exceptions.
45 return !isAsynchronousEHPersonality(Personality);
46 }
1515 #include "llvm/ADT/BitVector.h"
1616 #include "llvm/ADT/Statistic.h"
1717 #include "llvm/Analysis/CFG.h"
18 #include "llvm/Analysis/LibCallSemantics.h"
18 #include "llvm/Analysis/EHPersonalities.h"
1919 #include "llvm/Analysis/TargetTransformInfo.h"
2020 #include "llvm/IR/Dominators.h"
2121 #include "llvm/IR/Function.h"
1616 #include "llvm/ADT/STLExtras.h"
1717 #include "llvm/ADT/SmallString.h"
1818 #include "llvm/Analysis/ConstantFolding.h"
19 #include "llvm/Analysis/LibCallSemantics.h"
19 #include "llvm/Analysis/EHPersonalities.h"
2020 #include "llvm/CodeGen/MachineConstantPool.h"
2121 #include "llvm/CodeGen/MachineFrameInfo.h"
2222 #include "llvm/CodeGen/MachineFunctionInitializer.h"
99 #include "llvm/CodeGen/MachineModuleInfo.h"
1010 #include "llvm/ADT/PointerUnion.h"
1111 #include "llvm/ADT/TinyPtrVector.h"
12 #include "llvm/Analysis/LibCallSemantics.h"
12 #include "llvm/Analysis/EHPersonalities.h"
1313 #include "llvm/Analysis/ValueTracking.h"
1414 #include "llvm/CodeGen/MachineFunction.h"
1515 #include "llvm/CodeGen/MachineFunctionPass.h"
2727 #include "llvm/ADT/DepthFirstIterator.h"
2828 #include "llvm/ADT/SetOperations.h"
2929 #include "llvm/ADT/SmallVector.h"
30 #include "llvm/Analysis/LibCallSemantics.h"
30 #include "llvm/Analysis/EHPersonalities.h"
3131 #include "llvm/CodeGen/LiveIntervalAnalysis.h"
3232 #include "llvm/CodeGen/LiveStackAnalysis.h"
3333 #include "llvm/CodeGen/LiveVariables.h"
1818 #include "llvm/Analysis/AliasAnalysis.h"
1919 #include "llvm/Analysis/BranchProbabilityInfo.h"
2020 #include "llvm/Analysis/CFG.h"
21 #include "llvm/Analysis/LibCallSemantics.h"
21 #include "llvm/Analysis/EHPersonalities.h"
2222 #include "llvm/Analysis/TargetLibraryInfo.h"
2323 #include "llvm/CodeGen/Analysis.h"
2424 #include "llvm/CodeGen/FastISel.h"
1818 #include "llvm/CodeGen/Passes.h"
1919 #include "llvm/ADT/SetVector.h"
2020 #include "llvm/Analysis/CFG.h"
21 #include "llvm/Analysis/LibCallSemantics.h"
21 #include "llvm/Analysis/EHPersonalities.h"
2222 #include "llvm/CodeGen/WinEHFuncInfo.h"
2323 #include "llvm/Pass.h"
2424 #include "llvm/Support/Debug.h"
1818 #include "X86InstrInfo.h"
1919 #include "X86MachineFunctionInfo.h"
2020 #include "X86Subtarget.h"
21 #include "llvm/Analysis/LibCallSemantics.h"
21 #include "llvm/Analysis/EHPersonalities.h"
2222 #include "llvm/CodeGen/Passes.h" // For IDs of passes that are preserved.
2323 #include "llvm/CodeGen/MachineFunctionPass.h"
2424 #include "llvm/CodeGen/MachineInstrBuilder.h"
1717 #include "X86Subtarget.h"
1818 #include "X86TargetMachine.h"
1919 #include "llvm/ADT/SmallSet.h"
20 #include "llvm/Analysis/LibCallSemantics.h"
20 #include "llvm/Analysis/EHPersonalities.h"
2121 #include "llvm/CodeGen/MachineFrameInfo.h"
2222 #include "llvm/CodeGen/MachineFunction.h"
2323 #include "llvm/CodeGen/MachineInstrBuilder.h"
2424 #include "llvm/ADT/Statistic.h"
2525 #include "llvm/ADT/StringExtras.h"
2626 #include "llvm/ADT/StringSwitch.h"
27 #include "llvm/Analysis/LibCallSemantics.h"
27 #include "llvm/Analysis/EHPersonalities.h"
2828 #include "llvm/CodeGen/IntrinsicLowering.h"
2929 #include "llvm/CodeGen/MachineFrameInfo.h"
3030 #include "llvm/CodeGen/MachineFunction.h"
1414 //===----------------------------------------------------------------------===//
1515
1616 #include "X86.h"
17 #include "llvm/Analysis/LibCallSemantics.h"
17 #include "llvm/Analysis/EHPersonalities.h"
1818 #include "llvm/CodeGen/MachineModuleInfo.h"
1919 #include "llvm/CodeGen/Passes.h"
2020 #include "llvm/CodeGen/WinEHFuncInfo.h"
2020 #include "llvm/Support/raw_ostream.h"
2121 #include "llvm/Analysis/CallGraph.h"
2222 #include "llvm/Analysis/CallGraphSCCPass.h"
23 #include "llvm/Analysis/LibCallSemantics.h"
23 #include "llvm/Analysis/EHPersonalities.h"
2424 #include "llvm/IR/CFG.h"
2525 #include "llvm/IR/Constants.h"
2626 #include "llvm/IR/Function.h"
4141 #include "llvm/Analysis/AssumptionCache.h"
4242 #include "llvm/Analysis/CFG.h"
4343 #include "llvm/Analysis/ConstantFolding.h"
44 #include "llvm/Analysis/EHPersonalities.h"
4445 #include "llvm/Analysis/GlobalsModRef.h"
4546 #include "llvm/Analysis/InstructionSimplify.h"
46 #include "llvm/Analysis/LibCallSemantics.h"
4747 #include "llvm/Analysis/LoopInfo.h"
4848 #include "llvm/Analysis/MemoryBuiltins.h"
4949 #include "llvm/Analysis/TargetLibraryInfo.h"
3030 #include "llvm/Transforms/Instrumentation.h"
3131 #include "llvm/ADT/ArrayRef.h"
3232 #include "llvm/ADT/SmallVector.h"
33 #include "llvm/Analysis/LibCallSemantics.h"
33 #include "llvm/Analysis/EHPersonalities.h"
3434 #include "llvm/IR/CallSite.h"
3535 #include "llvm/IR/DataLayout.h"
3636 #include "llvm/IR/DebugInfo.h"
1919 #include "llvm/ADT/SetVector.h"
2020 #include "llvm/ADT/SmallPtrSet.h"
2121 #include "llvm/ADT/Statistic.h"
22 #include "llvm/Analysis/EHPersonalities.h"
2223 #include "llvm/Analysis/InstructionSimplify.h"
23 #include "llvm/Analysis/LibCallSemantics.h"
2424 #include "llvm/Analysis/MemoryBuiltins.h"
2525 #include "llvm/Analysis/ValueTracking.h"
2626 #include "llvm/IR/CFG.h"