Files
triton/test/lib/Analysis/TestAxisInfo.cpp

70 lines
1.8 KiB
C++
Raw Permalink Normal View History

#include "mlir/Pass/Pass.h"
2022-07-26 17:25:03 -07:00
#include "triton/Analysis/AxisInfo.h"
using namespace mlir;
2022-07-26 17:25:03 -07:00
namespace {
struct TestAxisInfoPass
2022-07-26 17:25:03 -07:00
: public PassWrapper<TestAxisInfoPass, OperationPass<FuncOp>> {
// LLVM15+
// MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestAlignmentPass);
2022-07-26 17:25:03 -07:00
void print(const std::string &name, raw_ostream &os, ArrayRef<int> vals) {
os << name << ": [";
2022-07-26 17:25:03 -07:00
for (size_t d = 0; d < vals.size(); d++) {
if (d != 0)
os << ", ";
os << vals[d];
}
os << "]";
}
StringRef getArgument() const final { return "test-print-alignment"; }
2022-07-26 17:25:03 -07:00
StringRef getDescription() const final {
return "print the result of the alignment analysis pass";
}
void runOnOperation() override {
2022-07-26 17:25:03 -07:00
Operation *operation = getOperation();
auto &os = llvm::errs();
os << "Testing: " << operation->getName() << "\n";
AxisInfoAnalysis analysis(&getContext());
analysis.run(operation);
2022-07-26 17:25:03 -07:00
operation->walk([&](Operation *op) {
if (op->getNumResults() < 1)
return;
2022-07-26 17:25:03 -07:00
for (Value result : op->getResults()) {
// std::ostringstream oss;
// result.print(oss);
// os << " => ";
2022-07-26 17:25:03 -07:00
LatticeElement<AxisInfo> *latticeElement =
analysis.lookupLatticeElement(result);
if (!latticeElement) {
os << "None\n";
return;
}
2022-07-26 17:25:03 -07:00
AxisInfo &info = latticeElement->getValue();
print("Contiguity", os, info.getContiguity());
os << " ; ";
print("Divisibility", os, info.getDivisibility());
os << " ; ";
print("Constancy", os, info.getConstancy());
os << " ( ";
result.print(os);
2022-07-26 17:25:03 -07:00
os << " ) ";
os << "\n";
}
});
}
};
2022-07-26 17:25:03 -07:00
} // namespace
2022-07-26 17:25:03 -07:00
namespace mlir {
namespace test {
void registerTestAlignmentPass() { PassRegistration<TestAxisInfoPass>(); }
2022-07-26 17:25:03 -07:00
} // namespace test
} // namespace mlir