LLVM  14.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"
22 
23 namespace llvm {
24 namespace mca {
25 
26 template <typename T>
27 class InstructionError : public ErrorInfo<InstructionError<T>> {
28 public:
29  static char ID;
30  std::string Message;
31  const T &Inst;
32 
33  InstructionError(std::string M, const T &MCI)
34  : Message(std::move(M)), Inst(MCI) {}
35 
36  void log(raw_ostream &OS) const override { OS << Message; }
37 
38  std::error_code convertToErrorCode() const override {
39  return inconvertibleErrorCode();
40  }
41 };
42 
43 template <typename T> char InstructionError<T>::ID;
44 
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;
53 
54 public:
55  ResourceCycles() : Numerator(0), Denominator(1) {}
56  ResourceCycles(unsigned Cycles, unsigned ResourceUnits = 1)
57  : Numerator(Cycles), Denominator(ResourceUnits) {}
58 
59  operator double() const {
60  assert(Denominator && "Invalid denominator (must be non-zero).");
61  return (Denominator == 1) ? Numerator : (double)Numerator / Denominator;
62  }
63 
64  unsigned getNumerator() const { return Numerator; }
65  unsigned getDenominator() const { return Denominator; }
66 
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.
71 };
72 
73 /// Populates vector Masks with processor resource masks.
74 ///
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.
80 ///
81 /// Example:
82 ///
83 /// ResourceA -- Mask: 0b001
84 /// ResourceB -- Mask: 0b010
85 /// ResourceAB -- Mask: 0b100 U (ResourceA::Mask | ResourceB::Mask) == 0b111
86 ///
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.
92 ///
93 /// Resource masks are used by the ResourceManager to solve set membership
94 /// problems with simple bit manipulation operations.
97 
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.
100 inline unsigned getResourceStateIndex(uint64_t Mask) {
101  assert(Mask && "Processor Resource Mask cannot be zero!");
102  return (std::numeric_limits<uint64_t>::digits - countLeadingZeros(Mask)) - 1;
103 }
104 
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 /// - ProcResourceCycles / #ProcResourceUnits (for every consumed resource).
109 double computeBlockRThroughput(const MCSchedModel &SM, unsigned DispatchWidth,
110  unsigned NumMicroOps,
111  ArrayRef<unsigned> ProcResourceUsage);
112 } // namespace mca
113 } // namespace llvm
114 
115 #endif // LLVM_MCA_SUPPORT_H
MathExtras.h
llvm
---------------------— PointerInfo ------------------------------------—
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:64
T
#define T
Definition: Mips16ISelLowering.cpp:341
llvm::mca::InstructionError::InstructionError
InstructionError(std::string M, const T &MCI)
Definition: Support.h:33
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:307
llvm::mca::InstructionError::Inst
const T & Inst
Definition: Support.h:31
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:53
llvm::mca::InstructionError::ID
static char ID
Definition: Support.h:29
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:1605
llvm::ErrorInfo
Base class for user error types.
Definition: Error.h:349
llvm::mca::InstructionError::convertToErrorCode
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
Definition: Support.h:38
llvm::ArrayRef< unsigned >
std
Definition: BitVector.h:838
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:245
llvm::mca::getResourceStateIndex
unsigned getResourceStateIndex(uint64_t Mask)
Definition: Support.h:100
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:225
llvm::mca::InstructionError::log
void log(raw_ostream &OS) const override
Print an error message to an output stream.
Definition: Support.h:36
SmallVector.h
llvm::mca::ResourceCycles::getDenominator
unsigned getDenominator() const
Definition: Support.h:65
llvm::mca::ResourceCycles::ResourceCycles
ResourceCycles(unsigned Cycles, unsigned ResourceUnits=1)
Definition: Support.h:56
llvm::mca::InstructionError::Message
std::string Message
Definition: Support.h:30
llvm::mca::InstructionError
Definition: Support.h:27
llvm::mca::ResourceCycles
This class represents the number of cycles per resource (fractions of cycles).
Definition: Support.h:51
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:55