Skip to content

Commit

Permalink
Use emitCallOrInvoke for all calls
Browse files Browse the repository at this point in the history
Since it handles adding the operand bundles.
  • Loading branch information
SingleAccretion committed Sep 18, 2023
1 parent 36a6d1c commit 8f157fe
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 19 deletions.
3 changes: 2 additions & 1 deletion src/coreclr/jit/llvm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<Value*> sigArgs = {});
llvm::CallBase* emitCallOrInvoke(llvm::FunctionCallee callee, ArrayRef<Value*> args = {});
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 Down
29 changes: 13 additions & 16 deletions src/coreclr/jit/llvmcodegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -2471,10 +2459,14 @@ llvm::CallBase* Llvm::emitHelperCall(CorInfoHelpFunc helperFunc, ArrayRef<Value*
return call;
}

llvm::CallBase* Llvm::emitCallOrInvoke(llvm::FunctionCallee callee, ArrayRef<Value*> args)
llvm::CallBase* Llvm::emitCallOrInvoke(llvm::Function* callee, ArrayRef<Value*> args)
{
return emitCallOrInvoke(callee, args, !callee->doesNotThrow());
}

llvm::CallBase* Llvm::emitCallOrInvoke(llvm::FunctionCallee callee, ArrayRef<Value*> args, bool isThrowingCall)
{
Function* llvmFunc = llvm::dyn_cast<Function>(callee.getCallee());
bool isThrowingCall = (llvmFunc == nullptr) || !llvmFunc->doesNotThrow();
llvm::BasicBlock* catchLlvmBlock = getUnwindLlvmBlockForCurrentInvoke();

llvm::SmallVector<llvm::OperandBundleDef, 1> bundles{};
Expand All @@ -2497,6 +2489,11 @@ llvm::CallBase* Llvm::emitCallOrInvoke(llvm::FunctionCallee callee, ArrayRef<Val
else
{
callInst = _builder.CreateCall(callee, args, bundles);

if (!isThrowingCall)
{
callInst->setDoesNotThrow();
}
}

if (isThrowingCall && (m_ehModel == CorInfoLlvmEHModel::Emulated))
Expand Down Expand Up @@ -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};
}
Expand Down
13 changes: 11 additions & 2 deletions src/coreclr/jit/llvmlower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 8f157fe

Please sign in to comment.