[LLVMdev] Casting and intrinsic function calls
Jordan Cheney
jordan.cheney at gmail.com
Wed Aug 28 14:55:59 PDT 2013
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>
More information about the llvm-dev
mailing list