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>
Anton Korobeynikov
2009-Apr-15 12:01 UTC
[LLVMdev] Patch: MSIL backend global pointers initialization
Hi, Artur> 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 ;).Ah, sorry. I missed that you're doing variadic calls, not casting variadic function to definite ones. I think you can construct CallSite and then iterate over the arguments grabbing their types and construct function type after that. -- With best regards, Anton Korobeynikov Faculty of Mathematics and Mechanics, Saint Petersburg State University
Artur Pietrek
2009-Apr-16 15:50 UTC
[LLVMdev] Patch: MSIL backend global pointers initialization
Hi Anton> > > 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 ;). > Ah, sorry. I missed that you're doing variadic calls, not casting > variadic function to definite ones. I think you can construct CallSite > and then iterate over the arguments grabbing their types and construct > function type after that. >So what do you think about that: // CallSites have equal signatures bool MSILWriter::cmpCallSite(CallSite A, CallSite B) { return (getCallSiteFType(A)==getCallSiteFType(B) && A.getAttributes()==B.getAttributes()); } // Comparision for std::lower_bound used in MSILWriter::printExternals() bool MSILWriter::compareCallSite(CallSite A, CallSite B) { return getCallSiteFType(A)<getCallSiteFType(B); } // Constructs function type from given CallSite FunctionType* MSILWriter::getCallSiteFType(CallSite CS) { std::vector<const Type *> params; CallSite::arg_iterator AI=CS.arg_begin(), AE = CS.arg_end(); for ( ; AI!=AE; ++AI ) params.push_back((*AI)->getType()); return FunctionType::get(CS.getCalledFunction()->getReturnType(), params,CS.getCalledFunction()->isVarArg()); } Thanks! Regards, Artur -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20090416/43320474/attachment.html>
Possibly Parallel Threads
- [LLVMdev] Patch: MSIL backend global pointers initialization
- [LLVMdev] Patch: MSIL backend global pointers initialization
- [LLVMdev] Patch: MSIL backend global pointers initialization
- [LLVMdev] Problem about "llc -march=msil"
- [LLVMdev] Patch: MSIL backend global pointers initialization