Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 1 | //=- WebAssemblyMachineFunctionInfo.cpp - WebAssembly Machine Function Info -=// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | /// |
| 10 | /// \file |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame^] | 11 | /// This file implements WebAssembly-specific per-machine-function |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 12 | /// information. |
| 13 | /// |
| 14 | //===----------------------------------------------------------------------===// |
| 15 | |
| 16 | #include "WebAssemblyMachineFunctionInfo.h" |
Dan Gohman | 2726b88 | 2016-10-06 22:29:32 +0000 | [diff] [blame] | 17 | #include "WebAssemblyISelLowering.h" |
| 18 | #include "WebAssemblySubtarget.h" |
| 19 | #include "llvm/CodeGen/Analysis.h" |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 20 | using namespace llvm; |
| 21 | |
| 22 | WebAssemblyFunctionInfo::~WebAssemblyFunctionInfo() {} |
Dan Gohman | 058fce5 | 2015-11-13 00:21:05 +0000 | [diff] [blame] | 23 | |
| 24 | void WebAssemblyFunctionInfo::initWARegs() { |
| 25 | assert(WARegs.empty()); |
| 26 | unsigned Reg = UnusedReg; |
| 27 | WARegs.resize(MF.getRegInfo().getNumVirtRegs(), Reg); |
| 28 | } |
Dan Gohman | 2726b88 | 2016-10-06 22:29:32 +0000 | [diff] [blame] | 29 | |
| 30 | void llvm::ComputeLegalValueVTs(const Function &F, const TargetMachine &TM, |
| 31 | Type *Ty, SmallVectorImpl<MVT> &ValueVTs) { |
| 32 | const DataLayout &DL(F.getParent()->getDataLayout()); |
| 33 | const WebAssemblyTargetLowering &TLI = |
| 34 | *TM.getSubtarget<WebAssemblySubtarget>(F).getTargetLowering(); |
| 35 | SmallVector<EVT, 4> VTs; |
| 36 | ComputeValueVTs(TLI, DL, Ty, VTs); |
| 37 | |
| 38 | for (EVT VT : VTs) { |
| 39 | unsigned NumRegs = TLI.getNumRegisters(F.getContext(), VT); |
| 40 | MVT RegisterVT = TLI.getRegisterType(F.getContext(), VT); |
| 41 | for (unsigned i = 0; i != NumRegs; ++i) |
| 42 | ValueVTs.push_back(RegisterVT); |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | void llvm::ComputeSignatureVTs(const Function &F, const TargetMachine &TM, |
| 47 | SmallVectorImpl<MVT> &Params, |
| 48 | SmallVectorImpl<MVT> &Results) { |
| 49 | ComputeLegalValueVTs(F, TM, F.getReturnType(), Results); |
| 50 | |
| 51 | if (Results.size() > 1) { |
| 52 | // WebAssembly currently can't lower returns of multiple values without |
| 53 | // demoting to sret (see WebAssemblyTargetLowering::CanLowerReturn). So |
| 54 | // replace multiple return values with a pointer parameter. |
| 55 | Results.clear(); |
| 56 | Params.push_back( |
| 57 | MVT::getIntegerVT(TM.createDataLayout().getPointerSizeInBits())); |
| 58 | } |
| 59 | |
| 60 | for (auto &Arg : F.args()) |
| 61 | ComputeLegalValueVTs(F, TM, Arg.getType(), Params); |
| 62 | } |