[LLVMdev] Passing an array to an external function
SArora
silkyar at umich.edu
Sat Jan 26 19:24:31 PST 2013
Hi all,
I am new to LLVM, and I am learning how to use LLVM for profiling. I need to
pass an array to an external method, and insert a call instruction to the
method in the code.
After reading a few source files, I've tried using GetElementPtrInst to pass
an array, but it fails at llvm::GetElementPtrInst::hasAllZeroIndices() const
+ 0
std::vector<Value*> Args(1);
//Vector with array values
SmallVector<Constant*, 2> counts;
counts.push_back(ConstantInt::get(Type::getInt32Ty(BB->getContext()),32,
false));
counts.push_back(ConstantInt::get(Type::getInt32Ty(BB->getContext()),12,
false));
//Array with 2 integers
ArrayType* ar_type =
llvm::ArrayType::get(llvm::Type::getInt32Ty(BI->getContext()),2);
Value* array = ConstantArray::get(&(*ar_type),
counts);
//Indicies
std::vector<Value*> ids(1);
ids.push_back(ConstantInt::get(Type::getInt32Ty(BB->getContext()),1));
ids.push_back(ConstantInt::get(Type::getInt32Ty(BB->getContext()),2));
Args[1] = GetElementPtrInst::Create(array, ids, "
");
//Instrument the branch target instructions
CallInst::Create(hook, Args, "",CI);
Also, I 'hook' is defined as M.getOrInsertFunction("hook",
Type::getVoidTy(M.getContext()),
PointerType::get(Type::getInt32PtrTy(M.getContext()),0), //??
(Type*)0);
Could someone kindly keep me a few pointers on passing arrays to an external
function (say with the signature void hook(int abc[]) ). I am probably wrong
all the way through, and would really appreciate some help.
Thanks!
--
View this message in context: http://llvm.1065342.n5.nabble.com/Passing-an-array-to-an-external-function-tp54208.html
Sent from the LLVM - Dev mailing list archive at Nabble.com.
More information about the llvm-dev
mailing list