[LLVMdev] Assertion `InReg && "Value not in map!"' failed

bhavani krishnan bhavi63 at yahoo.com
Sun Nov 16 22:04:45 PST 2008


Ah! I get it now. Thanks a lot !
I changed it to BitCastInst(AI,VoidPtrTy,"",j);

And now I am getting the following error :(. I have been stuck with this error before also. I know I am missing out something silly. What is the cause of this error and Please let me know how to fix it.

/home/bhavani/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:1130: llvm::SDOperand llvm::SelectionDAGLowering::getValue(const llvm::Value*): Assertion `InReg && "Value not in map!"' failed.

I know I am asking lot of questions but I am new to LLVM and am finding it hard to figure things out. Appreciate any help!

Thanks,
Bhavani




--- On Mon, 11/17/08, Nick Lewycky <nicholas at mxc.ca> wrote:

> From: Nick Lewycky <nicholas at mxc.ca>
> Subject: Re: [LLVMdev] Assertion `castIsValid(getOpcode(), S, Ty) && "Illegal BitCast"' failed.
> To: bhavi63 at yahoo.com, "LLVM Developers Mailing List" <llvmdev at cs.uiuc.edu>
> Date: Monday, November 17, 2008, 5:54 AM
> bhavani krishnan wrote:
> > ok.. So I am trying out what you have suggested. I
> have written the below code which basically tries to write
> the constant 10 to a file. myprint is a function pointer to
> a function which takes char * parameter and writes it to
> file.
> > 
> > Value *Ten = ConstantInt::get(Type::Int32Ty, 10);
> > const Type *VoidPtrTy =
> PointerType::getUnqual(Type::Int8Ty);
> > AllocaInst *AI = new AllocaInst(Type::Int32Ty);
> > Value *ST = new StoreInst(Ten,AI,false,4,j);
> 
> Realize that StoreInst's don't have a result. A
> 'store' does not evaluate to a particular value at
> run time. Its type is Void.
> 
> > Value *BT = new
> BitCastInst(ST,VoidPtrTy,"",j);
> 
> Trying to cast (void) to (void*) is invalid. Instead, you
> should cast the AllocaInst, ala:
> 
>   Value *BT = new BitCastInst(AI,VoidPtrTy,"",j);
> 
> Nick
> 
> > CallInst *CallPrint = CallInst::Create(myprint, BT,
> "", j);
> > CallPrint->setTailCall(true);
> > 
> > I am getting the following error while executing.
> >  Assertion `castIsValid(getOpcode(), S, Ty) &&
> "Illegal BitCast"' failed.
> > 
> > What am I doing wrong :(? I always get stuck badly
> when these assertions fail :(. Please help me out here.
> Thanks,
> > Bhavani
> > 
> > 
> > 
> > --- On Sun, 11/16/08, Eli Friedman
> <eli.friedman at gmail.com> wrote:
> > 
> >> From: Eli Friedman <eli.friedman at gmail.com>
> >> Subject: Re: [LLVMdev] How do I get the result of
> an instruction?
> >> To: bhavi63 at yahoo.com
> >> Cc: "LLVM Developers Mailing List"
> <llvmdev at cs.uiuc.edu>, "John Criswell"
> <criswell at uiuc.edu>
> >> Date: Sunday, November 16, 2008, 9:22 PM
> >> On Sun, Nov 16, 2008 at 7:54 AM, bhavani krishnan
> >> <bhavi63 at yahoo.com> wrote:
> >>> Hi,
> >>> 
> >>> I am writing an optimization pass where I need
> to
> >> instrument the code such that I need to store the
> results of
> >> some instructions in file. Using llc -march=cpp
> option I
> >> figured out how to add a function(say writeToFile)
> which
> >> takes char* parameter and writes to file. Now, I
> need put in
> >> a CallInst which calls writeToFile passing the
> Instruction
> >> result as parameter. How do I do this?
> >>> So, in my optimization pass...
> >>> Func *myprint = makewriteToFile() //creates a
> function
> >> which writes to file
> >>> for (Function::iterator i = func->begin(),
> e =
> >> func->end(); i != e; ++i)
> >>> {
> >>>        blk=i;
> >>>        for (BasicBlock::iterator j =
> blk->begin(),
> >> k = blk->end(); j != k; ++j){
> >>>            Instruction *inst = j;
> >>>            //if inst satisfies my condition,
> write
> >> reults to file
> >>>            CallInst *CallPrint =
> >> CallInst::Create(myprint, ???, "", j);
> >>>            CallPrint->setTailCall(true);
> >>>       }
> >>> }
> >>> What do I put in the ???. How do I cast
> Instruction
> >> *inst into char * which can be passed into the
> function?
> >> 
> >> Well, you can do something like the following:
> >> define i32 @f() nounwind {
> >> entry:
> >> 	%x = alloca i32
> >> 	%resulttoprint = call i32 (...)* @a() nounwind
> >> ;start instrumentation
> >> 	store i32 %resulttoprint, i32* %x, align 4
> >> 	%x1 = bitcast i32* %x to i8*
> >> 	call void @print(i8* %x1) nounwind
> >> ;end instrumentation
> >> 	ret i32 %resulttoprint
> >> }
> >> 
> >> That said, you might need to do something
> that's aware
> >> of the type of
> >> the result; printing a value in human-readable
> form
> >> requires calling
> >> something like printf.
> >> 
> >> -Eli
> > 
> > 
> > 
> >       _______________________________________________
> > LLVM Developers mailing list
> > LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
> >



      



More information about the llvm-dev mailing list