LLVM 23.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 bool operator==(const MachineInstr *Other) const { return MI == Other; }
47 bool operator!=(const MachineInstr *Other) const { return MI != Other; }
48
49 operator bool() const { return MI; }
50
51 friend struct DenseMapInfo<SPIRVTypeInst>;
52};
53
54template <> struct DenseMapInfo<SPIRVTypeInst> {
57 return {MIInfo::getEmptyKey(), SPIRVTypeInst::UncheckedConstructor()};
58 }
60 return {MIInfo::getTombstoneKey(), SPIRVTypeInst::UncheckedConstructor()};
61 }
62 static unsigned getHashValue(SPIRVTypeInst Ty) {
63 return MIInfo::getHashValue(Ty.MI);
64 }
65 static bool isEqual(SPIRVTypeInst Ty1, SPIRVTypeInst Ty2) {
66 return Ty1 == Ty2;
67 }
68};
69
70} // namespace llvm
71#endif
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,...
bool operator==(const MachineInstr *Other) const
SPIRVTypeInst & operator=(const SPIRVTypeInst &Other)=default
SPIRVTypeInst(const MachineInstr &MI)
const MachineInstr * operator->() const
bool operator==(const SPIRVTypeInst &Other) const
SPIRVTypeInst(const SPIRVTypeInst &Other)=default
bool operator!=(const MachineInstr *Other) const
bool operator!=(const SPIRVTypeInst &Other) const
const MachineInstr & operator*() const
This is an optimization pass for GlobalISel generic memory operations.
Definition Types.h:26
@ Other
Any other memory.
Definition ModRef.h:68
static SPIRVTypeInst getEmptyKey()
DenseMapInfo< MachineInstr * > MIInfo
static unsigned getHashValue(SPIRVTypeInst Ty)
static SPIRVTypeInst getTombstoneKey()
static bool isEqual(SPIRVTypeInst Ty1, SPIRVTypeInst Ty2)
An information struct used to provide DenseMap with the various necessary components for a given valu...