comparison gen/tollvm.cpp @ 344:e20ce6d8d374 trunk

[svn r365] Implemented raw struct equality comparison, uses C memcmp. Renamed DtoDelegateCompare to DtoDelegateEquals, for consistency with the other equality helpers.
author lindquist
date Sun, 13 Jul 2008 04:11:08 +0200
parents 7086a84ab3d6
children f273f5c58a9a
comparison
equal deleted inserted replaced
343:15eb8f5f2441 344:e20ce6d8d374
184 return LLStructType::get(i8ptr, funcptr, 0); 184 return LLStructType::get(i8ptr, funcptr, 0);
185 } 185 }
186 186
187 ////////////////////////////////////////////////////////////////////////////////////////// 187 //////////////////////////////////////////////////////////////////////////////////////////
188 188
189 LLValue* DtoDelegateCompare(TOK op, LLValue* lhs, LLValue* rhs) 189 LLValue* DtoDelegateEquals(TOK op, LLValue* lhs, LLValue* rhs)
190 { 190 {
191 Logger::println("Doing delegate compare"); 191 Logger::println("Doing delegate equality");
192 llvm::ICmpInst::Predicate pred = (op == TOKequal || op == TOKidentity) ? llvm::ICmpInst::ICMP_EQ : llvm::ICmpInst::ICMP_NE; 192 llvm::ICmpInst::Predicate pred = (op == TOKequal || op == TOKidentity) ? llvm::ICmpInst::ICMP_EQ : llvm::ICmpInst::ICMP_NE;
193 llvm::Value *b1, *b2; 193 llvm::Value *b1, *b2;
194 if (rhs == NULL) 194 if (rhs == NULL)
195 { 195 {
196 LLValue* l = DtoLoad(DtoGEPi(lhs,0,0)); 196 LLValue* l = DtoLoad(DtoGEPi(lhs,0,0));
438 fn = GET_INTRINSIC_DECL(memcpy_i64); 438 fn = GET_INTRINSIC_DECL(memcpy_i64);
439 else 439 else
440 fn = GET_INTRINSIC_DECL(memcpy_i32); 440 fn = GET_INTRINSIC_DECL(memcpy_i32);
441 441
442 gIR->ir->CreateCall4(fn, dst, src, nbytes, DtoConstUint(0), ""); 442 gIR->ir->CreateCall4(fn, dst, src, nbytes, DtoConstUint(0), "");
443 }
444
445 //////////////////////////////////////////////////////////////////////////////////////////
446
447 LLValue* DtoMemCmp(LLValue* lhs, LLValue* rhs, LLValue* nbytes)
448 {
449 // int memcmp ( const void * ptr1, const void * ptr2, size_t num );
450
451 LLFunction* fn = gIR->module->getFunction("memcmp");
452 if (!fn)
453 {
454 std::vector<const LLType*> params(3);
455 params[0] = getVoidPtrType();
456 params[1] = getVoidPtrType();
457 params[2] = DtoSize_t();
458 const LLFunctionType* fty = LLFunctionType::get(LLType::Int32Ty, params, false);
459 fn = LLFunction::Create(fty, LLGlobalValue::ExternalLinkage, "memcmp", gIR->module);
460 }
461
462 lhs = DtoBitCast(lhs,getVoidPtrType());
463 rhs = DtoBitCast(rhs,getVoidPtrType());
464
465 return gIR->ir->CreateCall3(fn, lhs, rhs, nbytes, "tmp");
443 } 466 }
444 467
445 ////////////////////////////////////////////////////////////////////////////////////////// 468 //////////////////////////////////////////////////////////////////////////////////////////
446 469
447 void DtoAggrZeroInit(LLValue* v) 470 void DtoAggrZeroInit(LLValue* v)