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