LLVM 24.0.0git
PISACacheCtrlMMRA.cpp
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
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 implements PISA cache-control MMRA metadata handling.
11///
12//===----------------------------------------------------------------------===//
13
14#include "PISACacheCtrlMMRA.h"
15#include "llvm/ADT/STLExtras.h"
18#include "llvm/ADT/StringRef.h"
19#include "llvm/ADT/Twine.h"
21#include "llvm/IR/Instruction.h"
22#include "llvm/IR/LLVMContext.h"
24#include "llvm/IR/Metadata.h"
26
27using namespace llvm;
28
29constexpr StringLiteral CacheCtrlMMRAPrefix = "pisa.cache.ctrl";
30
31std::optional<unsigned> PISA::getCacheCtrlFromMMRA(const Instruction &I) {
32 MMRAMetadata MMRA(I);
34 for (const MMRAMetadata::TagT &Tag : MMRA) {
35 StringRef Prefix = Tag.first;
36 StringRef Suffix = Tag.second;
37 if (Prefix != CacheCtrlMMRAPrefix)
38 continue;
39 unsigned Value;
40 if (Suffix.getAsInteger(10, Value))
41 return std::nullopt;
43 Values.push_back(Value);
44 }
45 if (Values.empty())
46 return std::nullopt;
47 if (Values.size() > 1) {
50 OS << "instruction has conflicting pisa.cache.ctrl MMRA tags: {";
52 OS << "}; keeping " << Values.front();
53 I.getContext().diagnose(
55 }
56 return Values.front();
57}
58
60 LLVMContext &Ctx = I.getContext();
61
63 MMRAMetadata Existing(I);
64 for (const MMRAMetadata::TagT &Tag : Existing) {
65 if (Tag.first != CacheCtrlMMRAPrefix)
66 Tags.push_back(Tag);
67 }
68
71
72 I.setMetadata(LLVMContext::MD_mmra, MMRAMetadata::getMD(Ctx, Tags));
73}
74
76 std::optional<unsigned> Value = getCacheCtrlFromMMRA(From);
77 if (Value)
79}
#define I(x, y, z)
Definition MD5.cpp:57
This file provides utility for Memory Model Relaxation Annotations (MMRAs).
This file contains the declarations for metadata subclasses.
constexpr StringLiteral CacheCtrlMMRAPrefix
This file declares PISA cache-control MMRA metadata handling.
const char * Msg
This file contains some templates that are useful if you are working with the STL at all.
This file defines the SmallString class.
This file defines the SmallVector class.
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:76
Helper class to manipulate !mmra metadata nodes.
static LLVM_ABI MDTuple * getMD(LLVMContext &Ctx, ArrayRef< TagT > Tags)
Creates !mmra metadata from Tags.
std::pair< StringRef, StringRef > TagT
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition SmallString.h:28
reference emplace_back(ArgTypes &&... Args)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
A wrapper around a string literal that serves as a proxy for constructing global tables of StringRefs...
Definition StringRef.h:880
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
bool getAsInteger(unsigned Radix, T &Result) const
Parse the current string as an integer of the specified radix.
Definition StringRef.h:482
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
LLVM Value Representation.
Definition Value.h:75
A raw_ostream that writes to an SmallVector or SmallString.
void copyCacheCtrlMMRA(const Instruction &From, Instruction &To)
void setCacheCtrlMMRA(Instruction &I, unsigned Value)
std::optional< unsigned > getCacheCtrlFromMMRA(const Instruction &I)
This is an optimization pass for GlobalISel generic memory operations.
RelativeUniformCounterPtr Values
Definition InstrProf.h:91
void interleaveComma(const Container &c, StreamT &os, UnaryFunctor each_fn)
Definition STLExtras.h:2334
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition STLExtras.h:1963
StringRef toStringRef(bool B)
Construct a string ref from a boolean.