110e730a2SDan Gohman //=- WebAssemblyMachineFunctionInfo.cpp - WebAssembly Machine Function Info -=// 210e730a2SDan Gohman // 310e730a2SDan Gohman // The LLVM Compiler Infrastructure 410e730a2SDan Gohman // 510e730a2SDan Gohman // This file is distributed under the University of Illinois Open Source 610e730a2SDan Gohman // License. See LICENSE.TXT for details. 710e730a2SDan Gohman // 810e730a2SDan Gohman //===----------------------------------------------------------------------===// 910e730a2SDan Gohman /// 1010e730a2SDan Gohman /// \file 1110e730a2SDan Gohman /// \brief This file implements WebAssembly-specific per-machine-function 1210e730a2SDan Gohman /// information. 1310e730a2SDan Gohman /// 1410e730a2SDan Gohman //===----------------------------------------------------------------------===// 1510e730a2SDan Gohman 1610e730a2SDan Gohman #include "WebAssemblyMachineFunctionInfo.h" 17*2726b88cSDan Gohman #include "WebAssemblyISelLowering.h" 18*2726b88cSDan Gohman #include "WebAssemblySubtarget.h" 19*2726b88cSDan Gohman #include "llvm/CodeGen/Analysis.h" 2010e730a2SDan Gohman using namespace llvm; 2110e730a2SDan Gohman 2210e730a2SDan Gohman WebAssemblyFunctionInfo::~WebAssemblyFunctionInfo() {} 23058fce54SDan Gohman 24058fce54SDan Gohman void WebAssemblyFunctionInfo::initWARegs() { 25058fce54SDan Gohman assert(WARegs.empty()); 26058fce54SDan Gohman unsigned Reg = UnusedReg; 27058fce54SDan Gohman WARegs.resize(MF.getRegInfo().getNumVirtRegs(), Reg); 28058fce54SDan Gohman } 29*2726b88cSDan Gohman 30*2726b88cSDan Gohman void llvm::ComputeLegalValueVTs(const Function &F, const TargetMachine &TM, 31*2726b88cSDan Gohman Type *Ty, SmallVectorImpl<MVT> &ValueVTs) { 32*2726b88cSDan Gohman const DataLayout &DL(F.getParent()->getDataLayout()); 33*2726b88cSDan Gohman const WebAssemblyTargetLowering &TLI = 34*2726b88cSDan Gohman *TM.getSubtarget<WebAssemblySubtarget>(F).getTargetLowering(); 35*2726b88cSDan Gohman SmallVector<EVT, 4> VTs; 36*2726b88cSDan Gohman ComputeValueVTs(TLI, DL, Ty, VTs); 37*2726b88cSDan Gohman 38*2726b88cSDan Gohman for (EVT VT : VTs) { 39*2726b88cSDan Gohman unsigned NumRegs = TLI.getNumRegisters(F.getContext(), VT); 40*2726b88cSDan Gohman MVT RegisterVT = TLI.getRegisterType(F.getContext(), VT); 41*2726b88cSDan Gohman for (unsigned i = 0; i != NumRegs; ++i) 42*2726b88cSDan Gohman ValueVTs.push_back(RegisterVT); 43*2726b88cSDan Gohman } 44*2726b88cSDan Gohman } 45*2726b88cSDan Gohman 46*2726b88cSDan Gohman void llvm::ComputeSignatureVTs(const Function &F, const TargetMachine &TM, 47*2726b88cSDan Gohman SmallVectorImpl<MVT> &Params, 48*2726b88cSDan Gohman SmallVectorImpl<MVT> &Results) { 49*2726b88cSDan Gohman ComputeLegalValueVTs(F, TM, F.getReturnType(), Results); 50*2726b88cSDan Gohman 51*2726b88cSDan Gohman if (Results.size() > 1) { 52*2726b88cSDan Gohman // WebAssembly currently can't lower returns of multiple values without 53*2726b88cSDan Gohman // demoting to sret (see WebAssemblyTargetLowering::CanLowerReturn). So 54*2726b88cSDan Gohman // replace multiple return values with a pointer parameter. 55*2726b88cSDan Gohman Results.clear(); 56*2726b88cSDan Gohman Params.push_back( 57*2726b88cSDan Gohman MVT::getIntegerVT(TM.createDataLayout().getPointerSizeInBits())); 58*2726b88cSDan Gohman } 59*2726b88cSDan Gohman 60*2726b88cSDan Gohman for (auto &Arg : F.args()) 61*2726b88cSDan Gohman ComputeLegalValueVTs(F, TM, Arg.getType(), Params); 62*2726b88cSDan Gohman } 63