LLVM 24.0.0git
AMDGPUMachineModuleInfo.h
Go to the documentation of this file.
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
19#include "llvm/IR/LLVMContext.h"
20
21namespace llvm {
22
24private:
25
26 // All supported memory/synchronization scopes can be found here:
27 // http://llvm.org/docs/AMDGPUUsage.html#memory-scopes
28
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 /// Cluster synchronization scope ID (cross address space).
36 SyncScope::ID ClusterSSID;
37 /// System synchronization scope ID (single address space).
38 SyncScope::ID SystemOneAddressSpaceSSID;
39 /// Agent synchronization scope ID (single address space).
40 SyncScope::ID AgentOneAddressSpaceSSID;
41 /// Workgroup synchronization scope ID (single address space).
42 SyncScope::ID WorkgroupOneAddressSpaceSSID;
43 /// Wavefront synchronization scope ID (single address space).
44 SyncScope::ID WavefrontOneAddressSpaceSSID;
45 /// Single thread synchronization scope ID (single address space).
46 SyncScope::ID SingleThreadOneAddressSpaceSSID;
47 /// Cluster synchronization scope ID (single address space).
48 SyncScope::ID ClusterOneAddressSpaceSSID;
49
50public:
52
53 /// \returns Agent synchronization scope ID (cross address space).
55 return AgentSSID;
56 }
57 /// \returns Workgroup synchronization scope ID (cross address space).
59 return WorkgroupSSID;
60 }
61 /// \returns Wavefront synchronization scope ID (cross address space).
63 return WavefrontSSID;
64 }
65 /// \returns Cluster synchronization scope ID (cross address space).
66 SyncScope::ID getClusterSSID() const { return ClusterSSID; }
67 /// \returns System synchronization scope ID (single address space).
69 return SystemOneAddressSpaceSSID;
70 }
71 /// \returns Agent synchronization scope ID (single address space).
73 return AgentOneAddressSpaceSSID;
74 }
75 /// \returns Workgroup synchronization scope ID (single address space).
77 return WorkgroupOneAddressSpaceSSID;
78 }
79 /// \returns Wavefront synchronization scope ID (single address space).
81 return WavefrontOneAddressSpaceSSID;
82 }
83 /// \returns Single thread synchronization scope ID (single address space).
85 return SingleThreadOneAddressSpaceSSID;
86 }
87 /// \returns Single thread synchronization scope ID (single address space).
89 return ClusterOneAddressSpaceSSID;
90 }
91
92 /// In AMDGPU, synchronization scopes are inclusive: a larger scope is
93 /// inclusive of a smaller one (e.g. agent includes workgroup).
94 ///
95 /// Returns the merged synchronization scope of \p A and \p B: the smallest
96 /// scope that is inclusive of both. Takes the larger inclusion level and,
97 /// if either scope is cross-address-space, the result is also
98 /// cross-address-space (since a one-AS scope cannot subsume a cross-AS
99 /// scope at the same level).
100 ///
101 /// \returns The merged scope ID, or "std::nullopt" if either scope is not
102 /// supported by the AMDGPU target.
103 std::optional<SyncScope::ID> getMergedSyncScopeID(SyncScope::ID A,
104 SyncScope::ID B) const {
105 // Ordered from smallest to largest scope. Level is the index.
106 // Cross-AS and one-AS scopes share the same inclusion ordering level.
107 // Level | Cross-AS scope | One-AS scope
108 // ------+------------------+----------------------
109 // 0 | singlethread | singlethread-one-as
110 // 1 | wavefront | wavefront-one-as
111 // 2 | workgroup | workgroup-one-as
112 // 3 | cluster | cluster-one-as
113 // 4 | agent | agent-one-as
114 // 5 | system | one-as
115 const SyncScope::ID CrossAS[] = {
118 const SyncScope::ID OneAS[] = {
122
123 // Returns {level, isOneAS} for a given scope, or nullopt if unsupported.
124 auto GetLevelAndOneAS =
125 [&](SyncScope::ID SSID) -> std::optional<std::pair<unsigned, bool>> {
126 for (auto [I, Cross, One] : llvm::enumerate(CrossAS, OneAS)) {
127 if (Cross == SSID)
128 return std::make_pair(I, false);
129 if (One == SSID)
130 return std::make_pair(I, true);
131 }
132 return std::nullopt;
133 };
134
135 auto AI = GetLevelAndOneAS(A);
136 auto BI = GetLevelAndOneAS(B);
137 if (!AI || !BI)
138 return std::nullopt;
139
140 unsigned Level = std::max(AI->first, BI->first);
141 // If either scope is cross-AS, the result must be cross-AS.
142 return (AI->second && BI->second) ? OneAS[Level] : CrossAS[Level];
143 }
144};
145
146} // end namespace llvm
147
148#endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUMACHINEMODULEINFO_H
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define I(x, y, z)
Definition MD5.cpp:57
AMDGPUMachineModuleInfo(const MachineModuleInfo &MMI)
SyncScope::ID getClusterOneAddressSpaceSSID() const
SyncScope::ID getAgentOneAddressSpaceSSID() const
SyncScope::ID getSingleThreadOneAddressSpaceSSID() const
SyncScope::ID getWavefrontOneAddressSpaceSSID() const
std::optional< SyncScope::ID > getMergedSyncScopeID(SyncScope::ID A, SyncScope::ID B) const
In AMDGPU, synchronization scopes are inclusive: a larger scope is inclusive of a smaller one (e....
SyncScope::ID getSystemOneAddressSpaceSSID() const
SyncScope::ID getWorkgroupOneAddressSpaceSSID() const
MachineModuleInfoELF(const MachineModuleInfo &)
This class contains meta information specific to a module.
@ SingleThread
Synchronized with respect to signal handlers executing in the same thread.
Definition LLVMContext.h:55
@ System
Synchronized with respect to all concurrently executing threads.
Definition LLVMContext.h:58
This is an optimization pass for GlobalISel generic memory operations.
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are tuples (A, B,...
Definition STLExtras.h:2554