15#ifndef LLVM_MCA_HARDWAREUNITS_RESOURCEMANAGER_H
16#define LLVM_MCA_HARDWAREUNITS_RESOURCEMANAGER_H
49 ResourceStrategy(
const ResourceStrategy &) =
delete;
50 ResourceStrategy &operator=(
const ResourceStrategy &) =
delete;
122 : ResourceUnitMask(UnitMask), NextInSequenceMask(UnitMask),
123 RemovedFromNextInSequence(0) {}
138 const unsigned ProcResourceDescIndex;
200 const int BufferSize;
203 unsigned AvailableSlots;
214 bool isSubResourceReady(
uint64_t SubResMask)
const {
215 return ReadyMask & SubResMask;
222 unsigned getProcResourceID()
const {
return ProcResourceDescIndex; }
223 uint64_t getResourceMask()
const {
return ResourceMask; }
224 uint64_t getReadyMask()
const {
return ReadyMask; }
225 int getBufferSize()
const {
return BufferSize; }
227 bool isBuffered()
const {
return BufferSize > 0; }
228 bool isInOrder()
const {
return BufferSize == 1; }
231 bool isADispatchHazard()
const {
return BufferSize == 0; }
239 LLVM_ABI bool isReady(
unsigned NumUnits = 1)
const;
243 bool isAResourceGroup()
const {
return IsAGroup; }
245 bool containsResource(
uint64_t ID)
const {
return ResourceMask &
ID; }
257 unsigned getNumUnits()
const {
258 return isAResourceGroup() ? 1U :
llvm::popcount(ResourceSizeMask);
276 bool reserveBuffer() {
281 assert(AvailableSlots <=
static_cast<unsigned>(BufferSize));
282 return AvailableSlots;
286 void releaseBuffer() {
292 assert(AvailableSlots <=
static_cast<unsigned>(BufferSize));
309typedef std::pair<unsigned, unsigned> BufferUsageEntry;
347 std::vector<std::unique_ptr<ResourceState>> Resources;
348 std::vector<std::unique_ptr<ResourceStrategy>> Strategies;
351 std::vector<uint64_t> Resource2Groups;
386 unsigned getNumUnits(
uint64_t ResourceID)
const;
390 LLVM_ABI void setCustomStrategyImpl(std::unique_ptr<ResourceStrategy> S,
399 void setCustomStrategy(std::unique_ptr<ResourceStrategy> S,
400 unsigned ResourceID) {
402 "Invalid resource index in input!");
403 return setCustomStrategyImpl(std::move(S), ProcResID2Mask[ResourceID]);
408 LLVM_ABI ResourceStateEvent canBeDispatched(
uint64_t ConsumedBuffers)
const;
436 uint64_t getProcResUnitMask()
const {
return ProcResUnitMask; }
437 uint64_t getAvailableProcResUnits()
const {
return AvailableProcResUnits; }
439 using ResourceWithCycles = std::pair<ResourceRef, ReleaseAtCycles>;
441 void issueInstruction(
const InstrDesc &Desc,
442 SmallVectorImpl<ResourceWithCycles> &Pipes) {
443 if (
Desc.HasPartiallyOverlappingGroups)
444 return issueInstructionImpl(Desc, Pipes);
446 return fastIssueInstruction(Desc, Pipes);
456 fastIssueInstruction(
const InstrDesc &Desc,
457 SmallVectorImpl<ResourceWithCycles> &Pipes);
465 issueInstructionImpl(
const InstrDesc &Desc,
466 SmallVectorImpl<ResourceWithCycles> &Pipes);
468 LLVM_ABI void cycleEvent(SmallVectorImpl<ResourceRef> &ResourcesFreed);
472 for (
const std::unique_ptr<ResourceState> &Resource : Resources)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the DenseMap class.
@ Unavailable
We know the block is not fully available. This is a fixpoint.
Move duplicate certain instructions close to their use
This file defines abstractions used by the Pipeline to model register reads, register writes and inst...
static constexpr unsigned SM(unsigned Version)
This file defines the SmallVector class.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
DefaultResourceStrategy(uint64_t UnitMask)
void used(uint64_t Mask) override
Called by the ResourceManager when a processor resource group, or a processor resource with multiple ...
~DefaultResourceStrategy() override=default
uint64_t select(uint64_t ReadyMask) override
Selects a processor resource unit from a ReadyMask.
A processor resource descriptor.
virtual uint64_t select(uint64_t ReadyMask)=0
Selects a processor resource unit from a ReadyMask.
virtual ~ResourceStrategy()
virtual void used(uint64_t ResourceMask)
Called by the ResourceManager when a processor resource group, or a processor resource with multiple ...
ResourceStrategy()=default
Helper functions used by various pipeline components.
char InstructionError< T >::ID
ResourceStateEvent
Used to notify the internal state of a processor resource.
std::pair< uint64_t, uint64_t > ResourceRef
This is an optimization pass for GlobalISel generic memory operations.
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
constexpr int popcount(T Value) noexcept
Count the number of set bits in a value.
Define a kind of processor resource that will be modeled by the scheduler.
Machine model for scheduling, bundling, and heuristics.