0

I'm new to LLVM Backend development and I'm discovering some of its working by modifying an existing backend, compiling the llvm-project and observing the changes brought to the binaries and their effect on source code compilation. I wanted to know how can I swap the ADD and SUB instructions in the RISCV assemblies so that when I compile a C code that does the sum of numbers, the binary actually does the difference of those two numbers. I learned that this can't be done by simply swapping the ADD and SUB definitions in RISCVInstrInfo.td but rather should be done at the time llvm generates assembly from the IR.

(I found it very challenging to read the documentation of the CodeGenerator and SelectionDAG - which I will eventually do in order to learn more on how the backends work)

3
  • I guess you want a hint and a rewarding journey, right? You'll probably find it simplest and/or most educational to try to identify the IR add/sub instructions before the backend produces assembly from IR. Commented May 3, 2024 at 14:56
  • @arnt Yes! But i want to know at which point exactly llvm maps the add IR instruction to the assembly instruction (SelectionDAG? MachineDAG? MachineInstr? MCInst?) and how does it achieve it. But anyways my question was just for me to start discovering this part of machine code generation, I guess I m going to read the documentation right away. Commented May 3, 2024 at 15:54
  • Compile the debug version of the library and set a breakpoint in the constructor of the class that implements that machine instructions. Commented May 4, 2024 at 12:12

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.