LLVM 22.0.0git
MemoryModelRelaxationAnnotations.h
Go to the documentation of this file.
1//===- MemoryModelRelaxationAnnotations.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/// This file provides utility for Memory Model Relaxation Annotations (MMRAs).
11/// Those annotations are represented using Metadata. The MMRATagSet class
12/// offers a simple API to parse the metadata and perform common operations on
13/// it. The MMRAMetadata class is a simple tuple of MDNode that provides easy
14/// access to all MMRA annotations on an instruction.
15//
16//===----------------------------------------------------------------------===//
17
18#ifndef LLVM_IR_MEMORYMODELRELAXATIONANNOTATIONS_H
19#define LLVM_IR_MEMORYMODELRELAXATIONANNOTATIONS_H
20
21#include "llvm/ADT/DenseSet.h"
22#include "llvm/ADT/StringRef.h"
24
25#include <utility>
26
27namespace llvm {
28
29template <typename T> class ArrayRef;
30
31class MDNode;
32class MDTuple;
33class Metadata;
34class raw_ostream;
35class LLVMContext;
36class Instruction;
37
38/// Helper class to manipulate `!mmra` metadata nodes.
39///
40/// This can be visualized as a set of "tags", with each tag
41/// representing a particular property of an instruction, as
42/// explained in the MemoryModelRelaxationAnnotations docs.
43///
44/// This class (and the optimizer in general) does not reason
45/// about the exact nature of the tags and the properties they
46/// imply. It just sees the metadata as a collection of tags, which
47/// are a prefix/suffix pair of strings.
49public:
50 using TagT = std::pair<StringRef, StringRef>;
53
54 /// \name Constructors
55 /// @{
56 MMRAMetadata() = default;
59 /// @}
60
61 /// \name Metadata Helpers & Builders
62 /// @{
63
64 /// Combines \p A and \p B according to MMRA semantics.
65 /// \returns !mmra metadata for the combined MMRAs.
66 LLVM_ABI static MDNode *combine(LLVMContext &Ctx, const MMRAMetadata &A,
67 const MMRAMetadata &B);
68
69 /// Creates !mmra metadata for a single tag.
70 ///
71 /// !mmra metadata can either be a single tag, or a MDTuple containing
72 /// multiple tags.
73 LLVM_ABI static MDTuple *getTagMD(LLVMContext &Ctx, StringRef Prefix,
74 StringRef Suffix);
75 static MDTuple *getTagMD(LLVMContext &Ctx, const TagT &T) {
76 return getTagMD(Ctx, T.first, T.second);
77 }
78
79 /// Creates !mmra metadata from \p Tags.
80 /// \returns nullptr or a MDTuple* from \p Tags.
82
83 /// \returns true if \p MD is a well-formed MMRA tag.
84 LLVM_ABI static bool isTagMD(const Metadata *MD);
85
86 /// @}
87
88 /// \name Compatibility Helpers
89 /// @{
90
91 /// \returns whether the MMRAs on \p A and \p B are compatible.
92 static bool checkCompatibility(const Instruction &A, const Instruction &B) {
93 return MMRAMetadata(A).isCompatibleWith(B);
94 }
95
96 /// \returns whether this set of tags is compatible with \p Other.
98
99 /// @}
100
101 /// \name Content Queries
102 /// @{
103
104 LLVM_ABI bool hasTag(StringRef Prefix, StringRef Suffix) const;
105 LLVM_ABI bool hasTagWithPrefix(StringRef Prefix) const;
106
109 LLVM_ABI bool empty() const;
110 LLVM_ABI unsigned size() const;
111
112 /// @}
113
114 LLVM_ABI void print(raw_ostream &OS) const;
115 LLVM_ABI void dump() const;
116
117 operator bool() const { return !Tags.empty(); }
118 bool operator==(const MMRAMetadata &Other) const {
119 return Tags == Other.Tags;
120 }
121 bool operator!=(const MMRAMetadata &Other) const {
122 return Tags != Other.Tags;
123 }
124
125private:
126 SetT Tags;
127};
128
129/// \returns true if \p I can have !mmra metadata.
130LLVM_ABI bool canInstructionHaveMMRAs(const Instruction &I);
131
132} // namespace llvm
133
134#endif
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_ABI
Definition Compiler.h:213
This file defines the DenseSet and SmallDenseSet classes.
#define I(x, y, z)
Definition MD5.cpp:57
#define T
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
Implements a dense probed hash-table based set.
Definition DenseSet.h:279
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:68
Metadata node.
Definition Metadata.h:1078
Tuple of metadata.
Definition Metadata.h:1497
Helper class to manipulate !mmra metadata nodes.
static LLVM_ABI MDTuple * getTagMD(LLVMContext &Ctx, StringRef Prefix, StringRef Suffix)
Creates !mmra metadata for a single tag.
static bool checkCompatibility(const Instruction &A, const Instruction &B)
static MDTuple * getTagMD(LLVMContext &Ctx, const TagT &T)
bool operator!=(const MMRAMetadata &Other) const
bool operator==(const MMRAMetadata &Other) const
LLVM_ABI void print(raw_ostream &OS) const
static LLVM_ABI MDNode * combine(LLVMContext &Ctx, const MMRAMetadata &A, const MMRAMetadata &B)
Combines A and B according to MMRA semantics.
static LLVM_ABI MDTuple * getMD(LLVMContext &Ctx, ArrayRef< TagT > Tags)
Creates !mmra metadata from Tags.
LLVM_ABI const_iterator begin() const
LLVM_ABI bool hasTag(StringRef Prefix, StringRef Suffix) const
LLVM_ABI const_iterator end() const
MMRAMetadata()=default
LLVM_ABI bool isCompatibleWith(const MMRAMetadata &Other) const
std::pair< StringRef, StringRef > TagT
LLVM_ABI bool hasTagWithPrefix(StringRef Prefix) const
static LLVM_ABI bool isTagMD(const Metadata *MD)
Root of the metadata hierarchy.
Definition Metadata.h:64
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI bool canInstructionHaveMMRAs(const Instruction &I)
@ Other
Any other memory.
Definition ModRef.h:68