I am a beginner LLVM Backend Developer for RISCV. I was writing selection patterns for several bit manipulation instructions. I understood that I should use intrinsic functions instead of writing selection DAG in this post. I used intrinsic functions for both selection pattern and c code. However, I couldn’t convert the ctpop
, and ctlz
instructions to target instructions.
I also tried to look for similar questions and got help from them. Here is the most related one.
My selection patterns and c codes are below.
//pattern for cntp
def : Pat< (ctpop GPR:$src1), (cntp GPR:$src1) >;//pcnt -> cpop name changed
// I also tried this but not working. // def : Pat< (i32 (ctpop i32:$src1)), (cntp i32:$src1) >;
//pattern for cntz
def : Pat< (ctlz GPR:$src1), (cntz GPR:$src1) >;
unsigned int clz2(unsigned int rs1){
return __builtin_clz(rs1);
}
unsigned int cntp_fun(unsigned int rs1){
return __builtin_popcount(rs1);
}
I can see the intrinsic functions in ll files. However, I couldn’t see the cntz
and cntp
which are custom instructions in assembly files. I only saw many basic instructions to make the same process.
In the future, I will aim to use ctpop
and ctlz
in different selection patterns, not one-to-one as in this case.