[LLVMdev] How to access the return value of a CallInst

John Criswell criswell at illinois.edu
Sun May 16 07:17:17 PDT 2010


Cong Wang wrote:
> Hi all:
>     I am trying to get the return value of a call instruction that I
> inserted during the optimization pass I wrote. I have something like
> the following:
>   

The CallInst is its return value.  They are one and the same.

Replace "InitCall.getCalledValue()" with "InitCall" in the 
CastInst::CreateTruncOrBitCast call, and it should work.

-- John T.

>    CallInst *InitCall = CallInst::Create(InitFn, Args.begin(), Args.end(),
>                                            "log_load_addr_ret", LI);
>    CastInst *InsertedCast =
> CastInst::CreateTruncOrBitCast(InitCall.getCalledValue(),
> LI->getType(), "return_load", LI);
>
>    I assume that getCalledValue() will give me the return value of the
> InitCall CallInst.
>    This compiles fine.
>    But the CastInst cannot be created. The runtime error is :
> opt: /panfs/panasas-01.cs.wisc.edu/scratch/wang/LLVM/src/llvm/lib/VMCore/Instructions.cpp:2338:
> llvm::TruncInst::TruncInst(llvm::Value*, const llvm::Type*, const
> llvm::Twine&, llvm::Instruction*): Assertion `castIsValid(getOpcode(),
> S, Ty) && "Illegal Trunc"' failed.
> 0   opt             0x000000000084e8bf
> 1   opt             0x000000000084f37a
> 2   libpthread.so.0 0x000000310ac0e930
> 3   libc.so.6       0x000000310a030265 gsignal + 53
> 4   libc.so.6       0x000000310a031d10 abort + 272
> 5   libc.so.6       0x000000310a0296e6 __assert_fail + 246
> 6   opt             0x00000000007aad58
> 7   opt             0x00000000007aae33
> llvm::CastInst::Create(llvm::Instruction::CastOps, llvm::Value*,
> llvm::Type const*, llvm::Twine const&, llvm::Instruction*) + 211
> 8   opt             0x00000000004f4695
> llvm::RSProfilers_std::InstrumentLoadStoreInBlock(llvm::BasicBlock*,
> llvm::GlobalValue*, llvm::GlobalValue*, llvm::GlobalValue*,
> llvm::GlobalValue*, llvm::GlobalValue*, llvm::GlobalValue*) + 4101
> 9   opt             0x00000000004ecb3f
> 10  opt             0x00000000007d5140
> llvm::MPPassManager::runOnModule(llvm::Module&) + 464
> 11  opt             0x00000000007d76b5
> llvm::PassManagerImpl::run(llvm::Module&) + 149
> 12  opt             0x00000000007d778d
> llvm::PassManager::run(llvm::Module&) + 13
> 13  opt             0x000000000049c68b main + 2315
> 14  libc.so.6       0x000000310a01d994 __libc_start_main + 244
> 15  opt             0x0000000000492759 __gxx_personality_v0 + 393
>
>
>    The goal of all this is to convert the return value to some other
> form. The return value is always 64 bit int but I from time to time
> needs other form, such a 32 bit int.
>    Thanks for any input in advance.
>   




More information about the llvm-dev mailing list