-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
124 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#include <iostream> | ||
#include "CustomStages/MCADFetchDelayStage.h" | ||
|
||
namespace llvm { | ||
namespace mcad { | ||
|
||
struct MCADInstructionFetchedEvent {}; | ||
|
||
bool MCADFetchDelayStage::hasWorkToComplete() const { | ||
return !instrQueue.empty(); | ||
} | ||
|
||
bool MCADFetchDelayStage::isAvailable(const llvm::mca::InstRef &IR) const { | ||
return checkNextStage(IR); | ||
} | ||
|
||
llvm::Error MCADFetchDelayStage::forwardDueInstrs() { | ||
while(!instrQueue.empty() && instrQueue.front().delayCyclesLeft == 0) { | ||
llvm::mca::InstRef IR = instrQueue.front().IR; | ||
if (llvm::Error Val = moveToTheNextStage(IR)) { | ||
return Val; | ||
} | ||
instrQueue.pop_front(); | ||
} | ||
return llvm::ErrorSuccess(); | ||
} | ||
|
||
llvm::Error MCADFetchDelayStage::execute(llvm::mca::InstRef &IR) { | ||
// We (ab-)use the LastGenericEventType to create a notification when the instruction first enters this stage. | ||
// We use this elsewhere to calculate the number of cycles between when an instruction first enters the pipeline and the end of its execution. | ||
notifyEvent<llvm::mca::HWInstructionEvent>(llvm::mca::HWInstructionEvent(llvm::mca::HWInstructionEvent::LastGenericEventType, IR)); | ||
const llvm::mca::Instruction *I = IR.getInstruction(); | ||
const llvm::mca::InstrDesc &ID = I->getDesc(); | ||
const llvm::MCInstrDesc &MCID = MCII.get(I->getOpcode()); | ||
bool immediatelyExecute = true; | ||
unsigned delayCyclesLeft = 0; | ||
if(MCID.isBranch()) { | ||
// delayed, will have to wait | ||
delayCyclesLeft = 100; | ||
} | ||
instrQueue.emplace_back(DelayedInstr { delayCyclesLeft, IR }); | ||
// if the instruction is not delayed, execute it immediately (it will | ||
// have a delayCyclesLeft of 0 and be at the top of the queue) | ||
return forwardDueInstrs(); | ||
} | ||
|
||
llvm::Error MCADFetchDelayStage::cycleStart() { | ||
if(!instrQueue.empty()) { | ||
instrQueue.front().delayCyclesLeft--; | ||
} | ||
return forwardDueInstrs(); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// This class does not model a real hardware stage. It is used to block the | ||
// pipeline for a number of cycles to prevent further instructions from being | ||
// fetched. We use this to model the cost of branch mispredictions. | ||
|
||
#ifndef LLVM_MCAD_FETCH_DELAY_STAGE_H | ||
#define LLVM_MCAD_FETCH_DELAY_STAGE_H | ||
|
||
#include "llvm/MC/MCInstrInfo.h" | ||
#include "llvm/MCA/SourceMgr.h" | ||
#include "llvm/MCA/Stages/Stage.h" | ||
|
||
#include <vector> | ||
#include <queue> | ||
|
||
namespace llvm { | ||
namespace mcad { | ||
|
||
class MCADFetchDelayStage : public llvm::mca::Stage { | ||
|
||
struct DelayedInstr { | ||
unsigned delayCyclesLeft; | ||
llvm::mca::InstRef IR; | ||
}; | ||
|
||
const llvm::MCInstrInfo &MCII; | ||
std::deque<DelayedInstr> instrQueue = {}; | ||
|
||
public: | ||
MCADFetchDelayStage(const llvm::MCInstrInfo &MCII) : MCII(MCII) {} | ||
|
||
bool hasWorkToComplete() const override; | ||
bool isAvailable(const llvm::mca::InstRef &IR) const override; | ||
llvm::Error execute(llvm::mca::InstRef &IR) override; | ||
|
||
//llvm::Error cycleStart() override; | ||
llvm::Error cycleStart() override; | ||
|
||
llvm::Error forwardDueInstrs(); | ||
|
||
///// Called after the pipeline is resumed from pausing state. | ||
//virtual Error cycleResume() { return ErrorSuccess(); } | ||
|
||
///// Called once at the end of each cycle. | ||
|
||
}; | ||
|
||
} | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters