1//===-- AMDGPUMachineInstrs.h -*- 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//
9/// Convenience wrappers and helpers for AMDGPU-specific machine instructions.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_LIB_TARGET_AMDGPU_AMDGPUMACHINEINSTRS_H
14#define LLVM_LIB_TARGET_AMDGPU_AMDGPUMACHINEINSTRS_H
15
16#include "SIInstrInfo.h"
17#include "Utils/AMDGPUBaseInfo.h"
18#include "llvm/CodeGen/MachineInstr.h"
19
20namespace llvm {
21namespace AMDGPUMI {
22
23// Wrapper for the whole-dword VGPR "as memory" (address space 13) load/store
24// pseudos. The movrel form reads its index from M0, the GPR_IDX form from $idx:
25// movrel: load (outs data), (ins offset) store (ins data, offset)
26// gpr_idx: load (outs data), (ins idx, offset) store (ins data, idx, offset)
27class VLoadStoreIdxInst : public MachineInstr {
28 const AMDGPU::VLdStIdxOpcodeInfo &getInfo() const {
29 return *AMDGPU::getVLdStIdxOpcodeInfoByOpcode(Opc: getOpcode());
30 }
31
32public:
33 bool isGPRIdx() const { return getInfo().IsGPRIdx; }
34
35 MachineOperand &getDataOp() { return getOperand(i: 0); }
36 MachineOperand &getIdxOp() {
37 assert(isGPRIdx() && "movrel form reads its index from M0");
38 return getOperand(i: 1);
39 }
40 MachineOperand &getOffsetOp() { return getOperand(i: isGPRIdx() ? 2 : 1); }
41 const MachineOperand &getDataOp() const { return getOperand(i: 0); }
42 const MachineOperand &getIdxOp() const {
43 assert(isGPRIdx() && "movrel form reads its index from M0");
44 return getOperand(i: 1);
45 }
46 const MachineOperand &getOffsetOp() const {
47 return getOperand(i: isGPRIdx() ? 2 : 1);
48 }
49
50 unsigned getBitWidth() const { return getInfo().BitWidth; }
51
52 // The VGPRs an index can reach, which excludes the AGPRs that gfx90a+ counts
53 // as addressable.
54 static unsigned getNumIndexableVGPRs(const MachineFunction &MF);
55
56 // Whether an access of this many bits is supported. Each supported width has
57 // a load and a store pseudo of both forms.
58 static bool isSupportedBitWidth(unsigned Bits);
59
60 static bool classof(const MachineInstr *MI) {
61 return SIInstrFlags::isVGPRAsMem(O: *MI);
62 }
63};
64
65} // end namespace AMDGPUMI
66} // end namespace llvm
67
68#endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUMACHINEINSTRS_H
69