Replace std::vector with llvm::SmallVector in gen/tollvm.cpp.

This commit is contained in:
kai
2013-01-26 21:37:59 +01:00
parent ed5ede3fda
commit 28e3a4d80f

View File

@@ -515,9 +515,7 @@ LLValue* DtoGEP1(LLValue* ptr, LLValue* i0, const char* var, llvm::BasicBlock* b
LLValue* DtoGEP(LLValue* ptr, LLValue* i0, LLValue* i1, const char* var, llvm::BasicBlock* bb) LLValue* DtoGEP(LLValue* ptr, LLValue* i0, LLValue* i1, const char* var, llvm::BasicBlock* bb)
{ {
LLSmallVector<LLValue*,2> v(2); LLValue* v[2] = { i0, i1 };
v[0] = i0;
v[1] = i1;
return llvm::GetElementPtrInst::Create(ptr, v, var?var:"tmp", bb?bb:gIR->scopebb()); return llvm::GetElementPtrInst::Create(ptr, v, var?var:"tmp", bb?bb:gIR->scopebb());
} }
@@ -532,9 +530,7 @@ LLValue* DtoGEPi1(LLValue* ptr, unsigned i, const char* var, llvm::BasicBlock* b
LLValue* DtoGEPi(LLValue* ptr, unsigned i0, unsigned i1, const char* var, llvm::BasicBlock* bb) LLValue* DtoGEPi(LLValue* ptr, unsigned i0, unsigned i1, const char* var, llvm::BasicBlock* bb)
{ {
LLSmallVector<LLValue*,2> v(2); LLValue* v[2] = { DtoConstUint(i0), DtoConstUint(i1) };
v[0] = DtoConstUint(i0);
v[1] = DtoConstUint(i1);
return llvm::GetElementPtrInst::Create(ptr, v, var?var:"tmp", bb?bb:gIR->scopebb()); return llvm::GetElementPtrInst::Create(ptr, v, var?var:"tmp", bb?bb:gIR->scopebb());
} }
@@ -550,13 +546,13 @@ LLConstant* DtoGEPi(LLConstant* ptr, unsigned i0, unsigned i1)
void DtoMemSet(LLValue* dst, LLValue* val, LLValue* nbytes) void DtoMemSet(LLValue* dst, LLValue* val, LLValue* nbytes)
{ {
dst = DtoBitCast(dst,getVoidPtrType()); LLType* VoidPtrTy = getVoidPtrType();
LLType* intTy = DtoSize_t(); dst = DtoBitCast(dst, VoidPtrTy);
LLType *VoidPtrTy = getVoidPtrType();
LLType *Tys[2] ={VoidPtrTy, intTy}; LLType* Tys[] = { VoidPtrTy, DtoSize_t() };
llvm::Function* fn = llvm::Intrinsic::getDeclaration(gIR->module, llvm::Function* fn = llvm::Intrinsic::getDeclaration(gIR->module,
llvm::Intrinsic::memset, llvm::makeArrayRef(Tys, 2)); llvm::Intrinsic::memset, Tys);
gIR->ir->CreateCall5(fn, dst, val, nbytes, DtoConstUint(1), DtoConstBool(false), ""); gIR->ir->CreateCall5(fn, dst, val, nbytes, DtoConstUint(1), DtoConstBool(false), "");
} }
@@ -572,14 +568,14 @@ void DtoMemSetZero(LLValue* dst, LLValue* nbytes)
void DtoMemCpy(LLValue* dst, LLValue* src, LLValue* nbytes, unsigned align) void DtoMemCpy(LLValue* dst, LLValue* src, LLValue* nbytes, unsigned align)
{ {
dst = DtoBitCast(dst,getVoidPtrType()); LLType* VoidPtrTy = getVoidPtrType();
src = DtoBitCast(src,getVoidPtrType());
LLType* intTy = DtoSize_t(); dst = DtoBitCast(dst, VoidPtrTy);
LLType *VoidPtrTy = getVoidPtrType(); src = DtoBitCast(src, VoidPtrTy);
LLType *Tys[3] ={VoidPtrTy, VoidPtrTy, intTy};
LLType* Tys[] ={ VoidPtrTy, VoidPtrTy, DtoSize_t() };
llvm::Function* fn = llvm::Intrinsic::getDeclaration(gIR->module, llvm::Function* fn = llvm::Intrinsic::getDeclaration(gIR->module,
llvm::Intrinsic::memcpy, llvm::makeArrayRef(Tys, 3)); llvm::Intrinsic::memcpy, Tys);
gIR->ir->CreateCall5(fn, dst, src, nbytes, DtoConstUint(align), DtoConstBool(false), ""); gIR->ir->CreateCall5(fn, dst, src, nbytes, DtoConstUint(align), DtoConstBool(false), "");
} }
@@ -590,19 +586,18 @@ LLValue* DtoMemCmp(LLValue* lhs, LLValue* rhs, LLValue* nbytes)
{ {
// int memcmp ( const void * ptr1, const void * ptr2, size_t num ); // int memcmp ( const void * ptr1, const void * ptr2, size_t num );
LLType* VoidPtrTy = getVoidPtrType();
LLFunction* fn = gIR->module->getFunction("memcmp"); LLFunction* fn = gIR->module->getFunction("memcmp");
if (!fn) if (!fn)
{ {
std::vector<LLType*> params(3); LLType* Tys[] = { VoidPtrTy, VoidPtrTy, DtoSize_t() };
params[0] = getVoidPtrType(); LLFunctionType* fty = LLFunctionType::get(LLType::getInt32Ty(gIR->context()),
params[1] = getVoidPtrType(); Tys, false);
params[2] = DtoSize_t();
LLFunctionType* fty = LLFunctionType::get(LLType::getInt32Ty(gIR->context()), params, false);
fn = LLFunction::Create(fty, LLGlobalValue::ExternalLinkage, "memcmp", gIR->module); fn = LLFunction::Create(fty, LLGlobalValue::ExternalLinkage, "memcmp", gIR->module);
} }
lhs = DtoBitCast(lhs,getVoidPtrType()); lhs = DtoBitCast(lhs, VoidPtrTy);
rhs = DtoBitCast(rhs,getVoidPtrType()); rhs = DtoBitCast(rhs, VoidPtrTy);
return gIR->ir->CreateCall3(fn, lhs, rhs, nbytes, "tmp"); return gIR->ir->CreateCall3(fn, lhs, rhs, nbytes, "tmp");
} }
@@ -971,13 +966,13 @@ LLStructType* DtoInterfaceInfoType()
return gIR->interfaceInfoType; return gIR->interfaceInfoType;
// build interface info type // build interface info type
std::vector<LLType*> types; LLSmallVector<LLType*, 3> types;
// ClassInfo classinfo // ClassInfo classinfo
ClassDeclaration* cd2 = ClassDeclaration::classinfo; ClassDeclaration* cd2 = ClassDeclaration::classinfo;
DtoResolveClass(cd2); DtoResolveClass(cd2);
types.push_back(DtoType(cd2->type)); types.push_back(DtoType(cd2->type));
// void*[] vtbl // void*[] vtbl
std::vector<LLType*> vtbltypes; LLSmallVector<LLType*, 2> vtbltypes;
vtbltypes.push_back(DtoSize_t()); vtbltypes.push_back(DtoSize_t());
LLType* byteptrptrty = getPtrToType(getPtrToType(LLType::getInt8Ty(gIR->context()))); LLType* byteptrptrty = getPtrToType(getPtrToType(LLType::getInt8Ty(gIR->context())));
vtbltypes.push_back(byteptrptrty); vtbltypes.push_back(byteptrptrty);
@@ -1006,20 +1001,19 @@ LLStructType* DtoMutexType()
llvm::Type *Int32Ty = llvm::Type::getInt32Ty(gIR->context()); llvm::Type *Int32Ty = llvm::Type::getInt32Ty(gIR->context());
// Build RTL_CRITICAL_SECTION; size is 24 (32bit) or 40 (64bit) // Build RTL_CRITICAL_SECTION; size is 24 (32bit) or 40 (64bit)
std::vector<LLType*> rtl_types; LLType *rtl_types[] = {
rtl_types.push_back(VoidPtrTy); // Pointer to DebugInfo VoidPtrTy, // Pointer to DebugInfo
rtl_types.push_back(Int32Ty); // LockCount Int32Ty, // LockCount
rtl_types.push_back(Int32Ty); // RecursionCount Int32Ty, // RecursionCount
rtl_types.push_back(VoidPtrTy); // Handle of OwningThread VoidPtrTy, // Handle of OwningThread
rtl_types.push_back(VoidPtrTy); // Handle of LockSemaphore VoidPtrTy, // Handle of LockSemaphore
rtl_types.push_back(VoidPtrTy); // SpinCount VoidPtrTy // SpinCount
};
LLStructType* rtl = LLStructType::create(gIR->context(), rtl_types, "RTL_CRITICAL_SECTION"); LLStructType* rtl = LLStructType::create(gIR->context(), rtl_types, "RTL_CRITICAL_SECTION");
// Build D_CRITICAL_SECTION; size is 28 (32bit) or 48 (64bit) // Build D_CRITICAL_SECTION; size is 28 (32bit) or 48 (64bit)
LLStructType* mutex = LLStructType::create(gIR->context(), "D_CRITICAL_SECTION"); LLStructType *mutex = LLStructType::create(gIR->context(), "D_CRITICAL_SECTION");
std::vector<LLType*> types; LLType *types[] = { getPtrToType(mutex), rtl };
types.push_back(getPtrToType(mutex));
types.push_back(rtl);
mutex->setBody(types); mutex->setBody(types);
// Cache type // Cache type
@@ -1035,25 +1029,25 @@ LLStructType* DtoMutexType()
} }
// pthread_fastlock // pthread_fastlock
std::vector<LLType*> types2; LLType *types2[] = {
types2.push_back(DtoSize_t()); DtoSize_t(),
types2.push_back(LLType::getInt32Ty(gIR->context())); LLType::getInt32Ty(gIR->context()
};
LLStructType* fastlock = LLStructType::get(gIR->context(), types2); LLStructType* fastlock = LLStructType::get(gIR->context(), types2);
// pthread_mutex // pthread_mutex
std::vector<LLType*> types1; LLType *types1[] = {
types1.push_back(LLType::getInt32Ty(gIR->context())); LLType::getInt32Ty(gIR->context()),
types1.push_back(LLType::getInt32Ty(gIR->context())); LLType::getInt32Ty(gIR->context()),
types1.push_back(getVoidPtrType()); getVoidPtrType(),
types1.push_back(LLType::getInt32Ty(gIR->context())); LLType::getInt32Ty(gIR->context()),
types1.push_back(fastlock); fastlock
};
LLStructType* pmutex = LLStructType::get(gIR->context(), types1); LLStructType* pmutex = LLStructType::get(gIR->context(), types1);
// D_CRITICAL_SECTION // D_CRITICAL_SECTION
LLStructType* mutex = LLStructType::create(gIR->context(), "D_CRITICAL_SECTION"); LLStructType* mutex = LLStructType::create(gIR->context(), "D_CRITICAL_SECTION");
std::vector<LLType*> types; LLType *types[] = { getPtrToType(mutex), pmutex };
types.push_back(getPtrToType(mutex));
types.push_back(pmutex);
mutex->setBody(types); mutex->setBody(types);
// Cache type // Cache type
@@ -1073,13 +1067,14 @@ LLStructType* DtoModuleReferenceType()
LLStructType* st = LLStructType::create(gIR->context(), "ModuleReference"); LLStructType* st = LLStructType::create(gIR->context(), "ModuleReference");
// add members // add members
std::vector<LLType*> types; LLType *types[] = {
types.push_back(getPtrToType(st)); getPtrToType(st),
#if DMDV1 #if DMDV1
types.push_back(DtoType(Module::moduleinfo->type)); DtoType(Module::moduleinfo->type)
#else #else
types.push_back(DtoType(Module::moduleinfo->type->pointerTo())); DtoType(Module::moduleinfo->type->pointerTo())
#endif #endif
};
// resolve type // resolve type
st->setBody(types); st->setBody(types);
@@ -1100,10 +1095,8 @@ LLValue* DtoAggrPair(LLType* type, LLValue* V1, LLValue* V2, const char* name)
LLValue* DtoAggrPair(LLValue* V1, LLValue* V2, const char* name) LLValue* DtoAggrPair(LLValue* V1, LLValue* V2, const char* name)
{ {
llvm::SmallVector<LLType*, 2> types; LLType *types[] = { V1->getType(), V2->getType() };
types.push_back(V1->getType()); LLType *t = LLStructType::get(gIR->context(), types);
types.push_back(V2->getType());
LLType* t = LLStructType::get(gIR->context(), types);
return DtoAggrPair(t, V1, V2, name); return DtoAggrPair(t, V1, V2, name);
} }