comparison gen/passes/GarbageCollect2Stack.cpp @ 1343:c21a6654cce2

Update for metadata changes in LLVM trunk.
author Frits van Bommel <fvbommel wxs.nl>
date Mon, 11 May 2009 11:59:22 +0200
parents 4099548c80e0
children 3297edb697eb
comparison
equal deleted inserted replaced
1342:16d9afa22df4 1343:c21a6654cce2
200 GlobalVariable* global = A.M.getGlobalVariable(metaname); 200 GlobalVariable* global = A.M.getGlobalVariable(metaname);
201 if (!global || !global->hasInitializer()) 201 if (!global || !global->hasInitializer())
202 return false; 202 return false;
203 203
204 MDNode* node = dyn_cast<MDNode>(global->getInitializer()); 204 MDNode* node = dyn_cast<MDNode>(global->getInitializer());
205 if (!node || node->getNumOperands() != CD_NumFields) 205 if (!node || MD_GetNumElements(node) != CD_NumFields)
206 return false; 206 return false;
207 207
208 // Inserting destructor calls is not implemented yet, so classes 208 // Inserting destructor calls is not implemented yet, so classes
209 // with destructors are ignored for now. 209 // with destructors are ignored for now.
210 Constant* hasDestructor = dyn_cast<Constant>(node->getOperand(CD_Finalize)); 210 Constant* hasDestructor = dyn_cast<Constant>(MD_GetElement(node, CD_Finalize));
211 // We can't stack-allocate if the class has a custom deallocator 211 // We can't stack-allocate if the class has a custom deallocator
212 // (Custom allocators don't get turned into this runtime call, so 212 // (Custom allocators don't get turned into this runtime call, so
213 // those can be ignored) 213 // those can be ignored)
214 Constant* hasCustomDelete = dyn_cast<Constant>(node->getOperand(CD_CustomDelete)); 214 Constant* hasCustomDelete = dyn_cast<Constant>(MD_GetElement(node, CD_CustomDelete));
215 if (hasDestructor == NULL || hasCustomDelete == NULL) 215 if (hasDestructor == NULL || hasCustomDelete == NULL)
216 return false; 216 return false;
217 217
218 if (ConstantExpr::getOr(hasDestructor, hasCustomDelete) 218 if (ConstantExpr::getOr(hasDestructor, hasCustomDelete)
219 != ConstantInt::getFalse()) 219 != ConstantInt::getFalse())
220 return false; 220 return false;
221 221
222 Ty = node->getOperand(CD_BodyType)->getType(); 222 Ty = MD_GetElement(node, CD_BodyType)->getType();
223 return true; 223 return true;
224 } 224 }
225 225
226 // The default promote() should be fine. 226 // The default promote() should be fine.
227 227
364 Changed = true; 364 Changed = true;
365 365
366 IRBuilder<> Builder(BB, Inst); 366 IRBuilder<> Builder(BB, Inst);
367 Value* newVal = info->promote(CS, Builder, A); 367 Value* newVal = info->promote(CS, Builder, A);
368 368
369 DEBUG(DOUT << "Promoted to: " << *newVal);
370
369 // Make sure the type is the same as it was before, and replace all 371 // Make sure the type is the same as it was before, and replace all
370 // uses of the runtime call with the alloca. 372 // uses of the runtime call with the alloca.
371 if (newVal->getType() != Inst->getType()) 373 if (newVal->getType() != Inst->getType())
372 newVal = Builder.CreateBitCast(newVal, Inst->getType()); 374 newVal = Builder.CreateBitCast(newVal, Inst->getType());
373 Inst->replaceAllUsesWith(newVal); 375 Inst->replaceAllUsesWith(newVal);
393 395
394 MDNode* node = dyn_cast<MDNode>(global->getInitializer()); 396 MDNode* node = dyn_cast<MDNode>(global->getInitializer());
395 if (!node) 397 if (!node)
396 return NULL; 398 return NULL;
397 399
398 if (node->getNumOperands() != TD_NumFields || 400 if (MD_GetNumElements(node) != TD_NumFields ||
399 (TD_Confirm >= 0 && node->getOperand(TD_Confirm)->stripPointerCasts() != ti_global)) 401 (TD_Confirm >= 0 && MD_GetElement(node, TD_Confirm)->stripPointerCasts() != ti_global))
400 return NULL; 402 return NULL;
401 403
402 return node->getOperand(TD_Type)->getType(); 404 return MD_GetElement(node, TD_Type)->getType();
403 } 405 }
404 406
405 407
406 #endif //USE_METADATA 408 #endif //USE_METADATA