|
18 | 18 | namespace mca {
|
19 | 19 |
|
20 | 20 | bool FetchStage::hasWorkToComplete() const {
|
21 |
| - return CurrentInstruction.get() || SM.hasNext(); |
| 21 | + return CurrentInstruction.isValid(); |
22 | 22 | }
|
23 | 23 |
|
24 | 24 | bool FetchStage::isAvailable(const InstRef & /* unused */) const {
|
25 |
| - if (!CurrentInstruction) |
26 |
| - return false; |
27 |
| - assert(SM.hasNext() && "Unexpected internal state!"); |
28 |
| - const SourceRef SR = SM.peekNext(); |
29 |
| - InstRef IR(SR.first, CurrentInstruction.get()); |
30 |
| - return checkNextStage(IR); |
| 25 | + if (CurrentInstruction.isValid()) |
| 26 | + return checkNextStage(CurrentInstruction); |
| 27 | + return false; |
31 | 28 | }
|
32 | 29 |
|
33 | 30 | llvm::Error FetchStage::getNextInstruction() {
|
34 |
| - assert(!CurrentInstruction && "There is already an instruction to process!"); |
| 31 | + assert(!CurrentInstruction.isValid() && |
| 32 | + "There is already an instruction to process!"); |
35 | 33 | if (!SM.hasNext())
|
36 | 34 | return llvm::ErrorSuccess();
|
37 | 35 | const SourceRef SR = SM.peekNext();
|
38 | 36 | llvm::Expected<std::unique_ptr<Instruction>> InstOrErr =
|
39 | 37 | IB.createInstruction(SR.second);
|
40 | 38 | if (!InstOrErr)
|
41 | 39 | return InstOrErr.takeError();
|
42 |
| - CurrentInstruction = std::move(InstOrErr.get()); |
| 40 | + std::unique_ptr<Instruction> Inst = std::move(InstOrErr.get()); |
| 41 | + CurrentInstruction = InstRef(SR.first, Inst.get()); |
| 42 | + Instructions[SR.first] = std::move(Inst); |
| 43 | + SM.updateNext(); |
43 | 44 | return llvm::ErrorSuccess();
|
44 | 45 | }
|
45 | 46 |
|
46 | 47 | llvm::Error FetchStage::execute(InstRef & /*unused */) {
|
47 |
| - assert(CurrentInstruction && "There is no instruction to process!"); |
48 |
| - const SourceRef SR = SM.peekNext(); |
49 |
| - InstRef IR(SR.first, CurrentInstruction.get()); |
50 |
| - assert(checkNextStage(IR) && "Invalid fetch!"); |
51 |
| - |
52 |
| - Instructions[IR.getSourceIndex()] = std::move(CurrentInstruction); |
53 |
| - if (llvm::Error Val = moveToTheNextStage(IR)) |
| 48 | + assert(CurrentInstruction.isValid() && "There is no instruction to process!"); |
| 49 | + if (llvm::Error Val = moveToTheNextStage(CurrentInstruction)) |
54 | 50 | return Val;
|
55 | 51 |
|
56 |
| - SM.updateNext(); |
57 |
| - |
58 | 52 | // Move the program counter.
|
| 53 | + CurrentInstruction.invalidate(); |
59 | 54 | return getNextInstruction();
|
60 | 55 | }
|
61 | 56 |
|
62 | 57 | llvm::Error FetchStage::cycleStart() {
|
63 |
| - if (!CurrentInstruction) |
| 58 | + if (!CurrentInstruction.isValid()) |
64 | 59 | return getNextInstruction();
|
65 | 60 | return llvm::ErrorSuccess();
|
66 | 61 | }
|
|
0 commit comments