-
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.
first working version with naive branch predictor
- Loading branch information
Showing
10 changed files
with
174 additions
and
14 deletions.
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,26 @@ | ||
#ifndef LLVM_MCAD_ABSTRACT_BRANCH_PREDICTOR_UNIT_H | ||
#define LLVM_MCAD_ABSTRACT_BRANCH_PREDICTOR_UNIT_H | ||
|
||
#include <optional> | ||
#include "llvm/MCA/Instruction.h" | ||
#include "llvm/MCA/HardwareUnits/HardwareUnit.h" | ||
#include "MetadataRegistry.h" | ||
#include "MetadataCategories.h" | ||
|
||
namespace llvm { | ||
namespace mcad { | ||
|
||
class AbstractBranchPredictorUnit : public llvm::mca::HardwareUnit { | ||
|
||
public: | ||
~AbstractBranchPredictorUnit() {} | ||
virtual void recordTakenBranch(MDInstrAddr IA, MDInstrAddr destAddr) = 0; | ||
virtual MDInstrAddr predictBranch(MDInstrAddr IA) = 0; | ||
virtual unsigned getMispredictionPenalty() = 0; | ||
|
||
}; | ||
|
||
} | ||
} | ||
|
||
#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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#include <map> | ||
#include "CustomHWUnits/NaiveBranchPredictorUnit.h" | ||
|
||
namespace llvm { | ||
namespace mcad { | ||
|
||
void NaiveBranchPredictorUnit::recordTakenBranch(MDInstrAddr IA, MDInstrAddr destAddr) { | ||
branchHistory[IA] = destAddr; | ||
} | ||
|
||
MDInstrAddr NaiveBranchPredictorUnit::predictBranch(MDInstrAddr IA) { | ||
if(branchHistory.find(IA) != branchHistory.end()) { | ||
return branchHistory[IA]; | ||
} | ||
// We have no history on this; predict a fall-through branch | ||
// FIXME: fix this to use actual branch instruction size, which is likely | ||
// larger than one byte. | ||
return MDInstrAddr { IA.addr + 1 }; | ||
} | ||
|
||
} | ||
} |
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,28 @@ | ||
#ifndef LLVM_MCAD_NAIVE_BRANCH_PREDICTOR_UNIT_H | ||
#define LLVM_MCAD_NAIVE_BRANCH_PREDICTOR_UNIT_H | ||
|
||
#include <map> | ||
#include "CustomHWUnits/AbstractBranchPredictorUnit.h" | ||
|
||
namespace llvm { | ||
namespace mcad { | ||
|
||
class NaiveBranchPredictorUnit : public AbstractBranchPredictorUnit { | ||
unsigned mispredictionPenalty; | ||
std::map<MDInstrAddr, MDInstrAddr> branchHistory = {}; | ||
|
||
public: | ||
NaiveBranchPredictorUnit(unsigned mispredictionPenalty = 20) : mispredictionPenalty(mispredictionPenalty) {}; | ||
|
||
void recordTakenBranch(MDInstrAddr IA, MDInstrAddr destAddr) override; | ||
MDInstrAddr predictBranch(MDInstrAddr IA) override; | ||
unsigned getMispredictionPenalty() override { | ||
return mispredictionPenalty; | ||
} | ||
|
||
}; | ||
|
||
} | ||
} | ||
|
||
#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
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,21 @@ | ||
#include "llvm/MCA/Instruction.h" | ||
#include <optional> | ||
#include "MetadataRegistry.h" | ||
#include "MetadataCategories.h" | ||
|
||
namespace llvm { | ||
namespace mcad { | ||
|
||
std::optional<MDInstrAddr> getMDInstrAddrForInstr(MetadataRegistry &MD, const llvm::mca::InstRef &IR) { | ||
const llvm::mca::Instruction *I = IR.getInstruction(); | ||
auto instrId = I->getIdentifier(); | ||
if (instrId.has_value()) { | ||
auto &Registry = MD[llvm::mcad::MD_InstrAddr]; | ||
auto instrAddr = Registry.get<MDInstrAddr>(*instrId); | ||
return instrAddr; | ||
} | ||
return std::nullopt; | ||
} | ||
|
||
} | ||
} |
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