================ @@ -678,6 +680,54 @@ class SIMemoryLegalizer final : public MachineFunctionPass { bool runOnMachineFunction(MachineFunction &MF) override; }; +static std::array<std::pair<StringLiteral, SIAtomicAddrSpace>, 3> ASNames = {{ + {"global", SIAtomicAddrSpace::GLOBAL}, + {"local", SIAtomicAddrSpace::LDS}, + {"image", SIAtomicAddrSpace::SCRATCH}, +}}; + +void diagnoseUnknownMMRAASName(const MachineInstr &MI, StringRef AS) { + const MachineFunction *MF = MI.getMF(); + const Function &Fn = MF->getFunction(); + std::string Str; + raw_string_ostream OS(Str); + OS << "unknown address space '" << AS << "'; expected one of "; + ListSeparator LS; + for (const auto &[Name, Val] : ASNames) + OS << LS << '\'' << Name << '\''; + DiagnosticInfoUnsupported BadTag(Fn, Str, MI.getDebugLoc(), DS_Warning); + Fn.getContext().diagnose(BadTag); +} + +/// Reads \p MI's MMRAs to parse the "amdgpu-as" MMRA. +/// If this tag isn't present, or if it has no meaningful values, returns \p +/// Default. Otherwise returns all the address spaces concerned by the MMRA. +static SIAtomicAddrSpace getFenceAddrSpaceMMRA(const MachineInstr &MI, + SIAtomicAddrSpace Default) { + static constexpr StringLiteral FenceASPrefix = "amdgpu-as"; + + auto MMRA = MMRAMetadata(MI.getMMRAMetadata()); + if (!MMRA) + return Default; + + SIAtomicAddrSpace Result = SIAtomicAddrSpace::NONE; + for (const auto &[Prefix, Suffix] : MMRA) { + if (Prefix != FenceASPrefix) + continue; + + auto It = find_if(ASNames, [Suffix = Suffix](auto &Pair) { ---------------- Pierre-vh wrote:
Lambdas can't capture structured bindings (`auto [a, b] = pair`) in C++17, I think it comes in C++20 or 23? https://github.com/llvm/llvm-project/pull/78572 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits