From 8f157fed2f1ae2f7b977920e00635bcd6fb87772 Mon Sep 17 00:00:00 2001 From: Single Accretion Date: Wed, 13 Sep 2023 18:24:38 +0200 Subject: [PATCH] Use emitCallOrInvoke for all calls Since it handles adding the operand bundles. --- src/coreclr/jit/llvm.h | 3 ++- src/coreclr/jit/llvmcodegen.cpp | 29 +++++++++++++---------------- src/coreclr/jit/llvmlower.cpp | 13 +++++++++++-- 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/src/coreclr/jit/llvm.h b/src/coreclr/jit/llvm.h index fa8eabfb7b6f..4f9a5610be9f 100644 --- a/src/coreclr/jit/llvm.h +++ b/src/coreclr/jit/llvm.h @@ -504,7 +504,8 @@ class Llvm void emitJumpToThrowHelper(Value* jumpCondValue, SpecialCodeKind throwKind); Value* emitCheckedArithmeticOperation(llvm::Intrinsic::ID intrinsicId, Value* op1Value, Value* op2Value); llvm::CallBase* emitHelperCall(CorInfoHelpFunc helperFunc, ArrayRef sigArgs = {}); - llvm::CallBase* emitCallOrInvoke(llvm::FunctionCallee callee, ArrayRef args = {}); + llvm::CallBase* emitCallOrInvoke(llvm::Function* callee, ArrayRef args = {}); + llvm::CallBase* emitCallOrInvoke(llvm::FunctionCallee callee, ArrayRef args, bool isThrowingCall); FunctionType* createFunctionType(); llvm::FunctionCallee consumeCallTarget(GenTreeCall* call); diff --git a/src/coreclr/jit/llvmcodegen.cpp b/src/coreclr/jit/llvmcodegen.cpp index 85db48bf5b11..69f8e06059ac 100644 --- a/src/coreclr/jit/llvmcodegen.cpp +++ b/src/coreclr/jit/llvmcodegen.cpp @@ -1765,19 +1765,7 @@ void Llvm::buildCall(GenTreeCall* call) } llvm::FunctionCallee llvmFuncCallee = consumeCallTarget(call); - Value* callValue; - if (call->IsUnmanaged()) - { - // We do not support exceptions propagating through native<->managed boundaries. - llvm::CallInst* callInst = _builder.CreateCall(llvmFuncCallee, argVec); - callInst->addFnAttr(llvm::Attribute::NoUnwind); - - callValue = callInst; - } - else - { - callValue = emitCallOrInvoke(llvmFuncCallee, argVec); - } + Value* callValue = emitCallOrInvoke(llvmFuncCallee, argVec, mayPhysicallyThrow(call)); mapGenTreeToValue(call, callValue); } @@ -2471,10 +2459,14 @@ llvm::CallBase* Llvm::emitHelperCall(CorInfoHelpFunc helperFunc, ArrayRef args) +llvm::CallBase* Llvm::emitCallOrInvoke(llvm::Function* callee, ArrayRef args) +{ + return emitCallOrInvoke(callee, args, !callee->doesNotThrow()); +} + +llvm::CallBase* Llvm::emitCallOrInvoke(llvm::FunctionCallee callee, ArrayRef args, bool isThrowingCall) { Function* llvmFunc = llvm::dyn_cast(callee.getCallee()); - bool isThrowingCall = (llvmFunc == nullptr) || !llvmFunc->doesNotThrow(); llvm::BasicBlock* catchLlvmBlock = getUnwindLlvmBlockForCurrentInvoke(); llvm::SmallVector bundles{}; @@ -2497,6 +2489,11 @@ llvm::CallBase* Llvm::emitCallOrInvoke(llvm::FunctionCallee callee, ArrayRefsetDoesNotThrow(); + } } if (isThrowingCall && (m_ehModel == CorInfoLlvmEHModel::Emulated)) @@ -2569,7 +2566,7 @@ llvm::FunctionCallee Llvm::consumeCallTarget(GenTreeCall* call) { FunctionType* callFuncType = createFunctionTypeForCall(call); Function* calleeAccessorFunc = getOrCreateExternalLlvmFunctionAccessor(symbolName); - Value* calleeValue = _builder.CreateCall(calleeAccessorFunc); + Value* calleeValue = emitCallOrInvoke(calleeAccessorFunc); callee = {callFuncType, calleeValue}; } diff --git a/src/coreclr/jit/llvmlower.cpp b/src/coreclr/jit/llvmlower.cpp index 70528614d23b..05896cf927e9 100644 --- a/src/coreclr/jit/llvmlower.cpp +++ b/src/coreclr/jit/llvmlower.cpp @@ -1898,9 +1898,18 @@ CORINFO_GENERIC_HANDLE Llvm::generateUnwindTable() // bool Llvm::mayPhysicallyThrow(GenTree* node) { - if (node->IsHelperCall()) + if (node->IsCall()) { - return helperCallMayPhysicallyThrow(node->AsCall()->GetHelperNum()); + if (node->IsHelperCall()) + { + return helperCallMayPhysicallyThrow(node->AsCall()->GetHelperNum()); + } + + // We do not support exceptions propagating through native<->managed boundaries. + if (node->AsCall()->IsUnmanaged()) + { + return false; + } } return node->OperMayThrow(_compiler);