[llvm-dev] ARM Backend BuildMI operand issues

Julius Hiller via llvm-dev llvm-dev at lists.llvm.org
Thu Mar 22 09:29:56 PDT 2018


Hello everyone,

I'm working on a MachineFunctionPass that inserts a list of instructions 
into an Module so a later Pass can work on them.
To do so I load a dummy .ll file created from a main stub, create the 
needed function stubs (ModulePass), insert Blocks and create 
instructions using BuildMI.
I started with branch instructions:

         const TargetMachine &TM = MF.getTarget();
         const MCInstrInfo *TII = TM.getMCInstrInfo();
         DebugLoc DL;
         BuildMI(BB, BB.end(), DL, TII->get(ARM::B)).addMBB(trgBlock);

these are working fine.
When creating an compare instruction like cmp r0, 1 with:

          BuildMI(BB, BB.end(), DL, TII->get(ARM::tCMPi8),0).addImm(1);

I get the following error:

         .../include/llvm/MC/MCInst.h:81: int64_t
    llvm::MCOperand::getImm() const: Assertion `isImm() && "This is not
    an immediate"' failed.

Which even after hours I can't make sense why the operand kind is wrong.

Another thing I noticed is that using ARM::tB results in the following 
error:

    .../include/llvm/ADT/SmallVector.h:154: const T&
    llvm::SmallVectorTemplateCommon<T, <template-parameter-1-2>
     >::operator[](llvm::SmallVectorTemplateCommon<T,
    <template-parameter-1-2> >::size_type) const [with T =
    llvm::MCOperand; <template-parameter-1-2> = void;
    llvm::SmallVectorTemplateCommon<T, <template-parameter-1-2>
     >::const_reference = const llvm::MCOperand&;
    llvm::SmallVectorTemplateCommon<T, <template-parameter-1-2>
     >::size_type = long unsigned int]: Assertion `idx < size()' failed.

The architecture is ARMv6-m, I am using llvm 7, the dummy.ll was created 
with llvm 3.9
Hope to find some help here, best regards

Julius Hiller
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180322/1841c203/attachment-0001.html>


More information about the llvm-dev mailing list