21#define GEN_PASS_DEF_TOSATOSPIRVTOSAMARKGRAPHCONSTANTS
22#include "mlir/Conversion/Passes.h.inc"
27constexpr uint32_t maxInlineConstElements = 16;
28constexpr uint32_t maxInlineConstShapeElements = 32;
30std::optional<ElementsAttr> getConstantValues(Operation *op) {
31 if (
auto constOp = dyn_cast<tosa::ConstOp>(op))
32 return constOp.getValuesAttr();
33 if (
auto constShapeOp = dyn_cast<tosa::ConstShapeOp>(op))
34 return constShapeOp.getValuesAttr();
38bool shouldMarkGraphConstant(Operation *op) {
42 std::optional<ElementsAttr> values = getConstantValues(op);
46 uint32_t maxInlineElements = isa<tosa::ConstOp>(op)
47 ? maxInlineConstElements
48 : maxInlineConstShapeElements;
49 return values->size() > maxInlineElements;
52void setGraphConstantId(Operation *op, uint32_t
id) {
53 auto i32Type = IntegerType::get(op->getContext(), 32);
57struct TosaToSPIRVTosaMarkGraphConstants final
58 : impl::TosaToSPIRVTosaMarkGraphConstantsBase<
59 TosaToSPIRVTosaMarkGraphConstants> {
60 void runOnOperation()
override {
61 uint32_t nextConstantId = 0;
63 getOperation().walk([&](Operation *op) {
64 if (!isa<tosa::ConstOp, tosa::ConstShapeOp>(op))
70 <<
"`; this pass assigns graph constant IDs automatically and "
71 "does not support pre-marked constants";
75 if (shouldMarkGraphConstant(op))
76 setGraphConstantId(op, nextConstantId++);
80 if (
result.wasInterrupted())
88 return std::make_unique<TosaToSPIRVTosaMarkGraphConstants>();
static WalkResult advance()
static WalkResult interrupt()
std::unique_ptr< Pass > createTosaToSPIRVTosaMarkGraphConstants()
constexpr llvm::StringLiteral graphARMGraphConstantIdAttrName
Include the generated interface declarations.