Is it Possible to Set a specified bit of a specified register?

Hi !!

Im writing a Backend for a ‘C’ Frontend.
I want to implement an instruction that can set a specified bit of a Specified Register.

ex:

Mov R1, 9 ; // 9 is the bit i want to change

Set R2,R1,1 ; // modify R2’s 9th bit to 1

Above example shows the expected output

I have following Questions:

  1. how to tell compiler to use a specific register (R2 in this case) for a given instruction? i cant set it as reserved since i need it to be used in other instructions too. I cant use a “PreRegisterAllocationPass” since the register would be allocated and will become reusable later

  2. How to access the specified bit of a register ( R2’s 9th bit in this case)

  3. How do i write a ‘C’ Program for this instruction? i tried using the bitfields in a structure, but it was getting casted in the IR. So,I couldnt access using the structure.

Please Tell me some ways to solve above challenges

Thanks,

Avinash

What are you actually trying to achieve? Why do you care which
register (if any) some bit resided in?

In a backend, you should either define restrictions as to what
register a particular instruction operates on (`set can only take R1
as input and R2 as output'), or allow "any" register to be used.

To make the compiler generate that particular instruction, you may
need to make it an llvm intrinsic, so the generic backend leaves it
alone.