Skip to content

Commit

Permalink
Update to llvm 16.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
hanchenye committed Mar 22, 2023
1 parent c6ebacb commit 1f24e21
Show file tree
Hide file tree
Showing 15 changed files with 202 additions and 170 deletions.
2 changes: 1 addition & 1 deletion include/scalehls/Dialect/HLS/HLSOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def YieldOp : HLSOp<"dataflow.yield", [NoMemoryEffect, ReturnLike, Terminator,
let arguments = (ins Variadic<AnyType>:$results);
let assemblyFormat = "$results attr-dict `:` type($results)";

let builders = [OpBuilder<(ins), "build($_builder, $_state, llvm::None);">];
let builders = [OpBuilder<(ins), "build($_builder, $_state, std::nullopt);">];
}

def ToStreamOp : HLSOp<"dataflow.to_stream", [NoMemoryEffect]> {
Expand Down
2 changes: 1 addition & 1 deletion lib/Dialect/HLS/HLS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -992,7 +992,7 @@ struct AlwaysTrueOrFalseSelect : public OpRewritePattern<AffineSelectOp> {

// Add induction variable constraints.
for (auto arg : args)
if (isForInductionVar(arg))
if (isAffineForInductionVar(arg))
(void)constrs.addAffineForOpDomain(getForInductionVarOwner(arg));

// Always false if there's no known solution for the constraints.
Expand Down
8 changes: 4 additions & 4 deletions lib/Dialect/HLS/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ std::pair<bool, bool> scalehls::ifAlwaysTrueOrFalse(mlir::AffineIfOp ifOp) {
FlatAffineValueConstraints constrs;
constrs.addAffineIfOpDomain(ifOp);
for (auto operand : operands)
if (isForInductionVar(operand)) {
if (isAffineForInductionVar(operand)) {
auto iv = getForInductionVarOwner(operand);
if (failed(constrs.addAffineForOpDomain(iv)))
continue;
Expand Down Expand Up @@ -814,8 +814,8 @@ scalehls::checkSameLevel(Operation *lhsOp, Operation *rhsOp) {
unsigned scalehls::getCommonSurroundingLoops(Operation *A, Operation *B,
AffineLoopBand *band) {
SmallVector<AffineForOp, 4> loopsA, loopsB;
getLoopIVs(*A, &loopsA);
getLoopIVs(*B, &loopsB);
getAffineForIVs(*A, &loopsA);
getAffineForIVs(*B, &loopsB);

unsigned minNumLoops = std::min(loopsA.size(), loopsB.size());
unsigned numCommonLoops = 0;
Expand Down Expand Up @@ -847,7 +847,7 @@ scalehls::getBoundOfAffineMap(AffineMap map, ValueRange operands) {
for (auto operand : operands) {
// Only if the affine map operands are induction variable, the calculation
// is possible.
if (!isForInductionVar(operand))
if (!isAffineForInductionVar(operand))
return Optional<std::pair<int64_t, int64_t>>();

// Only if the owner for op of the induction variable has constant bound,
Expand Down
4 changes: 2 additions & 2 deletions lib/Transforms/Dataflow/CreateDataflowFromLinalg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@ struct ForwardFuseGenericOp : public OpRewritePattern<linalg::GenericOp> {
bool matched = false;
auto body = op.getBody();

if (op.getNumOutputs() == 1 &&
if (op.getOutputs().size() == 1 &&
llvm::hasSingleElement(body->getOperations())) {
auto output = body->getTerminator()->getOperand(0);

// Copy from input to output.
if (op.getNumInputs() == 1 && output == body->getArgument(0))
if (op.getInputs().size() == 1 && output == body->getArgument(0))
matched = true;

// Copy from constant to output.
Expand Down
2 changes: 1 addition & 1 deletion lib/Transforms/Dataflow/EliminateMultiProducer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ struct BufferMultiProducer : public OpRewritePattern<ScheduleOp> {
// loop induction variables and meanwhile the load has identity
// memory access map.
AffineLoopBand band;
getLoopIVs(*read, &band);
getAffineForIVs(*read, &band);

llvm::SmallDenseSet<Value> depInductionVars;
for (auto loop : band)
Expand Down
59 changes: 35 additions & 24 deletions lib/Transforms/Dataflow/PlaceDataflowBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,41 @@ struct PlaceBuffer : public OpRewritePattern<func::FuncOp> {
: OpRewritePattern<func::FuncOp>(context), threshold(threshold),
placeExternalBuffer(placeExternalBuffer) {}

// TODO: For now, we use a heuristic to determine the buffer location.
MemRefType getPlacedType(MemRefType type, bool isConstBuffer) const {
auto kind = MemoryKind::BRAM_T2P;
if (placeExternalBuffer || isConstBuffer)
kind = type.getNumElements() >= threshold ? MemoryKind::DRAM
: MemoryKind::BRAM_T2P;
auto newType = MemRefType::get(
type.getShape(), type.getElementType(), type.getLayout().getAffineMap(),
MemoryKindAttr::get(type.getContext(), kind));
return newType;
}

MemRefType getPlacedOnDramType(MemRefType type) const {
auto newType = MemRefType::get(
type.getShape(), type.getElementType(), type.getLayout().getAffineMap(),
MemoryKindAttr::get(type.getContext(), MemoryKind::DRAM));
return newType;
}

LogicalResult matchAndRewrite(func::FuncOp func,
PatternRewriter &rewriter) const override {
bool hasChanged = false;

for (auto arg : func.getArguments())
if (auto type = arg.getType().dyn_cast<MemRefType>())
arg.setType(getPlacedOnDramType(type));
if (auto type = arg.getType().dyn_cast<MemRefType>()) {
if (auto attr = type.getMemorySpace())
if (attr.isa<MemoryKindAttr>())
continue;

auto newType = MemRefType::get(
type.getShape(), type.getElementType(),
type.getLayout().getAffineMap(),
MemoryKindAttr::get(type.getContext(), MemoryKind::DRAM));
arg.setType(newType);
hasChanged = true;
}

func.walk([&](hls::BufferLikeInterface buffer) {
buffer.getMemref().setType(getPlacedType(
buffer.getMemrefType(), isa<ConstBufferOp>(buffer.getOperation())));
auto type = buffer.getMemref().getType().cast<MemRefType>();
if (auto attr = type.getMemorySpace())
if (attr.isa<MemoryKindAttr>())
return WalkResult::advance();

auto kind = MemoryKind::BRAM_T2P;
if (placeExternalBuffer || isa<ConstBufferOp>(buffer.getOperation()))
kind = type.getNumElements() >= threshold ? MemoryKind::DRAM
: MemoryKind::BRAM_T2P;
auto newType =
MemRefType::get(type.getShape(), type.getElementType(),
type.getLayout().getAffineMap(),
MemoryKindAttr::get(type.getContext(), kind));
buffer.getMemref().setType(newType);
hasChanged = true;
return WalkResult::advance();
});

func.walk([](YieldOp yield) {
Expand All @@ -59,7 +66,7 @@ struct PlaceBuffer : public OpRewritePattern<func::FuncOp> {
func.setType(rewriter.getFunctionType(
func.front().getArgumentTypes(),
func.front().getTerminator()->getOperandTypes()));
return success();
return success(hasChanged);
}

private:
Expand Down Expand Up @@ -104,10 +111,14 @@ struct PlaceDataflowBuffer
auto func = getOperation();
auto context = func.getContext();

llvm::outs() << "1\n";

mlir::RewritePatternSet patterns(context);
patterns.add<PlaceBuffer>(context, threshold, placeExternalBuffer);
(void)applyOpPatternsAndFold(func, std::move(patterns));

llvm::outs() << "2\n";

patterns.clear();
patterns.add<HoistDramBuffer>(context);
(void)applyPatternsAndFoldGreedily(func, std::move(patterns));
Expand Down
4 changes: 2 additions & 2 deletions lib/Transforms/Directive/QoREstimation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void ScaleHLSEstimator::getPartitionIndices(Operation *op) {
for (auto operand : accessMap.getOperands()) {
if (operandIdx < accessMap.getNumDims()) {
int64_t step = 1;
if (isForInductionVar(operand))
if (isAffineForInductionVar(operand))
step = getForInductionVarOwner(operand).getStep();

dimReplacements.push_back(step * builder.getAffineDimExpr(operandIdx));
Expand Down Expand Up @@ -308,7 +308,7 @@ int64_t ScaleHLSEstimator::getDepMinII(int64_t II, func::FuncOp func,
int64_t ScaleHLSEstimator::getDepMinII(int64_t II, AffineForOp forOp,
MemAccessesMap &map) {
AffineLoopBand band;
getLoopIVs(forOp.front(), &band);
getAffineForIVs(forOp.front(), &band);

// Find all loop levels whose dependency need to be checked.
SmallVector<unsigned, 8> loopDepths;
Expand Down
10 changes: 5 additions & 5 deletions lib/Transforms/Loop/AffineLoopFusion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ struct MemRefDependenceGraph {
for (Block::iterator it = std::next(Block::iterator(srcNodeInst));
it != Block::iterator(dstNodeInst); ++it) {
Operation *op = &(*it);
if (srcDepInsts.count(op) > 0 && firstSrcDepPos == None)
if (srcDepInsts.count(op) > 0 && firstSrcDepPos == std::nullopt)
firstSrcDepPos = pos;
if (dstDepInsts.count(op) > 0)
lastDstDepPos = pos;
Expand Down Expand Up @@ -824,7 +824,7 @@ bool MemRefDependenceGraph::init(hls::StageLikeInterface f) {
for (auto value : opInst->getResults()) {
for (auto *user : value.getUsers()) {
SmallVector<AffineForOp, 4> loops;
getLoopIVs(*user, &loops);
getAffineForIVs(*user, &loops);
if (loops.empty())
continue;
assert(forToNodeMap.count(loops[0].getOperation()) > 0);
Expand Down Expand Up @@ -1116,7 +1116,7 @@ static bool isFusionProfitable(Operation *srcOpInst, Operation *srcStoreOpInst,

// Compute cost of sliced and unsliced src loop nest.
SmallVector<AffineForOp, 4> srcLoopIVs;
getLoopIVs(*srcOpInst, &srcLoopIVs);
getAffineForIVs(*srcOpInst, &srcLoopIVs);

// Walk src loop nest and collect stats.
LoopNestStats srcLoopNestStats;
Expand Down Expand Up @@ -1776,7 +1776,7 @@ struct GreedyFusion {
dstNode->getLoadOpsForMemref(memref, &dstLoadOpInsts);

AffineLoopBand dstLoopIVs;
getLoopIVs(*dstLoadOpInsts[0], &dstLoopIVs);
getAffineForIVs(*dstLoadOpInsts[0], &dstLoopIVs);
unsigned dstLoopDepthTest = dstLoopIVs.size();
auto sibAffineForOp = cast<AffineForOp>(sibNode->op);

Expand Down Expand Up @@ -1890,7 +1890,7 @@ struct GreedyFusion {
if (auto loadOp = dyn_cast<AffineReadOpInterface>(user)) {
// Gather loops surrounding 'use'.
SmallVector<AffineForOp, 4> loops;
getLoopIVs(*user, &loops);
getAffineForIVs(*user, &loops);
// Skip 'use' if it is not within a loop nest.
if (loops.empty())
continue;
Expand Down
4 changes: 2 additions & 2 deletions lib/Transforms/Memory/SimplifyCopy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ struct SplitElementwiseGenericOp : public OpRewritePattern<linalg::GenericOp> {

LogicalResult matchAndRewrite(linalg::GenericOp op,
PatternRewriter &rewriter) const override {
if (isElementwiseGenericOp(op) && op.getNumInputs() == 1 &&
op.getNumOutputs() == 1) {
if (isElementwiseGenericOp(op) && op.getInputs().size() == 1 &&
op.getOutputs().size() == 1) {
auto &input = op->getOpOperand(0);
auto &output = op->getOpOperand(1);
if (input.get() == output.get())
Expand Down
2 changes: 1 addition & 1 deletion llvm-project
Loading

0 comments on commit 1f24e21

Please sign in to comment.