LLVM  13.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"
18 #include "llvm/ADT/SmallVector.h"
19 #include "llvm/MC/MCSchedule.h"
20 #include "llvm/Support/Error.h"
21 
22 namespace llvm {
23 namespace mca {
24 
25 template <typename T>
26 class InstructionError : public ErrorInfo<InstructionError<T>> {
27 public:
28  static char ID;
29  std::string Message;
30  const T &Inst;
31 
32  InstructionError(std::string M, const T &MCI)
33  : Message(std::move(M)), Inst(MCI) {}
34 
35  void log(raw_ostream &OS) const override { OS << Message; }
36 
37  std::error_code convertToErrorCode() const override {
38  return inconvertibleErrorCode();
39  }
40 };
41 
42 template <typename T> char InstructionError<T>::ID;
43 
44 /// This class represents the number of cycles per resource (fractions of
45 /// cycles). That quantity is managed here as a ratio, and accessed via the
46 /// double cast-operator below. The two quantities, number of cycles and
47 /// number of resources, are kept separate. This is used by the
48 /// ResourcePressureView to calculate the average resource cycles
49 /// per instruction/iteration.
51  unsigned Numerator, Denominator;
52 
53 public:
54  ResourceCycles() : Numerator(0), Denominator(1) {}
55  ResourceCycles(unsigned Cycles, unsigned ResourceUnits = 1)
56  : Numerator(Cycles), Denominator(ResourceUnits) {}
57 
58  operator double() const {
59  assert(Denominator && "Invalid denominator (must be non-zero).");
60  return (Denominator == 1) ? Numerator : (double)Numerator / Denominator;
61  }
62 
63  unsigned getNumerator() const { return Numerator; }
64  unsigned getDenominator() const { return Denominator; }
65 
66  // Add the components of RHS to this instance. Instead of calculating
67  // the final value here, we keep track of the numerator and denominator
68  // separately, to reduce floating point error.
70 };
71 
72 /// Populates vector Masks with processor resource masks.
73 ///
74 /// The number of bits set in a mask depends on the processor resource type.
75 /// Each processor resource mask has at least one bit set. For groups, the
76 /// number of bits set in the mask is equal to the cardinality of the group plus
77 /// one. Excluding the most significant bit, the remaining bits in the mask
78 /// identify processor resources that are part of the group.
79 ///
80 /// Example:
81 ///
82 /// ResourceA -- Mask: 0b001
83 /// ResourceB -- Mask: 0b010
84 /// ResourceAB -- Mask: 0b100 U (ResourceA::Mask | ResourceB::Mask) == 0b111
85 ///
86 /// ResourceAB is a processor resource group containing ResourceA and ResourceB.
87 /// Each resource mask uniquely identifies a resource; both ResourceA and
88 /// ResourceB only have one bit set.
89 /// ResourceAB is a group; excluding the most significant bit in the mask, the
90 /// remaining bits identify the composition of the group.
91 ///
92 /// Resource masks are used by the ResourceManager to solve set membership
93 /// problems with simple bit manipulation operations.
96 
97 // Returns the index of the highest bit set. For resource masks, the position of
98 // the highest bit set can be used to construct a resource mask identifier.
99 inline unsigned getResourceStateIndex(uint64_t Mask) {
100  assert(Mask && "Processor Resource Mask cannot be zero!");
101  return (std::numeric_limits<uint64_t>::digits - countLeadingZeros(Mask)) - 1;
102 }
103 
104 /// Compute the reciprocal block throughput from a set of processor resource
105 /// cycles. The reciprocal block throughput is computed as the MAX between:
106 /// - NumMicroOps / DispatchWidth
107 /// - ProcResourceCycles / #ProcResourceUnits (for every consumed resource).
108 double computeBlockRThroughput(const MCSchedModel &SM, unsigned DispatchWidth,
109  unsigned NumMicroOps,
110  ArrayRef<unsigned> ProcResourceUsage);
111 } // namespace mca
112 } // namespace llvm
113 
114 #endif // LLVM_MCA_SUPPORT_H
llvm
This class represents lattice values for constants.
Definition: AllocatorList.h:23
M
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
Definition: README.txt:252
double
into xmm2 addss xmm2 xmm1 xmm3 addss xmm3 movaps xmm0 unpcklps xmm0 ret seems silly when it could just be one addps Expand libm rounding functions main should enable SSE DAZ mode and other fast SSE modes Think about doing i64 math in SSE regs on x86 This testcase should have no SSE instructions in and only one load from a constant double
Definition: README-SSE.txt:85
Error.h
llvm::mca::ResourceCycles::getNumerator
unsigned getNumerator() const
Definition: Support.h:63
T
#define T
Definition: Mips16ISelLowering.cpp:341
llvm::mca::InstructionError::InstructionError
InstructionError(std::string M, const T &MCI)
Definition: Support.h:32
llvm::BitmaskEnumDetail::Mask
std::underlying_type_t< E > Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
Definition: BitmaskEnum.h:80
llvm::mca::computeBlockRThroughput
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:82
llvm::MutableArrayRef
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Definition: ArrayRef.h:298
llvm::mca::InstructionError::Inst
const T & Inst
Definition: Support.h:30
llvm::mca::ResourceCycles::operator+=
ResourceCycles & operator+=(const ResourceCycles &RHS)
Definition: Support.cpp:23
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:50
llvm::mca::InstructionError::ID
static char ID
Definition: Support.h:28
MCSchedule.h
ArrayRef.h
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::move
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:1556
llvm::ErrorInfo
Base class for user error types.
Definition: Error.h:350
llvm::mca::InstructionError::convertToErrorCode
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
Definition: Support.h:37
llvm::ArrayRef< unsigned >
std
Definition: BitVector.h:941
llvm::inconvertibleErrorCode
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Definition: Error.cpp:77
llvm::MCSchedModel
Machine model for scheduling, bundling, and heuristics.
Definition: MCSchedule.h:244
llvm::mca::getResourceStateIndex
unsigned getResourceStateIndex(uint64_t Mask)
Definition: Support.h:99
llvm::countLeadingZeros
unsigned countLeadingZeros(T Val, ZeroBehavior ZB=ZB_Width)
Count number of 0's from the most significant bit to the least stopping at the first 1.
Definition: MathExtras.h:226
llvm::mca::InstructionError::log
void log(raw_ostream &OS) const override
Print an error message to an output stream.
Definition: Support.h:35
SmallVector.h
llvm::mca::ResourceCycles::getDenominator
unsigned getDenominator() const
Definition: Support.h:64
llvm::mca::ResourceCycles::ResourceCycles
ResourceCycles(unsigned Cycles, unsigned ResourceUnits=1)
Definition: Support.h:55
llvm::mca::InstructionError::Message
std::string Message
Definition: Support.h:29
llvm::mca::InstructionError
Definition: Support.h:26
llvm::mca::ResourceCycles
This class represents the number of cycles per resource (fractions of cycles).
Definition: Support.h:50
llvm::mca::computeProcResourceMasks
void computeProcResourceMasks(const MCSchedModel &SM, MutableArrayRef< uint64_t > Masks)
Populates vector Masks with processor resource masks.
Definition: Support.cpp:39
llvm::mca::ResourceCycles::ResourceCycles
ResourceCycles()
Definition: Support.h:54