<div dir="ltr">Hi All,<div><br></div><div>I am trying to modify the RISCV backend of LLVM compiler. I would like to reserve a few registers and used them to mask the target of jump/load instructions. The reserved registers will be set by some loader code. </div><div><p style="color:rgb(51,51,51);font-family:Verdana,Geneva,sans-serif;font-size:13.3333px">Before every load/store or branch instruction, I want to check if the address is in bounds by masking their destination with the masks that will be stored in the registers that were reserved. These registers will be initialized by an initial loader code and should never be changed afterward (hence reserved). As an example, the following instruction:</p><p style="color:rgb(51,51,51);font-family:Verdana,Geneva,sans-serif;font-size:13.3333px">jalr rd, rs, imm</p><p style="color:rgb(51,51,51);font-family:Verdana,Geneva,sans-serif;font-size:13.3333px">should be replaced by:</p><p style="color:rgb(51,51,51);font-family:Verdana,Geneva,sans-serif;font-size:13.3333px">addi t1, rs, imm<br>and t1, t1, s2              // s2 is one of the reserved registers<br>jalr rd, t1, 0                </p><p style="color:rgb(51,51,51);font-family:Verdana,Geneva,sans-serif;font-size:13.3333px">I tried looking in the tabelgen files and RISCV interfaces like RISCVISelLowering, RISCVISelDAGtoDAG, InstPrinter, etc. Can anyone suggest where should I try making changes to get the desired effect or point me to some documentation or code examples?</p><p style="color:rgb(51,51,51);font-family:Verdana,Geneva,sans-serif;font-size:13.3333px">Thanks!<br>Nikhil Bansal</p></div></div>