summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
diff options
context:
space:
mode:
authorJF Bastien <jfb@google.com>2015-08-24 21:59:51 +0000
committerJF Bastien <jfb@google.com>2015-08-24 21:59:51 +0000
commitd8a9d66d50a8c86721925eec6a1ab10a6c8d19be (patch)
treefc071951ef0fa1f7db8956d12c8036cad95a888a /llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
parentd8879c85f68250baa6f2ebc463259201782e8460 (diff)
downloadbcm5719-llvm-d8a9d66d50a8c86721925eec6a1ab10a6c8d19be.tar.gz
bcm5719-llvm-d8a9d66d50a8c86721925eec6a1ab10a6c8d19be.zip
call
llvm-svn: 245882
Diffstat (limited to 'llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp')
-rw-r--r--llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp73
1 files changed, 70 insertions, 3 deletions
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
index dfeec770d5a..d9efc190b5b 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
@@ -19,6 +19,7 @@
#include "WebAssemblyTargetMachine.h"
#include "WebAssemblyTargetObjectFile.h"
#include "llvm/CodeGen/Analysis.h"
+#include "llvm/CodeGen/CallingConvLower.h"
#include "llvm/CodeGen/MachineRegisterInfo.h"
#include "llvm/CodeGen/SelectionDAG.h"
#include "llvm/IR/DiagnosticInfo.h"
@@ -164,9 +165,13 @@ MVT WebAssemblyTargetLowering::getScalarShiftAmountTy(const DataLayout &DL,
const char *
WebAssemblyTargetLowering::getTargetNodeName(unsigned Opcode) const {
switch (static_cast<WebAssemblyISD::NodeType>(Opcode)) {
- case WebAssemblyISD::FIRST_NUMBER: break;
- case WebAssemblyISD::RETURN: return "WebAssemblyISD::RETURN";
- case WebAssemblyISD::ARGUMENT: return "WebAssemblyISD::ARGUMENT";
+ case WebAssemblyISD::FIRST_NUMBER:
+ break;
+#define HANDLE_NODETYPE(NODE) \
+ case WebAssemblyISD::NODE: \
+ return "WebAssemblyISD::" #NODE;
+#include "WebAssemblyISD.def"
+#undef HANDLE_NODETYPE
}
return nullptr;
}
@@ -185,6 +190,68 @@ static void fail(SDLoc DL, SelectionDAG &DAG, const char *msg) {
DiagnosticInfoUnsupported(DL, *MF.getFunction(), msg, SDValue()));
}
+SDValue
+WebAssemblyTargetLowering::LowerCall(CallLoweringInfo &CLI,
+ SmallVectorImpl<SDValue> &InVals) const {
+ SelectionDAG &DAG = CLI.DAG;
+ SDLoc DL = CLI.DL;
+ SDValue Chain = CLI.Chain;
+ SDValue Callee = CLI.Callee;
+ MachineFunction &MF = DAG.getMachineFunction();
+
+ CallingConv::ID CallConv = CLI.CallConv;
+ if (CallConv != CallingConv::C)
+ fail(DL, DAG, "WebAssembly doesn't support non-C calling conventions");
+ if (CLI.IsTailCall || MF.getTarget().Options.GuaranteedTailCallOpt)
+ fail(DL, DAG, "WebAssembly doesn't support tail call yet");
+ if (CLI.IsPatchPoint)
+ fail(DL, DAG, "WebAssembly doesn't support patch point yet");
+
+ SmallVectorImpl<ISD::OutputArg> &Outs = CLI.Outs;
+ SmallVectorImpl<SDValue> &OutVals = CLI.OutVals;
+ Type *retTy = CLI.RetTy;
+ bool IsStructRet = (Outs.empty()) ? false : Outs[0].Flags.isSRet();
+ if (IsStructRet)
+ fail(DL, DAG, "WebAssembly doesn't support struct return yet");
+ if (Outs.size() > 1)
+ fail(DL, DAG, "WebAssembly doesn't support more than 1 returned value yet");
+
+ SmallVectorImpl<ISD::InputArg> &Ins = CLI.Ins;
+ ArgListTy &Args = CLI.getArgs();
+ bool IsVarArg = CLI.IsVarArg;
+ if (IsVarArg)
+ fail(DL, DAG, "WebAssembly doesn't support varargs yet");
+ // Analyze operands of the call, assigning locations to each operand.
+ SmallVector<CCValAssign, 16> ArgLocs;
+ CCState CCInfo(CallConv, IsVarArg, MF, ArgLocs, *DAG.getContext());
+ unsigned NumBytes = CCInfo.getNextStackOffset();
+
+ auto PtrVT = getPointerTy(MF.getDataLayout());
+ auto Zero = DAG.getConstant(0, CLI.DL, PtrVT, true);
+ auto NB = DAG.getConstant(NumBytes, CLI.DL, PtrVT, true);
+ Chain = DAG.getCALLSEQ_START(Chain, NB, CLI.DL);
+
+ SmallVector<SDValue, 16> Ops;
+ Ops.push_back(Chain);
+ Ops.push_back(CLI.Callee);
+ Ops.append(CLI.OutVals.begin(), CLI.OutVals.end());
+
+ SmallVector<EVT, 8> Tys;
+ for (const auto &In : CLI.Ins)
+ Tys.push_back(In.VT);
+ Tys.push_back(MVT::Other);
+ SDVTList TyList = CLI.DAG.getVTList(Tys);
+ SDValue Res = CLI.DAG.getNode(WebAssemblyISD::CALL, CLI.DL, TyList, Ops);
+ InVals.push_back(Res);
+ Chain = Res.getValue(1);
+
+ // FIXME: handle CLI.RetSExt and CLI.RetZExt?
+
+ Chain = CLI.DAG.getCALLSEQ_END(Chain, NB, Zero, SDValue(), CLI.DL);
+
+ return Chain;
+}
+
bool WebAssemblyTargetLowering::CanLowerReturn(
CallingConv::ID CallConv, MachineFunction &MF, bool IsVarArg,
const SmallVectorImpl<ISD::OutputArg> &Outs, LLVMContext &Context) const {
OpenPOWER on IntegriCloud