Zheng Wang
2010-Apr-08 16:19 UTC
[LLVMdev] Check the location of the definition of a Value object
Hello, How to check whether a value object is within a particular basic block or not. I have the following LLVM bytecode: ------------------------ entry: ... %2 = call i32 (...)* @atoi(i8*%1) nounwind ... -- bb1: .. %5 = icmp sgt i32 %2, %i.0 ... ----------------- Here I got the corresponding pointer of the Value object of *%2*. How can I check whether it is defined in *entry* or not? I tried: --------------------- //Value* pb corresponding to %2 for (BasicBlock::iterator I=entry->begin(), e=entry.end(); I != e; I++) { if (I == pb) return true; } return false; ---------------------- However, I got errors when compiled the code. Could anyone give some simple examples about this issue? Thanks. Cheers, Zheng
John Criswell
2010-Apr-08 16:25 UTC
[LLVMdev] Check the location of the definition of a Value object
Zheng Wang wrote:> Hello, > > How to check whether a value object is within a particular basic block or not. >There is a much simpler way to do this. Assuming that Value * pb holds the pointer to the value of %2, you do the following: 1) Check to see if %2 is an instruction (use dyn_cast<Instruction>(pb) and see if the result is NULL). If it's not an instruction, then it's definitely not defined in the entry block. 2) Use the result of dyn_cast<Instruction>(pb) to get the basic block in which the instruction is defined. So, you do // Entry is a Basic Block pointer pointing to the function's entry block if (Instruction * PBI = dyn_cast<Instruction>(pb)) { if (PBI->getParent() == Entry) // pb is an instruction defined in the entry basic block. -- John T.> I have the following LLVM bytecode: > > ------------------------ > entry: > ... > %2 = call i32 (...)* @atoi(i8*%1) nounwind > ... > > -- > bb1: > .. > %5 = icmp sgt i32 %2, %i.0 > ... > ----------------- > > Here I got the corresponding pointer of the Value object of *%2*. How > can I check whether it is defined in *entry* or not? > > I tried: > --------------------- > //Value* pb corresponding to %2 > for (BasicBlock::iterator I=entry->begin(), e=entry.end(); I != e; I++) > { > if (I == pb) > return true; > } > return false; > ---------------------- > > However, I got errors when compiled the code. Could anyone give some > simple examples about this issue? > > Thanks. > > Cheers, > Zheng > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >
Zheng Wang
2010-Apr-08 16:33 UTC
[LLVMdev] Check the location of the definition of a Value object
Cheers John! On 8 April 2010 17:25, John Criswell <criswell at uiuc.edu> wrote:> Zheng Wang wrote: >> >> Hello, >> >> How to check whether a value object is within a particular basic block or >> not. >> > > There is a much simpler way to do this. Assuming that Value * pb holds the > pointer to the value of %2, you do the following: > > 1) Check to see if %2 is an instruction (use dyn_cast<Instruction>(pb) and > see if the result is NULL). If it's not an instruction, then it's > definitely not defined in the entry block. > > 2) Use the result of dyn_cast<Instruction>(pb) to get the basic block in > which the instruction is defined. > > So, you do > > // Entry is a Basic Block pointer pointing to the function's entry block > if (Instruction * PBI = dyn_cast<Instruction>(pb)) { > if (PBI->getParent() == Entry) > // pb is an instruction defined in the entry basic block. > > > -- John T. > >> I have the following LLVM bytecode: >> >> ------------------------ >> entry: >> ... >> %2 = call i32 (...)* @atoi(i8*%1) nounwind >> ... >> >> -- >> bb1: >> .. >> %5 = icmp sgt i32 %2, %i.0 >> ... >> ----------------- >> >> Here I got the corresponding pointer of the Value object of *%2*. How >> can I check whether it is defined in *entry* or not? >> >> I tried: >> --------------------- >> //Value* pb corresponding to %2 >> for (BasicBlock::iterator I=entry->begin(), e=entry.end(); I != e; I++) >> { >> if (I == pb) >> return true; >> } >> return false; >> ---------------------- >> >> However, I got errors when compiled the code. Could anyone give some >> simple examples about this issue? >> >> Thanks. >> >> Cheers, >> Zheng >> _______________________________________________ >> LLVM Developers mailing list >> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu >> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >> > >-- Best regards, WANG Zheng