diff options
author | Dan Gohman <dan433584@gmail.com> | 2016-10-06 22:29:32 +0000 |
---|---|---|
committer | Dan Gohman <dan433584@gmail.com> | 2016-10-06 22:29:32 +0000 |
commit | 2726b88c038737460a4502915ff427db5854b3e7 (patch) | |
tree | 4c4ad476a660cea533b0fa28b41d701e4f6adece /llvm/lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.cpp | |
parent | 3a643e8d46d06da4c6648a12e48ceb6ab6dc3733 (diff) | |
download | bcm5719-llvm-2726b88c038737460a4502915ff427db5854b3e7.tar.gz bcm5719-llvm-2726b88c038737460a4502915ff427db5854b3e7.zip |
[WebAssemby] Implement block signatures.
Per spec changes, this implements block signatures, and adds just enough
logic to produce correct block signatures at the ends of functions.
Differential Revision: https://reviews.llvm.org/D25144
llvm-svn: 283503
Diffstat (limited to 'llvm/lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.cpp')
-rw-r--r-- | llvm/lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.cpp index 225c5d32cb5..ccf6a18b32e 100644 --- a/llvm/lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.cpp +++ b/llvm/lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.cpp @@ -14,6 +14,9 @@ //===----------------------------------------------------------------------===// #include "WebAssemblyMachineFunctionInfo.h" +#include "WebAssemblyISelLowering.h" +#include "WebAssemblySubtarget.h" +#include "llvm/CodeGen/Analysis.h" using namespace llvm; WebAssemblyFunctionInfo::~WebAssemblyFunctionInfo() {} @@ -23,3 +26,37 @@ void WebAssemblyFunctionInfo::initWARegs() { unsigned Reg = UnusedReg; WARegs.resize(MF.getRegInfo().getNumVirtRegs(), Reg); } + +void llvm::ComputeLegalValueVTs(const Function &F, const TargetMachine &TM, + Type *Ty, SmallVectorImpl<MVT> &ValueVTs) { + const DataLayout &DL(F.getParent()->getDataLayout()); + const WebAssemblyTargetLowering &TLI = + *TM.getSubtarget<WebAssemblySubtarget>(F).getTargetLowering(); + SmallVector<EVT, 4> VTs; + ComputeValueVTs(TLI, DL, Ty, VTs); + + for (EVT VT : VTs) { + unsigned NumRegs = TLI.getNumRegisters(F.getContext(), VT); + MVT RegisterVT = TLI.getRegisterType(F.getContext(), VT); + for (unsigned i = 0; i != NumRegs; ++i) + ValueVTs.push_back(RegisterVT); + } +} + +void llvm::ComputeSignatureVTs(const Function &F, const TargetMachine &TM, + SmallVectorImpl<MVT> &Params, + SmallVectorImpl<MVT> &Results) { + ComputeLegalValueVTs(F, TM, F.getReturnType(), Results); + + if (Results.size() > 1) { + // WebAssembly currently can't lower returns of multiple values without + // demoting to sret (see WebAssemblyTargetLowering::CanLowerReturn). So + // replace multiple return values with a pointer parameter. + Results.clear(); + Params.push_back( + MVT::getIntegerVT(TM.createDataLayout().getPointerSizeInBits())); + } + + for (auto &Arg : F.args()) + ComputeLegalValueVTs(F, TM, Arg.getType(), Params); +} |