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;
194 const int BufferSize;
197 unsigned AvailableSlots;
210 bool isSubResourceReady(
uint64_t SubResMask)
const {
211 return ReadyMask & SubResMask;
218 unsigned getProcResourceID()
const {
return ProcResourceDescIndex; }
219 uint64_t getResourceMask()
const {
return ResourceMask; }
220 uint64_t getReadyMask()
const {
return ReadyMask; }
221 int getBufferSize()
const {
return BufferSize; }
223 bool isBuffered()
const {
return BufferSize > 0; }
224 bool isInOrder()
const {
return BufferSize == 1; }
227 bool isADispatchHazard()
const {
return BufferSize == 0; }
235 LLVM_ABI bool isReady(
unsigned NumUnits = 1)
const;
239 bool isAResourceGroup()
const {
return IsAGroup; }
241 bool containsResource(
uint64_t ID)
const {
return ResourceMask &
ID; }
253 unsigned getNumUnits()
const {
254 return isAResourceGroup() ? 1U :
llvm::popcount(ResourceSizeMask);
272 bool reserveBuffer() {
277 assert(AvailableSlots <=
static_cast<unsigned>(BufferSize));
278 return AvailableSlots;
282 void releaseBuffer() {
288 assert(AvailableSlots <=
static_cast<unsigned>(BufferSize));
305typedef std::pair<unsigned, unsigned> BufferUsageEntry;
343 std::vector<std::unique_ptr<ResourceState>> Resources;
344 std::vector<std::unique_ptr<ResourceStrategy>> Strategies;
347 std::vector<uint64_t> Resource2Groups;
382 unsigned getNumUnits(
uint64_t ResourceID)
const;
386 LLVM_ABI void setCustomStrategyImpl(std::unique_ptr<ResourceStrategy> S,
395 void setCustomStrategy(std::unique_ptr<ResourceStrategy> S,
396 unsigned ResourceID) {
398 "Invalid resource index in input!");
399 return setCustomStrategyImpl(std::move(S), ProcResID2Mask[ResourceID]);
404 LLVM_ABI ResourceStateEvent canBeDispatched(
uint64_t ConsumedBuffers)
const;
432 uint64_t getProcResUnitMask()
const {
return ProcResUnitMask; }
433 uint64_t getAvailableProcResUnits()
const {
return AvailableProcResUnits; }
435 using ResourceWithCycles = std::pair<ResourceRef, ReleaseAtCycles>;
437 void issueInstruction(
const InstrDesc &Desc,
438 SmallVectorImpl<ResourceWithCycles> &Pipes) {
439 if (
Desc.HasPartiallyOverlappingGroups)
440 return issueInstructionImpl(Desc, Pipes);
442 return fastIssueInstruction(Desc, Pipes);
452 fastIssueInstruction(
const InstrDesc &Desc,
453 SmallVectorImpl<ResourceWithCycles> &Pipes);
461 issueInstructionImpl(
const InstrDesc &Desc,
462 SmallVectorImpl<ResourceWithCycles> &Pipes);
464 LLVM_ABI void cycleEvent(SmallVectorImpl<ResourceRef> &ResourcesFreed);
468 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...
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 ...
virtual ~DefaultResourceStrategy()=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)
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.