Skip to content

Commit

Permalink
[Arc] Add statistics to the FindInitialVectors pass (#7113)
Browse files Browse the repository at this point in the history
  • Loading branch information
elhewaty authored Jun 1, 2024
1 parent 5e95aa0 commit 8e47286
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 10 deletions.
10 changes: 10 additions & 0 deletions include/circt/Dialect/Arc/ArcPasses.td
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ def FindInitialVectors : Pass<"arc-find-initial-vectors", "mlir::ModuleOp"> {
let summary = "Find initial groups of vectorizable ops";
let constructor = "circt::arc::createFindInitialVectorsPass()";
let dependentDialects = ["arc::ArcDialect"];
let statistics = [
Statistic<"numOfVectorizedOps", "vectorizedOps",
"Total number of ops that were vectorized">,
Statistic<"numOfSavedOps", "numOfSavedOps",
"Total number of ops saved after FindInitialVectors pass">,
Statistic<"biggestSeedVector", "biggestSeedVector",
"Size of the biggest seed vector">,
Statistic<"numOfVectorsCreated", "numOfVectorsCreated",
"Total number of VectorizeOps the pass inserted">,
];
}

def GroupResetsAndEnables : Pass<"arc-group-resets-and-enables",
Expand Down
45 changes: 35 additions & 10 deletions lib/Dialect/Arc/Transforms/FindInitialVectors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "mlir/Transforms/GreedyPatternRewriteDriver.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>

#define DEBUG_TYPE "find-initial-vectors"

Expand All @@ -44,6 +45,22 @@ using namespace circt;
using namespace arc;
using llvm::SmallMapVector;

namespace {
struct FindInitialVectorsPass
: public impl::FindInitialVectorsBase<FindInitialVectorsPass> {
void runOnOperation() override;

struct StatisticVars {
size_t vecOps{0};
size_t savedOps{0};
size_t bigSeedVec{0};
size_t vecCreated{0};
};

StatisticVars stat;
};
} // namespace

namespace {
struct TopologicalOrder {
/// An integer rank assigned to each operation.
Expand Down Expand Up @@ -124,7 +141,7 @@ struct Vectorizer {
return success();
}

LogicalResult vectorize();
LogicalResult vectorize(FindInitialVectorsPass::StatisticVars &stat);
// Store Isomorphic ops together
SmallMapVector<Key, SmallVector<Operation *>, 16> candidates;
TopologicalOrder order;
Expand Down Expand Up @@ -159,7 +176,10 @@ struct DenseMapInfo<Key> {

// When calling this function we assume that we have the candidate groups of
// isomorphic ops so we need to feed them to the `VectorizeOp`
LogicalResult Vectorizer::vectorize() {
LogicalResult
Vectorizer::vectorize(FindInitialVectorsPass::StatisticVars &stat) {
LLVM_DEBUG(llvm::dbgs() << "- Vectorizing the ops in block" << block << "\n");

if (failed(collectSeeds(block)))
return failure();

Expand All @@ -177,6 +197,12 @@ LogicalResult Vectorizer::vectorize() {
ops[0]->getNumOperands() == 0)
continue;

// Collect Statistics
stat.vecOps += ops.size();
stat.savedOps += ops.size() - 1;
stat.bigSeedVec = std::max(ops.size(), stat.bigSeedVec);
++stat.vecCreated;

// Here, we have a bunch of isomorphic ops, we need to extract the operands
// results and attributes of every op and store them in a vector
// Holds the operands
Expand All @@ -194,6 +220,7 @@ LogicalResult Vectorizer::vectorize() {
ImplicitLocOpBuilder builder(ops[0]->getLoc(), ops[0]);
auto vectorizeOp =
builder.create<VectorizeOp>(resultTypes, operandValueRanges);

// Now we have the operands, results and attributes, now we need to get
// the blocks.

Expand Down Expand Up @@ -229,24 +256,22 @@ LogicalResult Vectorizer::vectorize() {
return success();
}

namespace {
struct FindInitialVectorsPass
: public impl::FindInitialVectorsBase<FindInitialVectorsPass> {
void runOnOperation() override;
};
} // namespace

void FindInitialVectorsPass::runOnOperation() {
for (auto moduleOp : getOperation().getOps<hw::HWModuleOp>()) {
auto result = moduleOp.walk([&](Block *block) {
if (!mayHaveSSADominance(*block->getParent()))
if (failed(Vectorizer(block).vectorize()))
if (failed(Vectorizer(block).vectorize(stat)))
return WalkResult::interrupt();
return WalkResult::advance();
});
if (result.wasInterrupted())
return signalPassFailure();
}

numOfVectorizedOps = stat.vecOps;
numOfSavedOps = stat.savedOps;
biggestSeedVector = stat.bigSeedVec;
numOfVectorsCreated = stat.vecCreated;
}

std::unique_ptr<Pass> arc::createFindInitialVectorsPass() {
Expand Down

0 comments on commit 8e47286

Please sign in to comment.