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:
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.
--
Regards
James Wang
.-- .- -. --. @ -.-. ... .-.-.- .-- .. ... -.-. .-.-.- . -.. ..-
John Criswell
2010-May-16 14:17 UTC
[LLVMdev] How to access the return value of a CallInst
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. >
Possibly Parallel Threads
- [LLVMdev] rotate
- [LLVMdev] How to change the type of an Instruction?
- Bug#603727: xen-hypervisor-4.0-amd64: i386 Dom0 crashes after doing some I/O on local storage (software Raid1 on SAS-drives with mpt2sas driver)
- 3.0.0-rc2: Xen: High amount of kernel "reserved" memory, about 33% in 256MB DOMU
- [PATCH v3 0/11] tests/qemu: Add program for tracing and analyzing boot times.