Reputation: 1406
In my llvm IR code, I have the following line:
%tmp = call i32 @decf1(void (i8*)* bitcast (void (%a_type*)* @decf2 to void (i8*)*), i8 %x3, i8* @external_type)
I am trying to extract a_type
and decf2
programmatically, but I seem not to get access to them.
bool runOnFunction(Function &F) override {
errs() << "Initializing Test pass\n";
for (BasicBlock &BB : F) {
for (Instruction &I : BB) {
// New Instruction
errs() << "\n\n"
<< "=====================\n"
<< "- - - - - - - - - - -\n"
<< "NewInstruction:\n";
I.dump();
errs() << "\n";
// New Operands
errs() << "- - - - - - - - - - -\n"
<< "Operands:\n";
for (Use &U : I.operands()) {
errs() << "Type: ";
U->getType()->print(errs());
errs() << "\n";
errs() << "Name: " << U->getName() << "\n";
}
errs() << "\n";
}
This pass produces me the following output for the instruction containing the cast.
=====================
- - - - - - - - - - -
NewInstruction:
%tmp = call i32 @decf1(void (i8*)* bitcast (void (%a_type*)* @decf2 to void (i8*)*), i8 %x3, i8* @external_type)
- - - - - - - - - - -
Operands:
Type: void (i8*)*
Name:
Is Instruction: No
Is Function: No
Type: i8
Name: x3
Is Instruction: Yes
%x3 = mul i8 %x2, %x2
Is Function: No
Type: i8*
Name: external_type
Is Instruction: No
Is Function: No
Type: i32 (void (i8*)*, i8, i8*)*
Name: decf1
Is Instruction: No
Is Function: Yes
Is Declaration: Yes
It seems that the first printed operand has to do with the bitcast. How can I get the bitcast and the operands/type/function it is casting?
Upvotes: 1
Views: 1387
Reputation: 1406
It seems that Value::stripPointerCasts()
is a way to get the the cast decf2
function as a Function *
.
Still need to elaborate on how to get the a_type
from there.
Upvotes: 2