Remove the need to build temporary std::vector.
This commit is contained in:
parent
b748d34f48
commit
e7ad6c7439
1 changed files with 45 additions and 44 deletions
|
|
@ -86,6 +86,13 @@
|
||||||
namespace llvm{
|
namespace llvm{
|
||||||
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(EngineBuilder, LLVMEngineBuilderRef)
|
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(EngineBuilder, LLVMEngineBuilderRef)
|
||||||
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(TargetMachine, LLVMTargetMachineRef)
|
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(TargetMachine, LLVMTargetMachineRef)
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline T **unwrap(LLVMTypeRef *Tys, unsigned Length) {
|
||||||
|
(void)Length;
|
||||||
|
return reinterpret_cast<T**>(Tys);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -139,13 +146,9 @@ LLVMValueRef LLVMMetaDataGet(LLVMModuleRef modref, LLVMValueRef * valrefs,
|
||||||
{
|
{
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
LLVMContext & context = unwrap(modref)->getContext();
|
LLVMContext & context = unwrap(modref)->getContext();
|
||||||
std::vector<Value*> vals;
|
MDNode * const node = MDNode::get(
|
||||||
vals.reserve(valct);
|
context,
|
||||||
for(unsigned i = 0; i < valct; ++i ){
|
makeArrayRef(unwrap<Value>(valrefs, valct), valct));
|
||||||
vals.push_back(unwrap(valrefs[i]));
|
|
||||||
}
|
|
||||||
|
|
||||||
MDNode * const node = MDNode::get(context, vals);
|
|
||||||
return wrap(node);
|
return wrap(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -789,47 +792,46 @@ LLVMValueRef LLVMInstGetCalledFunction(LLVMValueRef inst)
|
||||||
return llvm::wrap(CallSite(instp).getCalledFunction());
|
return llvm::wrap(CallSite(instp).getCalledFunction());
|
||||||
}
|
}
|
||||||
|
|
||||||
/* llvm::unwrap a set of `n' wrapped objects starting at `values',
|
///* llvm::unwrap a set of `n' wrapped objects starting at `values',
|
||||||
* into a vector of pointers to llvm::unwrapped objects `out'. */
|
// * into a vector of pointers to llvm::unwrapped objects `out'. */
|
||||||
template <typename W, typename UW>
|
//template <typename W, typename UW>
|
||||||
void unwrap_vec(W *values, unsigned n, std::vector<UW *>& out)
|
//void unwrap_vec(W *values, unsigned n, std::vector<UW *>& out)
|
||||||
{
|
//{
|
||||||
out.clear();
|
// out.clear();
|
||||||
out.reserve(n);
|
// out.reserve(n);
|
||||||
while (n--) {
|
// while (n--) {
|
||||||
UW *p = llvm::unwrap(*values);
|
// UW *p = llvm::unwrap(*values);
|
||||||
assert(p);
|
// assert(p);
|
||||||
out.push_back(p);
|
// out.push_back(p);
|
||||||
++values;
|
// ++values;
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
|
||||||
/* Same as llvm::unwrap_vec, but use a vector of const pointers. */
|
///* Same as llvm::unwrap_vec, but use a vector of const pointers. */
|
||||||
template <typename W, typename UW>
|
//template <typename W, typename UW>
|
||||||
void unwrap_cvec(W *values, unsigned n, std::vector<const UW *>& out)
|
//void unwrap_cvec(W *values, unsigned n, std::vector<const UW *>& out)
|
||||||
{
|
//{
|
||||||
out.clear();
|
// out.clear();
|
||||||
|
|
||||||
|
// while (n--) {
|
||||||
|
// UW *p = llvm::unwrap(*values);
|
||||||
|
// assert(p);
|
||||||
|
// out.push_back(p);
|
||||||
|
// ++values;
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
while (n--) {
|
|
||||||
UW *p = llvm::unwrap(*values);
|
|
||||||
assert(p);
|
|
||||||
out.push_back(p);
|
|
||||||
++values;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
LLVMValueRef LLVMBuildRetMultiple(LLVMBuilderRef builder,
|
LLVMValueRef LLVMBuildRetMultiple(LLVMBuilderRef builder,
|
||||||
LLVMValueRef *values, unsigned n_values)
|
LLVMValueRef *values, unsigned n_values)
|
||||||
{
|
{
|
||||||
|
using namespace llvm;
|
||||||
assert(values);
|
assert(values);
|
||||||
|
|
||||||
std::vector<llvm::Value *> values_vec;
|
IRBuilder<> *builderp = unwrap(builder);
|
||||||
unwrap_vec(values, n_values, values_vec);
|
|
||||||
|
|
||||||
llvm::IRBuilder<> *builderp = llvm::unwrap(builder);
|
|
||||||
assert(builderp);
|
assert(builderp);
|
||||||
|
|
||||||
return llvm::wrap(builderp->CreateAggregateRet(&values_vec[0], values_vec.size()));
|
return wrap(builderp->CreateAggregateRet(unwrap<Value>(values, n_values), n_values));
|
||||||
}
|
}
|
||||||
|
|
||||||
LLVMValueRef LLVMBuildGetResult(LLVMBuilderRef builder,
|
LLVMValueRef LLVMBuildGetResult(LLVMBuilderRef builder,
|
||||||
|
|
@ -927,16 +929,15 @@ void LLVMSetDoesNotThrow(LLVMValueRef fn, int DoesNotThrow)
|
||||||
LLVMValueRef LLVMGetIntrinsic(LLVMModuleRef module, int id,
|
LLVMValueRef LLVMGetIntrinsic(LLVMModuleRef module, int id,
|
||||||
LLVMTypeRef *types, unsigned n_types)
|
LLVMTypeRef *types, unsigned n_types)
|
||||||
{
|
{
|
||||||
|
using namespace llvm;
|
||||||
assert(types);
|
assert(types);
|
||||||
|
|
||||||
std::vector< llvm::Type* > types_vec;
|
Module *modulep = unwrap(module);
|
||||||
unwrap_vec(types, n_types, types_vec);
|
|
||||||
|
|
||||||
llvm::Module *modulep = llvm::unwrap(module);
|
|
||||||
assert(modulep);
|
assert(modulep);
|
||||||
|
|
||||||
llvm::Function *intfunc = llvm::Intrinsic::getDeclaration(modulep,
|
Function *intfunc = Intrinsic::getDeclaration(modulep, Intrinsic::ID(id),
|
||||||
llvm::Intrinsic::ID(id), types_vec);
|
makeArrayRef(unwrap<Type>(types, n_types),
|
||||||
|
n_types));
|
||||||
|
|
||||||
return wrap(intfunc);
|
return wrap(intfunc);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue