12cab237bSDimitry Andric //===--- AMDGPUMachineModuleInfo.h ------------------------------*- C++ -*-===// 22cab237bSDimitry Andric // 32cab237bSDimitry Andric // The LLVM Compiler Infrastructure 42cab237bSDimitry Andric // 52cab237bSDimitry Andric // This file is distributed under the University of Illinois Open Source 62cab237bSDimitry Andric // License. See LICENSE.TXT for details. 72cab237bSDimitry Andric // 82cab237bSDimitry Andric //===----------------------------------------------------------------------===// 92cab237bSDimitry Andric // 102cab237bSDimitry Andric /// \file 11*4ba319b5SDimitry Andric /// AMDGPU Machine Module Info. 122cab237bSDimitry Andric /// 132cab237bSDimitry Andric // 142cab237bSDimitry Andric //===----------------------------------------------------------------------===// 152cab237bSDimitry Andric 162cab237bSDimitry Andric #ifndef LLVM_LIB_TARGET_AMDGPU_AMDGPUMACHINEMODULEINFO_H 172cab237bSDimitry Andric #define LLVM_LIB_TARGET_AMDGPU_AMDGPUMACHINEMODULEINFO_H 182cab237bSDimitry Andric 192cab237bSDimitry Andric #include "llvm/ADT/None.h" 202cab237bSDimitry Andric #include "llvm/ADT/Optional.h" 212cab237bSDimitry Andric #include "llvm/CodeGen/MachineModuleInfo.h" 222cab237bSDimitry Andric #include "llvm/CodeGen/MachineModuleInfoImpls.h" 232cab237bSDimitry Andric #include "llvm/IR/LLVMContext.h" 242cab237bSDimitry Andric 252cab237bSDimitry Andric namespace llvm { 262cab237bSDimitry Andric 272cab237bSDimitry Andric class AMDGPUMachineModuleInfo final : public MachineModuleInfoELF { 282cab237bSDimitry Andric private: 292cab237bSDimitry Andric 302cab237bSDimitry Andric // All supported memory/synchronization scopes can be found here: 312cab237bSDimitry Andric // http://llvm.org/docs/AMDGPUUsage.html#memory-scopes 322cab237bSDimitry Andric 33*4ba319b5SDimitry Andric /// Agent synchronization scope ID. 342cab237bSDimitry Andric SyncScope::ID AgentSSID; 35*4ba319b5SDimitry Andric /// Workgroup synchronization scope ID. 362cab237bSDimitry Andric SyncScope::ID WorkgroupSSID; 37*4ba319b5SDimitry Andric /// Wavefront synchronization scope ID. 382cab237bSDimitry Andric SyncScope::ID WavefrontSSID; 392cab237bSDimitry Andric 40*4ba319b5SDimitry Andric /// In AMDGPU target synchronization scopes are inclusive, meaning a 412cab237bSDimitry Andric /// larger synchronization scope is inclusive of a smaller synchronization 422cab237bSDimitry Andric /// scope. 432cab237bSDimitry Andric /// 442cab237bSDimitry Andric /// \returns \p SSID's inclusion ordering, or "None" if \p SSID is not 452cab237bSDimitry Andric /// supported by the AMDGPU target. getSyncScopeInclusionOrdering(SyncScope::ID SSID)462cab237bSDimitry Andric Optional<uint8_t> getSyncScopeInclusionOrdering(SyncScope::ID SSID) const { 472cab237bSDimitry Andric if (SSID == SyncScope::SingleThread) 482cab237bSDimitry Andric return 0; 492cab237bSDimitry Andric else if (SSID == getWavefrontSSID()) 502cab237bSDimitry Andric return 1; 512cab237bSDimitry Andric else if (SSID == getWorkgroupSSID()) 522cab237bSDimitry Andric return 2; 532cab237bSDimitry Andric else if (SSID == getAgentSSID()) 542cab237bSDimitry Andric return 3; 552cab237bSDimitry Andric else if (SSID == SyncScope::System) 562cab237bSDimitry Andric return 4; 572cab237bSDimitry Andric 582cab237bSDimitry Andric return None; 592cab237bSDimitry Andric } 602cab237bSDimitry Andric 612cab237bSDimitry Andric public: 622cab237bSDimitry Andric AMDGPUMachineModuleInfo(const MachineModuleInfo &MMI); 632cab237bSDimitry Andric 642cab237bSDimitry Andric /// \returns Agent synchronization scope ID. getAgentSSID()652cab237bSDimitry Andric SyncScope::ID getAgentSSID() const { 662cab237bSDimitry Andric return AgentSSID; 672cab237bSDimitry Andric } 682cab237bSDimitry Andric /// \returns Workgroup synchronization scope ID. getWorkgroupSSID()692cab237bSDimitry Andric SyncScope::ID getWorkgroupSSID() const { 702cab237bSDimitry Andric return WorkgroupSSID; 712cab237bSDimitry Andric } 722cab237bSDimitry Andric /// \returns Wavefront synchronization scope ID. getWavefrontSSID()732cab237bSDimitry Andric SyncScope::ID getWavefrontSSID() const { 742cab237bSDimitry Andric return WavefrontSSID; 752cab237bSDimitry Andric } 762cab237bSDimitry Andric 77*4ba319b5SDimitry Andric /// In AMDGPU target synchronization scopes are inclusive, meaning a 782cab237bSDimitry Andric /// larger synchronization scope is inclusive of a smaller synchronization 792cab237bSDimitry Andric /// scope. 802cab237bSDimitry Andric /// 812cab237bSDimitry Andric /// \returns True if synchronization scope \p A is larger than or equal to 822cab237bSDimitry Andric /// synchronization scope \p B, false if synchronization scope \p A is smaller 832cab237bSDimitry Andric /// than synchronization scope \p B, or "None" if either synchronization scope 842cab237bSDimitry Andric /// \p A or \p B is not supported by the AMDGPU target. isSyncScopeInclusion(SyncScope::ID A,SyncScope::ID B)852cab237bSDimitry Andric Optional<bool> isSyncScopeInclusion(SyncScope::ID A, SyncScope::ID B) const { 862cab237bSDimitry Andric const auto &AIO = getSyncScopeInclusionOrdering(A); 872cab237bSDimitry Andric const auto &BIO = getSyncScopeInclusionOrdering(B); 882cab237bSDimitry Andric if (!AIO || !BIO) 892cab237bSDimitry Andric return None; 902cab237bSDimitry Andric 912cab237bSDimitry Andric return AIO.getValue() > BIO.getValue(); 922cab237bSDimitry Andric } 932cab237bSDimitry Andric }; 942cab237bSDimitry Andric 952cab237bSDimitry Andric } // end namespace llvm 962cab237bSDimitry Andric 972cab237bSDimitry Andric #endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUMACHINEMODULEINFO_H 98