AgentStack
Browse Sign in
Browse Why AgentStack Sell Docs
Sign in
SKILL verified MIT Self-run

Mlir

skill-mohitmishra786-low-level-dev-skills-mlir · by mohitmishra786

MLIR skill for multi-level intermediate representation. Use when writing custom dialects, defining ops with ODS, writing lowering passes, running mlir-opt, or building ML compilers with Torch-MLIR/IREE. Activates on queries about MLIR, dialect, ODS, mlir-opt, linalg, lowering pass, or Torch-MLIR.

No reviews yet
0 installs
23 views
0.0% view→install

Install

$ agentstack add skill-mohitmishra786-low-level-dev-skills-mlir

✓ scanned · ✓ verified, works with Claude Code, Cursor, and more.

Security review

✓ Passed

No issues found. Passed automated security review. · v0.1.0 How review works →

  • Prompt-injection patterns
  • Secret / credential exfiltration
  • Dangerous shell & filesystem operations
  • Untrusted network calls
  • Known-malicious package signatures

What it can access

  • Network access No
  • Filesystem access No
  • Shell / process execution No
  • Environment & secrets No
  • Dynamic code execution No

From automated source analysis of v0.1.0. “Used” means the capability is present in the source — more access means more to trust, not that it’s unsafe.

View the full security report →

Verified badge

Passed review? Show it. Paste this badge into your README, it links to the public security report.

AgentStack Verified badge Links to your public security report.
[![AgentStack Verified](https://agentstack.voostack.com/badges/verified.svg)](https://agentstack.voostack.com/security/report/skill-mohitmishra786-low-level-dev-skills-mlir)

Reliability & compatibility

Security review passed
0 installs to date
no reviews yet
2mo ago

Declared compatibility

Claude CodeClaude Desktop

Compatibility is declared by the source manifest. End-to-end runtime verification is coming, see below.

Preview Execution monitoring

We're building live execution health for every listing: tool-call success rate, median latency, uptime, and last-checked timestamps, measured, not self-reported. It isn't live yet, so we don't show numbers we can't stand behind.

How agent discovery & health will work →
Are you the author of Mlir? Claim this listing to set pricing, connect Stripe payouts, and keep 70% of every sale.
Sign up to claim

About

MLIR

Purpose

Guide agents through MLIR (Multi-Level IR): ops, regions, blocks, and values; built-in dialects (arith, func, memref, affine, linalg); writing custom dialects with ODS; lowering passes with ConversionPattern; mlir-opt CLI; and ML compiler use cases (Torch-MLIR, IREE).

When to Use

  • Building a domain-specific compiler IR (graphics, ML, hardware DSL)
  • Lowering high-level ops to LLVM or GPU dialects
  • Writing progressive lowering pipelines (linalg → loops → LLVM)
  • Integrating with IREE or Torch-MLIR for ML deployment
  • Creating reusable transformation passes across dialects
  • Prototyping compiler optimizations at the right abstraction level

Workflow

1. MLIR structure

Module
└── func.func @main()
    └── region
        └── block ^bb0:
            └── operations (ops) producing SSA values

Key concepts:

  • Operation — instruction-like node (arith.addi, memref.load)
  • Region — container of blocks (functions, control flow)
  • Block — CFG node with ordered ops
  • Value — SSA result of an op or block argument

2. Built-in dialects

| Dialect | Purpose | |---------|---------| | arith | Integer/float arithmetic | | func | Function definitions and calls | | memref | Buffer abstraction with shapes/strides | | affine | Affine loop nests, map/set constraints | | linalg | Structured linear algebra ops | | scf | Structured control flow (for, if) | | llvm | LLVM IR dialect for final lowering | | gpu | GPU kernel launches |

// example.mlir
func.func @add(%a: memref, %b: memref, %c: memref) {
  %c0 = arith.constant 0 : index
  %c4 = arith.constant 4 : index
  scf.for %i = %c0 to %c4 step %c1 {
    %av = memref.load %a[%i] : memref
    %bv = memref.load %b[%i] : memref
    %sum = arith.addf %av, %bv : f32
    memref.store %sum, %c[%i] : memref
  }
  return
}

3. mlir-opt CLI

# Parse and print
mlir-opt example.mlir

# Run canonicalization
mlir-opt example.mlir -canonicalize

# Lower affine to scf
mlir-opt affine.mlir -lower-affine

# Full pipeline toward LLVM
mlir-opt input.mlir \
  --linalg-bufferize \
  --convert-linalg-to-loops \
  --convert-scf-to-cf \
  --convert-arith-to-llvm \
  --convert-memref-to-llvm \
  --convert-func-to-llvm \
  -o llvm.mlir

4. ODS — Operation Definition Specification

// MyOps.td
include "mlir/IR/OpBase.td"

def My_Dialect : Dialect {
    let name = "my";
    let summary = "My custom dialect";
}

class My_Op traits = []> :
    Op;

def AddOp : My_Op {
    let summary = "Add two values";
    let arguments = (ins AnyType:$lhs, AnyType:$rhs);
    let results = (outs AnyType:$result);
    let assemblyFormat = "$lhs `,` $rhs attr-dict `:` type($result)";
}
# Generate C++ from TableGen
mlir-tblgen -gen-op-defs MyOps.td -I include/ -o MyOps.cpp.inc

5. Custom dialect C++ implementation

#include "mlir/IR/DialectImplementation.h"
#include "MyDialect.h"

#include "MyOps.cpp.inc"

void MyDialect::initialize() {
    addOperations();
}

#define GET_OP_CLASSES
#include "MyOps.cpp.inc"

6. Lowering passes

#include "mlir/Conversion/LLVMCommon/ConversionTarget.h"
#include "mlir/Transforms/DialectConversion.h"

struct AddOpLowering : OpConversionPattern {
    using OpConversionPattern::OpConversionPattern;

    LogicalResult matchAndRewrite(my::AddOp op, OpAdaptor adaptor,
                                  ConversionPatternRewriter &rewriter) const override {
        rewriter.replaceOpWithNewOp(op, adaptor.getLhs(), adaptor.getRhs());
        return success();
    }
};

void populateLoweringPatterns(RewritePatternSet &patterns) {
    patterns.add(patterns.getContext());
}

// In pass:
mlir::ConversionTarget target(*context);
target.addIllegalDialect();
target.addLegalDialect();

if (failed(applyPartialConversion(module, target, std::move(patterns))))
    signalPassFailure();

7. linalg for ML compilers

%0 = linalg.matmul ins(%A, %B : tensor, tensor)
                   outs(%C : tensor) -> tensor

Lowering path: linalgscf loops → affinellvm

8. Torch-MLIR and IREE

# Torch-MLIR: PyTorch → MLIR
python -m torch_mlir.tools.import-onnx --onnx-model model.onnx -o model.mlir

# IREE: MLIR → GPU/CPU executable
iree-compile --iree-hal-target-backends=llvm-cpu model.mlir -o model.vmfb
iree-run-module --module=model.vmfb --function=main

Common Problems

| Symptom | Cause | Fix | |---------|-------|-----| | Dialect not registered | Missing registerDialect | Register in tool/pass init | | ODS build failure | TableGen include path | Check -I for mlir/IR/OpBase.td | | Lowering incomplete | Illegal ops remain | Debug with --mlir-print-ir-after-failure | | Type mismatch in pattern | Wrong adaptor types | Use OpAdaptor typed accessors | | mlir-opt crash | Invalid IR | Run -verify-each | | Empty function after lowering | All ops illegal, none converted | Add missing patterns |

Related Skills

  • skills/compiler-internals/llvm-passes — LLVM pass equivalents
  • skills/compiler-internals/compiler-frontend — AST to MLIR import
  • skills/compiler-internals/jit-compilation — JIT compiled MLIR→LLVM
  • skills/compilers/llvm — LLVM IR output target
  • skills/gpu/cuda — GPU dialect lowering targets
  • skills/gpu/triton-lang — alternative GPU kernel IR

Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

Install and usage instructions live in the source repository linked above.

Reviews

No reviews yet, be the first.

Versions

  • v0.1.0 Imported from the upstream source.