<div dir="ltr">Hello everyone, I'm a newbie of llvm. I'm trying to insert Intel MPX instruction BNDCU with BuildMI. I add my machinefunctionpass at addPreEmitPass2.<div>Here is the code of insertion: </div><div><br><div>BuildMI(MBB, MI, DL, TII->get(X86::BNDCU64rr)).addReg(X86::BND2, RegState::Define).addReg(X86::R10);<br></div></div><div><br></div><div>And here is to stack track  when I compiler program with modified llc:</div><div><div>/home/shenyouren/workspace/build-llvm/bin/llc -o obj/simple.s obj/simple-opt.bc</div><div>llc: /home/shenyouren/workspace/llvm/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.</div><div>Stack dump:</div><div>0.      Program arguments: /home/shenyouren/workspace/build-llvm/bin/llc -o obj/simple.s obj/simple-opt.bc</div><div>1.      Running pass 'Function Pass Manager' on module 'obj/simple-opt.bc'.</div><div>2.      Running pass 'X86 Assembly Printer' on function '@main'</div><div>#0 0x0000000003879bdf llvm::sys::PrintStackTrace(llvm::raw_ostream&) /home/shenyouren/workspace/llvm/lib/Support/Unix/Signals.inc:398:0</div><div>#1 0x0000000003879c72 PrintStackTraceSignalHandler(void*) /home/shenyouren/workspace/llvm/lib/Support/Unix/Signals.inc:462:0</div><div>#2 0x0000000003877e5b llvm::sys::RunSignalHandlers() /home/shenyouren/workspace/llvm/lib/Support/Signals.cpp:49:0</div><div>#3 0x0000000003879454 SignalHandler(int) /home/shenyouren/workspace/llvm/lib/Support/Unix/Signals.inc:252:0</div><div>#4 0x00007fcc8f4c9390 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x11390)</div><div>#5 0x00007fcc8e67e428 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x35428)</div><div>#6 0x00007fcc8e68002a abort (/lib/x86_64-linux-gnu/libc.so.6+0x3702a)</div><div>#7 0x00007fcc8e676bd7 (/lib/x86_64-linux-gnu/libc.so.6+0x2dbd7)</div><div>#8 0x00007fcc8e676c82 (/lib/x86_64-linux-gnu/libc.so.6+0x2dc82)</div><div>#9 0x00000000016b63bb llvm::SmallVectorTemplateCommon<llvm::MCOperand, void>::operator[](unsigned long) const /home/shenyouren/workspace/llvm/include/llvm/ADT/SmallVector.h:154:0</div><div>#10 0x00000000016b63bb llvm::MCInst::getOperand(unsigned int) const /home/shenyouren/workspace/llvm/include/llvm/MC/MCInst.h:182:0</div><div>#11 0x00000000026695fd llvm::X86ATTInstPrinter::printOperand(llvm::MCInst const*, unsigned int, llvm::raw_ostream&) /home/shenyouren/workspace/llvm/lib/Target/X86/InstPrinter/X86ATTInstPrinter.cpp:185:0</div><div>#12 0x0000000002664c06 llvm::X86ATTInstPrinter::printInstruction(llvm::MCInst const*, llvm::raw_ostream&) /home/shenyouren/workspace/build-llvm/lib/Target/X86/X86GenAsmWriter.inc:48204:0</div><div>#13 0x0000000002668edc llvm::X86ATTInstPrinter::printInst(llvm::MCInst const*, llvm::raw_ostream&, llvm::StringRef, llvm::MCSubtargetInfo const&) /home/shenyouren/workspace/llvm/lib/Target/X86/InstPrinter/X86ATTInstPrinter.cpp:89:0</div><div>#14 0x00000000031d5811 llvm::MCTargetStreamer::prettyPrintAsm(llvm::MCInstPrinter&, llvm::raw_ostream&, llvm::MCInst const&, llvm::MCSubtargetInfo const&) /home/shenyouren/workspace/llvm/lib/MC/MCStreamer.cpp:856:0</div><div>#15 0x00000000031690e2 (anonymous namespace)::MCAsmStreamer::EmitInstruction(llvm::MCInst const&, llvm::MCSubtargetInfo const&, bool) /home/shenyouren/workspace/llvm/lib/MC/MCAsmStreamer.cpp:1752:0</div><div>#16 0x0000000002355fdf llvm::X86AsmPrinter::EmitAndCountInstruction(llvm::MCInst&) /home/shenyouren/workspace/llvm/lib/Target/X86/X86MCInstLower.cpp:107:0</div><div>#17 0x0000000002360ae9 llvm::X86AsmPrinter::EmitInstruction(llvm::MachineInstr const*) /home/shenyouren/workspace/llvm/lib/Target/X86/X86MCInstLower.cpp:2604:0</div><div>#18 0x000000000292e629 llvm::AsmPrinter::EmitFunctionBody() /home/shenyouren/workspace/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp:1086:0</div><div>#19 0x0000000002352908 llvm::X86AsmPrinter::runOnMachineFunction(llvm::MachineFunction&) /home/shenyouren/workspace/llvm/lib/Target/X86/X86AsmPrinter.cpp:79:0</div><div>#20 0x0000000002bc6afa llvm::MachineFunctionPass::runOnFunction(llvm::Function&) /home/shenyouren/workspace/llvm/lib/CodeGen/MachineFunctionPass.cpp:62:0</div><div>#21 0x000000000307eeac llvm::FPPassManager::runOnFunction(llvm::Function&) /home/shenyouren/workspace/llvm/lib/IR/LegacyPassManager.cpp:1520:0</div><div>#22 0x000000000307f045 llvm::FPPassManager::runOnModule(llvm::Module&) /home/shenyouren/workspace/llvm/lib/IR/LegacyPassManager.cpp:1541:0</div><div>#23 0x000000000307f3c0 (anonymous namespace)::MPPassManager::runOnModule(llvm::Module&) /home/shenyouren/workspace/llvm/lib/IR/LegacyPassManager.cpp:1597:0</div><div>#24 0x000000000307fad5 llvm::legacy::PassManagerImpl::run(llvm::Module&) /home/shenyouren/workspace/llvm/lib/IR/LegacyPassManager.cpp:1700:0</div><div>#25 0x000000000307fce1 llvm::legacy::PassManager::run(llvm::Module&) /home/shenyouren/workspace/llvm/lib/IR/LegacyPassManager.cpp:1732:0</div><div>#26 0x00000000013e9361 compileModule(char**, llvm::LLVMContext&) /home/shenyouren/workspace/llvm/tools/llc/llc.cpp:575:0</div><div>#27 0x00000000013e7a6d main /home/shenyouren/workspace/llvm/tools/llc/llc.cpp:345:0</div><div>#28 0x00007fcc8e669830 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x20830)</div><div>#29 0x00000000013e5779 _start (/home/shenyouren/workspace/build-llvm/bin/llc+0x13e5779)</div><div>Makefile:25: recipe for target 'obj/simple.s' failed</div></div><div><br></div><div>I have checked X86ATTInstPrinter::printInstruction(llvm::MCInst const*, llvm::raw_ostream&) /home/shenyouren/workspace/build-llvm/lib/Target/X86/X86GenAsmWriter.inc:48204, and it will invoke printOperand(MI, 2, O); And I guess the BNDCU only have 2 operand, that's why it failed. <br>But I don't know how to fix it. </div><div>Is there anyone know how to solve this problem? I really appreciate for any help!</div></div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr">Best Regards.<div>Youren Shen</div></div></div>