LLVM 19.0.0git
Go to the documentation of this file.
1//===--------------------- Support.h ----------------------------*- C++ -*-===//
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
8/// \file
10/// Helper functions used by various pipeline components.
17#include "llvm/ADT/ArrayRef.h"
19#include "llvm/MC/MCSchedule.h"
20#include "llvm/Support/Error.h"
23namespace llvm {
24namespace mca {
26template <typename T>
27class InstructionError : public ErrorInfo<InstructionError<T>> {
29 static char ID;
30 std::string Message;
31 const T &Inst;
33 InstructionError(std::string M, const T &MCI)
34 : Message(std::move(M)), Inst(MCI) {}
36 void log(raw_ostream &OS) const override { OS << Message; }
38 std::error_code convertToErrorCode() const override {
40 }
43template <typename T> char InstructionError<T>::ID;
45/// This class represents the number of cycles per resource (fractions of
46/// cycles). That quantity is managed here as a ratio, and accessed via the
47/// double cast-operator below. The two quantities, number of cycles and
48/// number of resources, are kept separate. This is used by the
49/// ResourcePressureView to calculate the average resource cycles
50/// per instruction/iteration.
52 unsigned Numerator, Denominator;
55 ReleaseAtCycles() : Numerator(0), Denominator(1) {}
56 ReleaseAtCycles(unsigned Cycles, unsigned ResourceUnits = 1)
57 : Numerator(Cycles), Denominator(ResourceUnits) {}
59 operator double() const {
60 assert(Denominator && "Invalid denominator (must be non-zero).");
61 return (Denominator == 1) ? Numerator : (double)Numerator / Denominator;
62 }
64 unsigned getNumerator() const { return Numerator; }
65 unsigned getDenominator() const { return Denominator; }
67 // Add the components of RHS to this instance. Instead of calculating
68 // the final value here, we keep track of the numerator and denominator
69 // separately, to reduce floating point error.
73/// Populates vector Masks with processor resource masks.
75/// The number of bits set in a mask depends on the processor resource type.
76/// Each processor resource mask has at least one bit set. For groups, the
77/// number of bits set in the mask is equal to the cardinality of the group plus
78/// one. Excluding the most significant bit, the remaining bits in the mask
79/// identify processor resources that are part of the group.
81/// Example:
83/// ResourceA -- Mask: 0b001
84/// ResourceB -- Mask: 0b010
85/// ResourceAB -- Mask: 0b100 U (ResourceA::Mask | ResourceB::Mask) == 0b111
87/// ResourceAB is a processor resource group containing ResourceA and ResourceB.
88/// Each resource mask uniquely identifies a resource; both ResourceA and
89/// ResourceB only have one bit set.
90/// ResourceAB is a group; excluding the most significant bit in the mask, the
91/// remaining bits identify the composition of the group.
93/// Resource masks are used by the ResourceManager to solve set membership
94/// problems with simple bit manipulation operations.
98// Returns the index of the highest bit set. For resource masks, the position of
99// the highest bit set can be used to construct a resource mask identifier.
100inline unsigned getResourceStateIndex(uint64_t Mask) {
101 assert(Mask && "Processor Resource Mask cannot be zero!");
102 return llvm::Log2_64(Mask);
105/// Compute the reciprocal block throughput from a set of processor resource
106/// cycles. The reciprocal block throughput is computed as the MAX between:
107/// - NumMicroOps / DispatchWidth
108/// - ProcReleaseAtCycles / #ProcResourceUnits (for every consumed resource).
109double computeBlockRThroughput(const MCSchedModel &SM, unsigned DispatchWidth,
110 unsigned NumMicroOps,
111 ArrayRef<unsigned> ProcResourceUsage);
112} // namespace mca
113} // namespace llvm
115#endif // LLVM_MCA_SUPPORT_H
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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:352
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Definition: ArrayRef.h:307
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
Definition: Support.h:38
void log(raw_ostream &OS) const override
Print an error message to an output stream.
Definition: Support.h:36
InstructionError(std::string M, const T &MCI)
Definition: Support.h:33
This class represents the number of cycles per resource (fractions of cycles).
Definition: Support.h:51
unsigned getNumerator() const
Definition: Support.h:64
ReleaseAtCycles & operator+=(const ReleaseAtCycles &RHS)
Definition: Support.cpp:24
unsigned getDenominator() const
Definition: Support.h:65
ReleaseAtCycles(unsigned Cycles, unsigned ResourceUnits=1)
Definition: Support.h:56
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
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
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:100
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Definition: Error.cpp:90
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:330
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:1849
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:858
Machine model for scheduling, bundling, and heuristics.
Definition: MCSchedule.h:253