X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FCodeGen%2FMachineModuleInfo.cpp;h=8360745ff167268a5c6619287b56f3ee2875e067;hb=c92da3882ee4e18153bb36fcdf33af393aba8259;hp=32d8394527a1ae7d3447e03181108ee0c1248d7f;hpb=73ef58ab92d5cd23b119b7f206e5f8a8c529098d;p=oota-llvm.git diff --git a/lib/CodeGen/MachineModuleInfo.cpp b/lib/CodeGen/MachineModuleInfo.cpp index 32d8394527a..8360745ff16 100644 --- a/lib/CodeGen/MachineModuleInfo.cpp +++ b/lib/CodeGen/MachineModuleInfo.cpp @@ -1476,6 +1476,8 @@ MachineModuleInfo::MachineModuleInfo() , FrameMoves() , LandingPads() , Personalities() +, CallsEHReturn(0) +, CallsUnwindInit(0) { // Always emit "no personality" info Personalities.push_back(NULL); @@ -1522,6 +1524,9 @@ void MachineModuleInfo::EndFunction() { LandingPads.clear(); TypeInfos.clear(); FilterIds.clear(); + FilterEnds.clear(); + CallsEHReturn = 0; + CallsUnwindInit = 0; } /// getDescFor - Convert a Value to a debug information descriptor. @@ -1721,6 +1726,13 @@ void MachineModuleInfo::addFilterTypeInfo(MachineBasicBlock *LandingPad, LP.TypeIds.push_back(getFilterIDFor(IdsInFilter)); } +/// addCleanup - Add a cleanup action for a landing pad. +/// +void MachineModuleInfo::addCleanup(MachineBasicBlock *LandingPad) { + LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad); + LP.TypeIds.push_back(0); +} + /// TidyLandingPads - Remap landing pad labels and remove any deleted landing /// pads. void MachineModuleInfo::TidyLandingPads() { @@ -1734,12 +1746,12 @@ void MachineModuleInfo::TidyLandingPads() { LandingPads.erase(LandingPads.begin() + i); continue; } - + for (unsigned j=0; j != LandingPads[i].BeginLabels.size(); ) { unsigned BeginLabel = MappedLabel(LandingPad.BeginLabels[j]); unsigned EndLabel = MappedLabel(LandingPad.EndLabels[j]); - - + + if (!BeginLabel || !EndLabel) { LandingPad.BeginLabels.erase(LandingPad.BeginLabels.begin() + j); LandingPad.EndLabels.erase(LandingPad.EndLabels.begin() + j); @@ -1750,7 +1762,19 @@ void MachineModuleInfo::TidyLandingPads() { LandingPad.EndLabels[j] = EndLabel; ++j; } - + + // Remove landing pads with no try-ranges. + if (!LandingPads[i].BeginLabels.size()) { + LandingPads.erase(LandingPads.begin() + i); + continue; + } + + // If there is no landing pad, ensure that the list of typeids is empty. + // If the only typeid is a cleanup, this is the same as having no typeids. + if (!LandingPad.LandingPadBlock || + (LandingPad.TypeIds.size() == 1 && !LandingPad.TypeIds[0])) + LandingPad.TypeIds.clear(); + ++i; } } @@ -1768,13 +1792,30 @@ unsigned MachineModuleInfo::getTypeIDFor(GlobalVariable *TI) { /// getFilterIDFor - Return the filter id for the specified typeinfos. This is /// function wide. int MachineModuleInfo::getFilterIDFor(std::vector &TyIds) { - // TODO: map duplicate filters to the same filter id; a filter equal to the - // tail of an existing filter also need not be added; re-order filters and - // filter elements to maximize this kind of sharing. + // If the new filter coincides with the tail of an existing filter, then + // re-use the existing filter. Folding filters more than this requires + // re-ordering filters and/or their elements - probably not worth it. + for (std::vector::iterator I = FilterEnds.begin(), + E = FilterEnds.end(); I != E; ++I) { + unsigned i = *I, j = TyIds.size(); + + while (i && j) + if (FilterIds[--i] != TyIds[--j]) + goto try_next; + + if (!j) + // The new filter coincides with range [i, end) of the existing filter. + return -(1 + i); + +try_next:; + } + + // Add the new filter. int FilterID = -(1 + FilterIds.size()); FilterIds.reserve(FilterIds.size() + TyIds.size() + 1); for (unsigned I = 0, N = TyIds.size(); I != N; ++I) FilterIds.push_back(TyIds[I]); + FilterEnds.push_back(FilterIds.size()); FilterIds.push_back(0); // terminator return FilterID; }