Mercurial > projects > ldc
comparison gen/complex.cpp @ 244:a95056b3c996 trunk
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
Did a lot of smaller cleans up here and there.
Replaced more llvm::Foo with LLFoo for common stuff.
Split up tollvm.cpp.
author | lindquist |
---|---|
date | Mon, 09 Jun 2008 09:37:08 +0200 |
parents | 0806379a5eca |
children | 4aa2b6753059 |
comparison
equal
deleted
inserted
replaced
243:4d006f7b2ada | 244:a95056b3c996 |
---|---|
3 #include "mtype.h" | 3 #include "mtype.h" |
4 #include "declaration.h" | 4 #include "declaration.h" |
5 | 5 |
6 #include "gen/complex.h" | 6 #include "gen/complex.h" |
7 #include "gen/tollvm.h" | 7 #include "gen/tollvm.h" |
8 #include "gen/llvmhelpers.h" | |
8 #include "gen/irstate.h" | 9 #include "gen/irstate.h" |
9 #include "gen/dvalue.h" | 10 #include "gen/dvalue.h" |
10 | 11 |
11 ////////////////////////////////////////////////////////////////////////////////////////// | 12 ////////////////////////////////////////////////////////////////////////////////////////// |
12 | 13 |
305 // (l.re==r.re && l.im==r.im) | 306 // (l.re==r.re && l.im==r.im) |
306 LLValue* b1 = new llvm::FCmpInst(cmpop, a, c, "tmp", gIR->scopebb()); | 307 LLValue* b1 = new llvm::FCmpInst(cmpop, a, c, "tmp", gIR->scopebb()); |
307 LLValue* b2 = new llvm::FCmpInst(cmpop, b, d, "tmp", gIR->scopebb()); | 308 LLValue* b2 = new llvm::FCmpInst(cmpop, b, d, "tmp", gIR->scopebb()); |
308 return gIR->ir->CreateAnd(b1,b2,"tmp"); | 309 return gIR->ir->CreateAnd(b1,b2,"tmp"); |
309 } | 310 } |
311 | |
312 ////////////////////////////////////////////////////////////////////////////////////////// | |
313 | |
314 DValue* DtoCastComplex(DValue* val, Type* _to) | |
315 { | |
316 Type* to = DtoDType(_to); | |
317 Type* vty = val->getType(); | |
318 if (to->iscomplex()) { | |
319 if (vty->size() == to->size()) | |
320 return val; | |
321 | |
322 llvm::Value *re, *im; | |
323 DtoGetComplexParts(val, re, im); | |
324 const LLType* toty = DtoComplexBaseType(to); | |
325 | |
326 if (to->size() < vty->size()) { | |
327 re = gIR->ir->CreateFPTrunc(re, toty, "tmp"); | |
328 im = gIR->ir->CreateFPTrunc(im, toty, "tmp"); | |
329 } | |
330 else if (to->size() > vty->size()) { | |
331 re = gIR->ir->CreateFPExt(re, toty, "tmp"); | |
332 im = gIR->ir->CreateFPExt(im, toty, "tmp"); | |
333 } | |
334 else { | |
335 return val; | |
336 } | |
337 | |
338 if (val->isComplex()) | |
339 return new DComplexValue(_to, re, im); | |
340 | |
341 // unfortunately at this point, the cast value can show up as the lvalue for += and similar expressions. | |
342 // so we need to give it storage, or fix the system that handles this stuff (DLRValue) | |
343 LLValue* mem = new llvm::AllocaInst(DtoType(_to), "castcomplextmp", gIR->topallocapoint()); | |
344 DtoComplexSet(mem, re, im); | |
345 return new DLRValue(val->getType(), val->getRVal(), _to, mem); | |
346 } | |
347 else if (to->isimaginary()) { | |
348 if (val->isComplex()) | |
349 return new DImValue(to, val->isComplex()->im); | |
350 LLValue* v = val->getRVal(); | |
351 DImValue* im = new DImValue(to, DtoLoad(DtoGEPi(v,0,1,"tmp"))); | |
352 return DtoCastFloat(im, to); | |
353 } | |
354 else if (to->isfloating()) { | |
355 if (val->isComplex()) | |
356 return new DImValue(to, val->isComplex()->re); | |
357 LLValue* v = val->getRVal(); | |
358 DImValue* re = new DImValue(to, DtoLoad(DtoGEPi(v,0,0,"tmp"))); | |
359 return DtoCastFloat(re, to); | |
360 } | |
361 else | |
362 assert(0); | |
363 } |