[LLVMdev] Question about accessing coprocesser register in prologue

Tim Northover t.p.northover at gmail.com
Tue Feb 19 23:41:49 PST 2013


Hi,

> The assembly that I want to add into prologue is something like this
>
> mrc p15, 0, r0, c13, c0, 3
>
> I tried it using BuildMI() but couldn't find a register symbol which is
> matched with the cp-register on the register table(ARMGenRegisterInfo.inc).

If you look at MRC's definition in ARMInstrInfo.td, most of the
operands are just immediates rather than registers as far as LLVM is
concerned.

Also, assembling an instruction gives:
$ echo "mrc p15, 0, r0, c13, c0, 3" | llvm-mc -arch=arm -show-inst
        mrc     p15, #0, r0, c13, c0, #3 @ <MCInst #247 MRC
                                        @  <MCOperand Reg:60>
                                        @  <MCOperand Imm:15>
                                        @  <MCOperand Imm:0>
                                        @  <MCOperand Imm:13>
                                        @  <MCOperand Imm:0>
                                        @  <MCOperand Imm:3>
                                        @  <MCOperand Imm:14>
                                        @  <MCOperand Reg:0>>

The last two operands are the usual predication every ARM instruction
gets, so this confirms that your BuildMI should be:

AddDefaultPred(BuildMI(MBB, MBBI, dl, TII.get(ARM::MRC), ARM::R0)
               .addImm(15).addImm(0).addImm(13).addImm(0).addImm(3));

Remember that r0 might be in use for a function argument though!

Hope this helps.

Tim.



More information about the llvm-dev mailing list