2015-07-30 06:32:47 +08:00
|
|
|
// WebAssemblyMachineFunctionInfo.h-WebAssembly machine function info-*- C++ -*-
|
2015-06-30 07:51:55 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
///
|
|
|
|
/// \file
|
|
|
|
/// \brief This file declares WebAssembly-specific per-machine-function
|
|
|
|
/// information.
|
|
|
|
///
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYMACHINEFUNCTIONINFO_H
|
|
|
|
#define LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYMACHINEFUNCTIONINFO_H
|
|
|
|
|
2015-12-12 07:49:46 +08:00
|
|
|
#include "MCTargetDesc/WebAssemblyMCTargetDesc.h"
|
2015-06-30 07:51:55 +08:00
|
|
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
|
|
|
/// This class is derived from MachineFunctionInfo and contains private
|
|
|
|
/// WebAssembly-specific information for each MachineFunction.
|
|
|
|
class WebAssemblyFunctionInfo final : public MachineFunctionInfo {
|
|
|
|
MachineFunction &MF;
|
|
|
|
|
2015-11-11 09:33:02 +08:00
|
|
|
std::vector<MVT> Params;
|
2016-10-07 06:29:32 +08:00
|
|
|
std::vector<MVT> Results;
|
2016-10-25 07:27:49 +08:00
|
|
|
std::vector<MVT> Locals;
|
2015-10-06 08:27:55 +08:00
|
|
|
|
2015-11-13 01:04:33 +08:00
|
|
|
/// A mapping from CodeGen vreg index to WebAssembly register number.
|
|
|
|
std::vector<unsigned> WARegs;
|
|
|
|
|
2015-11-17 00:18:28 +08:00
|
|
|
/// A mapping from CodeGen vreg index to a boolean value indicating whether
|
|
|
|
/// the given register is considered to be "stackified", meaning it has been
|
|
|
|
/// determined or made to meet the stack requirements:
|
|
|
|
/// - single use (per path)
|
|
|
|
/// - single def (per path)
|
2015-12-03 02:08:49 +08:00
|
|
|
/// - defined and used in LIFO order with other stack registers
|
2015-11-17 00:18:28 +08:00
|
|
|
BitVector VRegStackified;
|
|
|
|
|
2016-02-11 03:51:04 +08:00
|
|
|
// A virtual register holding the pointer to the vararg buffer for vararg
|
|
|
|
// functions. It is created and set in TLI::LowerFormalArguments and read by
|
|
|
|
// TLI::LowerVASTART
|
|
|
|
unsigned VarargVreg = -1U;
|
|
|
|
|
2016-11-08 06:00:48 +08:00
|
|
|
// A virtual register holding the base pointer for functions that have
|
|
|
|
// overaligned values on the user stack.
|
|
|
|
unsigned BasePtrVreg = -1U;
|
|
|
|
|
2016-02-11 03:51:04 +08:00
|
|
|
public:
|
2016-05-10 12:24:02 +08:00
|
|
|
explicit WebAssemblyFunctionInfo(MachineFunction &MF) : MF(MF) {}
|
2015-06-30 07:51:55 +08:00
|
|
|
~WebAssemblyFunctionInfo() override;
|
2015-10-06 08:27:55 +08:00
|
|
|
|
2015-11-11 09:33:02 +08:00
|
|
|
void addParam(MVT VT) { Params.push_back(VT); }
|
|
|
|
const std::vector<MVT> &getParams() const { return Params; }
|
|
|
|
|
2016-10-07 06:29:32 +08:00
|
|
|
void addResult(MVT VT) { Results.push_back(VT); }
|
|
|
|
const std::vector<MVT> &getResults() const { return Results; }
|
|
|
|
|
2017-02-25 07:18:00 +08:00
|
|
|
void setNumLocals(size_t NumLocals) { Locals.resize(NumLocals, MVT::i32); }
|
|
|
|
void setLocal(size_t i, MVT VT) { Locals[i] = VT; }
|
2016-10-25 07:27:49 +08:00
|
|
|
void addLocal(MVT VT) { Locals.push_back(VT); }
|
|
|
|
const std::vector<MVT> &getLocals() const { return Locals; }
|
|
|
|
|
2016-02-11 03:51:04 +08:00
|
|
|
unsigned getVarargBufferVreg() const {
|
|
|
|
assert(VarargVreg != -1U && "Vararg vreg hasn't been set");
|
|
|
|
return VarargVreg;
|
|
|
|
}
|
|
|
|
void setVarargBufferVreg(unsigned Reg) { VarargVreg = Reg; }
|
|
|
|
|
2016-11-08 06:00:48 +08:00
|
|
|
unsigned getBasePointerVreg() const {
|
|
|
|
assert(BasePtrVreg != -1U && "Base ptr vreg hasn't been set");
|
|
|
|
return BasePtrVreg;
|
|
|
|
}
|
|
|
|
void setBasePointerVreg(unsigned Reg) { BasePtrVreg = Reg; }
|
|
|
|
|
2015-11-13 08:21:05 +08:00
|
|
|
static const unsigned UnusedReg = -1u;
|
|
|
|
|
2015-11-17 00:18:28 +08:00
|
|
|
void stackifyVReg(unsigned VReg) {
|
2016-10-25 03:49:43 +08:00
|
|
|
assert(MF.getRegInfo().getUniqueVRegDef(VReg));
|
2015-11-17 00:18:28 +08:00
|
|
|
if (TargetRegisterInfo::virtReg2Index(VReg) >= VRegStackified.size())
|
|
|
|
VRegStackified.resize(TargetRegisterInfo::virtReg2Index(VReg) + 1);
|
|
|
|
VRegStackified.set(TargetRegisterInfo::virtReg2Index(VReg));
|
|
|
|
}
|
|
|
|
bool isVRegStackified(unsigned VReg) const {
|
|
|
|
if (TargetRegisterInfo::virtReg2Index(VReg) >= VRegStackified.size())
|
|
|
|
return false;
|
|
|
|
return VRegStackified.test(TargetRegisterInfo::virtReg2Index(VReg));
|
|
|
|
}
|
|
|
|
|
2015-11-13 08:21:05 +08:00
|
|
|
void initWARegs();
|
2015-11-13 01:04:33 +08:00
|
|
|
void setWAReg(unsigned VReg, unsigned WAReg) {
|
2015-11-13 08:21:05 +08:00
|
|
|
assert(WAReg != UnusedReg);
|
2015-11-26 05:13:02 +08:00
|
|
|
assert(TargetRegisterInfo::virtReg2Index(VReg) < WARegs.size());
|
2015-11-13 01:04:33 +08:00
|
|
|
WARegs[TargetRegisterInfo::virtReg2Index(VReg)] = WAReg;
|
|
|
|
}
|
2015-12-12 07:49:46 +08:00
|
|
|
unsigned getWAReg(unsigned Reg) const {
|
2016-05-10 12:24:02 +08:00
|
|
|
assert(TargetRegisterInfo::virtReg2Index(Reg) < WARegs.size());
|
|
|
|
return WARegs[TargetRegisterInfo::virtReg2Index(Reg)];
|
2015-11-13 01:04:33 +08:00
|
|
|
}
|
2016-05-21 08:21:56 +08:00
|
|
|
|
|
|
|
// For a given stackified WAReg, return the id number to print with push/pop.
|
|
|
|
static unsigned getWARegStackId(unsigned Reg) {
|
|
|
|
assert(Reg & INT32_MIN);
|
|
|
|
return Reg & INT32_MAX;
|
|
|
|
}
|
2015-06-30 07:51:55 +08:00
|
|
|
};
|
|
|
|
|
2016-10-07 06:29:32 +08:00
|
|
|
void ComputeLegalValueVTs(const Function &F, const TargetMachine &TM,
|
|
|
|
Type *Ty, SmallVectorImpl<MVT> &ValueVTs);
|
|
|
|
|
|
|
|
void ComputeSignatureVTs(const Function &F, const TargetMachine &TM,
|
|
|
|
SmallVectorImpl<MVT> &Params,
|
|
|
|
SmallVectorImpl<MVT> &Results);
|
|
|
|
|
2015-06-30 07:51:55 +08:00
|
|
|
} // end namespace llvm
|
|
|
|
|
|
|
|
#endif
|