[llvm] [RFC] Memory Model Relaxation Annotations (PR #78569)

Sameer Sahasrabuddhe via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 28 05:09:34 PDT 2024


================
@@ -0,0 +1,106 @@
+//===- MemoryModelRelaxationAnnotations.h -----------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+/// \file
+/// This file provides utility for Memory Model Relaxation Annotations (MMRAs).
+/// Those annotations are represented using Metadata. The MMRATagSet class
+/// offers a simple API to parse the metadata and perform common operations on
+/// it. The MMRAMetadata class is a simple tuple of MDNode that provides easy
+/// access to all MMRA annotations on an instruction.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_IR_MEMORYMODELRELAXATIONANNOTATIONS_H
+#define LLVM_IR_MEMORYMODELRELAXATIONANNOTATIONS_H
+
+#include <set>
+#include <string>
+#include <tuple>
+#include <vector>
+
+namespace llvm {
+
+class MDNode;
+class MDTuple;
+class StringRef;
+class raw_ostream;
+class LLVMContext;
+class Instruction;
+
+/// Helper class for `!mmra` metadata nodes which can both build MMRA MDNodes,
+/// and parse them.
+///
+/// This can be visualized as a set of "tags", with each tag
+/// representing a particular property of an instruction, as
+/// explained in the MemoryModelRelaxationAnnotations docs.
+///
+/// This class (and the optimizer in general) does not reason
+/// about the exact nature of the tags and the properties they
+/// imply. It just sees the metadata as a collection of tags, which
+/// are a prefix/suffix pair of strings.
+class MMRAMetadata {
+public:
+  using TagT = std::pair<std::string, std::string>;
+  using SetT = std::set<TagT>;
----------------
ssahasra wrote:

I am trying to understand this from the programmer's manual. It seems to me that since the components of the tag are strings owned by Metadata, they can be StringRef instead of std::string? Also, the manual kinda says that the std::set is the not the best choice for anything. So maybe DenseSet is a better choice? Especially since a pair of StringRef might satisfy the property "DenseSet is a great way to unique small values that are not simple pointers."

In particular, it seems to me that most uses of this helper class are on the stack, so any set that is efficient on the stack is more suited than std::set.

https://github.com/llvm/llvm-project/pull/78569


More information about the llvm-commits mailing list