33 lines
985 B
C++
33 lines
985 B
C++
#pragma once
|
|
|
|
#include "llvm/ADT/ArrayRef.h"
|
|
#include "llvm/ADT/SmallVector.h"
|
|
#include <cassert>
|
|
#include <cstdint>
|
|
|
|
namespace onnx_mlir {
|
|
|
|
// Emptiness is normalized after consumption. Capacity and consumed prefixes
|
|
// cannot affect virtual timing, readiness, or the remaining FIFO sequence.
|
|
class PimDependencyTokens {
|
|
llvm::SmallVector<uint64_t, 1> values;
|
|
size_t head = 0;
|
|
public:
|
|
void initialize(size_t distance) { values.assign(distance, 0); head = 0; }
|
|
bool empty() const { return values.empty(); }
|
|
void push(uint64_t time) { values.push_back(time); }
|
|
uint64_t consume() {
|
|
assert(!empty());
|
|
uint64_t time = values[head++];
|
|
if (head == values.size()) { values.clear(); head = 0; }
|
|
else if (head >= values.size() - head) {
|
|
values.erase(values.begin(), values.begin() + head);
|
|
head = 0;
|
|
}
|
|
return time;
|
|
}
|
|
llvm::ArrayRef<uint64_t> remaining() const { return llvm::ArrayRef(values).drop_front(head); }
|
|
};
|
|
|
|
} // namespace onnx_mlir
|