I've been asked to do a LLVM function that allows me to find: jump/branch, load/store, call, 'arithmetic and other type of instruction'.
As far as I managed to do, I've been able to find the CallInst, LoadInst, StoreInst and BranchInst doing the following code with dyn_cast:
for (const Function &F : *M)
for (const BasicBlock &BB : F)
for (const Instruction &I : BB)
if (const StoreInst *SI = dyn_cast<StoreInst>(&I))
count++;;
I'm struggling to find a way of extracting all the arithmetic and 'other type' instructions.
Thanks for your time.
You can see here
Use
if (llvm::isa <llvm::LoadInst> (I))
or llvm::StoreInst
, etc.
For instruction containing binary operators, llvm::isa <llvm::BinaryOperator> (I)
can't differentiate them. Use
if (!strncmp(I.getOpcodeName(), "add", 4))
or
if (I.getOpcode == llvm::Add)
You can find the OpcodeNames and Opcode here and here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With