LLVM 22.0.0git
llvm::mca::LSUnit Class Reference

Default Load/Store Unit (LS Unit) for simulated processors. More...

#include "llvm/MCA/HardwareUnits/LSUnit.h"

Inheritance diagram for llvm::mca::LSUnit:
[legend]

Classes

class  MemoryGroup
 A node of a memory dependency graph. More...

Public Member Functions

 LSUnit (const MCSchedModel &SM)
 LSUnit (const MCSchedModel &SM, unsigned LQ, unsigned SQ)
 LSUnit (const MCSchedModel &SM, unsigned LQ, unsigned SQ, bool AssumeNoAlias)
Status isAvailable (const InstRef &IR) const override
 Returns LSU_AVAILABLE if there are enough load/store queue entries to accomodate instruction IR.
bool isReady (const InstRef &IR) const override
 Check if a peviously dispatched instruction IR is now ready for execution.
bool isPending (const InstRef &IR) const override
 Check if instruction IR only depends on memory instructions that are currently executing.
bool isWaiting (const InstRef &IR) const override
 Check if instruction IR is still waiting on memory operations, and the wait time is still unknown.
bool hasDependentUsers (const InstRef &IR) const override
const CriticalDependency getCriticalPredecessor (unsigned GroupId) override
unsigned dispatch (const InstRef &IR) override
 Allocates LS resources for instruction IR.
virtual void onInstructionIssued (const InstRef &IR) override
virtual void onInstructionRetired (const InstRef &IR) override
virtual void onInstructionExecuted (const InstRef &IR) override
virtual void cycleEvent () override
virtual void dump () const override
Public Member Functions inherited from llvm::mca::LSUnitBase
 LSUnitBase (const MCSchedModel &SM, unsigned LoadQueueSize, unsigned StoreQueueSize, bool AssumeNoAlias)
virtual ~LSUnitBase ()
unsigned getLoadQueueSize () const
 Returns the total number of entries in the load queue.
unsigned getStoreQueueSize () const
 Returns the total number of entries in the store queue.
unsigned getUsedLQEntries () const
unsigned getUsedSQEntries () const
void acquireLQSlot ()
void acquireSQSlot ()
void releaseLQSlot ()
void releaseSQSlot ()
bool assumeNoAlias () const
bool isSQEmpty () const
bool isLQEmpty () const
bool isSQFull () const
bool isLQFull () const
Public Member Functions inherited from llvm::mca::HardwareUnit
 HardwareUnit ()=default
virtual ~HardwareUnit ()

Protected Attributes

DenseMap< unsigned, std::unique_ptr< MemoryGroup > > Groups
 Used to map group identifiers to MemoryGroups.
unsigned NextGroupID = 1
unsigned CurrentLoadGroupID
unsigned CurrentLoadBarrierGroupID
unsigned CurrentStoreGroupID
unsigned CurrentStoreBarrierGroupID

Additional Inherited Members

Public Types inherited from llvm::mca::LSUnitBase
enum  Status { LSU_AVAILABLE = 0 , LSU_LQUEUE_FULL , LSU_SQUEUE_FULL }

Detailed Description

Default Load/Store Unit (LS Unit) for simulated processors.

Each load (or store) consumes one entry in the load (or store) queue.

Rules are: 1) A younger load is allowed to pass an older load only if there are no stores nor barriers in between the two loads. 2) An younger store is not allowed to pass an older store. 3) A younger store is not allowed to pass an older load. 4) A younger load is allowed to pass an older store only if the load does not alias with the store.

This class optimistically assumes that loads don't alias store operations. Under this assumption, younger loads are always allowed to pass older stores (this would only affects rule 4). Essentially, this class doesn't perform any sort alias analysis to identify aliasing loads and stores.

To enforce aliasing between loads and stores, flag AssumeNoAlias must be set to false by the constructor of LSUnit.

Note that this class doesn't know about the existence of different memory types for memory operations (example: write-through, write-combining, etc.). Derived classes are responsible for implementing that extra knowledge, and provide different sets of rules for loads and stores by overriding method isReady(). To emulate a write-combining memory type, rule 2. must be relaxed in a derived class to enable the reordering of non-aliasing store operations.

No assumptions are made by this class on the size of the store buffer. This class doesn't know how to identify cases where store-to-load forwarding may occur.

LSUnit doesn't attempt to predict whether a load or store hits or misses the L1 cache. To be more specific, LSUnit doesn't know anything about cache hierarchy and memory types. It only knows if an instruction "mayLoad" and/or "mayStore". For loads, the scheduling model provides an "optimistic" load-to-use latency (which usually matches the load-to-use latency for when there is a hit in the L1D). Derived classes may expand this knowledge.

Class MCInstrDesc in LLVM doesn't know about serializing operations, nor memory-barrier like instructions. LSUnit conservatively assumes that an instruction which mayLoad and has unmodeled side effects behave like a "soft" load-barrier. That means, it serializes loads without forcing a flush of the load queue. Similarly, instructions that both mayStore and have unmodeled side / effects are treated like store barriers. A full memory barrier is a 'mayLoad' and 'mayStore' instruction with unmodeled side effects. This is obviously inaccurate, but this is the best that we can do at the moment.

Each load/store barrier consumes one entry in the load/store queue. A load/store barrier enforces ordering of loads/stores:

  • A younger load cannot pass a load barrier.
  • A younger store cannot pass a store barrier.

A younger load has to wait for the memory load barrier to execute. A load/store barrier is "executed" when it becomes the oldest entry in the load/store queue(s). That also means, all the older loads/stores have already been executed.

Definition at line 196 of file LSUnit.h.

Constructor & Destructor Documentation

◆ LSUnit() [1/3]

llvm::mca::LSUnit::LSUnit ( const MCSchedModel & SM)
inline

Definition at line 411 of file LSUnit.h.

References LSUnit().

Referenced by LSUnit(), and LSUnit().

◆ LSUnit() [2/3]

llvm::mca::LSUnit::LSUnit ( const MCSchedModel & SM,
unsigned LQ,
unsigned SQ )
inline

Definition at line 413 of file LSUnit.h.

References LSUnit().

◆ LSUnit() [3/3]

llvm::mca::LSUnit::LSUnit ( const MCSchedModel & SM,
unsigned LQ,
unsigned SQ,
bool AssumeNoAlias )
inline

Member Function Documentation

◆ cycleEvent()

void llvm::mca::LSUnit::cycleEvent ( )
overridevirtual

Implements llvm::mca::LSUnitBase.

Definition at line 44 of file LSUnit.cpp.

References cycleEvent(), G, and Groups.

Referenced by cycleEvent().

◆ dispatch()

unsigned llvm::mca::LSUnit::dispatch ( const InstRef & IR)
overridevirtual

Allocates LS resources for instruction IR.

This method assumes that a previous call to isAvailable(IR) succeeded returning LSU_AVAILABLE.

Rules are: By default, rules are:

  1. A store may not pass a previous store.
  2. A load may not pass a previous store unless flag 'NoAlias' is set.
  3. A load may pass a previous load.
  4. A store may not pass a previous load (regardless of flag 'NoAlias').
  5. A load has to wait until an older load barrier is fully executed.
  6. A store has to wait until an older store barrier is fully executed.

Implements llvm::mca::LSUnitBase.

Definition at line 69 of file LSUnit.cpp.

References llvm::mca::LSUnitBase::acquireLQSlot(), llvm::mca::LSUnitBase::acquireSQSlot(), llvm::mca::LSUnit::MemoryGroup::addInstruction(), llvm::mca::LSUnit::MemoryGroup::addSuccessor(), assert(), llvm::mca::LSUnitBase::assumeNoAlias(), CurrentLoadBarrierGroupID, CurrentLoadGroupID, CurrentStoreBarrierGroupID, CurrentStoreGroupID, llvm::dbgs(), dispatch(), llvm::mca::InstructionBase::getMayLoad(), llvm::mca::InstructionBase::getMayStore(), IR, llvm::mca::InstructionBase::isALoadBarrier(), llvm::mca::InstructionBase::isAStoreBarrier(), and LLVM_DEBUG.

Referenced by dispatch().

◆ dump()

◆ getCriticalPredecessor()

const CriticalDependency llvm::mca::LSUnit::getCriticalPredecessor ( unsigned GroupId)
inlineoverridevirtual

◆ hasDependentUsers()

bool llvm::mca::LSUnit::hasDependentUsers ( const InstRef & IR) const
inlineoverridevirtual

◆ isAvailable()

LSUnit::Status llvm::mca::LSUnit::isAvailable ( const InstRef & IR) const
overridevirtual

◆ isPending()

bool llvm::mca::LSUnit::isPending ( const InstRef & IR) const
inlineoverridevirtual

Check if instruction IR only depends on memory instructions that are currently executing.

Implements llvm::mca::LSUnitBase.

Definition at line 430 of file LSUnit.h.

References IR, and llvm::mca::LSUnit::MemoryGroup::isPending().

◆ isReady()

bool llvm::mca::LSUnit::isReady ( const InstRef & IR) const
inlineoverridevirtual

Check if a peviously dispatched instruction IR is now ready for execution.

Implements llvm::mca::LSUnitBase.

Definition at line 424 of file LSUnit.h.

References IR, and llvm::mca::LSUnit::MemoryGroup::isReady().

◆ isWaiting()

bool llvm::mca::LSUnit::isWaiting ( const InstRef & IR) const
inlineoverridevirtual

Check if instruction IR is still waiting on memory operations, and the wait time is still unknown.

Implements llvm::mca::LSUnitBase.

Definition at line 436 of file LSUnit.h.

References IR, and llvm::mca::LSUnit::MemoryGroup::isWaiting().

◆ onInstructionExecuted()

◆ onInstructionIssued()

virtual void llvm::mca::LSUnit::onInstructionIssued ( const InstRef & IR)
inlineoverridevirtual

Implements llvm::mca::LSUnitBase.

Definition at line 468 of file LSUnit.h.

References Groups, and IR.

◆ onInstructionRetired()

Member Data Documentation

◆ CurrentLoadBarrierGroupID

unsigned llvm::mca::LSUnit::CurrentLoadBarrierGroupID
protected

Definition at line 406 of file LSUnit.h.

Referenced by dispatch(), LSUnit(), and onInstructionExecuted().

◆ CurrentLoadGroupID

unsigned llvm::mca::LSUnit::CurrentLoadGroupID
protected

Definition at line 405 of file LSUnit.h.

Referenced by dispatch(), LSUnit(), and onInstructionExecuted().

◆ CurrentStoreBarrierGroupID

unsigned llvm::mca::LSUnit::CurrentStoreBarrierGroupID
protected

Definition at line 408 of file LSUnit.h.

Referenced by dispatch(), LSUnit(), and onInstructionExecuted().

◆ CurrentStoreGroupID

unsigned llvm::mca::LSUnit::CurrentStoreGroupID
protected

Definition at line 407 of file LSUnit.h.

Referenced by dispatch(), LSUnit(), and onInstructionExecuted().

◆ Groups

DenseMap<unsigned, std::unique_ptr<MemoryGroup> > llvm::mca::LSUnit::Groups
protected

Used to map group identifiers to MemoryGroups.

Definition at line 402 of file LSUnit.h.

Referenced by cycleEvent(), dump(), onInstructionExecuted(), and onInstructionIssued().

◆ NextGroupID

unsigned llvm::mca::LSUnit::NextGroupID = 1
protected

Definition at line 403 of file LSUnit.h.


The documentation for this class was generated from the following files: