Skip to content
This repository has been archived by the owner on Mar 15, 2022. It is now read-only.

Add makeCall wrapper #457

Merged
merged 1 commit into from
Apr 18, 2015
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
3 changes: 2 additions & 1 deletion include/Reader/abisignature.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,14 @@ class ABICallSignature : public ABISignature {
/// \param Reader The \p GenIR instance that will be used to emit
/// IR.
/// \param Target The call target.
/// \param MayThrow True iff the callee may raise an exception
/// \param Args The arguments to the call.
/// \param IndirectionCell The indirection cell argument for the call, if
/// any.
/// \param CallNode [out] The call instruction.
///
/// \returns The result of the call to the target.
llvm::Value *emitCall(GenIR &Reader, llvm::Value *Target,
llvm::Value *emitCall(GenIR &Reader, llvm::Value *Target, bool mayThrow,
llvm::ArrayRef<llvm::Value *> Args,
llvm::Value *IndirectionCell,
llvm::Value **CallNode) const;
Expand Down
9 changes: 5 additions & 4 deletions include/Reader/reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -3134,15 +3134,16 @@ class ReaderBase {
IRNode *ThisArg) = 0;

// Helper callback used by rdrCall to emit call code.
virtual IRNode *genCall(ReaderCallTargetData *CallTargetData,
virtual IRNode *genCall(ReaderCallTargetData *CallTargetData, bool MayThrow,
std::vector<IRNode *> Args, IRNode **CallNode) = 0;

virtual bool canMakeDirectCall(ReaderCallTargetData *CallTargetData) = 0;

// Generate call to helper
virtual IRNode *callHelper(CorInfoHelpFunc HelperID, IRNode *Dst,
IRNode *Arg1 = nullptr, IRNode *Arg2 = nullptr,
IRNode *Arg3 = nullptr, IRNode *Arg4 = nullptr,
virtual IRNode *callHelper(CorInfoHelpFunc HelperID, bool MayThrow,
IRNode *Dst, IRNode *Arg1 = nullptr,
IRNode *Arg2 = nullptr, IRNode *Arg3 = nullptr,
IRNode *Arg4 = nullptr,
ReaderAlignType Alignment = Reader_AlignUnknown,
bool IsVolatile = false, bool NoCtor = false,
bool CanMoveUp = false) = 0;
Expand Down
43 changes: 29 additions & 14 deletions include/Reader/readerir.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/Verifier.h"
#include "llvm/IR/CFG.h"
#include "llvm/IR/CallSite.h"
#include "reader.h"
#include "abi.h"
#include "abisignature.h"
Expand Down Expand Up @@ -719,26 +720,27 @@ class GenIR : public ReaderBase {
IRNode *ThisArg) override;

// Helper callback used by rdrCall to emit call code.
IRNode *genCall(ReaderCallTargetData *CallTargetInfo,
IRNode *genCall(ReaderCallTargetData *CallTargetInfo, bool MayThrow,
std::vector<IRNode *> Args, IRNode **CallNode) override;

bool canMakeDirectCall(ReaderCallTargetData *CallTargetData) override;

// Generate call to helper
IRNode *callHelper(CorInfoHelpFunc HelperID, IRNode *Dst,
IRNode *callHelper(CorInfoHelpFunc HelperID, bool MayThrow, IRNode *Dst,
IRNode *Arg1 = nullptr, IRNode *Arg2 = nullptr,
IRNode *Arg3 = nullptr, IRNode *Arg4 = nullptr,
ReaderAlignType Alignment = Reader_AlignUnknown,
bool IsVolatile = false, bool NoCtor = false,
bool CanMoveUp = false) override;

// Generate call to helper
IRNode *callHelperImpl(CorInfoHelpFunc HelperID, llvm::Type *ReturnType,
IRNode *Arg1 = nullptr, IRNode *Arg2 = nullptr,
IRNode *Arg3 = nullptr, IRNode *Arg4 = nullptr,
ReaderAlignType Alignment = Reader_AlignUnknown,
bool IsVolatile = false, bool NoCtor = false,
bool CanMoveUp = false);
llvm::CallSite callHelperImpl(CorInfoHelpFunc HelperID, bool MayThrow,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not something that you have to change now, but it might be nice if this method took an ArrayRef<Value*> instead of the optional IRNode parameters.

llvm::Type *ReturnType, IRNode *Arg1 = nullptr,
IRNode *Arg2 = nullptr, IRNode *Arg3 = nullptr,
IRNode *Arg4 = nullptr,
ReaderAlignType Alignment = Reader_AlignUnknown,
bool IsVolatile = false, bool NoCtor = false,
bool CanMoveUp = false);

/// Generate special generics helper that might need to insert flow. The
/// helper is called if NullCheckArg is null at compile-time or if it
Expand Down Expand Up @@ -1031,17 +1033,19 @@ class GenIR : public ReaderBase {
///
/// \param Condition Condition that will trigger the call.
/// \param HelperId Id of the call helper.
/// \param MayThrow true if the helper call may raise an exception.
/// \param ReturnType Return type of the call helper.
/// \param Arg1 First helper argument.
/// \param Arg2 Second helper argument.
/// \param CallReturns true iff the helper call returns.
/// \param CallBlockName Name of the basic block that will contain the call.
/// \returns Generated call instruction.
llvm::CallInst *genConditionalHelperCall(llvm::Value *Condition,
CorInfoHelpFunc HelperId,
llvm::Type *ReturnType, IRNode *Arg1,
IRNode *Arg2, bool CallReturns,
const llvm::Twine &CallBlockName);
/// \returns Generated call/invoke instruction.
llvm::CallSite genConditionalHelperCall(llvm::Value *Condition,
CorInfoHelpFunc HelperId,
bool MayThrow, llvm::Type *ReturnType,
IRNode *Arg1, IRNode *Arg2,
bool CallReturns,
const llvm::Twine &CallBlockName);

/// Generate a call to the throw helper if the condition is met.
///
Expand Down Expand Up @@ -1144,6 +1148,17 @@ class GenIR : public ReaderBase {
return makeLoad(Address, IsVolatile, false);
}

/// \brief Create a call or invoke instruction
///
/// The call is inserted at the LLVMBuilder's current insertion point.
///
/// \param Callee Target of the call
/// \param MayThrow True if the callee may raise an exception
/// \param Args Arguments to pass to the callee
/// \returns A \p CallSite wrapping the CallInst or InvokeInst
llvm::CallSite makeCall(llvm::Value *Callee, bool MayThrow,
llvm::ArrayRef<llvm::Value *> Args);

/// Store a value to an argument passed indirectly.
///
/// The storage backing such arguments may be loacted on the heap; any stores
Expand Down
10 changes: 5 additions & 5 deletions lib/Reader/abisignature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ ABICallSignature::ABICallSignature(const ReaderCallSignature &TheSignature,
: ABISignature(TheSignature, Reader, TheABIInfo), Signature(TheSignature) {}

Value *ABICallSignature::emitCall(GenIR &Reader, llvm::Value *Target,
llvm::ArrayRef<Value *> Args,
bool MayThrow, llvm::ArrayRef<Value *> Args,
llvm::Value *IndirectionCell,
llvm::Value **CallNode) const {
assert(Target->getType()->isIntegerTy(Reader.TargetPointerSizeInBits));
Expand Down Expand Up @@ -150,7 +150,7 @@ Value *ABICallSignature::emitCall(GenIR &Reader, llvm::Value *Target,
Type *FunctionPtrTy = Reader.getUnmanagedPointerType(FunctionTy);

Target = Builder.CreateIntToPtr(Target, FunctionPtrTy);
CallInst *Call = Builder.CreateCall(Target, Arguments);
CallSite Call = Reader.makeCall(Target, MayThrow, Arguments);

CallingConv::ID CC;
if (HasIndirectionCell) {
Expand All @@ -159,18 +159,18 @@ Value *ABICallSignature::emitCall(GenIR &Reader, llvm::Value *Target,
} else {
CC = getLLVMCallingConv(Signature.getCallingConvention());
}
Call->setCallingConv(CC);
Call.setCallingConv(CC);

if (ResultNode == nullptr) {
assert(!HasIndirectResult);
const CallArgType &SigResultType = Signature.getResultType();
Type *Ty = Reader.getType(SigResultType.CorType, SigResultType.Class);
ResultNode = coerce(Reader, Ty, Call);
ResultNode = coerce(Reader, Ty, Call.getInstruction());
} else {
ResultNode = Builder.CreateLoad(ResultNode);
}

*CallNode = Call;
*CallNode = Call.getInstruction();
return ResultNode;
}

Expand Down
Loading