namespace mca {
bool FetchStage::hasWorkToComplete() const {
- return CurrentInstruction.get() || SM.hasNext();
+ return CurrentInstruction.isValid();
}
bool FetchStage::isAvailable(const InstRef & /* unused */) const {
- if (!CurrentInstruction)
- return false;
- assert(SM.hasNext() && "Unexpected internal state!");
- const SourceRef SR = SM.peekNext();
- InstRef IR(SR.first, CurrentInstruction.get());
- return checkNextStage(IR);
+ if (CurrentInstruction.isValid())
+ return checkNextStage(CurrentInstruction);
+ return false;
}
llvm::Error FetchStage::getNextInstruction() {
- assert(!CurrentInstruction && "There is already an instruction to process!");
+ assert(!CurrentInstruction.isValid() &&
+ "There is already an instruction to process!");
if (!SM.hasNext())
return llvm::ErrorSuccess();
const SourceRef SR = SM.peekNext();
IB.createInstruction(SR.second);
if (!InstOrErr)
return InstOrErr.takeError();
- CurrentInstruction = std::move(InstOrErr.get());
+ std::unique_ptr<Instruction> Inst = std::move(InstOrErr.get());
+ CurrentInstruction = InstRef(SR.first, Inst.get());
+ Instructions[SR.first] = std::move(Inst);
+ SM.updateNext();
return llvm::ErrorSuccess();
}
llvm::Error FetchStage::execute(InstRef & /*unused */) {
- assert(CurrentInstruction && "There is no instruction to process!");
- const SourceRef SR = SM.peekNext();
- InstRef IR(SR.first, CurrentInstruction.get());
- assert(checkNextStage(IR) && "Invalid fetch!");
-
- Instructions[IR.getSourceIndex()] = std::move(CurrentInstruction);
- if (llvm::Error Val = moveToTheNextStage(IR))
+ assert(CurrentInstruction.isValid() && "There is no instruction to process!");
+ if (llvm::Error Val = moveToTheNextStage(CurrentInstruction))
return Val;
- SM.updateNext();
-
// Move the program counter.
+ CurrentInstruction.invalidate();
return getNextInstruction();
}
llvm::Error FetchStage::cycleStart() {
- if (!CurrentInstruction)
+ if (!CurrentInstruction.isValid())
return getNextInstruction();
return llvm::ErrorSuccess();
}