Revert " [LoongArch][ISel] Check the number of sign bits in `PatGprGpr_32` (#107432)"
[llvm-project.git] / llvm / lib / Target / AMDGPU / AMDGPUMachineModuleInfo.h
blob5c2ecaa65714f8c38a236bf61d640c02535df4c2
1 //===--- AMDGPUMachineModuleInfo.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 /// \file
10 /// AMDGPU Machine Module Info.
11 ///
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_LIB_TARGET_AMDGPU_AMDGPUMACHINEMODULEINFO_H
16 #define LLVM_LIB_TARGET_AMDGPU_AMDGPUMACHINEMODULEINFO_H
18 #include "llvm/CodeGen/MachineModuleInfoImpls.h"
19 #include "llvm/IR/LLVMContext.h"
21 namespace llvm {
23 class AMDGPUMachineModuleInfo final : public MachineModuleInfoELF {
24 private:
26 // All supported memory/synchronization scopes can be found here:
27 // http://llvm.org/docs/AMDGPUUsage.html#memory-scopes
29 /// Agent synchronization scope ID (cross address space).
30 SyncScope::ID AgentSSID;
31 /// Workgroup synchronization scope ID (cross address space).
32 SyncScope::ID WorkgroupSSID;
33 /// Wavefront synchronization scope ID (cross address space).
34 SyncScope::ID WavefrontSSID;
35 /// System synchronization scope ID (single address space).
36 SyncScope::ID SystemOneAddressSpaceSSID;
37 /// Agent synchronization scope ID (single address space).
38 SyncScope::ID AgentOneAddressSpaceSSID;
39 /// Workgroup synchronization scope ID (single address space).
40 SyncScope::ID WorkgroupOneAddressSpaceSSID;
41 /// Wavefront synchronization scope ID (single address space).
42 SyncScope::ID WavefrontOneAddressSpaceSSID;
43 /// Single thread synchronization scope ID (single address space).
44 SyncScope::ID SingleThreadOneAddressSpaceSSID;
46 /// In AMDGPU target synchronization scopes are inclusive, meaning a
47 /// larger synchronization scope is inclusive of a smaller synchronization
48 /// scope.
49 ///
50 /// \returns \p SSID's inclusion ordering, or "std::nullopt" if \p SSID is not
51 /// supported by the AMDGPU target.
52 std::optional<uint8_t>
53 getSyncScopeInclusionOrdering(SyncScope::ID SSID) const {
54 if (SSID == SyncScope::SingleThread ||
55 SSID == getSingleThreadOneAddressSpaceSSID())
56 return 0;
57 else if (SSID == getWavefrontSSID() ||
58 SSID == getWavefrontOneAddressSpaceSSID())
59 return 1;
60 else if (SSID == getWorkgroupSSID() ||
61 SSID == getWorkgroupOneAddressSpaceSSID())
62 return 2;
63 else if (SSID == getAgentSSID() ||
64 SSID == getAgentOneAddressSpaceSSID())
65 return 3;
66 else if (SSID == SyncScope::System ||
67 SSID == getSystemOneAddressSpaceSSID())
68 return 4;
70 return std::nullopt;
73 /// \returns True if \p SSID is restricted to single address space, false
74 /// otherwise
75 bool isOneAddressSpace(SyncScope::ID SSID) const {
76 return SSID == getSingleThreadOneAddressSpaceSSID() ||
77 SSID == getWavefrontOneAddressSpaceSSID() ||
78 SSID == getWorkgroupOneAddressSpaceSSID() ||
79 SSID == getAgentOneAddressSpaceSSID() ||
80 SSID == getSystemOneAddressSpaceSSID();
83 public:
84 AMDGPUMachineModuleInfo(const MachineModuleInfo &MMI);
86 /// \returns Agent synchronization scope ID (cross address space).
87 SyncScope::ID getAgentSSID() const {
88 return AgentSSID;
90 /// \returns Workgroup synchronization scope ID (cross address space).
91 SyncScope::ID getWorkgroupSSID() const {
92 return WorkgroupSSID;
94 /// \returns Wavefront synchronization scope ID (cross address space).
95 SyncScope::ID getWavefrontSSID() const {
96 return WavefrontSSID;
98 /// \returns System synchronization scope ID (single address space).
99 SyncScope::ID getSystemOneAddressSpaceSSID() const {
100 return SystemOneAddressSpaceSSID;
102 /// \returns Agent synchronization scope ID (single address space).
103 SyncScope::ID getAgentOneAddressSpaceSSID() const {
104 return AgentOneAddressSpaceSSID;
106 /// \returns Workgroup synchronization scope ID (single address space).
107 SyncScope::ID getWorkgroupOneAddressSpaceSSID() const {
108 return WorkgroupOneAddressSpaceSSID;
110 /// \returns Wavefront synchronization scope ID (single address space).
111 SyncScope::ID getWavefrontOneAddressSpaceSSID() const {
112 return WavefrontOneAddressSpaceSSID;
114 /// \returns Single thread synchronization scope ID (single address space).
115 SyncScope::ID getSingleThreadOneAddressSpaceSSID() const {
116 return SingleThreadOneAddressSpaceSSID;
119 /// In AMDGPU target synchronization scopes are inclusive, meaning a
120 /// larger synchronization scope is inclusive of a smaller synchronization
121 /// scope.
123 /// \returns True if synchronization scope \p A is larger than or equal to
124 /// synchronization scope \p B, false if synchronization scope \p A is smaller
125 /// than synchronization scope \p B, or "std::nullopt" if either
126 /// synchronization scope \p A or \p B is not supported by the AMDGPU target.
127 std::optional<bool> isSyncScopeInclusion(SyncScope::ID A,
128 SyncScope::ID B) const {
129 const auto &AIO = getSyncScopeInclusionOrdering(A);
130 const auto &BIO = getSyncScopeInclusionOrdering(B);
131 if (!AIO || !BIO)
132 return std::nullopt;
134 bool IsAOneAddressSpace = isOneAddressSpace(A);
135 bool IsBOneAddressSpace = isOneAddressSpace(B);
137 return *AIO >= *BIO &&
138 (IsAOneAddressSpace == IsBOneAddressSpace || !IsAOneAddressSpace);
142 } // end namespace llvm
144 #endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUMACHINEMODULEINFO_H