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, >::operator(llvm::SmallVectorTemplateCommon<T, >::size_type) const [with T = llvm::MCOperand; = void; llvm::SmallVectorTemplateCommon<T, >::const_reference = const llvm::MCOperand&; llvm::SmallVectorTemplateCommon<T, >::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