comparison gen/structs.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 aaade6ded589
children 5320fe65a65d
comparison
equal deleted inserted replaced
343:15eb8f5f2441 344:e20ce6d8d374
11 #include "gen/tollvm.h" 11 #include "gen/tollvm.h"
12 #include "gen/llvmhelpers.h" 12 #include "gen/llvmhelpers.h"
13 #include "gen/arrays.h" 13 #include "gen/arrays.h"
14 #include "gen/logger.h" 14 #include "gen/logger.h"
15 #include "gen/structs.h" 15 #include "gen/structs.h"
16 #include "gen/dvalue.h"
16 17
17 #include "ir/irstruct.h" 18 #include "ir/irstruct.h"
18 19
19 ////////////////////////////////////////////////////////////////////////////////////////// 20 //////////////////////////////////////////////////////////////////////////////////////////
20 LLConstant* DtoConstStructInitializer(StructInitializer* si) 21 LLConstant* DtoConstStructInitializer(StructInitializer* si)
376 377
377 sd->ir.DModule = gIR->dmodule; 378 sd->ir.DModule = gIR->dmodule;
378 } 379 }
379 380
380 ////////////////////////////////////////////////////////////////////////////////////////// 381 //////////////////////////////////////////////////////////////////////////////////////////
382 //////////////////////////// D STRUCT UTILITIES ////////////////////////////////////
383 //////////////////////////////////////////////////////////////////////////////////////////
384
385 LLValue* DtoStructEquals(TOK op, DValue* lhs, DValue* rhs)
386 {
387 Type* t = lhs->getType()->toBasetype();
388 assert(t->ty == Tstruct);
389
390 // set predicate
391 llvm::ICmpInst::Predicate cmpop;
392 if (op == TOKequal)
393 cmpop = llvm::ICmpInst::ICMP_EQ;
394 else
395 cmpop = llvm::ICmpInst::ICMP_NE;
396
397 // call memcmp
398 size_t sz = getABITypeSize(DtoType(t));
399 LLValue* val = DtoMemCmp(lhs->getRVal(), rhs->getRVal(), DtoConstSize_t(sz));
400 return gIR->ir->CreateICmp(cmpop, val, LLConstantInt::get(val->getType(), 0, false), "tmp");
401 }
402
403 //////////////////////////////////////////////////////////////////////////////////////////
381 //////////////////////////// D UNION HELPER CLASS //////////////////////////////////// 404 //////////////////////////// D UNION HELPER CLASS ////////////////////////////////////
382 ////////////////////////////////////////////////////////////////////////////////////////// 405 //////////////////////////////////////////////////////////////////////////////////////////
383 406
384 DUnion::DUnion() 407 DUnion::DUnion()
385 { 408 {