Detect rvv instruction using BOLT pass

Hi. I want to detect whether there is certain riscv vector(rvv) instruction in the input executable file, so I write a BOLT pass. I did it in the same way as BOLT detect whether there’s a call instruction isRISCVCall. However, I found that RISCV::VSETIVLI returns the opcode for MachineInstr, while others like RISCV::JAL returns the opcode for MCInst.

I added a helper function in RISCVMCPlusBuilder

bool isRISCVVsetivli(const MachineInstr &Inst) const {
    if(Inst.getOpcode() != RISCV::VSETIVLI || Inst.getOpcode() != RISCV::VSETVLI)
    {
      outs() << Inst.getOpcode() <<  "    " << RISCV::VSETIVLI;
      return false;
    }
    return true;
  }

and my pass looks like this

if (!BC.isRISCV())
    return;
  for (auto &BFI : BC.getBinaryFunctions()) 
  { 
    for (BinaryBasicBlock &BB : BFI.second) 
    {
      for (auto II = BB.begin(); II != BB.end(); ++II) 
      {
        MCInst &Inst = *II;
        outs() << Inst;
        if(BC.MIB->isRISCVVsetivli(Inst))
           outs() << "yes\n";
        else
          outs() << "no\n";
      }
    }
  }

and the result is there is no yes in the commandline even though the input file contains vsetivli instruction.
So how can i detect whether there’s an rvv instruction using BOLT pass?

Try printing the disassembly for the function that you know it has this rvv instruction:

llvm-bolt --print-only=your-function-name-here.* --print-all

See if it shows up. If it doesn’t, then the function that has the instruction you are looking for is probably not making it to your pass.

If it is showing up and you are certain that the function with the rvv instruction is running in your loop, then I would just make a debug build and set a breakpoint to see what is happening and why it is not being recognized.

1 Like

Thanks a lot for your reply. It turned out that the function didn’t show up, and I’ll try to figure what happened there.

1 Like