LLVM 24.0.0git
SPIRVTypeInst.h
Go to the documentation of this file.
1//===-- SPIRVTypeInst.h - 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// SPIRVTypeInst is used to represent a SPIR-V type instruction.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_LIB_TARGET_SPIRV_SPIRVTYPEINST_H
14#define LLVM_LIB_TARGET_SPIRV_SPIRVTYPEINST_H
15
17
18namespace llvm {
19class MachineInstr;
21
22class SPIRVTypeInst {
23 const MachineInstr *MI;
24
25 // Used by DenseMapInfo to bypass the assertion. The thombstone and empty keys
26 // are not null. They are -1 and -2 aligned to the appropiate pointer size.
27 struct UncheckedConstructor {};
28 SPIRVTypeInst(const MachineInstr *MI, UncheckedConstructor) : MI(MI) {};
29
30public:
31 SPIRVTypeInst(const MachineInstr &MI) : SPIRVTypeInst(&MI) {}
32 SPIRVTypeInst(const MachineInstr *MI = nullptr);
33
34 // No need to verify the register since it's already verified by the copied
35 // object.
36 SPIRVTypeInst(const SPIRVTypeInst &Other) = default;
37 SPIRVTypeInst &operator=(const SPIRVTypeInst &Other) = default;
38
39 const MachineInstr &operator*() const { return *MI; }
40 const MachineInstr *operator->() const { return MI; }
41 operator const MachineInstr *() const { return MI; }
42
43 bool operator==(const SPIRVTypeInst &Other) const { return MI == Other.MI; }
44 bool operator!=(const SPIRVTypeInst &Other) const { return MI != Other.MI; }
45
46 operator bool() const { return MI; }
47
48 // Returns true if this is an OpTypeInt instruction.
49 // If N is non-zero, also checks that the bit width matches N.
50 bool isTypeIntN(unsigned N = 0) const;
51 // Returns true if this is an OpTypeFloat instruction.
52 bool isAnyTypeFloat() const;
53 // Returns true if this is an OpTypeInt or OpTypeFloat instruction.
54 bool isTypeIntOrFloat() const { return isTypeIntN() || isAnyTypeFloat(); }
55 // Returns true if this is an OpTypePointer or OpTypeUntypedPointerKHR
56 // instruction.
57 bool isPointer() const;
58 // Returns true if this is an OpTypePointer instruction.
59 bool isTypePtr() const;
60 // Returns true if this is an OpTypeUntypedPointerKHR instruction.
61 bool isTypeUntypedPtr() const;
62
63 friend struct DenseMapInfo<SPIRVTypeInst>;
64};
65
66template <> struct DenseMapInfo<SPIRVTypeInst> {
68 static unsigned getHashValue(SPIRVTypeInst Ty) {
69 return MIInfo::getHashValue(Ty.MI);
70 }
71 static bool isEqual(SPIRVTypeInst Ty1, SPIRVTypeInst Ty2) {
72 return Ty1 == Ty2;
73 }
74};
75
76} // namespace llvm
77#endif // LLVM_LIB_TARGET_SPIRV_SPIRVTYPEINST_H
This file defines DenseMapInfo traits for DenseMap.
IRTranslator LLVM IR MI
Representation of each machine instruction.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
SPIRVTypeInst & operator=(const SPIRVTypeInst &Other)=default
bool isTypeIntOrFloat() const
bool isAnyTypeFloat() const
bool isTypeIntN(unsigned N=0) const
SPIRVTypeInst(const MachineInstr &MI)
const MachineInstr * operator->() const
bool operator==(const SPIRVTypeInst &Other) const
bool isTypeUntypedPtr() const
SPIRVTypeInst(const SPIRVTypeInst &Other)=default
bool operator!=(const SPIRVTypeInst &Other) const
const MachineInstr & operator*() const
This is an optimization pass for GlobalISel generic memory operations.
@ Other
Any other memory.
Definition ModRef.h:68
#define N
DenseMapInfo< MachineInstr * > MIInfo
static unsigned getHashValue(SPIRVTypeInst Ty)
static bool isEqual(SPIRVTypeInst Ty1, SPIRVTypeInst Ty2)
An information struct used to provide DenseMap with the various necessary components for a given valu...