Hello, I am attempting to use llvm casting and intrinsic functions to do basic operations on Value pointers. I have read the online documentation and relevant portions of the source code and wrote the following code to do a Float to Double cast and then a log operation- Value *castFP(Value *i, Type *ty) const { return b->CreateFPCast(i, ty, n); } \\b is an IRBuilder and TheModule is an llvm::Module Value *intrinsic(Value *i, Intrinsic::ID id) const { vector<Type*> args; args.push_back(i->getType()); Function *intrinsic = Intrinsic::getDeclaration(TheModule, id, args); return b->CreateCall(intrinsic, i, n); } Value *log(Value *i) const { i = castFP(i, Type::getDoubleTy(getGlobalContext())); return intrinsic(i, Intrinsic::log); } In this example the initial type of i on the log function call is a Float (tested and confirmed) but when I run the code I get- Assertion failed: (getOperand(0)->getType() == cast<PointerType>(getOperand(1)->getType())->getElementType() && "Ptr must be a pointer to Val type!"), function AssertOK, file ../llvm/lib/IR/Instructions.cpp, line 1086. Illegal instruction: 4 The error occurs in the CreateCall portion of the intrinsic function. Does anyone know why or of a better way to go about this seemingly simple task? This is my first time using llvm so apologies is something is very wrong. Any help would be greatly appreciated! Thanks, Jordan -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130828/e94f7602/attachment.html>
Jordan Cheney <jordan.cheney at gmail.com> writes:> I am attempting to use llvm casting and intrinsic functions to do > basic operations on Value pointers. I have read the online > documentation and relevant portions of the source code and wrote the > following code to do a Float to Double cast and then a log operation- > > Value *castFP(Value *i, Type *ty) const { return b->CreateFPCast(i, ty, n); } \\b is an IRBuilder and TheModule is an llvm::Module > > Value *intrinsic(Value *i, Intrinsic::ID id) const { vector<Type*> > args; args.push_back(i->getType()); Function *intrinsic > Intrinsic::getDeclaration(TheModule, id, args); return > b->CreateCall(intrinsic, i, n); } > Value *log(Value *i) const { i = castFP(i, Type::getDoubleTy(getGlobalContext())); return intrinsic(i, Intrinsic::log); } > > In this example the initial type of i on the log function call is a Float (tested and confirmed) but when I run the code I get- > > Assertion failed: (getOperand(0)->getType() => cast<PointerType>(getOperand(1)->getType())->getElementType() && "Ptr > must be a pointer to Val type!"), function AssertOK, file > ../llvm/lib/IR/Instructions.cpp, line 1086. > Illegal instruction: 4 > > The error occurs in the CreateCall portion of the intrinsic function. > Does anyone know why or of a better way to go about this seemingly > simple task? This is my first time using llvm so apologies is > something is very wrong. Any help would be greatly appreciated!Assuming that you are using LLVM from SVN, that assert is in StoreInst::AssertOK and I see no StoreInst in your code sample. Run your code under a debugger and take a backtrace on the assert. My guess is that the problem is elsewhere.
Reasonably Related Threads
- [LLVMdev] Kaleidoscope toy4 failure seg fault on llvm::ExecutionEngine::getTargetData (this=0x0)
- [LLVMdev] Kaleidoscope toy4 failure seg fault on llvm::ExecutionEngine::getTargetData (this=0x0)
- [LLVMdev] llvm.atomic.barrier implementation
- How to migrate x86_sse2_psrl_dq after LLVM v3.8?
- [LLVMdev] about creating the first value of the storeinst