[svn r365] Implemented raw struct equality comparison, uses C memcmp.

Renamed DtoDelegateCompare to DtoDelegateEquals, for consistency with the other equality helpers.
This commit is contained in:
Tomas Lindquist Olsen
2008-07-13 04:11:08 +02:00
parent 4b8d048d59
commit a4e4f34a34
6 changed files with 69 additions and 5 deletions

View File

@@ -13,6 +13,7 @@
#include "gen/arrays.h"
#include "gen/logger.h"
#include "gen/structs.h"
#include "gen/dvalue.h"
#include "ir/irstruct.h"
@@ -377,6 +378,28 @@ void DtoDefineStruct(StructDeclaration* sd)
sd->ir.DModule = gIR->dmodule;
}
//////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////// D STRUCT UTILITIES ////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////
LLValue* DtoStructEquals(TOK op, DValue* lhs, DValue* rhs)
{
Type* t = lhs->getType()->toBasetype();
assert(t->ty == Tstruct);
// set predicate
llvm::ICmpInst::Predicate cmpop;
if (op == TOKequal)
cmpop = llvm::ICmpInst::ICMP_EQ;
else
cmpop = llvm::ICmpInst::ICMP_NE;
// call memcmp
size_t sz = getABITypeSize(DtoType(t));
LLValue* val = DtoMemCmp(lhs->getRVal(), rhs->getRVal(), DtoConstSize_t(sz));
return gIR->ir->CreateICmp(cmpop, val, LLConstantInt::get(val->getType(), 0, false), "tmp");
}
//////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////// D UNION HELPER CLASS ////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////