Konstantin Zhuravlyov | e9a5a77 | 2017-07-21 21:19:23 +0000 | [diff] [blame] | 1 | //===--- AMDGPUMachineModuleInfo.h ------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | /// \file |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame^] | 11 | /// AMDGPU Machine Module Info. |
Konstantin Zhuravlyov | e9a5a77 | 2017-07-21 21:19:23 +0000 | [diff] [blame] | 12 | /// |
| 13 | // |
| 14 | //===----------------------------------------------------------------------===// |
| 15 | |
| 16 | #ifndef LLVM_LIB_TARGET_AMDGPU_AMDGPUMACHINEMODULEINFO_H |
| 17 | #define LLVM_LIB_TARGET_AMDGPU_AMDGPUMACHINEMODULEINFO_H |
| 18 | |
Konstantin Zhuravlyov | c8c9d4a | 2017-09-07 16:14:21 +0000 | [diff] [blame] | 19 | #include "llvm/ADT/None.h" |
| 20 | #include "llvm/ADT/Optional.h" |
Konstantin Zhuravlyov | e9a5a77 | 2017-07-21 21:19:23 +0000 | [diff] [blame] | 21 | #include "llvm/CodeGen/MachineModuleInfo.h" |
| 22 | #include "llvm/CodeGen/MachineModuleInfoImpls.h" |
| 23 | #include "llvm/IR/LLVMContext.h" |
| 24 | |
| 25 | namespace llvm { |
| 26 | |
| 27 | class AMDGPUMachineModuleInfo final : public MachineModuleInfoELF { |
| 28 | private: |
| 29 | |
| 30 | // All supported memory/synchronization scopes can be found here: |
| 31 | // http://llvm.org/docs/AMDGPUUsage.html#memory-scopes |
| 32 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame^] | 33 | /// Agent synchronization scope ID. |
Konstantin Zhuravlyov | e9a5a77 | 2017-07-21 21:19:23 +0000 | [diff] [blame] | 34 | SyncScope::ID AgentSSID; |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame^] | 35 | /// Workgroup synchronization scope ID. |
Konstantin Zhuravlyov | e9a5a77 | 2017-07-21 21:19:23 +0000 | [diff] [blame] | 36 | SyncScope::ID WorkgroupSSID; |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame^] | 37 | /// Wavefront synchronization scope ID. |
Konstantin Zhuravlyov | e9a5a77 | 2017-07-21 21:19:23 +0000 | [diff] [blame] | 38 | SyncScope::ID WavefrontSSID; |
| 39 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame^] | 40 | /// In AMDGPU target synchronization scopes are inclusive, meaning a |
Konstantin Zhuravlyov | c8c9d4a | 2017-09-07 16:14:21 +0000 | [diff] [blame] | 41 | /// larger synchronization scope is inclusive of a smaller synchronization |
| 42 | /// scope. |
| 43 | /// |
| 44 | /// \returns \p SSID's inclusion ordering, or "None" if \p SSID is not |
| 45 | /// supported by the AMDGPU target. |
| 46 | Optional<uint8_t> getSyncScopeInclusionOrdering(SyncScope::ID SSID) const { |
| 47 | if (SSID == SyncScope::SingleThread) |
| 48 | return 0; |
| 49 | else if (SSID == getWavefrontSSID()) |
| 50 | return 1; |
| 51 | else if (SSID == getWorkgroupSSID()) |
| 52 | return 2; |
| 53 | else if (SSID == getAgentSSID()) |
| 54 | return 3; |
| 55 | else if (SSID == SyncScope::System) |
| 56 | return 4; |
| 57 | |
| 58 | return None; |
| 59 | } |
| 60 | |
Konstantin Zhuravlyov | e9a5a77 | 2017-07-21 21:19:23 +0000 | [diff] [blame] | 61 | public: |
| 62 | AMDGPUMachineModuleInfo(const MachineModuleInfo &MMI); |
| 63 | |
| 64 | /// \returns Agent synchronization scope ID. |
| 65 | SyncScope::ID getAgentSSID() const { |
| 66 | return AgentSSID; |
| 67 | } |
| 68 | /// \returns Workgroup synchronization scope ID. |
| 69 | SyncScope::ID getWorkgroupSSID() const { |
| 70 | return WorkgroupSSID; |
| 71 | } |
| 72 | /// \returns Wavefront synchronization scope ID. |
| 73 | SyncScope::ID getWavefrontSSID() const { |
| 74 | return WavefrontSSID; |
| 75 | } |
Konstantin Zhuravlyov | c8c9d4a | 2017-09-07 16:14:21 +0000 | [diff] [blame] | 76 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame^] | 77 | /// In AMDGPU target synchronization scopes are inclusive, meaning a |
Konstantin Zhuravlyov | c8c9d4a | 2017-09-07 16:14:21 +0000 | [diff] [blame] | 78 | /// larger synchronization scope is inclusive of a smaller synchronization |
| 79 | /// scope. |
| 80 | /// |
| 81 | /// \returns True if synchronization scope \p A is larger than or equal to |
| 82 | /// synchronization scope \p B, false if synchronization scope \p A is smaller |
| 83 | /// than synchronization scope \p B, or "None" if either synchronization scope |
| 84 | /// \p A or \p B is not supported by the AMDGPU target. |
| 85 | Optional<bool> isSyncScopeInclusion(SyncScope::ID A, SyncScope::ID B) const { |
| 86 | const auto &AIO = getSyncScopeInclusionOrdering(A); |
| 87 | const auto &BIO = getSyncScopeInclusionOrdering(B); |
| 88 | if (!AIO || !BIO) |
| 89 | return None; |
| 90 | |
| 91 | return AIO.getValue() > BIO.getValue(); |
| 92 | } |
Konstantin Zhuravlyov | e9a5a77 | 2017-07-21 21:19:23 +0000 | [diff] [blame] | 93 | }; |
| 94 | |
| 95 | } // end namespace llvm |
| 96 | |
| 97 | #endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUMACHINEMODULEINFO_H |