LLVM 23.0.0git
WebAssemblyRegisterBankInfo.cpp
Go to the documentation of this file.
1//===-- WebAssemblyRegisterBankInfo.cpp -------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8/// \file
9/// This file implements the targeting of the RegisterBankInfo class for
10/// WebAssembly.
11/// \todo This should be generated by TableGen.
12//===----------------------------------------------------------------------===//
13
20
21#define GET_TARGET_REGBANK_IMPL
22
23#include "WebAssemblyGenRegisterBank.inc"
24
25namespace llvm {
26namespace WebAssembly {
33
35 {0, 64, I64RegBank}};
36
37} // namespace WebAssembly
38} // namespace llvm
39
40using namespace llvm;
41
44
47 unsigned Opc = MI.getOpcode();
48 const MachineFunction &MF = *MI.getParent()->getParent();
49 const MachineRegisterInfo &MRI = MF.getRegInfo();
50
51 if ((Opc != TargetOpcode::COPY && !isPreISelGenericOpcode(Opc)) ||
52 Opc == TargetOpcode::G_PHI) {
55 if (Mapping.isValid())
56 return Mapping;
57 }
58
59 const unsigned NumOperands = MI.isCopyLike() ? 1 : MI.getNumOperands();
60 unsigned MappingID = DefaultMappingID;
61
62 // Track the size and bank of each register. We don't do partial mappings.
63 SmallVector<unsigned, 8> OpSize(NumOperands);
64 SmallVector<WebAssembly::PartialMappingIdx, 8> OpRegBankIdx(NumOperands);
65 for (unsigned Idx = 0; Idx < NumOperands; ++Idx) {
66 auto &MO = MI.getOperand(Idx);
67 if (!MO.isReg() || !MO.getReg())
68 continue;
69
70 LLT Ty = MRI.getType(MO.getReg());
71 if (!Ty.isValid())
72 continue;
73
74 OpSize[Idx] = Ty.getSizeInBits().getKnownMinValue();
75
76 if (Ty.isInteger()) {
77 if (OpSize[Idx] == 32) {
78 OpRegBankIdx[Idx] = WebAssembly::PMI_I32;
79 } else if (OpSize[Idx] == 64) {
80 OpRegBankIdx[Idx] = WebAssembly::PMI_I64;
81 }
82 }
83 }
84
85 SmallVector<const ValueMapping *, 8> OpdsMapping(NumOperands);
86 for (unsigned Idx = 0; Idx < NumOperands; ++Idx) {
87 if (MI.getOperand(Idx).isReg() && MI.getOperand(Idx).getReg()) {
88 LLT Ty = MRI.getType(MI.getOperand(Idx).getReg());
89 if (!Ty.isValid())
90 continue;
91
92 if (OpRegBankIdx[Idx] <= 0) {
94 }
95
96 const auto &Mapping = getValueMapping(
98 1);
99
100 if (!Mapping.isValid())
102
103 OpdsMapping[Idx] = &Mapping;
104 }
105 }
106
107 return getInstructionMapping(MappingID, /*Cost=*/1,
108 getOperandsMapping(OpdsMapping), NumOperands);
109}
IRTranslator LLVM IR MI
Register const TargetRegisterInfo * TRI
This file provides WebAssembly-specific target descriptions.
This file declares the targeting of the RegisterBankInfo class for WebAssembly.
This file contains the WebAssembly implementation of the WebAssemblyRegisterInfo class.
This file declares the WebAssembly-specific subclass of TargetSubtarget.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Representation of each machine instruction.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
LLT getType(Register Reg) const
Get the low-level type of Reg or LLT{} if Reg is not a generic (target independent) virtual register.
Helper class that represents how the value of an instruction may be mapped and what is the related co...
bool isValid() const
Check whether this object is valid.
const InstructionMapping & getInstructionMapping(unsigned ID, unsigned Cost, const ValueMapping *OperandsMapping, unsigned NumOperands) const
Method to get a uniquely generated InstructionMapping.
const ValueMapping & getValueMapping(unsigned StartIdx, unsigned Length, const RegisterBank &RegBank) const
The most common ValueMapping consists of a single PartialMapping.
const InstructionMapping & getInvalidInstructionMapping() const
Method to get a uniquely generated invalid InstructionMapping.
const ValueMapping * getOperandsMapping(Iterator Begin, Iterator End) const
Get the uniquely generated array of ValueMapping for the elements of between Begin and End.
static const unsigned DefaultMappingID
Identifier used when the related instruction mapping instance is generated by target independent code...
const InstructionMapping & getInstrMappingImpl(const MachineInstr &MI) const
Try to get the mapping of MI.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
const InstructionMapping & getInstrMapping(const MachineInstr &MI) const override
Get the mapping of the different operands of MI on the register bank.
WebAssemblyRegisterBankInfo(const TargetRegisterInfo &TRI)
const RegisterBankInfo::PartialMapping PartMappings[]
This is an optimization pass for GlobalISel generic memory operations.
bool isPreISelGenericOpcode(unsigned Opcode)
Check whether the given Opcode is a generic opcode that is not supposed to appear after ISel.
Helper struct that represents how a value is partially mapped into a register.