blob: e6d4268a66e15f596bdb7ae5bca2b5d8f72502dc [file] [log] [blame]
Konstantin Zhuravlyove9a5a772017-07-21 21:19:23 +00001//===--- AMDGPUMachineModuleInfo.h ------------------------------*- C++ -*-===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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
Konstantin Zhuravlyove9a5a772017-07-21 21:19:23 +00006//
7//===----------------------------------------------------------------------===//
8//
9/// \file
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000010/// AMDGPU Machine Module Info.
Konstantin Zhuravlyove9a5a772017-07-21 21:19:23 +000011///
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_LIB_TARGET_AMDGPU_AMDGPUMACHINEMODULEINFO_H
16#define LLVM_LIB_TARGET_AMDGPU_AMDGPUMACHINEMODULEINFO_H
17
Konstantin Zhuravlyovc8c9d4a2017-09-07 16:14:21 +000018#include "llvm/ADT/None.h"
19#include "llvm/ADT/Optional.h"
Konstantin Zhuravlyove9a5a772017-07-21 21:19:23 +000020#include "llvm/CodeGen/MachineModuleInfo.h"
21#include "llvm/CodeGen/MachineModuleInfoImpls.h"
22#include "llvm/IR/LLVMContext.h"
23
24namespace llvm {
25
26class AMDGPUMachineModuleInfo final : public MachineModuleInfoELF {
27private:
28
29 // All supported memory/synchronization scopes can be found here:
30 // http://llvm.org/docs/AMDGPUUsage.html#memory-scopes
31
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000032 /// Agent synchronization scope ID.
Konstantin Zhuravlyove9a5a772017-07-21 21:19:23 +000033 SyncScope::ID AgentSSID;
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000034 /// Workgroup synchronization scope ID.
Konstantin Zhuravlyove9a5a772017-07-21 21:19:23 +000035 SyncScope::ID WorkgroupSSID;
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000036 /// Wavefront synchronization scope ID.
Konstantin Zhuravlyove9a5a772017-07-21 21:19:23 +000037 SyncScope::ID WavefrontSSID;
38
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000039 /// In AMDGPU target synchronization scopes are inclusive, meaning a
Konstantin Zhuravlyovc8c9d4a2017-09-07 16:14:21 +000040 /// larger synchronization scope is inclusive of a smaller synchronization
41 /// scope.
42 ///
43 /// \returns \p SSID's inclusion ordering, or "None" if \p SSID is not
44 /// supported by the AMDGPU target.
45 Optional<uint8_t> getSyncScopeInclusionOrdering(SyncScope::ID SSID) const {
46 if (SSID == SyncScope::SingleThread)
47 return 0;
48 else if (SSID == getWavefrontSSID())
49 return 1;
50 else if (SSID == getWorkgroupSSID())
51 return 2;
52 else if (SSID == getAgentSSID())
53 return 3;
54 else if (SSID == SyncScope::System)
55 return 4;
56
57 return None;
58 }
59
Konstantin Zhuravlyove9a5a772017-07-21 21:19:23 +000060public:
61 AMDGPUMachineModuleInfo(const MachineModuleInfo &MMI);
62
63 /// \returns Agent synchronization scope ID.
64 SyncScope::ID getAgentSSID() const {
65 return AgentSSID;
66 }
67 /// \returns Workgroup synchronization scope ID.
68 SyncScope::ID getWorkgroupSSID() const {
69 return WorkgroupSSID;
70 }
71 /// \returns Wavefront synchronization scope ID.
72 SyncScope::ID getWavefrontSSID() const {
73 return WavefrontSSID;
74 }
Konstantin Zhuravlyovc8c9d4a2017-09-07 16:14:21 +000075
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000076 /// In AMDGPU target synchronization scopes are inclusive, meaning a
Konstantin Zhuravlyovc8c9d4a2017-09-07 16:14:21 +000077 /// larger synchronization scope is inclusive of a smaller synchronization
78 /// scope.
79 ///
80 /// \returns True if synchronization scope \p A is larger than or equal to
81 /// synchronization scope \p B, false if synchronization scope \p A is smaller
82 /// than synchronization scope \p B, or "None" if either synchronization scope
83 /// \p A or \p B is not supported by the AMDGPU target.
84 Optional<bool> isSyncScopeInclusion(SyncScope::ID A, SyncScope::ID B) const {
85 const auto &AIO = getSyncScopeInclusionOrdering(A);
86 const auto &BIO = getSyncScopeInclusionOrdering(B);
87 if (!AIO || !BIO)
88 return None;
89
90 return AIO.getValue() > BIO.getValue();
91 }
Konstantin Zhuravlyove9a5a772017-07-21 21:19:23 +000092};
93
94} // end namespace llvm
95
96#endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUMACHINEMODULEINFO_H