mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-05 01:20:51 +03:00
driver/gen/ir: clang-format the world
This uses the LLVM style, which makes sense for sharing code with other LLVM projects. The DMD code we use will soon all be in D anyway.
This commit is contained in:
parent
123666cf89
commit
44b0f7b615
125 changed files with 28991 additions and 30602 deletions
257
gen/binops.cpp
257
gen/binops.cpp
|
@ -18,140 +18,131 @@
|
|||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
DValue* DtoBinAdd(DValue* lhs, DValue* rhs)
|
||||
{
|
||||
Type* t = lhs->getType();
|
||||
LLValue *l, *r;
|
||||
l = lhs->getRVal();
|
||||
r = rhs->getRVal();
|
||||
DValue *DtoBinAdd(DValue *lhs, DValue *rhs) {
|
||||
Type *t = lhs->getType();
|
||||
LLValue *l, *r;
|
||||
l = lhs->getRVal();
|
||||
r = rhs->getRVal();
|
||||
|
||||
LLValue* res;
|
||||
if (t->isfloating())
|
||||
res = gIR->ir->CreateFAdd(l, r);
|
||||
LLValue *res;
|
||||
if (t->isfloating())
|
||||
res = gIR->ir->CreateFAdd(l, r);
|
||||
else
|
||||
res = gIR->ir->CreateAdd(l, r);
|
||||
|
||||
return new DImValue(t, res);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
DValue *DtoBinSub(DValue *lhs, DValue *rhs) {
|
||||
Type *t = lhs->getType();
|
||||
LLValue *l, *r;
|
||||
l = lhs->getRVal();
|
||||
r = rhs->getRVal();
|
||||
|
||||
LLValue *res;
|
||||
if (t->isfloating())
|
||||
res = gIR->ir->CreateFSub(l, r);
|
||||
else
|
||||
res = gIR->ir->CreateSub(l, r);
|
||||
|
||||
return new DImValue(t, res);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
DValue *DtoBinMul(Type *targettype, DValue *lhs, DValue *rhs) {
|
||||
Type *t = lhs->getType();
|
||||
LLValue *l, *r;
|
||||
l = lhs->getRVal();
|
||||
r = rhs->getRVal();
|
||||
|
||||
LLValue *res;
|
||||
if (t->isfloating())
|
||||
res = gIR->ir->CreateFMul(l, r);
|
||||
else
|
||||
res = gIR->ir->CreateMul(l, r);
|
||||
return new DImValue(targettype, res);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
DValue *DtoBinDiv(Type *targettype, DValue *lhs, DValue *rhs) {
|
||||
Type *t = lhs->getType();
|
||||
LLValue *l, *r;
|
||||
l = lhs->getRVal();
|
||||
r = rhs->getRVal();
|
||||
|
||||
LLValue *res;
|
||||
if (t->isfloating())
|
||||
res = gIR->ir->CreateFDiv(l, r);
|
||||
else if (!isLLVMUnsigned(t))
|
||||
res = gIR->ir->CreateSDiv(l, r);
|
||||
else
|
||||
res = gIR->ir->CreateUDiv(l, r);
|
||||
return new DImValue(targettype, res);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
DValue *DtoBinRem(Type *targettype, DValue *lhs, DValue *rhs) {
|
||||
Type *t = lhs->getType();
|
||||
LLValue *l, *r;
|
||||
l = lhs->getRVal();
|
||||
r = rhs->getRVal();
|
||||
LLValue *res;
|
||||
if (t->isfloating())
|
||||
res = gIR->ir->CreateFRem(l, r);
|
||||
else if (!isLLVMUnsigned(t))
|
||||
res = gIR->ir->CreateSRem(l, r);
|
||||
else
|
||||
res = gIR->ir->CreateURem(l, r);
|
||||
return new DImValue(targettype, res);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
LLValue *DtoBinNumericEquals(Loc &loc, DValue *lhs, DValue *rhs, TOK op) {
|
||||
assert(op == TOKequal || op == TOKnotequal || op == TOKidentity ||
|
||||
op == TOKnotidentity);
|
||||
Type *t = lhs->getType()->toBasetype();
|
||||
assert(t->isfloating());
|
||||
Logger::println("numeric equality");
|
||||
|
||||
LLValue *res = 0;
|
||||
if (t->iscomplex()) {
|
||||
Logger::println("complex");
|
||||
res = DtoComplexEquals(loc, op, lhs, rhs);
|
||||
} else if (t->isfloating()) {
|
||||
Logger::println("floating");
|
||||
res = DtoBinFloatsEquals(loc, lhs, rhs, op);
|
||||
}
|
||||
|
||||
assert(res);
|
||||
return res;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
LLValue *DtoBinFloatsEquals(Loc &loc, DValue *lhs, DValue *rhs, TOK op) {
|
||||
LLValue *res = 0;
|
||||
if (op == TOKequal) {
|
||||
res = gIR->ir->CreateFCmpOEQ(lhs->getRVal(), rhs->getRVal());
|
||||
} else if (op == TOKnotequal) {
|
||||
res = gIR->ir->CreateFCmpUNE(lhs->getRVal(), rhs->getRVal());
|
||||
} else {
|
||||
llvm::ICmpInst::Predicate cmpop;
|
||||
if (op == TOKidentity)
|
||||
cmpop = llvm::ICmpInst::ICMP_EQ;
|
||||
else
|
||||
res = gIR->ir->CreateAdd(l, r);
|
||||
cmpop = llvm::ICmpInst::ICMP_NE;
|
||||
|
||||
return new DImValue( t, res );
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
DValue* DtoBinSub(DValue* lhs, DValue* rhs)
|
||||
{
|
||||
Type* t = lhs->getType();
|
||||
LLValue *l, *r;
|
||||
l = lhs->getRVal();
|
||||
r = rhs->getRVal();
|
||||
|
||||
LLValue* res;
|
||||
if (t->isfloating())
|
||||
res = gIR->ir->CreateFSub(l, r);
|
||||
else
|
||||
res = gIR->ir->CreateSub(l, r);
|
||||
|
||||
return new DImValue( t, res );
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
DValue* DtoBinMul(Type* targettype, DValue* lhs, DValue* rhs)
|
||||
{
|
||||
Type* t = lhs->getType();
|
||||
LLValue *l, *r;
|
||||
l = lhs->getRVal();
|
||||
r = rhs->getRVal();
|
||||
|
||||
LLValue* res;
|
||||
if (t->isfloating())
|
||||
res = gIR->ir->CreateFMul(l, r);
|
||||
else
|
||||
res = gIR->ir->CreateMul(l, r);
|
||||
return new DImValue( targettype, res );
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
DValue* DtoBinDiv(Type* targettype, DValue* lhs, DValue* rhs)
|
||||
{
|
||||
Type* t = lhs->getType();
|
||||
LLValue *l, *r;
|
||||
l = lhs->getRVal();
|
||||
r = rhs->getRVal();
|
||||
|
||||
LLValue* res;
|
||||
if (t->isfloating())
|
||||
res = gIR->ir->CreateFDiv(l, r);
|
||||
else if (!isLLVMUnsigned(t))
|
||||
res = gIR->ir->CreateSDiv(l, r);
|
||||
else
|
||||
res = gIR->ir->CreateUDiv(l, r);
|
||||
return new DImValue( targettype, res );
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
DValue* DtoBinRem(Type* targettype, DValue* lhs, DValue* rhs)
|
||||
{
|
||||
Type* t = lhs->getType();
|
||||
LLValue *l, *r;
|
||||
l = lhs->getRVal();
|
||||
r = rhs->getRVal();
|
||||
LLValue* res;
|
||||
if (t->isfloating())
|
||||
res = gIR->ir->CreateFRem(l, r);
|
||||
else if (!isLLVMUnsigned(t))
|
||||
res = gIR->ir->CreateSRem(l, r);
|
||||
else
|
||||
res = gIR->ir->CreateURem(l, r);
|
||||
return new DImValue( targettype, res );
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
LLValue* DtoBinNumericEquals(Loc& loc, DValue* lhs, DValue* rhs, TOK op)
|
||||
{
|
||||
assert(op == TOKequal || op == TOKnotequal ||
|
||||
op == TOKidentity || op == TOKnotidentity);
|
||||
Type* t = lhs->getType()->toBasetype();
|
||||
assert(t->isfloating());
|
||||
Logger::println("numeric equality");
|
||||
|
||||
LLValue* res = 0;
|
||||
if (t->iscomplex())
|
||||
{
|
||||
Logger::println("complex");
|
||||
res = DtoComplexEquals(loc, op, lhs, rhs);
|
||||
}
|
||||
else if (t->isfloating())
|
||||
{
|
||||
Logger::println("floating");
|
||||
res = DtoBinFloatsEquals(loc, lhs, rhs, op);
|
||||
}
|
||||
|
||||
assert(res);
|
||||
return res;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
LLValue* DtoBinFloatsEquals(Loc& loc, DValue* lhs, DValue* rhs, TOK op)
|
||||
{
|
||||
LLValue* res = 0;
|
||||
if (op == TOKequal) {
|
||||
res = gIR->ir->CreateFCmpOEQ(lhs->getRVal(), rhs->getRVal());
|
||||
} else if (op == TOKnotequal) {
|
||||
res = gIR->ir->CreateFCmpUNE(lhs->getRVal(), rhs->getRVal());
|
||||
} else {
|
||||
llvm::ICmpInst::Predicate cmpop;
|
||||
if (op == TOKidentity)
|
||||
cmpop = llvm::ICmpInst::ICMP_EQ;
|
||||
else
|
||||
cmpop = llvm::ICmpInst::ICMP_NE;
|
||||
|
||||
LLValue* sz = DtoConstSize_t(getTypeStoreSize(DtoType(lhs->getType())));
|
||||
LLValue* val = DtoMemCmp(makeLValue(loc, lhs), makeLValue(loc, rhs), sz);
|
||||
res = gIR->ir->CreateICmp(cmpop, val, LLConstantInt::get(val->getType(), 0, false));
|
||||
}
|
||||
assert(res);
|
||||
return res;
|
||||
LLValue *sz = DtoConstSize_t(getTypeStoreSize(DtoType(lhs->getType())));
|
||||
LLValue *val = DtoMemCmp(makeLValue(loc, lhs), makeLValue(loc, rhs), sz);
|
||||
res = gIR->ir->CreateICmp(cmpop, val,
|
||||
LLConstantInt::get(val->getType(), 0, false));
|
||||
}
|
||||
assert(res);
|
||||
return res;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue