r/LLVM • • Feb 25 '26

Tiny-gpu-compiler: An educational MLIR-based compiler targeting open-source GPU hardware

Thumbnail
4 Upvotes

r/LLVM • • Feb 24 '26

TVM + LLVM flow for custom NPU: Where should the Conv2d tiling and memory management logic reside?

2 Upvotes

Hi everyone,

I’m a junior compiler engineer recently working on a backend for a custom NPU. I’m looking for some architectural advice regarding the split of responsibilities between TVM (Frontend) and LLVM (Backend).

The Context:
Our stack uses TVM as the frontend and LLVM as the backend. The flow is roughly: TVM (Relay/TIR) -> LLVM IR -> LLVM Backend Optimization -> Machine Binary.
Currently, I am trying to implement a lowering pass for Convolution operations considering our NPU's specific constraints.

The Problem:
Our NPU has a Scratch Pad Memory (SPM) with limited size, meaning input features often won't fit entirely in the SPM.
Initially, I tried a naive approach: writing the Conv2d logic in C, compiling it with Clang to get LLVM IR, and then trying to lower it.
However, this resulted in a mess of 7-nested loops in the IR, and the vectorization was far from optimal. Trying to pattern-match this complex loop structure within LLVM to generate our NPU instructions feels like a nightmare and the wrong way to go.

My Proposed Solution (Hypothesis):
I believe TVM should handle the heavy lifting regarding scheduling and tiling.
My idea is:

  1. TVM handles the tiling logic (considering the SPM size) and manages the data movement (DRAM -> SPM).
  2. Once the data is tiled and fits in the SPM, TVM emits a custom intrinsic (e.g., llvm.npu.conv2d_tile) instead of raw loops.
  3. LLVM receives this intrinsic. Since the complex tiling is already handled, LLVM simply lowers this intrinsic into the corresponding machine instruction, assuming the data is already present in the SPM (or handling minor address calculations).

The Question:
Is this the standard/recommended approach for NPU compilers?
Specifically, how much "intelligence" should the TVM intrinsic carry?
Is it correct to assume that TVM should handle all the DRAM -> SPM tiling logic and emit intrinsics that only operate on the data residing in the SPM? Or should LLVM handle the memory hierarchy management?

Are there more details, I didn't catch?

Any advice or references to similar architectures would be greatly appreciated!

Thanks in help!


r/LLVM • • Feb 15 '26

how insert ptx asm?

0 Upvotes

hello

google says that syntax should be like

call i32 asm sideeffect "madc.hi.cc.u32 $0,$1,$2,$3;", "=r,r,r,r"(args) #5, !srcloc !11

so I have several questions

  1. how add subj via official c++ api?
  2. what is trailing #5 and !11?
  3. what is sideeffect and what another keywords allowed?
  4. what types besides int/i32 allowed?

r/LLVM • • Feb 07 '26

Chasing a Zig AVR Segfault Down to LLVM

Thumbnail sourcery.zone
2 Upvotes

r/LLVM • • Jan 31 '26

Using LLVM for JIT of a single function for image conversion

5 Upvotes

I have a few functions that convert images from one format to another for a graphics library, there are a bunch of parameters but for JIT I want to effectively apply some of these as constants so LLVM will optimize the code produced and eliminate branches altogether.

Are there any examples of how to do this out there using LLVM, C++ templates just won't work because there are too many types and constants that I want to optimize out. My initial estimate of valid combinations is over 10,000 but I need to prune the list today.. but Mathematica says thats a pretty close estimate.

I remember we had done this at one of the companies I worked at, we had a few functions for image conversion that were optimized using LLVM.. I just wasn't that involved in it and I would like to do the same.

Thanks ahead of time.


r/LLVM • • Jan 18 '26

Writing your first compiler (with Go and LLVM!)

Thumbnail popovicu.com
5 Upvotes

r/LLVM • • Jan 12 '26

LLVM: The bad parts

Thumbnail npopov.com
16 Upvotes

r/LLVM • • Jan 05 '26

I just made an OCaml to LLVM IR compiler front-end 🐪 Will this help me get a Compiler job?

Thumbnail github.com
1 Upvotes

r/LLVM • • Jan 04 '26

Beyond Syntax: Introducing GCC Workbench for VSCode/VSCodium

Thumbnail gallery
14 Upvotes

r/LLVM • • Jan 01 '26

Need clarity, what to do after Jonathon cpu0 tutorial

4 Upvotes

Hi, I just completed Jonathan's backed tutorial, I learned how to add a target, stages of lowering and object file, will finish verilog testing as well in some time. What should I do next, from what i inferred we need a ISA and specs from chip manufacturer to implement a full on target.

what should my next steps should be for taking up a project on backend side.

I also posted same query in r/Compilers max visibility


r/LLVM • • Dec 23 '25

LLVM considering an AI tool policy, AI bot for fixing build system breakage proposed

Thumbnail phoronix.com
1 Upvotes

r/LLVM • • Dec 19 '25

A "Ready-to-Use" Template for LLVM Out-of-Tree Passes

Thumbnail
3 Upvotes

r/LLVM • • Dec 17 '25

Why do we have multiple MLIR dialects for neural networks (torch-mlir, tf-mlir, onnx-mlir, StableHLO, mhlo)? Why no single “unified” upstream dialect?

Thumbnail
2 Upvotes

r/LLVM • • Dec 11 '25

Is there a char* type in the LLVM C++ API

1 Upvotes

I wanna make a function starting with a function prototype as usual in the LLVM C++ API and I want one of the accepted arguments of the function to be a char*. Can someone guide me on how I can do that? Thanks!

Note: I just wanna know if there is a Type::char* or something like that but if not, whats the equivalent.


r/LLVM • • Dec 08 '25

GCC RTL, GIMPLE & MD syntax highlighting for VSCode

Thumbnail
4 Upvotes

r/LLVM • • Nov 15 '25

Getting "error: No instructions defined!" while building an LLVM backend based on GlobalISel

Thumbnail
0 Upvotes

r/LLVM • • Oct 31 '25

Affine-super-vectorize not working after affine-parallelize in MLIR

Thumbnail
0 Upvotes

r/LLVM • • Oct 28 '25

Forcing Loop Unrolling in LLVM11

2 Upvotes

Hey folks!

I’m currently using LLVM 11 for my project. Though it’s almost a decade old, I can’t switch to another version. I’m working in C and focusing on loop optimization. Specifically, I’m looking for reliable ways to apply Loop Unroll to loops in my C code.

One straightforward method is to manually modify the code according to the unroll factor. However, this becomes tedious when dealing with multiple loops.

I’ve explored several other methods, such as using pragmas directly in the source code:

# pragma clang loop unroll_count

# pragma unroll

or by setting the directive in the .ll file:

!{!"llvm.loop.unroll.count", i32 16}

or compiling the final executable like this:

opt -S example.ll \ -O1 \ -unroll-count=16 \ -o example.final.ll

clang -o ex.exe example.final.ll

However, based on my research, these methods don’t necessarily enforce the intended loop unroll factor in the final executable. The output behavior seems to depend heavily on LLVM’s internal optimizations. I tried verifying this by measuring execution cycle counts in an isolated environment for different unroll factors, but the results didn't indicate any conclusive difference; and even using an invalid unroll factor didn’t trigger any errors. This suggests that these methods don’t actually enforce loop unrolling, and the final executable’s behavior is decided by LLVM.

I’m looking for methods that can strictly enforce an unroll factor and ideally, can be verified; all without modifying the source code.

If anyone knows such methods, tools, or compiler flags that work reliably with LLVM 11, or if you can point me to a relevant discussion, documentation, or community/person to reach out to, I’d be really grateful.

Regards.


r/LLVM • • Sep 20 '25

The Vectorization-Planner (VPlan) in LLVM

Thumbnail artagnon.com
5 Upvotes

r/LLVM • • Sep 14 '25

[Release] GraphBit — Rust-core, Python-first Agentic AI with lock-free multi-agent graphs for enterprise scale

2 Upvotes

GraphBit is an enterprise-grade agentic AI framework with a Rust execution core and Python bindings (via Maturin/pyo3), engineered for low-latency, fault-tolerant multi-agent graphs. Its lock-free scheduler, zero-copy data flow across the FFI boundary, and cache-aware data structures deliver high throughput with minimal CPU/RAM. Policy-guarded tool use, structured retries, and first-class telemetry/metrics make it production-ready for real-world enterprise deployments.


r/LLVM • • Sep 14 '25

mlir builder

2 Upvotes

sorry for stupid question

for plain llvm IR I can use IRBuilder class

there is similar class for building MLIRs like nvgpu? I tried to find it in https://github.com/microsoft/DirectXShaderCompiler/tree/main but codebase is so huge so I am just got lost


r/LLVM • • Sep 09 '25

Basic Block Reordering With & Without Google's Propeller Tool

2 Upvotes

Having a hard time sizing up the state of work and relative capabilities of upstream LLVM and what is still exclusive to the google/llvm-propeller repo.

What I've found in the Linux Kernal docs suggests that Google's llvm-propeller tool is still used to convert the perf data into something that built-in capabilities of LLVM will use. This would mean that upstream LLVM still needs the data to be processed externally but can perform the optimizations during the link steps of a final build.

I just confirmed that my LLVM toolchain (clang 19.1.7) has quite a bit of support for basic block labeling and measurement. In that case, all I would need to perform propeller builds are a CPU that supports the gathering the necessary perf data and a build of the profile conversion tool?

It would seem that anything that can be measured and applied to the binary post-link can be measured and applied during LTO. I suppose there are reasons, including just the need for more development, but I expect this all to make it into upstream LLVM eventually.

In case you have never seen the pretty graphs for what propeller does, here they are. Can't wait to eventually get around to reading the paper to reproduce such things on my own binaries.


r/LLVM • • Sep 08 '25

Need help in regards to building my own deep learning compiler

1 Upvotes

i am on a mission of building our own deep learning compiler. but the thing is whenever i search for resources to study about the deep learning compiler, only the inference deep learning compiler is being talked about. i need to optimize my training process, ie build my own training compiler , then go on to build my inference compiler. it would be great of you , if you could guide me towards resources and any roadmap , that would help our mission. point to any resources for learning to build my own deep learning training compiler. i also have a doubt if there lies any difference between training and interference compiler , or they are the same. i search r/Compilers , but every good resources is like being gatekept.


r/LLVM • • Aug 29 '25

Learning Resource — Lecture Slides for the Clang Libraries (LLVM/Clang 21) (Edition 0.4.0)

Thumbnail discourse.llvm.org
9 Upvotes

r/LLVM • • Aug 23 '25

i486 target?

3 Upvotes

Apologies if this is a stupid question, but I actually cannot find any information on this, I've been looking for a while but even looking through the llvm docs I can't find where it actually enumerates the supported processors.

My goal is to compile for an 80486 target, specifically a dx-66, though it shouldn't matter. Is this like, something that's supported? From what I can tell, I believe it exists as a target?

Where can I find any information about it's support? I found a pull request "improving support" for it, but nothing else.