1//===-- SPIRVTypeInst.cpp - SPIR-V Type Instruction -------------*- 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// Implementation associated to SPIRVTypeInst.h.
10//
11//===----------------------------------------------------------------------===//
12
13#include "SPIRVTypeInst.h"
14#include "MCTargetDesc/SPIRVMCTargetDesc.h"
15#include "SPIRVInstrInfo.h"
16
17namespace llvm {
18[[maybe_unused]] static bool definesATypeRegister(const MachineInstr &MI) {
19 const MachineRegisterInfo &MRI = MI.getMF()->getRegInfo();
20 return MRI.getRegClass(Reg: MI.getOperand(i: 0).getReg()) == &SPIRV::TYPERegClass;
21}
22
23SPIRVTypeInst::SPIRVTypeInst(const MachineInstr *MI) : MI(MI) {
24 // A SPIRV Type whose result is not a type is invalid.
25 assert(!MI || definesATypeRegister(*MI));
26}
27
28bool SPIRVTypeInst::isTypeIntN(unsigned N) const {
29 if (MI->getOpcode() != SPIRV::OpTypeInt)
30 return false;
31 if (N)
32 return MI->getOperand(i: 1).getImm() == N;
33 return true;
34}
35
36bool SPIRVTypeInst::isAnyTypeFloat() const {
37 return MI->getOpcode() == SPIRV::OpTypeFloat;
38}
39
40bool SPIRVTypeInst::isPointer() const {
41 unsigned Op = MI->getOpcode();
42 return Op == SPIRV::OpTypePointer || Op == SPIRV::OpTypeUntypedPointerKHR;
43}
44
45bool SPIRVTypeInst::isTypePtr() const {
46 return MI->getOpcode() == SPIRV::OpTypePointer;
47}
48} // namespace llvm
49