Error when adding Clang builtin to connect to LLVM intrinsic


I’m trying to add a new builtin/intrinsic to LLVM to support a new instruction in RISC-V, similar to this post: Questions on adding a CLANG builtin to connect to a LLVM intrinsic

I’ve followed all the steps in that post, and I’m getting the following compiler error:
test.cpp:10:5: error: cannot compile this l-value expression yet
Unexpected placeholder builtin type!
UNREACHABLE executed at /home/joseph/llvm-project/clang/lib/CodeGen/CodeGenTypes.cpp:642!

The only difference in my set up compared to the original poster’s is that I defined the new instruction in a TableGen file, like this:

def riscv_foo : SDNode<“RISCVISD::foo”, SDTypeProfile<0, 0, >, [SDNPHasChain]>;

let Predicates = [IsRV64] in {
def FOO : RVInstI<0b000, OPC_SYSTEM, (outs), (ins), “foo”, “”>,
Sched<> {
let rs1 = 0;
let rd = 0;
let imm12 = 27;

def : Pat<(riscv_foo), (FOO)>;

Maybe I am doing something wrong here. Any help would be appreciated.


That error message is coming from the clang side.

You didn’t post your modifications to clang, so I’m not completely sure what you did. My best guess is that you somehow didn’t write the signature for your builtin correctly in BuiltinsRISCV.def.


Thank you for getting back to me. It turns out I had some code in


from a previous attempt at trying this that I forgot to delete. It was at CheckRISCVBuiltinFunctionCall(). Deleting that made the previous error go away, so thank you for pointing me in the right direction (looking at clang vs. llvm).

Now I’m getting the same error as the other poster: “fatal error: error in backend: Cannot select:
intrinsic”. Would I need to add a pattern to RISCVISelDAGToDAG to complete this?


As far as I can tell, you don’t currently have any code in your backend that actually understands the intrinsic. There are a few places you can handle it: you can convert it to something else in your TargetLowering::LowerOperation(), you can lower it in your ISelDAGToDAG::Select(), or you can write a pattern for it. (You should be able to refer to the intrinsic as “int_riscv_foo”.)