AirCCallingConvention.cpp [plain text]
#include "config.h"
#include "AirCCallingConvention.h"
#if ENABLE(B3_JIT)
#include "AirCCallSpecial.h"
#include "AirCode.h"
#include "B3CCallValue.h"
#include "B3ValueInlines.h"
namespace JSC { namespace B3 { namespace Air {
namespace {
template<typename BankInfo>
Arg marshallCCallArgumentImpl(unsigned& argumentCount, unsigned& stackOffset, Value* child)
{
unsigned argumentIndex = argumentCount++;
if (argumentIndex < BankInfo::numberOfArgumentRegisters)
return Tmp(BankInfo::toArgumentRegister(argumentIndex));
unsigned slotSize;
if (isARM64() && isIOS()) {
slotSize = sizeofType(child->type());
} else {
slotSize = 8;
}
stackOffset = WTF::roundUpToMultipleOf(slotSize, stackOffset);
Arg result = Arg::callArg(stackOffset);
stackOffset += slotSize;
return result;
}
Arg marshallCCallArgument(
unsigned& gpArgumentCount, unsigned& fpArgumentCount, unsigned& stackOffset, Value* child)
{
switch (bankForType(child->type())) {
case GP:
return marshallCCallArgumentImpl<GPRInfo>(gpArgumentCount, stackOffset, child);
case FP:
return marshallCCallArgumentImpl<FPRInfo>(fpArgumentCount, stackOffset, child);
}
RELEASE_ASSERT_NOT_REACHED();
return Arg();
}
}
Vector<Arg> computeCCallingConvention(Code& code, CCallValue* value)
{
Vector<Arg> result;
result.append(Tmp(CCallSpecial::scratchRegister));
unsigned gpArgumentCount = 0;
unsigned fpArgumentCount = 0;
unsigned stackOffset = 0;
for (unsigned i = 1; i < value->numChildren(); ++i) {
result.append(
marshallCCallArgument(gpArgumentCount, fpArgumentCount, stackOffset, value->child(i)));
}
code.requestCallArgAreaSizeInBytes(WTF::roundUpToMultipleOf(stackAlignmentBytes(), stackOffset));
return result;
}
Tmp cCallResult(Type type)
{
switch (type) {
case Void:
return Tmp();
case Int32:
case Int64:
return Tmp(GPRInfo::returnValueGPR);
case Float:
case Double:
return Tmp(FPRInfo::returnValueFPR);
}
RELEASE_ASSERT_NOT_REACHED();
return Tmp();
}
Inst buildCCall(Code& code, Value* origin, const Vector<Arg>& arguments)
{
Inst inst(Patch, origin, Arg::special(code.cCallSpecial()));
inst.args.append(arguments[0]);
inst.args.append(Tmp(GPRInfo::returnValueGPR));
inst.args.append(Tmp(GPRInfo::returnValueGPR2));
inst.args.append(Tmp(FPRInfo::returnValueFPR));
for (unsigned i = 1; i < arguments.size(); ++i) {
Arg arg = arguments[i];
if (arg.isTmp())
inst.args.append(arg);
}
return inst;
}
} } }
#endif // ENABLE(B3_JIT)