comparison gen/complex.cpp @ 213:7816aafeea3c trunk

[svn r229] Updated the object.d implementation to the latest Tango. Fixed a bunch of the built-in typeinfos for arrays, they did not inherit TypeInfo_Array. Applied patch to tango/text/convert/Layout.d by fvbommel, closes #47 . Cleaned up some type code. Replaced uses of llvm::Type with LLType (a typedef), same for Value and Constant. Fixed a few cases where typeinfo for user structs could be emitted multiple times, seems to still be some cases of this :/
author lindquist
date Fri, 30 May 2008 19:32:04 +0200
parents 9d44ec83acd1
children 0806379a5eca
comparison
equal deleted inserted replaced
212:4c2689d57ba4 213:7816aafeea3c
12 12
13 const llvm::StructType* DtoComplexType(Type* type) 13 const llvm::StructType* DtoComplexType(Type* type)
14 { 14 {
15 Type* t = DtoDType(type); 15 Type* t = DtoDType(type);
16 16
17 const llvm::Type* base = DtoComplexBaseType(t); 17 const LLType* base = DtoComplexBaseType(t);
18 18
19 std::vector<const llvm::Type*> types; 19 std::vector<const LLType*> types;
20 types.push_back(base); 20 types.push_back(base);
21 types.push_back(base); 21 types.push_back(base);
22 22
23 return llvm::StructType::get(types); 23 return llvm::StructType::get(types);
24 } 24 }
25 25
26 const llvm::Type* DtoComplexBaseType(Type* t) 26 const LLType* DtoComplexBaseType(Type* t)
27 { 27 {
28 TY ty = DtoDType(t)->ty; 28 TY ty = DtoDType(t)->ty;
29 const llvm::Type* base; 29 const LLType* base;
30 if (ty == Tcomplex32) { 30 if (ty == Tcomplex32) {
31 return llvm::Type::FloatTy; 31 return llvm::Type::FloatTy;
32 } 32 }
33 else if (ty == Tcomplex64 || ty == Tcomplex80) { 33 else if (ty == Tcomplex64 || ty == Tcomplex80) {
34 return llvm::Type::DoubleTy; 34 return llvm::Type::DoubleTy;
38 } 38 }
39 } 39 }
40 40
41 ////////////////////////////////////////////////////////////////////////////////////////// 41 //////////////////////////////////////////////////////////////////////////////////////////
42 42
43 llvm::Constant* DtoConstComplex(Type* ty, llvm::Constant* re, llvm::Constant* im) 43 LLConstant* DtoConstComplex(Type* ty, LLConstant* re, LLConstant* im)
44 { 44 {
45 assert(0); 45 assert(0);
46 const llvm::Type* base = DtoComplexBaseType(ty); 46 const LLType* base = DtoComplexBaseType(ty);
47 47
48 std::vector<llvm::Constant*> inits; 48 std::vector<LLConstant*> inits;
49 inits.push_back(re); 49 inits.push_back(re);
50 inits.push_back(im); 50 inits.push_back(im);
51 51
52 const llvm::VectorType* vt = llvm::VectorType::get(base, 2); 52 const llvm::VectorType* vt = llvm::VectorType::get(base, 2);
53 return llvm::ConstantVector::get(vt, inits); 53 return llvm::ConstantVector::get(vt, inits);
54 } 54 }
55 55
56 llvm::Constant* DtoConstComplex(Type* _ty, long double re, long double im) 56 LLConstant* DtoConstComplex(Type* _ty, long double re, long double im)
57 { 57 {
58 TY ty = DtoDType(_ty)->ty; 58 TY ty = DtoDType(_ty)->ty;
59 59
60 llvm::ConstantFP* fre; 60 llvm::ConstantFP* fre;
61 llvm::ConstantFP* fim; 61 llvm::ConstantFP* fim;
62 62
63 const llvm::Type* base; 63 const LLType* base;
64 64
65 if (ty == Tcomplex32) { 65 if (ty == Tcomplex32) {
66 fre = DtoConstFP(Type::tfloat32, re); 66 fre = DtoConstFP(Type::tfloat32, re);
67 fim = DtoConstFP(Type::tfloat32, im); 67 fim = DtoConstFP(Type::tfloat32, im);
68 base = llvm::Type::FloatTy; 68 base = llvm::Type::FloatTy;
73 base = llvm::Type::DoubleTy; 73 base = llvm::Type::DoubleTy;
74 } 74 }
75 else 75 else
76 assert(0); 76 assert(0);
77 77
78 std::vector<llvm::Constant*> inits; 78 std::vector<LLConstant*> inits;
79 inits.push_back(fre); 79 inits.push_back(fre);
80 inits.push_back(fim); 80 inits.push_back(fim);
81 return llvm::ConstantStruct::get(DtoComplexType(_ty), inits); 81 return llvm::ConstantStruct::get(DtoComplexType(_ty), inits);
82 } 82 }
83 83
84 llvm::Constant* DtoUndefComplex(Type* _ty) 84 LLConstant* DtoUndefComplex(Type* _ty)
85 { 85 {
86 assert(0); 86 assert(0);
87 TY ty = DtoDType(_ty)->ty; 87 TY ty = DtoDType(_ty)->ty;
88 const llvm::Type* base; 88 const LLType* base;
89 if (ty == Tcomplex32) { 89 if (ty == Tcomplex32) {
90 base = llvm::Type::FloatTy; 90 base = llvm::Type::FloatTy;
91 } 91 }
92 else if (ty == Tcomplex64 || ty == Tcomplex80) { 92 else if (ty == Tcomplex64 || ty == Tcomplex80) {
93 base = llvm::Type::DoubleTy; 93 base = llvm::Type::DoubleTy;
94 } 94 }
95 else 95 else
96 assert(0); 96 assert(0);
97 97
98 std::vector<llvm::Constant*> inits; 98 std::vector<LLConstant*> inits;
99 inits.push_back(llvm::UndefValue::get(base)); 99 inits.push_back(llvm::UndefValue::get(base));
100 inits.push_back(llvm::UndefValue::get(base)); 100 inits.push_back(llvm::UndefValue::get(base));
101 101
102 const llvm::VectorType* vt = llvm::VectorType::get(base, 2); 102 const llvm::VectorType* vt = llvm::VectorType::get(base, 2);
103 return llvm::ConstantVector::get(vt, inits); 103 return llvm::ConstantVector::get(vt, inits);
104 } 104 }
105 105
106 ////////////////////////////////////////////////////////////////////////////////////////// 106 //////////////////////////////////////////////////////////////////////////////////////////
107 107
108 llvm::Value* DtoRealPart(DValue* val) 108 LLValue* DtoRealPart(DValue* val)
109 { 109 {
110 assert(0); 110 assert(0);
111 return gIR->ir->CreateExtractElement(val->getRVal(), DtoConstUint(0), "tmp"); 111 return gIR->ir->CreateExtractElement(val->getRVal(), DtoConstUint(0), "tmp");
112 } 112 }
113 113
114 ////////////////////////////////////////////////////////////////////////////////////////// 114 //////////////////////////////////////////////////////////////////////////////////////////
115 115
116 llvm::Value* DtoImagPart(DValue* val) 116 LLValue* DtoImagPart(DValue* val)
117 { 117 {
118 assert(0); 118 assert(0);
119 return gIR->ir->CreateExtractElement(val->getRVal(), DtoConstUint(1), "tmp"); 119 return gIR->ir->CreateExtractElement(val->getRVal(), DtoConstUint(1), "tmp");
120 } 120 }
121 121
128 128
129 if (val->isComplex() || t->iscomplex()) { 129 if (val->isComplex() || t->iscomplex()) {
130 return DtoCastComplex(val, to); 130 return DtoCastComplex(val, to);
131 } 131 }
132 132
133 const llvm::Type* base = DtoComplexBaseType(to); 133 const LLType* base = DtoComplexBaseType(to);
134 134
135 llvm::Constant* undef = llvm::UndefValue::get(base); 135 LLConstant* undef = llvm::UndefValue::get(base);
136 llvm::Constant* zero; 136 LLConstant* zero;
137 if (ty == Tfloat32 || ty == Timaginary32 || ty == Tcomplex32) 137 if (ty == Tfloat32 || ty == Timaginary32 || ty == Tcomplex32)
138 zero = llvm::ConstantFP::get(llvm::APFloat(0.0f)); 138 zero = llvm::ConstantFP::get(llvm::APFloat(0.0f));
139 else if (ty == Tfloat64 || ty == Timaginary64 || ty == Tcomplex64 || ty == Tfloat80 || ty == Timaginary80 || ty == Tcomplex80) 139 else if (ty == Tfloat64 || ty == Timaginary64 || ty == Tcomplex64 || ty == Tfloat80 || ty == Timaginary80 || ty == Tcomplex80)
140 zero = llvm::ConstantFP::get(llvm::APFloat(0.0)); 140 zero = llvm::ConstantFP::get(llvm::APFloat(0.0));
141 141
149 assert(0); 149 assert(0);
150 } 150 }
151 151
152 ////////////////////////////////////////////////////////////////////////////////////////// 152 //////////////////////////////////////////////////////////////////////////////////////////
153 153
154 void DtoComplexAssign(llvm::Value* l, llvm::Value* r) 154 void DtoComplexAssign(LLValue* l, LLValue* r)
155 { 155 {
156 DtoStore(DtoLoad(DtoGEPi(r, 0,0, "tmp")), DtoGEPi(l,0,0,"tmp")); 156 DtoStore(DtoLoad(DtoGEPi(r, 0,0, "tmp")), DtoGEPi(l,0,0,"tmp"));
157 DtoStore(DtoLoad(DtoGEPi(r, 0,1, "tmp")), DtoGEPi(l,0,1,"tmp")); 157 DtoStore(DtoLoad(DtoGEPi(r, 0,1, "tmp")), DtoGEPi(l,0,1,"tmp"));
158 } 158 }
159 159
160 void DtoComplexSet(llvm::Value* c, llvm::Value* re, llvm::Value* im) 160 void DtoComplexSet(LLValue* c, LLValue* re, LLValue* im)
161 { 161 {
162 DtoStore(re, DtoGEPi(c,0,0,"tmp")); 162 DtoStore(re, DtoGEPi(c,0,0,"tmp"));
163 DtoStore(im, DtoGEPi(c,0,1,"tmp")); 163 DtoStore(im, DtoGEPi(c,0,1,"tmp"));
164 } 164 }
165 165
166 ////////////////////////////////////////////////////////////////////////////////////////// 166 //////////////////////////////////////////////////////////////////////////////////////////
167 167
168 void DtoGetComplexParts(DValue* c, llvm::Value*& re, llvm::Value*& im) 168 void DtoGetComplexParts(DValue* c, LLValue*& re, LLValue*& im)
169 { 169 {
170 // lhs values 170 // lhs values
171 if (DComplexValue* cx = c->isComplex()) { 171 if (DComplexValue* cx = c->isComplex()) {
172 re = cx->re; 172 re = cx->re;
173 im = cx->im; 173 im = cx->im;
298 return new DComplexValue(type, re, im); 298 return new DComplexValue(type, re, im);
299 } 299 }
300 300
301 ////////////////////////////////////////////////////////////////////////////////////////// 301 //////////////////////////////////////////////////////////////////////////////////////////
302 302
303 llvm::Value* DtoComplexEquals(TOK op, DValue* lhs, DValue* rhs) 303 LLValue* DtoComplexEquals(TOK op, DValue* lhs, DValue* rhs)
304 { 304 {
305 Type* type = lhs->getType(); 305 Type* type = lhs->getType();
306 306
307 lhs = DtoComplex(type, lhs); 307 lhs = DtoComplex(type, lhs);
308 rhs = DtoComplex(type, rhs); 308 rhs = DtoComplex(type, rhs);
320 cmpop = llvm::FCmpInst::FCMP_OEQ; 320 cmpop = llvm::FCmpInst::FCMP_OEQ;
321 else 321 else
322 cmpop = llvm::FCmpInst::FCMP_UNE; 322 cmpop = llvm::FCmpInst::FCMP_UNE;
323 323
324 // (l.re==r.re && l.im==r.im) 324 // (l.re==r.re && l.im==r.im)
325 llvm::Value* b1 = new llvm::FCmpInst(cmpop, a, c, "tmp", gIR->scopebb()); 325 LLValue* b1 = new llvm::FCmpInst(cmpop, a, c, "tmp", gIR->scopebb());
326 llvm::Value* b2 = new llvm::FCmpInst(cmpop, b, d, "tmp", gIR->scopebb()); 326 LLValue* b2 = new llvm::FCmpInst(cmpop, b, d, "tmp", gIR->scopebb());
327 return gIR->ir->CreateAnd(b1,b2,"tmp"); 327 return gIR->ir->CreateAnd(b1,b2,"tmp");
328 } 328 }