How to use llvm-tblgen?

I am trying to compile the llvm/lib/Target/RISCV/ file using llvm-tblgen to view the generated records. I run the following command:

llvm-tblgen -I /media/user/Volume/llvm-project/llvm/include/ -o dump

But I get this error: error: Couldn't find class 'SDCallSeqStart'
def SDT_CallSeqStart : SDCallSeqStart<[SDTCisVT<0, i32>,

I get errors with every .td file in the LLVM source tree I try to compile with llvm-tblgen.

Each .td file is compiled much like a C++ file is in that it needs certain includes, or may be itself included in files.

In this case you have the file which is never actually compiled on its own, but included in In, llvm/include/llvm/Target/ is included, which itself includes llvm/include/llvm/Target/

Sound confusing? It is.

There is no option to force an include if the file doesn’t have it, so if you want just this one file’s output without compiling, I would just edit in include include "llvm/Target/" and compile it like that (the -I you have already should be enough to make that work).

In summary: You managed to pick a file that is never directly compiled, only ever included. It’s a bit of an anti pattern that doesn’t play well with IDEs and language servers either so I want to address it in future.

1 Like