How to use bugpoint for backend native code generation?

Hello,

I’m writing machine function passes for programs running with ARMv7-M ISA. My pass adds some instructions to the original code, and now I got

fatal error: error in backend: out of range pc-relative fixup value

when llvm generates native code after running the transformation pass. I think it’s because my transformation pass increases the size of the original code and thus some branch instructions cannot reach their destination (for example, the beq instruction can only jump to a pc-relative destination within range -256 to 254 bytes).

It looks like bugpoint is a good tool to pinpoint which branch instruction caused the error. Unfortunately the blogs I found online are all about using bugpoint for IR passes but not for native code generation. Can anyone give me some help on this issue? (pointing to a good tutorial, or sharing some techniques to pinpoint the troublesome instructions, etc.)

Thanks very much.

  • Jie

Currently bugpoint doesn’t support backend passes. We didn’t have any support for serializing MachineFunctions until relatively recently, and that support still isn’t really complete. Depending on the nature of your issue, opt-bisect-limit might be helpful; see http://llvm.org/docs/OptBisect.html .

That said, there’s probably a more straightforward way to track down your particular issue: you should be able to get a readable error message by just emitting assembly, then feeding the output to clang. And my first guess for the cause of the problem is that your pass is running after ARMConstantIslands, which is almost never what you want.

-Eli

Currently bugpoint doesn’t support backend passes. We didn’t have any support for serializing MachineFunctions until relatively recently, and that support still isn’t really complete. Depending on the nature of your issue, opt-bisect-limit might be helpful; see http://llvm.org/docs/OptBisect.html<https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_docs_OptBisect.html&d=DwMGaQ&c=kbmfwr1Yojg42sGEpaQh5ofMHBeTl9EI2eaqQZhHbOU&r=KAtyTEI8n3FritxDpKpR7rv3VjdmUs0luiVKZLb_bNI&m=N8T9xou8gKEMYjs_z4t_ajAvxVNR0Gi7DSTGkmK3UMU&s=i7-oSWHTWDhAbbHVN9ADDhdRRvguklobURQzSWuFVWM&e=> .

That said, there’s probably a more straightforward way to track down your particular issue: you should be able to get a readable error message by just emitting assembly, then feeding the output to clang. And my first guess for the cause of the problem is that your pass is running after ARMConstantIslands, which is almost never what you want.

Hi Eli,

Can you be more specific on “emitting assembly”? I know how to generate asm code from source code, but is there a way to generate native asm code after running machine function passes?

- Jie

-Eli

Comments inline.

Currently bugpoint doesn’t support backend passes. We didn’t have any support for serializing MachineFunctions until relatively recently, and that support still isn’t really complete. Depending on the nature of your issue, opt-bisect-limit might be helpful; see http://llvm.org/docs/OptBisect.html<https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_docs_OptBisect.html&d=DwMGaQ&c=kbmfwr1Yojg42sGEpaQh5ofMHBeTl9EI2eaqQZhHbOU&r=KAtyTEI8n3FritxDpKpR7rv3VjdmUs0luiVKZLb_bNI&m=N8T9xou8gKEMYjs_z4t_ajAvxVNR0Gi7DSTGkmK3UMU&s=i7-oSWHTWDhAbbHVN9ADDhdRRvguklobURQzSWuFVWM&e=> .

That said, there’s probably a more straightforward way to track down your particular issue: you should be able to get a readable error message by just emitting assembly, then feeding the output to clang. And my first guess for the cause of the problem is that your pass is running after ARMConstantIslands, which is almost never what you want.

Hi Eli,

Just an FYI, I tried to run my pass before ARMConstantIslandPass rather than after it, and it solved my problem, although I’m not very clear of why it works.

Thanks,
- Jie

-Eli