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