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
39
41 {0, 64, I64RegBank}};
42
44 // invalid
45 {nullptr, 0},
46 // up to 4 operands as I32
51 // up to 4 operands as I64
56};
57} // namespace WebAssembly
58} // namespace llvm
59
60using namespace llvm;
61
64
67 unsigned Opc = MI.getOpcode();
68 const MachineFunction &MF = *MI.getParent()->getParent();
69 const MachineRegisterInfo &MRI = MF.getRegInfo();
72
73 if ((Opc != TargetOpcode::COPY && !isPreISelGenericOpcode(Opc)) ||
74 Opc == TargetOpcode::G_PHI) {
77 if (Mapping.isValid())
78 return Mapping;
79 }
80
81 const unsigned NumOperands = MI.getNumOperands();
82 const ValueMapping *OperandsMapping = nullptr;
83 unsigned MappingID = DefaultMappingID;
84
85 const LLT Op0Ty = MRI.getType(MI.getOperand(0).getReg());
86 unsigned Op0Size = Op0Ty.getSizeInBits();
87
88 auto &Op0IntValueMapping =
91
92 using namespace TargetOpcode;
93 switch (Opc) {
94 case G_CONSTANT:
95 OperandsMapping = getOperandsMapping({&Op0IntValueMapping, nullptr});
96 break;
97 case G_IMPLICIT_DEF:
98 OperandsMapping = &Op0IntValueMapping;
99 break;
100 case G_ADD:
101 case G_SUB:
102 case G_MUL:
103 case G_UDIV:
104 case G_SDIV:
105 case G_UREM:
106 case G_SREM:
107 case G_AND:
108 case G_OR:
109 case G_XOR:
110 case G_ASHR:
111 case G_LSHR:
112 case G_SHL:
113 case G_CTLZ:
114 case G_CTLZ_ZERO_UNDEF:
115 case G_CTTZ:
116 case G_CTTZ_ZERO_UNDEF:
117 case G_CTPOP:
118 case G_ROTL:
119 case G_ROTR:
120 OperandsMapping = &Op0IntValueMapping;
121 break;
122 case G_ZEXT:
123 case G_ANYEXT:
124 case G_SEXT:
125 case G_TRUNC: {
126 const LLT Op1Ty = MRI.getType(MI.getOperand(1).getReg());
127 unsigned Op1Size = Op1Ty.getSizeInBits();
128
129 auto &Op1IntValueMapping =
132 OperandsMapping =
133 getOperandsMapping({&Op0IntValueMapping, &Op1IntValueMapping});
134 break;
135 }
136 case G_SEXT_INREG:
137 OperandsMapping =
138 getOperandsMapping({&Op0IntValueMapping, &Op0IntValueMapping, nullptr});
139 break;
140 case COPY: {
141 Register DstReg = MI.getOperand(0).getReg();
142 Register SrcReg = MI.getOperand(1).getReg();
143
144 const RegisterBank *DstRB = getRegBank(DstReg, MRI, TRI);
145 const RegisterBank *SrcRB = getRegBank(SrcReg, MRI, TRI);
146
147 if (!DstRB)
148 DstRB = SrcRB;
149 else if (!SrcRB)
150 SrcRB = DstRB;
151
152 assert(DstRB && SrcRB && "Both RegBank were nullptr");
153
154 if (DstRB != SrcRB) {
155 break; // for now, only allow no-op copies
156 }
157
159 MappingID, /*Cost=*/1, &Op0IntValueMapping,
160 // We only care about the mapping of the destination for COPY.
161 1);
162 }
163 }
164
165 if (!OperandsMapping)
167
168 return getInstructionMapping(MappingID, /*Cost=*/1, OperandsMapping,
169 NumOperands);
170}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
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.
constexpr TypeSize getSizeInBits() const
Returns the total size of the type. Must only be called on sized types.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
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 InstructionMapping & getInvalidInstructionMapping() const
Method to get a uniquely generated invalid InstructionMapping.
const RegisterBank & getRegBank(unsigned ID)
Get the register bank identified by ID.
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 class implements the register bank concept.
Wrapper class representing virtual and physical registers.
Definition Register.h:20
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 WebAssemblyRegisterInfo * getRegisterInfo() const override
Invariant opcodes: All instruction sets have these as their low opcodes.
const RegisterBankInfo::ValueMapping ValueMappings[]
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.
Helper struct that represents how a value is mapped through different register banks.