Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NativeAOT-LLVM] Stop generating catch funclets #2399

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/coreclr/jit/jiteh.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ struct EHblkDsc
// funclet index, just subtract 1.
unsigned short ebdFuncIndex;

#ifdef TARGET_WASM
// WASM backend rewrites the funclet table in a way that makes the above algorithm
// insufficient and so uses this auxiliary field for filter funclet indices.
unsigned short endFilterFuncIndex;
#endif // TARGET_WASM

#endif // FEATURE_EH_FUNCLETS

IL_OFFSET ebdTryBegOffset; // IL offsets of EH try/end regions as they are imported
Expand Down
1 change: 0 additions & 1 deletion src/coreclr/jit/llvm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ Llvm::Llvm(Compiler* compiler)
, _compiler(compiler)
, m_info(&compiler->info)
, _builder(m_context->Context)
, _blkToLlvmBlksMap(compiler->getAllocator(CMK_Codegen))
, _sdsuMap(compiler->getAllocator(CMK_Codegen))
, _localsMap(compiler->getAllocator(CMK_Codegen))
, m_ehModel(GetExceptionHandlingModel())
Expand Down
35 changes: 23 additions & 12 deletions src/coreclr/jit/llvm.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,12 @@ struct FunctionInfo
llvm::BasicBlock* ExceptionThrownReturnLlvmBlock;
};

struct EHRegionInfo
{
llvm::BasicBlock* UnwindBlock;
Value* CatchArgValue;
};

class SingleThreadedCompilationContext
{
public:
Expand Down Expand Up @@ -214,21 +220,21 @@ class Llvm

// Codegen members.
llvm::IRBuilder<> _builder;
JitHashTable<BasicBlock*, JitPtrKeyFuncs<BasicBlock>, LlvmBlockRange> _blkToLlvmBlksMap;
JitHashTable<GenTree*, JitPtrKeyFuncs<GenTree>, Value*> _sdsuMap;
JitHashTable<SSAName, SSAName, Value*> _localsMap;
std::vector<PhiPair> _phiPairs;
std::vector<FunctionInfo> m_functions;

CorInfoLlvmEHModel m_ehModel;
std::vector<llvm::BasicBlock*> m_EHUnwindLlvmBlocks;
std::vector<EHRegionInfo> m_EHRegionsInfo;
Value* m_exceptionThrownAddressValue = nullptr;

Value* m_rootFunctionShadowStackValue = nullptr;

// Codegen emit context.
unsigned m_currentLlvmFunctionIndex = ROOT_FUNC_IDX;
unsigned m_currentProtectedRegionIndex = EHblkDsc::NO_ENCLOSING_INDEX;
unsigned m_currentHandlerIndex = EHblkDsc::NO_ENCLOSING_INDEX;
LlvmBlockRange* m_currentLlvmBlocks = nullptr;

// DWARF debug info.
Expand Down Expand Up @@ -343,6 +349,7 @@ class Llvm
void Lower();

private:
void initializeFunclets();
void initializeLlvmArgInfo();

void lowerBlocks();
Expand Down Expand Up @@ -438,9 +445,10 @@ class Llvm
void generateProlog();
void initializeShadowStack();
void initializeLocals();
void initializeBlocks();
void generateUnwindBlocks();
void generateBlocks();
void generateBlock(BasicBlock* block);
void generateEHDispatch();
void fillPhis();
void generateAuxiliaryArtifacts();
void verifyGeneratedCode();
Expand Down Expand Up @@ -489,6 +497,7 @@ class Llvm
void buildKeepAlive(GenTreeUnOp* keepAliveNode);
void buildILOffset(GenTreeILOffset* ilOffsetNode);

void buildCatchRet(BasicBlock* block);
void buildCallFinally(BasicBlock* block);

Value* consumeAddressAndEmitNullCheck(GenTreeIndir* indir);
Expand All @@ -500,13 +509,9 @@ class Llvm

void emitJumpToThrowHelper(Value* jumpCondValue, SpecialCodeKind throwKind);
Value* emitCheckedArithmeticOperation(llvm::Intrinsic::ID intrinsicId, Value* op1Value, Value* op2Value);
llvm::CallBase* emitHelperCall(CorInfoHelpFunc helperFunc,
ArrayRef<Value*> sigArgs = {},
ArrayRef<llvm::OperandBundleDef> opBundles = {},
bool doTailCall = false);
llvm::CallBase* emitCallOrInvoke(
llvm::FunctionCallee callee, ArrayRef<Value*> args = {}, ArrayRef<llvm::OperandBundleDef> opBundles = {});
llvm::BasicBlock* getOrCreateExceptionThrownReturnBlock();
llvm::CallBase* emitHelperCall(CorInfoHelpFunc helperFunc, ArrayRef<Value*> sigArgs = {});
llvm::CallBase* emitCallOrInvoke(llvm::Function* callee, ArrayRef<Value*> args = {});
llvm::CallBase* emitCallOrInvoke(llvm::FunctionCallee callee, ArrayRef<Value*> args, bool isThrowingCall);

FunctionType* createFunctionType();
llvm::FunctionCallee consumeCallTarget(GenTreeCall* call);
Expand All @@ -518,7 +523,12 @@ class Llvm
std::function<FunctionType*()> createFunctionType,
std::function<void(Function*)> annotateFunction = [](Function*) { });
Function* getOrCreateExternalLlvmFunctionAccessor(StringRef name);

EHRegionInfo& getEHRegionInfo(unsigned ehIndex);
llvm::BasicBlock* getUnwindLlvmBlockForCurrentInvoke();
Function* getOrCreatePersonalityLlvmFunction(CorInfoLlvmEHModel ehModel);
llvm::CatchPadInst* getCatchPadForHandler(unsigned hndIndex);
llvm::BasicBlock* getOrCreateExceptionThrownReturnBlock();
Value* getOrCreateExceptionThrownAddressValue();

llvm::GlobalVariable* getOrCreateDataSymbol(StringRef symbolName, bool isThreadLocal = false);
Expand All @@ -532,9 +542,10 @@ class Llvm
Value* getOriginalShadowStack();

void setCurrentEmitContextForBlock(BasicBlock* block);
void setCurrentEmitContext(unsigned funcIdx, unsigned tryIndex, LlvmBlockRange* llvmBlock);
void setCurrentEmitContext(unsigned funcIdx, unsigned tryIndex, unsigned hndIndex, LlvmBlockRange* llvmBlock);
unsigned getCurrentLlvmFunctionIndex() const;
unsigned getCurrentProtectedRegionIndex() const;
unsigned getCurrentHandlerIndex() const;
LlvmBlockRange* getCurrentLlvmBlocks() const;

Function* getRootLlvmFunction();
Expand All @@ -543,13 +554,13 @@ class Llvm
FunctionInfo& getLlvmFunctionInfoForIndex(unsigned funcIdx);
unsigned getLlvmFunctionIndexForBlock(BasicBlock* block) const;
unsigned getLlvmFunctionIndexForProtectedRegion(unsigned tryIndex) const;
bool isLlvmFunctionReachable(unsigned funcIdx) const;

llvm::BasicBlock* createInlineLlvmBlock();
LlvmBlockRange* getLlvmBlocksForBlock(BasicBlock* block);
llvm::BasicBlock* getFirstLlvmBlockForBlock(BasicBlock* block);
llvm::BasicBlock* getLastLlvmBlockForBlock(BasicBlock* block);
llvm::BasicBlock* getOrCreatePrologLlvmBlockForFunction(unsigned funcIdx);
llvm::BasicBlock* getUnwindLlvmBlockForCurrentInvoke();

bool isReachable(BasicBlock* block) const;
BasicBlock* getFirstBlockForFunction(unsigned funcIdx) const;
Expand Down
Loading