LLVM Backend syntax error has not shown before compilation

I am currently coding on llvm/lib//target/RISCV/RISCVInstrInfo.td. For example, I am adding a new instruction and pattern for that instruction. Then, I build LLC by using these command cmake -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=RISCV -G Ninja ../llvm ninja llc. If a problem exists it shows during this process and I delete all the content of the folder to build LLC again. However, the errors (even if it is a syntax error) has shown almost at the end of the process.
I download LLVM tablegen extension for VSCode but it does not work very well.(It doesn’t show even any syntax error.)
Do you have any suggestions to get warning the errors earlier to save my time?

You should not need to delete the contents of the build folder. After you modify your source to fix the problem, just run ninja llc again and it should automatically rebuild only the necessary pieces.

2 Likes

As far as I know, we currently don’t have any static analyzer for TableGen. So you will not see any syntax error in the editor.

But you can try this to check your syntax, without rebuilding the whole project or even llc

${BUILD_DIR}/bin/llvm-tblgen -I ${SOURCE_DIR}/llvm/include/ RISCV.td

Before you run this, you need to build llvm-tblgen. Just run ninja llvm-tblgen in your build directory.

You can get more detail here: TableGen Overview

1 Like

Thank you so much. I applied and it worked.

Should I follow always these two steps orderly?

ninja llvm-tblgen
${BUILD_DIR}/bin/llvm-tblgen -I ${SOURCE_DIR}/llvm/include/ RISCV.td

or every times I will run ${BUILD_DIR}/bin/llvm-tblgen -I ${SOURCE_DIR}/llvm/include/ RISCV.td after run 1st times ninja llvm-tblgen.

It does no harm to run ninja llvm-tblgen each time, but if you have changed only RISCV.td then it is not necessary (ninja will report something like “nothing to do”).

1 Like

Is the build directory the directory that I build the LLVM or the directory that I build Backend? Because I get an error like that:

llvm@tutel:~/llvm-project/build$ ninja llvm-tblgen
ninja: no work to do.

I have a build folder in llvm-project folder. This includes LLVM and clang. I have another folder in llvm-project. It is RISCV_Backend which I build Backend.

Note: I have already llvm-tblgen file in the folder /llvm-project/build/bin. This comes I think because of the building of LLVM and clang.

That is your build directory.

That means you have already build it. It’s not an error by the way. It just tells you “No need to build it”

1 Like

Oh, my mistake. I thought of an error. I am sorry.
Thank you so much.

1 Like