You've already forked linux-packaging-mono
acceptance-tests
data
debian
docs
external
Newtonsoft.Json
api-doc-tools
api-snapshot
aspnetwebstack
bdwgc
binary-reference-assemblies
bockbuild
boringssl
cecil
cecil-legacy
corefx
corert
helix-binaries
ikdasm
ikvm
illinker-test-assets
linker
llvm-project
clang
clang-tools-extra
compiler-rt
eng
libcxx
libcxxabi
libunwind
lld
lldb
llvm
bindings
cmake
docs
examples
include
lib
Analysis
AsmParser
BinaryFormat
Bitcode
CodeGen
DebugInfo
Demangle
ExecutionEngine
FuzzMutate
Fuzzer
IR
IRReader
LTO
LineEditor
Linker
MC
Object
ObjectYAML
Option
Passes
ProfileData
Support
TableGen
Target
Testing
ToolDrivers
Transforms
Coroutines
Hello
IPO
InstCombine
Instrumentation
ObjCARC
Scalar
Utils
ASanStackFrameLayout.cpp
AddDiscriminators.cpp
BasicBlockUtils.cpp
BreakCriticalEdges.cpp
BuildLibCalls.cpp
BypassSlowDivision.cpp
CMakeLists.txt
CallPromotionUtils.cpp
CloneFunction.cpp
CloneModule.cpp
CodeExtractor.cpp
CtorUtils.cpp
DemoteRegToStack.cpp
EntryExitInstrumenter.cpp
EscapeEnumerator.cpp
Evaluator.cpp
FlattenCFG.cpp
FunctionComparator.cpp
FunctionImportUtils.cpp
GlobalStatus.cpp
ImportedFunctionsInliningStatistics.cpp
InlineFunction.cpp
InstructionNamer.cpp
IntegerDivision.cpp
LCSSA.cpp
LLVMBuild.txt
LibCallsShrinkWrap.cpp
Local.cpp
LoopSimplify.cpp
LoopUnroll.cpp
LoopUnrollPeel.cpp
LoopUnrollRuntime.cpp
LoopUtils.cpp
LoopVersioning.cpp
LowerInvoke.cpp
LowerMemIntrinsics.cpp
LowerSwitch.cpp
Mem2Reg.cpp
MetaRenamer.cpp
ModuleUtils.cpp
NameAnonGlobals.cpp
OrderedInstructions.cpp
PredicateInfo.cpp
PromoteMemoryToRegister.cpp
SSAUpdater.cpp
SanitizerStats.cpp
SimplifyCFG.cpp.REMOVED.git-id
SimplifyIndVar.cpp
SimplifyInstructions.cpp
SimplifyLibCalls.cpp
SplitModule.cpp
StripGCRelocates.cpp
StripNonLineTableDebugInfo.cpp
SymbolRewriter.cpp
UnifyFunctionExitNodes.cpp
Utils.cpp
VNCoercion.cpp
ValueMapper.cpp
Vectorize
CMakeLists.txt
LLVMBuild.txt
WindowsManifest
XRay
CMakeLists.txt
LLVMBuild.txt
projects
resources
runtimes
scripts
test
tools
unittests
utils
.arcconfig
.clang-format
.clang-tidy
.gitattributes
.gitignore
CMakeLists.txt
CODE_OWNERS.TXT
CREDITS.TXT
LICENSE.TXT
LLVMBuild.txt
README.txt
RELEASE_TESTERS.TXT
configure
llvm.spec.in
version.txt.in
nuget
openmp
polly
Directory.Build.props
Directory.Build.targets
NuGet.config
azure-pipelines.yml
build.cmd
build.sh
dir.common.props
global.json
llvm.proj
mxe-Win64.cmake.in
nuget-buildtasks
nunit-lite
roslyn-binaries
rx
xunit-binaries
how-to-bump-roslyn-binaries.md
ikvm-native
llvm
m4
man
mcs
mono
msvc
netcore
po
runtime
samples
scripts
support
tools
COPYING.LIB
LICENSE
Makefile.am
Makefile.in
NEWS
README.md
acinclude.m4
aclocal.m4
autogen.sh
code_of_conduct.md
compile
config.guess
config.h.in
config.rpath
config.sub
configure.REMOVED.git-id
configure.ac.REMOVED.git-id
depcomp
install-sh
ltmain.sh.REMOVED.git-id
missing
mkinstalldirs
mono-uninstalled.pc.in
test-driver
winconfig.h
96 lines
2.9 KiB
C++
96 lines
2.9 KiB
C++
//===- EscapeEnumerator.cpp -----------------------------------------------===//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
// This file is distributed under the University of Illinois Open Source
|
|
// License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// Defines a helper class that enumerates all possible exits from a function,
|
|
// including exception handling.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "llvm/Transforms/Utils/EscapeEnumerator.h"
|
|
#include "llvm/Analysis/EHPersonalities.h"
|
|
#include "llvm/IR/CallSite.h"
|
|
#include "llvm/IR/Module.h"
|
|
#include "llvm/Transforms/Utils/Local.h"
|
|
using namespace llvm;
|
|
|
|
static Constant *getDefaultPersonalityFn(Module *M) {
|
|
LLVMContext &C = M->getContext();
|
|
Triple T(M->getTargetTriple());
|
|
EHPersonality Pers = getDefaultEHPersonality(T);
|
|
return M->getOrInsertFunction(getEHPersonalityName(Pers),
|
|
FunctionType::get(Type::getInt32Ty(C), true));
|
|
}
|
|
|
|
IRBuilder<> *EscapeEnumerator::Next() {
|
|
if (Done)
|
|
return nullptr;
|
|
|
|
// Find all 'return', 'resume', and 'unwind' instructions.
|
|
while (StateBB != StateE) {
|
|
BasicBlock *CurBB = &*StateBB++;
|
|
|
|
// Branches and invokes do not escape, only unwind, resume, and return
|
|
// do.
|
|
TerminatorInst *TI = CurBB->getTerminator();
|
|
if (!isa<ReturnInst>(TI) && !isa<ResumeInst>(TI))
|
|
continue;
|
|
|
|
Builder.SetInsertPoint(TI);
|
|
return &Builder;
|
|
}
|
|
|
|
Done = true;
|
|
|
|
if (!HandleExceptions)
|
|
return nullptr;
|
|
|
|
if (F.doesNotThrow())
|
|
return nullptr;
|
|
|
|
// Find all 'call' instructions that may throw.
|
|
SmallVector<Instruction *, 16> Calls;
|
|
for (BasicBlock &BB : F)
|
|
for (Instruction &II : BB)
|
|
if (CallInst *CI = dyn_cast<CallInst>(&II))
|
|
if (!CI->doesNotThrow())
|
|
Calls.push_back(CI);
|
|
|
|
if (Calls.empty())
|
|
return nullptr;
|
|
|
|
// Create a cleanup block.
|
|
LLVMContext &C = F.getContext();
|
|
BasicBlock *CleanupBB = BasicBlock::Create(C, CleanupBBName, &F);
|
|
Type *ExnTy = StructType::get(Type::getInt8PtrTy(C), Type::getInt32Ty(C));
|
|
if (!F.hasPersonalityFn()) {
|
|
Constant *PersFn = getDefaultPersonalityFn(F.getParent());
|
|
F.setPersonalityFn(PersFn);
|
|
}
|
|
|
|
if (isFuncletEHPersonality(classifyEHPersonality(F.getPersonalityFn()))) {
|
|
report_fatal_error("Funclet EH not supported");
|
|
}
|
|
|
|
LandingPadInst *LPad =
|
|
LandingPadInst::Create(ExnTy, 1, "cleanup.lpad", CleanupBB);
|
|
LPad->setCleanup(true);
|
|
ResumeInst *RI = ResumeInst::Create(LPad, CleanupBB);
|
|
|
|
// Transform the 'call' instructions into 'invoke's branching to the
|
|
// cleanup block. Go in reverse order to make prettier BB names.
|
|
SmallVector<Value *, 16> Args;
|
|
for (unsigned I = Calls.size(); I != 0;) {
|
|
CallInst *CI = cast<CallInst>(Calls[--I]);
|
|
changeToInvokeAndSplitBasicBlock(CI, CleanupBB);
|
|
}
|
|
|
|
Builder.SetInsertPoint(RI);
|
|
return &Builder;
|
|
}
|