LLVM API Documentation
00001 //===-- llvm/CodeGen/MachineModuleInfo.cpp ----------------------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 00010 #include "llvm/CodeGen/MachineModuleInfo.h" 00011 #include "llvm/ADT/PointerUnion.h" 00012 #include "llvm/Analysis/ValueTracking.h" 00013 #include "llvm/CodeGen/MachineFunction.h" 00014 #include "llvm/CodeGen/MachineFunctionPass.h" 00015 #include "llvm/CodeGen/Passes.h" 00016 #include "llvm/IR/Constants.h" 00017 #include "llvm/IR/DerivedTypes.h" 00018 #include "llvm/IR/GlobalVariable.h" 00019 #include "llvm/IR/Module.h" 00020 #include "llvm/MC/MCObjectFileInfo.h" 00021 #include "llvm/MC/MCSymbol.h" 00022 #include "llvm/Support/Dwarf.h" 00023 #include "llvm/Support/ErrorHandling.h" 00024 using namespace llvm; 00025 using namespace llvm::dwarf; 00026 00027 // Handle the Pass registration stuff necessary to use DataLayout's. 00028 INITIALIZE_PASS(MachineModuleInfo, "machinemoduleinfo", 00029 "Machine Module Information", false, false) 00030 char MachineModuleInfo::ID = 0; 00031 00032 // Out of line virtual method. 00033 MachineModuleInfoImpl::~MachineModuleInfoImpl() {} 00034 00035 namespace llvm { 00036 class MMIAddrLabelMapCallbackPtr : CallbackVH { 00037 MMIAddrLabelMap *Map; 00038 public: 00039 MMIAddrLabelMapCallbackPtr() : Map(0) {} 00040 MMIAddrLabelMapCallbackPtr(Value *V) : CallbackVH(V), Map(0) {} 00041 00042 void setPtr(BasicBlock *BB) { 00043 ValueHandleBase::operator=(BB); 00044 } 00045 00046 void setMap(MMIAddrLabelMap *map) { Map = map; } 00047 00048 virtual void deleted(); 00049 virtual void allUsesReplacedWith(Value *V2); 00050 }; 00051 00052 class MMIAddrLabelMap { 00053 MCContext &Context; 00054 struct AddrLabelSymEntry { 00055 /// Symbols - The symbols for the label. This is a pointer union that is 00056 /// either one symbol (the common case) or a list of symbols. 00057 PointerUnion<MCSymbol *, std::vector<MCSymbol*>*> Symbols; 00058 00059 Function *Fn; // The containing function of the BasicBlock. 00060 unsigned Index; // The index in BBCallbacks for the BasicBlock. 00061 }; 00062 00063 DenseMap<AssertingVH<BasicBlock>, AddrLabelSymEntry> AddrLabelSymbols; 00064 00065 /// BBCallbacks - Callbacks for the BasicBlock's that we have entries for. We 00066 /// use this so we get notified if a block is deleted or RAUWd. 00067 std::vector<MMIAddrLabelMapCallbackPtr> BBCallbacks; 00068 00069 /// DeletedAddrLabelsNeedingEmission - This is a per-function list of symbols 00070 /// whose corresponding BasicBlock got deleted. These symbols need to be 00071 /// emitted at some point in the file, so AsmPrinter emits them after the 00072 /// function body. 00073 DenseMap<AssertingVH<Function>, std::vector<MCSymbol*> > 00074 DeletedAddrLabelsNeedingEmission; 00075 public: 00076 00077 MMIAddrLabelMap(MCContext &context) : Context(context) {} 00078 ~MMIAddrLabelMap() { 00079 assert(DeletedAddrLabelsNeedingEmission.empty() && 00080 "Some labels for deleted blocks never got emitted"); 00081 00082 // Deallocate any of the 'list of symbols' case. 00083 for (DenseMap<AssertingVH<BasicBlock>, AddrLabelSymEntry>::iterator 00084 I = AddrLabelSymbols.begin(), E = AddrLabelSymbols.end(); I != E; ++I) 00085 if (I->second.Symbols.is<std::vector<MCSymbol*>*>()) 00086 delete I->second.Symbols.get<std::vector<MCSymbol*>*>(); 00087 } 00088 00089 MCSymbol *getAddrLabelSymbol(BasicBlock *BB); 00090 std::vector<MCSymbol*> getAddrLabelSymbolToEmit(BasicBlock *BB); 00091 00092 void takeDeletedSymbolsForFunction(Function *F, 00093 std::vector<MCSymbol*> &Result); 00094 00095 void UpdateForDeletedBlock(BasicBlock *BB); 00096 void UpdateForRAUWBlock(BasicBlock *Old, BasicBlock *New); 00097 }; 00098 } 00099 00100 MCSymbol *MMIAddrLabelMap::getAddrLabelSymbol(BasicBlock *BB) { 00101 assert(BB->hasAddressTaken() && 00102 "Shouldn't get label for block without address taken"); 00103 AddrLabelSymEntry &Entry = AddrLabelSymbols[BB]; 00104 00105 // If we already had an entry for this block, just return it. 00106 if (!Entry.Symbols.isNull()) { 00107 assert(BB->getParent() == Entry.Fn && "Parent changed"); 00108 if (Entry.Symbols.is<MCSymbol*>()) 00109 return Entry.Symbols.get<MCSymbol*>(); 00110 return (*Entry.Symbols.get<std::vector<MCSymbol*>*>())[0]; 00111 } 00112 00113 // Otherwise, this is a new entry, create a new symbol for it and add an 00114 // entry to BBCallbacks so we can be notified if the BB is deleted or RAUWd. 00115 BBCallbacks.push_back(BB); 00116 BBCallbacks.back().setMap(this); 00117 Entry.Index = BBCallbacks.size()-1; 00118 Entry.Fn = BB->getParent(); 00119 MCSymbol *Result = Context.CreateTempSymbol(); 00120 Entry.Symbols = Result; 00121 return Result; 00122 } 00123 00124 std::vector<MCSymbol*> 00125 MMIAddrLabelMap::getAddrLabelSymbolToEmit(BasicBlock *BB) { 00126 assert(BB->hasAddressTaken() && 00127 "Shouldn't get label for block without address taken"); 00128 AddrLabelSymEntry &Entry = AddrLabelSymbols[BB]; 00129 00130 std::vector<MCSymbol*> Result; 00131 00132 // If we already had an entry for this block, just return it. 00133 if (Entry.Symbols.isNull()) 00134 Result.push_back(getAddrLabelSymbol(BB)); 00135 else if (MCSymbol *Sym = Entry.Symbols.dyn_cast<MCSymbol*>()) 00136 Result.push_back(Sym); 00137 else 00138 Result = *Entry.Symbols.get<std::vector<MCSymbol*>*>(); 00139 return Result; 00140 } 00141 00142 00143 /// takeDeletedSymbolsForFunction - If we have any deleted symbols for F, return 00144 /// them. 00145 void MMIAddrLabelMap:: 00146 takeDeletedSymbolsForFunction(Function *F, std::vector<MCSymbol*> &Result) { 00147 DenseMap<AssertingVH<Function>, std::vector<MCSymbol*> >::iterator I = 00148 DeletedAddrLabelsNeedingEmission.find(F); 00149 00150 // If there are no entries for the function, just return. 00151 if (I == DeletedAddrLabelsNeedingEmission.end()) return; 00152 00153 // Otherwise, take the list. 00154 std::swap(Result, I->second); 00155 DeletedAddrLabelsNeedingEmission.erase(I); 00156 } 00157 00158 00159 void MMIAddrLabelMap::UpdateForDeletedBlock(BasicBlock *BB) { 00160 // If the block got deleted, there is no need for the symbol. If the symbol 00161 // was already emitted, we can just forget about it, otherwise we need to 00162 // queue it up for later emission when the function is output. 00163 AddrLabelSymEntry Entry = AddrLabelSymbols[BB]; 00164 AddrLabelSymbols.erase(BB); 00165 assert(!Entry.Symbols.isNull() && "Didn't have a symbol, why a callback?"); 00166 BBCallbacks[Entry.Index] = 0; // Clear the callback. 00167 00168 assert((BB->getParent() == 0 || BB->getParent() == Entry.Fn) && 00169 "Block/parent mismatch"); 00170 00171 // Handle both the single and the multiple symbols cases. 00172 if (MCSymbol *Sym = Entry.Symbols.dyn_cast<MCSymbol*>()) { 00173 if (Sym->isDefined()) 00174 return; 00175 00176 // If the block is not yet defined, we need to emit it at the end of the 00177 // function. Add the symbol to the DeletedAddrLabelsNeedingEmission list 00178 // for the containing Function. Since the block is being deleted, its 00179 // parent may already be removed, we have to get the function from 'Entry'. 00180 DeletedAddrLabelsNeedingEmission[Entry.Fn].push_back(Sym); 00181 } else { 00182 std::vector<MCSymbol*> *Syms = Entry.Symbols.get<std::vector<MCSymbol*>*>(); 00183 00184 for (unsigned i = 0, e = Syms->size(); i != e; ++i) { 00185 MCSymbol *Sym = (*Syms)[i]; 00186 if (Sym->isDefined()) continue; // Ignore already emitted labels. 00187 00188 // If the block is not yet defined, we need to emit it at the end of the 00189 // function. Add the symbol to the DeletedAddrLabelsNeedingEmission list 00190 // for the containing Function. Since the block is being deleted, its 00191 // parent may already be removed, we have to get the function from 00192 // 'Entry'. 00193 DeletedAddrLabelsNeedingEmission[Entry.Fn].push_back(Sym); 00194 } 00195 00196 // The entry is deleted, free the memory associated with the symbol list. 00197 delete Syms; 00198 } 00199 } 00200 00201 void MMIAddrLabelMap::UpdateForRAUWBlock(BasicBlock *Old, BasicBlock *New) { 00202 // Get the entry for the RAUW'd block and remove it from our map. 00203 AddrLabelSymEntry OldEntry = AddrLabelSymbols[Old]; 00204 AddrLabelSymbols.erase(Old); 00205 assert(!OldEntry.Symbols.isNull() && "Didn't have a symbol, why a callback?"); 00206 00207 AddrLabelSymEntry &NewEntry = AddrLabelSymbols[New]; 00208 00209 // If New is not address taken, just move our symbol over to it. 00210 if (NewEntry.Symbols.isNull()) { 00211 BBCallbacks[OldEntry.Index].setPtr(New); // Update the callback. 00212 NewEntry = OldEntry; // Set New's entry. 00213 return; 00214 } 00215 00216 BBCallbacks[OldEntry.Index] = 0; // Update the callback. 00217 00218 // Otherwise, we need to add the old symbol to the new block's set. If it is 00219 // just a single entry, upgrade it to a symbol list. 00220 if (MCSymbol *PrevSym = NewEntry.Symbols.dyn_cast<MCSymbol*>()) { 00221 std::vector<MCSymbol*> *SymList = new std::vector<MCSymbol*>(); 00222 SymList->push_back(PrevSym); 00223 NewEntry.Symbols = SymList; 00224 } 00225 00226 std::vector<MCSymbol*> *SymList = 00227 NewEntry.Symbols.get<std::vector<MCSymbol*>*>(); 00228 00229 // If the old entry was a single symbol, add it. 00230 if (MCSymbol *Sym = OldEntry.Symbols.dyn_cast<MCSymbol*>()) { 00231 SymList->push_back(Sym); 00232 return; 00233 } 00234 00235 // Otherwise, concatenate the list. 00236 std::vector<MCSymbol*> *Syms =OldEntry.Symbols.get<std::vector<MCSymbol*>*>(); 00237 SymList->insert(SymList->end(), Syms->begin(), Syms->end()); 00238 delete Syms; 00239 } 00240 00241 00242 void MMIAddrLabelMapCallbackPtr::deleted() { 00243 Map->UpdateForDeletedBlock(cast<BasicBlock>(getValPtr())); 00244 } 00245 00246 void MMIAddrLabelMapCallbackPtr::allUsesReplacedWith(Value *V2) { 00247 Map->UpdateForRAUWBlock(cast<BasicBlock>(getValPtr()), cast<BasicBlock>(V2)); 00248 } 00249 00250 00251 //===----------------------------------------------------------------------===// 00252 00253 MachineModuleInfo::MachineModuleInfo(const MCAsmInfo &MAI, 00254 const MCRegisterInfo &MRI, 00255 const MCObjectFileInfo *MOFI) 00256 : ImmutablePass(ID), Context(&MAI, &MRI, MOFI, 0, false) { 00257 initializeMachineModuleInfoPass(*PassRegistry::getPassRegistry()); 00258 } 00259 00260 MachineModuleInfo::MachineModuleInfo() 00261 : ImmutablePass(ID), Context(0, 0, 0) { 00262 llvm_unreachable("This MachineModuleInfo constructor should never be called, " 00263 "MMI should always be explicitly constructed by " 00264 "LLVMTargetMachine"); 00265 } 00266 00267 MachineModuleInfo::~MachineModuleInfo() { 00268 } 00269 00270 bool MachineModuleInfo::doInitialization(Module &M) { 00271 00272 ObjFileMMI = 0; 00273 CompactUnwindEncoding = 0; 00274 CurCallSite = 0; 00275 CallsEHReturn = 0; 00276 CallsUnwindInit = 0; 00277 DbgInfoAvailable = UsesVAFloatArgument = false; 00278 // Always emit some info, by default "no personality" info. 00279 Personalities.push_back(NULL); 00280 AddrLabelSymbols = 0; 00281 TheModule = 0; 00282 00283 return false; 00284 } 00285 00286 bool MachineModuleInfo::doFinalization(Module &M) { 00287 00288 Personalities.clear(); 00289 00290 delete AddrLabelSymbols; 00291 AddrLabelSymbols = 0; 00292 00293 Context.reset(); 00294 00295 delete ObjFileMMI; 00296 ObjFileMMI = 0; 00297 00298 return false; 00299 } 00300 00301 /// EndFunction - Discard function meta information. 00302 /// 00303 void MachineModuleInfo::EndFunction() { 00304 // Clean up frame info. 00305 FrameInstructions.clear(); 00306 00307 // Clean up exception info. 00308 LandingPads.clear(); 00309 CallSiteMap.clear(); 00310 TypeInfos.clear(); 00311 FilterIds.clear(); 00312 FilterEnds.clear(); 00313 CallsEHReturn = 0; 00314 CallsUnwindInit = 0; 00315 CompactUnwindEncoding = 0; 00316 VariableDbgInfo.clear(); 00317 } 00318 00319 /// AnalyzeModule - Scan the module for global debug information. 00320 /// 00321 void MachineModuleInfo::AnalyzeModule(const Module &M) { 00322 // Insert functions in the llvm.used array (but not llvm.compiler.used) into 00323 // UsedFunctions. 00324 const GlobalVariable *GV = M.getGlobalVariable("llvm.used"); 00325 if (!GV || !GV->hasInitializer()) return; 00326 00327 // Should be an array of 'i8*'. 00328 const ConstantArray *InitList = cast<ConstantArray>(GV->getInitializer()); 00329 00330 for (unsigned i = 0, e = InitList->getNumOperands(); i != e; ++i) 00331 if (const Function *F = 00332 dyn_cast<Function>(InitList->getOperand(i)->stripPointerCasts())) 00333 UsedFunctions.insert(F); 00334 } 00335 00336 //===- Address of Block Management ----------------------------------------===// 00337 00338 00339 /// getAddrLabelSymbol - Return the symbol to be used for the specified basic 00340 /// block when its address is taken. This cannot be its normal LBB label 00341 /// because the block may be accessed outside its containing function. 00342 MCSymbol *MachineModuleInfo::getAddrLabelSymbol(const BasicBlock *BB) { 00343 // Lazily create AddrLabelSymbols. 00344 if (AddrLabelSymbols == 0) 00345 AddrLabelSymbols = new MMIAddrLabelMap(Context); 00346 return AddrLabelSymbols->getAddrLabelSymbol(const_cast<BasicBlock*>(BB)); 00347 } 00348 00349 /// getAddrLabelSymbolToEmit - Return the symbol to be used for the specified 00350 /// basic block when its address is taken. If other blocks were RAUW'd to 00351 /// this one, we may have to emit them as well, return the whole set. 00352 std::vector<MCSymbol*> MachineModuleInfo:: 00353 getAddrLabelSymbolToEmit(const BasicBlock *BB) { 00354 // Lazily create AddrLabelSymbols. 00355 if (AddrLabelSymbols == 0) 00356 AddrLabelSymbols = new MMIAddrLabelMap(Context); 00357 return AddrLabelSymbols->getAddrLabelSymbolToEmit(const_cast<BasicBlock*>(BB)); 00358 } 00359 00360 00361 /// takeDeletedSymbolsForFunction - If the specified function has had any 00362 /// references to address-taken blocks generated, but the block got deleted, 00363 /// return the symbol now so we can emit it. This prevents emitting a 00364 /// reference to a symbol that has no definition. 00365 void MachineModuleInfo:: 00366 takeDeletedSymbolsForFunction(const Function *F, 00367 std::vector<MCSymbol*> &Result) { 00368 // If no blocks have had their addresses taken, we're done. 00369 if (AddrLabelSymbols == 0) return; 00370 return AddrLabelSymbols-> 00371 takeDeletedSymbolsForFunction(const_cast<Function*>(F), Result); 00372 } 00373 00374 //===- EH -----------------------------------------------------------------===// 00375 00376 /// getOrCreateLandingPadInfo - Find or create an LandingPadInfo for the 00377 /// specified MachineBasicBlock. 00378 LandingPadInfo &MachineModuleInfo::getOrCreateLandingPadInfo 00379 (MachineBasicBlock *LandingPad) { 00380 unsigned N = LandingPads.size(); 00381 for (unsigned i = 0; i < N; ++i) { 00382 LandingPadInfo &LP = LandingPads[i]; 00383 if (LP.LandingPadBlock == LandingPad) 00384 return LP; 00385 } 00386 00387 LandingPads.push_back(LandingPadInfo(LandingPad)); 00388 return LandingPads[N]; 00389 } 00390 00391 /// addInvoke - Provide the begin and end labels of an invoke style call and 00392 /// associate it with a try landing pad block. 00393 void MachineModuleInfo::addInvoke(MachineBasicBlock *LandingPad, 00394 MCSymbol *BeginLabel, MCSymbol *EndLabel) { 00395 LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad); 00396 LP.BeginLabels.push_back(BeginLabel); 00397 LP.EndLabels.push_back(EndLabel); 00398 } 00399 00400 /// addLandingPad - Provide the label of a try LandingPad block. 00401 /// 00402 MCSymbol *MachineModuleInfo::addLandingPad(MachineBasicBlock *LandingPad) { 00403 MCSymbol *LandingPadLabel = Context.CreateTempSymbol(); 00404 LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad); 00405 LP.LandingPadLabel = LandingPadLabel; 00406 return LandingPadLabel; 00407 } 00408 00409 /// addPersonality - Provide the personality function for the exception 00410 /// information. 00411 void MachineModuleInfo::addPersonality(MachineBasicBlock *LandingPad, 00412 const Function *Personality) { 00413 LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad); 00414 LP.Personality = Personality; 00415 00416 for (unsigned i = 0; i < Personalities.size(); ++i) 00417 if (Personalities[i] == Personality) 00418 return; 00419 00420 // If this is the first personality we're adding go 00421 // ahead and add it at the beginning. 00422 if (Personalities[0] == NULL) 00423 Personalities[0] = Personality; 00424 else 00425 Personalities.push_back(Personality); 00426 } 00427 00428 /// addCatchTypeInfo - Provide the catch typeinfo for a landing pad. 00429 /// 00430 void MachineModuleInfo:: 00431 addCatchTypeInfo(MachineBasicBlock *LandingPad, 00432 ArrayRef<const GlobalVariable *> TyInfo) { 00433 LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad); 00434 for (unsigned N = TyInfo.size(); N; --N) 00435 LP.TypeIds.push_back(getTypeIDFor(TyInfo[N - 1])); 00436 } 00437 00438 /// addFilterTypeInfo - Provide the filter typeinfo for a landing pad. 00439 /// 00440 void MachineModuleInfo:: 00441 addFilterTypeInfo(MachineBasicBlock *LandingPad, 00442 ArrayRef<const GlobalVariable *> TyInfo) { 00443 LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad); 00444 std::vector<unsigned> IdsInFilter(TyInfo.size()); 00445 for (unsigned I = 0, E = TyInfo.size(); I != E; ++I) 00446 IdsInFilter[I] = getTypeIDFor(TyInfo[I]); 00447 LP.TypeIds.push_back(getFilterIDFor(IdsInFilter)); 00448 } 00449 00450 /// addCleanup - Add a cleanup action for a landing pad. 00451 /// 00452 void MachineModuleInfo::addCleanup(MachineBasicBlock *LandingPad) { 00453 LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad); 00454 LP.TypeIds.push_back(0); 00455 } 00456 00457 /// TidyLandingPads - Remap landing pad labels and remove any deleted landing 00458 /// pads. 00459 void MachineModuleInfo::TidyLandingPads(DenseMap<MCSymbol*, uintptr_t> *LPMap) { 00460 for (unsigned i = 0; i != LandingPads.size(); ) { 00461 LandingPadInfo &LandingPad = LandingPads[i]; 00462 if (LandingPad.LandingPadLabel && 00463 !LandingPad.LandingPadLabel->isDefined() && 00464 (!LPMap || (*LPMap)[LandingPad.LandingPadLabel] == 0)) 00465 LandingPad.LandingPadLabel = 0; 00466 00467 // Special case: we *should* emit LPs with null LP MBB. This indicates 00468 // "nounwind" case. 00469 if (!LandingPad.LandingPadLabel && LandingPad.LandingPadBlock) { 00470 LandingPads.erase(LandingPads.begin() + i); 00471 continue; 00472 } 00473 00474 for (unsigned j = 0, e = LandingPads[i].BeginLabels.size(); j != e; ++j) { 00475 MCSymbol *BeginLabel = LandingPad.BeginLabels[j]; 00476 MCSymbol *EndLabel = LandingPad.EndLabels[j]; 00477 if ((BeginLabel->isDefined() || 00478 (LPMap && (*LPMap)[BeginLabel] != 0)) && 00479 (EndLabel->isDefined() || 00480 (LPMap && (*LPMap)[EndLabel] != 0))) continue; 00481 00482 LandingPad.BeginLabels.erase(LandingPad.BeginLabels.begin() + j); 00483 LandingPad.EndLabels.erase(LandingPad.EndLabels.begin() + j); 00484 --j, --e; 00485 } 00486 00487 // Remove landing pads with no try-ranges. 00488 if (LandingPads[i].BeginLabels.empty()) { 00489 LandingPads.erase(LandingPads.begin() + i); 00490 continue; 00491 } 00492 00493 // If there is no landing pad, ensure that the list of typeids is empty. 00494 // If the only typeid is a cleanup, this is the same as having no typeids. 00495 if (!LandingPad.LandingPadBlock || 00496 (LandingPad.TypeIds.size() == 1 && !LandingPad.TypeIds[0])) 00497 LandingPad.TypeIds.clear(); 00498 ++i; 00499 } 00500 } 00501 00502 /// setCallSiteLandingPad - Map the landing pad's EH symbol to the call site 00503 /// indexes. 00504 void MachineModuleInfo::setCallSiteLandingPad(MCSymbol *Sym, 00505 ArrayRef<unsigned> Sites) { 00506 LPadToCallSiteMap[Sym].append(Sites.begin(), Sites.end()); 00507 } 00508 00509 /// getTypeIDFor - Return the type id for the specified typeinfo. This is 00510 /// function wide. 00511 unsigned MachineModuleInfo::getTypeIDFor(const GlobalVariable *TI) { 00512 for (unsigned i = 0, N = TypeInfos.size(); i != N; ++i) 00513 if (TypeInfos[i] == TI) return i + 1; 00514 00515 TypeInfos.push_back(TI); 00516 return TypeInfos.size(); 00517 } 00518 00519 /// getFilterIDFor - Return the filter id for the specified typeinfos. This is 00520 /// function wide. 00521 int MachineModuleInfo::getFilterIDFor(std::vector<unsigned> &TyIds) { 00522 // If the new filter coincides with the tail of an existing filter, then 00523 // re-use the existing filter. Folding filters more than this requires 00524 // re-ordering filters and/or their elements - probably not worth it. 00525 for (std::vector<unsigned>::iterator I = FilterEnds.begin(), 00526 E = FilterEnds.end(); I != E; ++I) { 00527 unsigned i = *I, j = TyIds.size(); 00528 00529 while (i && j) 00530 if (FilterIds[--i] != TyIds[--j]) 00531 goto try_next; 00532 00533 if (!j) 00534 // The new filter coincides with range [i, end) of the existing filter. 00535 return -(1 + i); 00536 00537 try_next:; 00538 } 00539 00540 // Add the new filter. 00541 int FilterID = -(1 + FilterIds.size()); 00542 FilterIds.reserve(FilterIds.size() + TyIds.size() + 1); 00543 FilterIds.insert(FilterIds.end(), TyIds.begin(), TyIds.end()); 00544 FilterEnds.push_back(FilterIds.size()); 00545 FilterIds.push_back(0); // terminator 00546 return FilterID; 00547 } 00548 00549 /// getPersonality - Return the personality function for the current function. 00550 const Function *MachineModuleInfo::getPersonality() const { 00551 // FIXME: Until PR1414 will be fixed, we're using 1 personality function per 00552 // function 00553 return !LandingPads.empty() ? LandingPads[0].Personality : NULL; 00554 } 00555 00556 /// getPersonalityIndex - Return unique index for current personality 00557 /// function. NULL/first personality function should always get zero index. 00558 unsigned MachineModuleInfo::getPersonalityIndex() const { 00559 const Function* Personality = NULL; 00560 00561 // Scan landing pads. If there is at least one non-NULL personality - use it. 00562 for (unsigned i = 0, e = LandingPads.size(); i != e; ++i) 00563 if (LandingPads[i].Personality) { 00564 Personality = LandingPads[i].Personality; 00565 break; 00566 } 00567 00568 for (unsigned i = 0, e = Personalities.size(); i < e; ++i) { 00569 if (Personalities[i] == Personality) 00570 return i; 00571 } 00572 00573 // This will happen if the current personality function is 00574 // in the zero index. 00575 return 0; 00576 }