Artur Pietrek
2009-Apr-07 13:17 UTC
[LLVMdev] Patch: MSIL backend global pointers initialization
Hello Anton> %1 = tail call i32 (i8*, ...)* @printf(i8* noalias getelementptr ([16 x > > i8]* @.str, i32 0, i32 0), i32 %0) nounwind > > %10 = call i32 (i8*, ...)* @printf(i8* noalias getelementptr ([11 x i8]* > > @.str2, i32 0, i32 0), i32 5) nounwind > > > > Instruction::isSameOperationAs() returns false for those two. Is it a > > bug or I misunderstood something? > These are two different instructions as you might see, thus - no bug :)OK, I just need the same signature for both of those instructions.> > > In any case I wrote my custom isSame() operator for this but I'll > > appreciate any hints. > Why do you need this? Won't be enough just to compare function types?I do something like this: static bool areSame(Instruction *A, Instruction *B) { if (A->getOpcode() != B->getOpcode()) return false; if (A->getType()->getTypeID() != B->getType()->getTypeID()) return false; unsigned int a = A->getNumOperands(); if (a != B->getNumOperands()) return false; for (unsigned int i = 0; i < a; ++i) if (A->getOperand(i)->getType()->getTypeID() != B->getOperand(i)->getType()->getTypeID()) return false; return true; } I'm not sure if it's too much. Thanks! Artur P.S. Sorry for that [Junk...] in few mails. It's our "great" antispammer, I will switch to gmail. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20090407/becbfa88/attachment.html>
Anton Korobeynikov
2009-Apr-07 13:48 UTC
[LLVMdev] Patch: MSIL backend global pointers initialization
Artur,> OK, I just need the same signature for both of those instructions.Both are callinsts of same function, isn't that enough? Since it's a variadic function there is also a bitcast to proper type. So, looking for type of callee (not result, but function type!) you'll obtain the real "signature" of callee and if you'll strip all pointer cast you'll obtain the "declaration" (=variadic) type of the callee. This should be enough for almost all purposes. You should not try to invent some custom "comparison schemes", almost surely in such situation you're reinventing the wheel :)> if (A->getType()->getTypeID() != B->getType()->getTypeID()) return false;TypeID is internal thing for type. All types are unique inside LLVM, so you should just compare Type*'s.> if (A->getOperand(i)->getType()->getTypeID() > != B->getOperand(i)->getType()->getTypeID()) return false;Same here. -- With best regards, Anton Korobeynikov Faculty of Mathematics and Mechanics, Saint Petersburg State University
Artur Pietrek
2009-Apr-08 10:25 UTC
[LLVMdev] Patch: MSIL backend global pointers initialization
Hi Anton,> > > OK, I just need the same signature for both of those instructions. > Both are callinsts of same function, isn't that enough? Since it's a > variadic function there is also a bitcast to proper type. So, looking > for type of callee (not result, but function type!) you'll obtain the > real "signature" of callee and if you'll strip all pointer cast you'll > obtain the "declaration" (=variadic) type of the callee. This should > be enough for almost all purposes. You should not try to invent some > custom "comparison schemes", almost surely in such situation you're > reinventing the wheel :) > > So I do this:if (CallInst *cinst = cast<CallInst>(instr)) { const FunctionType *FTy = cinst->getCalledFunction()->getFunctionType(); } What I get "i32 (i8*, ...)" How can I get something like "i32 (i8*, i32)"? Thanks for your help. Regards, Artur -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20090408/f50cc21b/attachment.html>
Artur Pietrek
2009-Apr-15 08:43 UTC
[LLVMdev] Patch: MSIL backend global pointers initialization
Hello,> So, looking for type of callee (not result, but function type!) you'll > obtain the > real "signature" of callee and if you'll strip all pointer cast you'll > obtain the "declaration" (=variadic) type of the callee.Maybe I misunderstood something but I just get the variadic declaration not the real "signature", like this: const CallInst *I = dyn_cast<CallInst>(A); my CallInst looks like: %1 = tail call i32 (i8*, ...)* @printf(i8* noalias %0, i32 123) nounwind const Value *Callee = I->getCalledValue(); my Callee is: declare i32 @printf(i8* nocapture, ...) nounwind const PointerType *PTy = cast<PointerType>(Callee->getType()); I get: i32 (i8*, ...)* const FunctionType *FTy = cast<FunctionType>(PTy->getElementType()); so I get: i32 (i8*, ...) The interesting for me part of the CallInst is printf(i8* noalias %0, i32 123). I was diging in doxygen documentation but I really can't see the easy way to compare those instructions and again finish with reinvented (but working) wheel ;). I would really appreciate help. Thanks! Artur -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20090415/62e93a2c/attachment.html>
Maybe Matching Threads
- [LLVMdev] Patch: MSIL backend global pointers initialization
- [LLVMdev] Patch: MSIL backend global pointers initialization
- [LLVMdev] Patch: MSIL backend global pointers initialization
- [LLVMdev] Patch: MSIL backend global pointers initialization
- [LLVMdev] Patch: MSIL backend global pointers initialization