Hi Nick, Thanks, that seemed to work. Nick Lewycky wrote:> > ivtm wrote: >> I am processing the LLVM instructions and right now I am at the 'call' >> instruction. >> For now I just want to print the argument type. >> >> For example in the following: >> >> %0 = tail call i32 (...)* @__FFF (i32 8) nounwind; <i32> [#uses=1] >> >> I need to get access to 'i32' and '8' separately. >> >> I do: >> >> CallInst *CI = dyn_cast<CallInst>(I); >> Value *v = CI->getOperand(1) >> >> I can get the type via v->getType() and that returns 'i32', which is >> good. >> >> But I also need to get the value '8'. >> >> I can get it via v->getValueID(), but in the documentation it says not to >> use that function. > > Heh. No, getValueID() returns '8' as the "ConstantIntVal" enum, not the > actual argument number. > >> Any other ideas what is the proper way to access the value '8' ? > > It's a ConstantInt, so cast it and retrieve the APInt then pull out the > number. Here: > > unsigned val; > if (ConstantInt *CI = dyn_cast<ConstantInt>(v)) { > val = CI->getValue()->getSExtValue(); > } > > Nick > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > >-- View this message in context: http://www.nabble.com/Printing-Function-Arguments-tp25638981p25639806.html Sent from the LLVM - Dev mailing list archive at Nabble.com.
Another question, I need to get the "%0" below in the: %0 = tail call i32 (...)* @__FFF (i32 8) nounwind; <i32> [#uses=1] that is, the return register. I am wondering in general, where should I look in the llvm codebase for parsing instructions ? I am looking at existing passes and also the header files like Function.h, etc to see what methods they have, but it takes a while to figure out the basic methods... ivtm wrote:> > Hi Nick, > > Thanks, that seemed to work. > > > Nick Lewycky wrote: >> >> ivtm wrote: >>> I am processing the LLVM instructions and right now I am at the 'call' >>> instruction. >>> For now I just want to print the argument type. >>> >>> For example in the following: >>> >>> %0 = tail call i32 (...)* @__FFF (i32 8) nounwind; <i32> [#uses=1] >>> >>> I need to get access to 'i32' and '8' separately. >>> >>> I do: >>> >>> CallInst *CI = dyn_cast<CallInst>(I); >>> Value *v = CI->getOperand(1) >>> >>> I can get the type via v->getType() and that returns 'i32', which is >>> good. >>> >>> But I also need to get the value '8'. >>> >>> I can get it via v->getValueID(), but in the documentation it says not >>> to >>> use that function. >> >> Heh. No, getValueID() returns '8' as the "ConstantIntVal" enum, not the >> actual argument number. >> >>> Any other ideas what is the proper way to access the value '8' ? >> >> It's a ConstantInt, so cast it and retrieve the APInt then pull out the >> number. Here: >> >> unsigned val; >> if (ConstantInt *CI = dyn_cast<ConstantInt>(v)) { >> val = CI->getValue()->getSExtValue(); >> } >> >> Nick >> _______________________________________________ >> LLVM Developers mailing list >> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu >> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >> >> > >-- View this message in context: http://www.nabble.com/Printing-Function-Arguments-tp25638981p25639926.html Sent from the LLVM - Dev mailing list archive at Nabble.com.
ivtm <martinaide1 at yahoo.com> writes:> Another question, I need to get the "%0" below in the: > > %0 = tail call i32 (...)* @__FFF (i32 8) nounwind; <i32> [#uses=1] > > that is, the return register.What information do you want, exactly? In your example, %0 is the CallInst. So if you have CallInst *ci = CallInst::Create(... then use `ci' whenever you want to use %0.> I am wondering in general, where should I look in the llvm codebase for > parsing instructions ? > > I am looking at existing passes and also the header files like Function.h, > etc to see what methods they have, but it takes a while to figure out the > basic methods...This is a bit better than looking at header files: http://llvm.org/doxygen/classes.html -- Óscar
ivtm wrote:> Another question, I need to get the "%0" below in the: > > %0 = tail call i32 (...)* @__FFF (i32 8) nounwind; <i32> [#uses=1] > > that is, the return register. > > I am wondering in general, where should I look in the llvm codebase for > parsing instructions ?The parser is in lib/AsmParser/. Nick> I am looking at existing passes and also the header files like Function.h, > etc to see what methods they have, but it takes a while to figure out the > basic methods... > > > > > > > ivtm wrote: >> Hi Nick, >> >> Thanks, that seemed to work. >> >> >> Nick Lewycky wrote: >>> ivtm wrote: >>>> I am processing the LLVM instructions and right now I am at the 'call' >>>> instruction. >>>> For now I just want to print the argument type. >>>> >>>> For example in the following: >>>> >>>> %0 = tail call i32 (...)* @__FFF (i32 8) nounwind; <i32> [#uses=1] >>>> >>>> I need to get access to 'i32' and '8' separately. >>>> >>>> I do: >>>> >>>> CallInst *CI = dyn_cast<CallInst>(I); >>>> Value *v = CI->getOperand(1) >>>> >>>> I can get the type via v->getType() and that returns 'i32', which is >>>> good. >>>> >>>> But I also need to get the value '8'. >>>> >>>> I can get it via v->getValueID(), but in the documentation it says not >>>> to >>>> use that function. >>> Heh. No, getValueID() returns '8' as the "ConstantIntVal" enum, not the >>> actual argument number. >>> >>>> Any other ideas what is the proper way to access the value '8' ? >>> It's a ConstantInt, so cast it and retrieve the APInt then pull out the >>> number. Here: >>> >>> unsigned val; >>> if (ConstantInt *CI = dyn_cast<ConstantInt>(v)) { >>> val = CI->getValue()->getSExtValue(); >>> } >>> >>> Nick >>> _______________________________________________ >>> LLVM Developers mailing list >>> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu >>> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >>> >>> >> >