LLVM 22.0.0git
Support.h
Go to the documentation of this file.
1//===--------------------- Support.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/// \file
9///
10/// Helper functions used by various pipeline components.
11///
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_MCA_SUPPORT_H
15#define LLVM_MCA_SUPPORT_H
16
17#include "llvm/ADT/ArrayRef.h"
19#include "llvm/MC/MCSchedule.h"
21#include "llvm/Support/Error.h"
23
24namespace llvm {
25namespace mca {
26
27template <typename T>
28class InstructionError : public ErrorInfo<InstructionError<T>> {
29public:
30 static char ID;
31 std::string Message;
32 const T &Inst;
33
34 InstructionError(std::string M, const T &MCI)
35 : Message(std::move(M)), Inst(MCI) {}
36
37 void log(raw_ostream &OS) const override { OS << Message; }
38
39 std::error_code convertToErrorCode() const override {
41 }
42};
43
44template <typename T> char InstructionError<T>::ID;
45
46/// This class represents the number of cycles per resource (fractions of
47/// cycles). That quantity is managed here as a ratio, and accessed via the
48/// double cast-operator below. The two quantities, number of cycles and
49/// number of resources, are kept separate. This is used by the
50/// ResourcePressureView to calculate the average resource cycles
51/// per instruction/iteration.
53 unsigned Numerator, Denominator;
54
55public:
56 ReleaseAtCycles() : Numerator(0), Denominator(1) {}
57 ReleaseAtCycles(unsigned Cycles, unsigned ResourceUnits = 1)
58 : Numerator(Cycles), Denominator(ResourceUnits) {}
59
60 operator double() const {
61 assert(Denominator && "Invalid denominator (must be non-zero).");
62 return (Denominator == 1) ? Numerator : (double)Numerator / Denominator;
63 }
64
65 unsigned getNumerator() const { return Numerator; }
66 unsigned getDenominator() const { return Denominator; }
67
68 // Add the components of RHS to this instance. Instead of calculating
69 // the final value here, we keep track of the numerator and denominator
70 // separately, to reduce floating point error.
72};
73
74/// Populates vector Masks with processor resource masks.
75///
76/// The number of bits set in a mask depends on the processor resource type.
77/// Each processor resource mask has at least one bit set. For groups, the
78/// number of bits set in the mask is equal to the cardinality of the group plus
79/// one. Excluding the most significant bit, the remaining bits in the mask
80/// identify processor resources that are part of the group.
81///
82/// Example:
83///
84/// ResourceA -- Mask: 0b001
85/// ResourceB -- Mask: 0b010
86/// ResourceAB -- Mask: 0b100 U (ResourceA::Mask | ResourceB::Mask) == 0b111
87///
88/// ResourceAB is a processor resource group containing ResourceA and ResourceB.
89/// Each resource mask uniquely identifies a resource; both ResourceA and
90/// ResourceB only have one bit set.
91/// ResourceAB is a group; excluding the most significant bit in the mask, the
92/// remaining bits identify the composition of the group.
93///
94/// Resource masks are used by the ResourceManager to solve set membership
95/// problems with simple bit manipulation operations.
98
99// Returns the index of the highest bit set. For resource masks, the position of
100// the highest bit set can be used to construct a resource mask identifier.
101inline unsigned getResourceStateIndex(uint64_t Mask) {
102 assert(Mask && "Processor Resource Mask cannot be zero!");
103 return llvm::Log2_64(Mask);
104}
105
106/// Compute the reciprocal block throughput from a set of processor resource
107/// cycles. The reciprocal block throughput is computed as the MAX between:
108/// - NumMicroOps / DispatchWidth
109/// - ProcReleaseAtCycles / #ProcResourceUnits (for every consumed resource).
111 unsigned DispatchWidth,
112 unsigned NumMicroOps,
113 ArrayRef<unsigned> ProcResourceUsage);
114} // namespace mca
115} // namespace llvm
116
117#endif // LLVM_MCA_SUPPORT_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define LLVM_ABI
Definition: Compiler.h:213
raw_pwrite_stream & OS
This file defines the SmallVector class.
Value * RHS
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
Base class for user error types.
Definition: Error.h:354
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Definition: ArrayRef.h:303
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
Definition: Support.h:39
void log(raw_ostream &OS) const override
Print an error message to an output stream.
Definition: Support.h:37
InstructionError(std::string M, const T &MCI)
Definition: Support.h:34
This class represents the number of cycles per resource (fractions of cycles).
Definition: Support.h:52
unsigned getNumerator() const
Definition: Support.h:65
LLVM_ABI ReleaseAtCycles & operator+=(const ReleaseAtCycles &RHS)
Definition: Support.cpp:24
unsigned getDenominator() const
Definition: Support.h:66
ReleaseAtCycles(unsigned Cycles, unsigned ResourceUnits=1)
Definition: Support.h:57
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
LLVM_ABI double computeBlockRThroughput(const MCSchedModel &SM, unsigned DispatchWidth, unsigned NumMicroOps, ArrayRef< unsigned > ProcResourceUsage)
Compute the reciprocal block throughput from a set of processor resource cycles.
Definition: Support.cpp:83
LLVM_ABI void computeProcResourceMasks(const MCSchedModel &SM, MutableArrayRef< uint64_t > Masks)
Populates vector Masks with processor resource masks.
Definition: Support.cpp:40
unsigned getResourceStateIndex(uint64_t Mask)
Definition: Support.h:101
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
LLVM_ABI std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Definition: Error.cpp:98
unsigned Log2_64(uint64_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
Definition: MathExtras.h:342
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1886
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:856
Machine model for scheduling, bundling, and heuristics.
Definition: MCSchedule.h:258