Mercurial > projects > ldc
comparison gen/toir.cpp @ 622:26fce59fe80a
Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Commented some logging calls that could potentially write out many megabytes of type dumps.
author | Tomas Lindquist Olsen <tomas.l.olsen@gmail.com> |
---|---|
date | Wed, 01 Oct 2008 18:32:31 +0200 |
parents | 722630261d62 |
children | eb444ed4a2d3 |
comparison
equal
deleted
inserted
replaced
619:722630261d62 | 622:26fce59fe80a |
---|---|
130 vd->toObjFile(0); // TODO: multiobj | 130 vd->toObjFile(0); // TODO: multiobj |
131 DtoConstInitGlobal(vd); | 131 DtoConstInitGlobal(vd); |
132 } | 132 } |
133 if (!vd->ir.isSet() || !vd->ir.getIrValue() || DtoType(vd->type)->isAbstract()) { | 133 if (!vd->ir.isSet() || !vd->ir.getIrValue() || DtoType(vd->type)->isAbstract()) { |
134 error("global variable %s not resolved", vd->toChars()); | 134 error("global variable %s not resolved", vd->toChars()); |
135 Logger::cout() << "unresolved global had type: " << *DtoType(vd->type) << '\n'; | 135 if (Logger::enabled()) |
136 Logger::cout() << "unresolved global had type: " << *DtoType(vd->type) << '\n'; | |
136 fatal(); | 137 fatal(); |
137 } | 138 } |
138 return new DVarValue(type, vd, vd->ir.getIrValue()); | 139 return new DVarValue(type, vd, vd->ir.getIrValue()); |
139 } | 140 } |
140 } | 141 } |
220 return llvm::ConstantExpr::getIntToPtr(i, t); | 221 return llvm::ConstantExpr::getIntToPtr(i, t); |
221 } | 222 } |
222 assert(llvm::isa<LLIntegerType>(t)); | 223 assert(llvm::isa<LLIntegerType>(t)); |
223 LLConstant* c = llvm::ConstantInt::get(t,(uint64_t)value,!type->isunsigned()); | 224 LLConstant* c = llvm::ConstantInt::get(t,(uint64_t)value,!type->isunsigned()); |
224 assert(c); | 225 assert(c); |
225 Logger::cout() << "value = " << *c << '\n'; | 226 if (Logger::enabled()) |
227 Logger::cout() << "value = " << *c << '\n'; | |
226 return c; | 228 return c; |
227 } | 229 } |
228 | 230 |
229 ////////////////////////////////////////////////////////////////////////////////////////// | 231 ////////////////////////////////////////////////////////////////////////////////////////// |
230 | 232 |
351 } | 353 } |
352 else | 354 else |
353 assert(0); | 355 assert(0); |
354 | 356 |
355 llvm::GlobalValue::LinkageTypes _linkage = llvm::GlobalValue::InternalLinkage;//WeakLinkage; | 357 llvm::GlobalValue::LinkageTypes _linkage = llvm::GlobalValue::InternalLinkage;//WeakLinkage; |
356 Logger::cout() << "type: " << *at << "\ninit: " << *_init << '\n'; | 358 if (Logger::enabled()) |
359 Logger::cout() << "type: " << *at << "\ninit: " << *_init << '\n'; | |
357 llvm::GlobalVariable* gvar = new llvm::GlobalVariable(at,true,_linkage,_init,".stringliteral",gIR->module); | 360 llvm::GlobalVariable* gvar = new llvm::GlobalVariable(at,true,_linkage,_init,".stringliteral",gIR->module); |
358 | 361 |
359 llvm::ConstantInt* zero = llvm::ConstantInt::get(LLType::Int32Ty, 0, false); | 362 llvm::ConstantInt* zero = llvm::ConstantInt::get(LLType::Int32Ty, 0, false); |
360 LLConstant* idxs[2] = { zero, zero }; | 363 LLConstant* idxs[2] = { zero, zero }; |
361 LLConstant* arrptr = llvm::ConstantExpr::getGetElementPtr(gvar,idxs,2); | 364 LLConstant* arrptr = llvm::ConstantExpr::getGetElementPtr(gvar,idxs,2); |
586 Type* t2 = e2->type->toBasetype(); | 589 Type* t2 = e2->type->toBasetype(); |
587 | 590 |
588 if (t1->ty == Tpointer && t2->ty == Tpointer) { | 591 if (t1->ty == Tpointer && t2->ty == Tpointer) { |
589 LLValue* lv = l->getRVal(); | 592 LLValue* lv = l->getRVal(); |
590 LLValue* rv = r->getRVal(); | 593 LLValue* rv = r->getRVal(); |
591 Logger::cout() << "lv: " << *lv << " rv: " << *rv << '\n'; | 594 if (Logger::enabled()) |
595 Logger::cout() << "lv: " << *lv << " rv: " << *rv << '\n'; | |
592 lv = p->ir->CreatePtrToInt(lv, DtoSize_t(), "tmp"); | 596 lv = p->ir->CreatePtrToInt(lv, DtoSize_t(), "tmp"); |
593 rv = p->ir->CreatePtrToInt(rv, DtoSize_t(), "tmp"); | 597 rv = p->ir->CreatePtrToInt(rv, DtoSize_t(), "tmp"); |
594 LLValue* diff = p->ir->CreateSub(lv,rv,"tmp"); | 598 LLValue* diff = p->ir->CreateSub(lv,rv,"tmp"); |
595 if (diff->getType() != DtoType(type)) | 599 if (diff->getType() != DtoType(type)) |
596 diff = p->ir->CreateIntToPtr(diff, DtoType(type), "tmp"); | 600 diff = p->ir->CreateIntToPtr(diff, DtoType(type), "tmp"); |
867 Logger::println("is immediate"); | 871 Logger::println("is immediate"); |
868 return v; | 872 return v; |
869 } | 873 } |
870 Logger::println("is nothing special"); | 874 Logger::println("is nothing special"); |
871 LLValue* lval = v->getLVal(); | 875 LLValue* lval = v->getLVal(); |
872 Logger::cout() << "lval: " << *lval << '\n'; | 876 if (Logger::enabled()) |
877 Logger::cout() << "lval: " << *lval << '\n'; | |
873 return new DImValue(type, DtoBitCast(v->getLVal(), DtoType(type))); | 878 return new DImValue(type, DtoBitCast(v->getLVal(), DtoType(type))); |
874 } | 879 } |
875 | 880 |
876 LLConstant* AddrExp::toConstElem(IRState* p) | 881 LLConstant* AddrExp::toConstElem(IRState* p) |
877 { | 882 { |
1007 assert(fdecl->vtblIndex > 0); | 1012 assert(fdecl->vtblIndex > 0); |
1008 assert(e1type->ty == Tclass); | 1013 assert(e1type->ty == Tclass); |
1009 | 1014 |
1010 LLValue* zero = llvm::ConstantInt::get(LLType::Int32Ty, 0, false); | 1015 LLValue* zero = llvm::ConstantInt::get(LLType::Int32Ty, 0, false); |
1011 LLValue* vtblidx = llvm::ConstantInt::get(LLType::Int32Ty, (size_t)fdecl->vtblIndex, false); | 1016 LLValue* vtblidx = llvm::ConstantInt::get(LLType::Int32Ty, (size_t)fdecl->vtblIndex, false); |
1012 Logger::cout() << "vthis: " << *vthis << '\n'; | 1017 if (Logger::enabled()) |
1018 Logger::cout() << "vthis: " << *vthis << '\n'; | |
1013 funcval = DtoGEP(vthis, zero, zero); | 1019 funcval = DtoGEP(vthis, zero, zero); |
1014 funcval = DtoLoad(funcval); | 1020 funcval = DtoLoad(funcval); |
1015 funcval = DtoGEP(funcval, zero, vtblidx, toChars()); | 1021 funcval = DtoGEP(funcval, zero, vtblidx, toChars()); |
1016 funcval = DtoLoad(funcval); | 1022 funcval = DtoLoad(funcval); |
1017 #if OPAQUE_VTBLS | 1023 #if OPAQUE_VTBLS |
1018 funcval = DtoBitCast(funcval, getPtrToType(DtoType(fdecl->type))); | 1024 funcval = DtoBitCast(funcval, getPtrToType(DtoType(fdecl->type))); |
1019 Logger::cout() << "funcval casted: " << *funcval << '\n'; | 1025 if (Logger::enabled()) |
1026 Logger::cout() << "funcval casted: " << *funcval << '\n'; | |
1020 #endif | 1027 #endif |
1021 } | 1028 } |
1022 // static call | 1029 // static call |
1023 else { | 1030 else { |
1024 DtoForceDeclareDsymbol(fdecl); | 1031 DtoForceDeclareDsymbol(fdecl); |
1246 } | 1253 } |
1247 if (!skip) | 1254 if (!skip) |
1248 { | 1255 { |
1249 LLValue* a = l->getRVal(); | 1256 LLValue* a = l->getRVal(); |
1250 LLValue* b = r->getRVal(); | 1257 LLValue* b = r->getRVal(); |
1251 Logger::cout() << "type 1: " << *a << '\n'; | 1258 if (Logger::enabled()) |
1252 Logger::cout() << "type 2: " << *b << '\n'; | 1259 { |
1260 Logger::cout() << "type 1: " << *a << '\n'; | |
1261 Logger::cout() << "type 2: " << *b << '\n'; | |
1262 } | |
1253 if (a->getType() != b->getType()) | 1263 if (a->getType() != b->getType()) |
1254 b = DtoBitCast(b, a->getType()); | 1264 b = DtoBitCast(b, a->getType()); |
1255 eval = p->ir->CreateICmp(cmpop, a, b, "tmp"); | 1265 eval = p->ir->CreateICmp(cmpop, a, b, "tmp"); |
1256 } | 1266 } |
1257 } | 1267 } |
1869 } | 1879 } |
1870 } | 1880 } |
1871 uval = src->getRVal(); | 1881 uval = src->getRVal(); |
1872 } | 1882 } |
1873 | 1883 |
1874 Logger::cout() << "context = " << *uval << '\n'; | 1884 if (Logger::enabled()) |
1885 Logger::cout() << "context = " << *uval << '\n'; | |
1875 | 1886 |
1876 LLValue* context = DtoGEPi(lval,0,0); | 1887 LLValue* context = DtoGEPi(lval,0,0); |
1877 LLValue* castcontext = DtoBitCast(uval, int8ptrty); | 1888 LLValue* castcontext = DtoBitCast(uval, int8ptrty); |
1878 DtoStore(castcontext, context); | 1889 DtoStore(castcontext, context); |
1879 | 1890 |
2158 // length | 2169 // length |
2159 size_t len = elements->dim; | 2170 size_t len = elements->dim; |
2160 | 2171 |
2161 // llvm target type | 2172 // llvm target type |
2162 const LLType* llType = DtoType(arrayType); | 2173 const LLType* llType = DtoType(arrayType); |
2163 Logger::cout() << (dyn?"dynamic":"static") << " array literal with length " << len << " of D type: '" << arrayType->toChars() << "' has llvm type: '" << *llType << "'\n"; | 2174 if (Logger::enabled()) |
2175 Logger::cout() << (dyn?"dynamic":"static") << " array literal with length " << len << " of D type: '" << arrayType->toChars() << "' has llvm type: '" << *llType << "'\n"; | |
2164 | 2176 |
2165 // llvm storage type | 2177 // llvm storage type |
2166 const LLType* llElemType = DtoTypeNotVoid(elemType); | 2178 const LLType* llElemType = DtoTypeNotVoid(elemType); |
2167 const LLType* llStoType = LLArrayType::get(llElemType, len); | 2179 const LLType* llStoType = LLArrayType::get(llElemType, len); |
2168 Logger::cout() << "llvm storage type: '" << *llStoType << "'\n"; | 2180 if (Logger::enabled()) |
2181 Logger::cout() << "llvm storage type: '" << *llStoType << "'\n"; | |
2169 | 2182 |
2170 // don't allocate storage for zero length dynamic array literals | 2183 // don't allocate storage for zero length dynamic array literals |
2171 if (dyn && len == 0) | 2184 if (dyn && len == 0) |
2172 { | 2185 { |
2173 // dmd seems to just make them null... | 2186 // dmd seems to just make them null... |
2283 tys.push_back(DtoType(vx->type)); | 2296 tys.push_back(DtoType(vx->type)); |
2284 } | 2297 } |
2285 const LLStructType* t = LLStructType::get(tys, sd->ir.irStruct->packed); | 2298 const LLStructType* t = LLStructType::get(tys, sd->ir.irStruct->packed); |
2286 if (t != llt) { | 2299 if (t != llt) { |
2287 if (getABITypeSize(t) != getABITypeSize(llt)) { | 2300 if (getABITypeSize(t) != getABITypeSize(llt)) { |
2288 Logger::cout() << "got size " << getABITypeSize(t) << ", expected " << getABITypeSize(llt) << '\n'; | 2301 if (Logger::enabled()) |
2302 Logger::cout() << "got size " << getABITypeSize(t) << ", expected " << getABITypeSize(llt) << '\n'; | |
2289 assert(0 && "type size mismatch"); | 2303 assert(0 && "type size mismatch"); |
2290 } | 2304 } |
2291 sptr = DtoBitCast(sptr, getPtrToType(t)); | 2305 sptr = DtoBitCast(sptr, getPtrToType(t)); |
2292 Logger::cout() << "sptr type is now: " << *t << '\n'; | 2306 if (Logger::enabled()) |
2307 Logger::cout() << "sptr type is now: " << *t << '\n'; | |
2293 } | 2308 } |
2294 } | 2309 } |
2295 | 2310 |
2296 // build | 2311 // build |
2297 unsigned j = 0; | 2312 unsigned j = 0; |
2298 for (unsigned i=0; i<n; ++i) | 2313 for (unsigned i=0; i<n; ++i) |
2299 { | 2314 { |
2300 Expression* vx = (Expression*)elements->data[i]; | 2315 Expression* vx = (Expression*)elements->data[i]; |
2301 if (!vx) continue; | 2316 if (!vx) continue; |
2302 | 2317 |
2303 Logger::cout() << "getting index " << j << " of " << *sptr << '\n'; | 2318 if (Logger::enabled()) |
2319 Logger::cout() << "getting index " << j << " of " << *sptr << '\n'; | |
2304 LLValue* arrptr = DtoGEPi(sptr,0,j); | 2320 LLValue* arrptr = DtoGEPi(sptr,0,j); |
2305 DValue* darrptr = new DVarValue(vx->type, arrptr); | 2321 DValue* darrptr = new DVarValue(vx->type, arrptr); |
2306 | 2322 |
2307 DValue* ve = vx->toElem(p); | 2323 DValue* ve = vx->toElem(p); |
2308 DtoAssign(loc, darrptr, ve); | 2324 DtoAssign(loc, darrptr, ve); |