diff options
| author | Jim Laskey <jlaskey@mac.com> | 2007-02-21 22:38:31 +0000 | 
|---|---|---|
| committer | Jim Laskey <jlaskey@mac.com> | 2007-02-21 22:38:31 +0000 | 
| commit | 88dd2fd332cfa98f9768a3cbaab3deecb6b4b616 (patch) | |
| tree | 27a3cb267234bafd4d51261cd81440ca5c21e33c | |
| parent | e0c549eeef7b854cf1f9027c788ffab017996278 (diff) | |
| download | bcm5719-llvm-88dd2fd332cfa98f9768a3cbaab3deecb6b4b616.tar.gz bcm5719-llvm-88dd2fd332cfa98f9768a3cbaab3deecb6b4b616.zip  | |
Add structures used for collecting eh information.
llvm-svn: 34473
| -rw-r--r-- | llvm/include/llvm/CodeGen/MachineModuleInfo.h | 78 | ||||
| -rw-r--r-- | llvm/lib/CodeGen/MachineModuleInfo.cpp | 94 | 
2 files changed, 172 insertions, 0 deletions
diff --git a/llvm/include/llvm/CodeGen/MachineModuleInfo.h b/llvm/include/llvm/CodeGen/MachineModuleInfo.h index 17e3ad80001..1439666e6a1 100644 --- a/llvm/include/llvm/CodeGen/MachineModuleInfo.h +++ b/llvm/include/llvm/CodeGen/MachineModuleInfo.h @@ -44,6 +44,7 @@ namespace llvm {  class Constant;  class DebugInfoDesc;  class GlobalVariable; +class MachineBasicBlock;  class MachineFunction;  class MachineMove;  class Module; @@ -949,6 +950,27 @@ public:  };  //===----------------------------------------------------------------------===// +/// LandingPadInfo - This structure is used to retain landing pad info for +/// the current function. +/// +struct LandingPadInfo { +  MachineBasicBlock *LandingPadBlock;   // Landing pad block. +  unsigned BeginLabel;                  // Label prior to invoke. +  unsigned EndLabel;                    // Label after invoke. +  unsigned LandingPadLabel;             // Label at beginning of landing pad. +  Function *Personality;                // Personality function. +  std::vector<unsigned> TypeIds;        // List of type ids. +   +  LandingPadInfo(MachineBasicBlock *MBB) +  : LandingPadBlock(MBB) +  , BeginLabel(0) +  , EndLabel(0) +  , LandingPadLabel(0) +  , TypeIds() +  {} +}; + +//===----------------------------------------------------------------------===//  /// MachineModuleInfo - This class contains meta information specific to a  /// module.  Queries can be made by different debugging and exception handling   /// schemes and reformated for specific use. @@ -987,6 +1009,14 @@ private:    // FrameMoves - List of moves done by a function's prolog.  Used to construct    // frame maps by debug and exception handling consumers.    std::vector<MachineMove> FrameMoves; +   +  // LandingPads - List of LandingPadInfo describing the landing pad information +  // in the current function. +  std::vector<LandingPadInfo> LandingPads; +   +  // TypeInfos - List of C++ TypeInfo used in the currect function. +  // +  std::vector<GlobalVariable *> TypeInfos;  public:    MachineModuleInfo(); @@ -1147,6 +1177,54 @@ public:    /// function's prologue.  Used to construct frame maps for debug and exception    /// handling comsumers.    std::vector<MachineMove> &getFrameMoves() { return FrameMoves; } +   +  //===-EH-----------------------------------------------------------------===// + +  /// getOrCreateLandingPadInfo - Find or create an LandingPadInfo for the +  /// specified MachineBasicBlock. +  LandingPadInfo &getOrCreateLandingPadInfo(MachineBasicBlock *LandingPad); + +  /// addInvoke - Provide the begin and end labels of an invoke style call and +  /// associate it with a try landing pad block. +  void addInvoke(MachineBasicBlock *LandingPad, unsigned BeginLabel, +                                                unsigned EndLabel); +   +  /// addLandingPad - Add a new panding pad.  Returns the label ID for the  +  /// landing pad entry. +  unsigned addLandingPad(MachineBasicBlock *LandingPad); +   +  /// addPersonality - Provide the personality function for the exception +  /// information. +  void addPersonality(MachineBasicBlock *LandingPad, Function *Personality); +   +  /// addCatchTypeInfo - Provide the catch typeinfo for a landing pad. +  /// +  void addCatchTypeInfo(MachineBasicBlock *LandingPad, +                        std::vector<GlobalVariable *> &TyInfo); +                         +  /// getTypeIDFor - Return the type id for the specified typeinfo.  This is  +  /// function wide. +  unsigned getTypeIDFor(GlobalVariable *TI); +   +  /// TidyLandingPads - Remap landing pad labels and remove any deleted landing +  /// pads. +  void TidyLandingPads(); +                         +  /// getLandingPadInfos - Return a reference to the landing pad info for the +  /// current function. +  const std::vector<LandingPadInfo> &getLandingPads() const { +    return LandingPads; +  } +   +  /// getTypeInfos - Return a reference to the C++ typeinfo for the current +  /// function. +  const std::vector<GlobalVariable *> &getTypeInfos() const { +    return TypeInfos; +  } +   +  /// getPersonality - Return a personality function if available.  The presence +  /// of one is required to emit exception handling info. +  Function *getPersonality() const;  }; // End class MachineModuleInfo diff --git a/llvm/lib/CodeGen/MachineModuleInfo.cpp b/llvm/lib/CodeGen/MachineModuleInfo.cpp index 4cc2a150ebc..adf7d29c049 100644 --- a/llvm/lib/CodeGen/MachineModuleInfo.cpp +++ b/llvm/lib/CodeGen/MachineModuleInfo.cpp @@ -1472,6 +1472,7 @@ MachineModuleInfo::MachineModuleInfo()  , ScopeMap()  , RootScope(NULL)  , FrameMoves() +, LandingPads()  {}  MachineModuleInfo::~MachineModuleInfo() { @@ -1510,6 +1511,10 @@ void MachineModuleInfo::EndFunction() {    // Clean up frame info.    FrameMoves.clear(); +   +  // Clean up exception info. +  LandingPads.clear(); +  TypeInfos.clear();  }  /// getDescFor - Convert a Value to a debug information descriptor. @@ -1640,6 +1645,95 @@ DebugScope *MachineModuleInfo::getOrCreateScope(DebugInfoDesc *ScopeDesc) {    return Slot;  } +//===-EH-------------------------------------------------------------------===// + +/// getOrCreateLandingPadInfo - Find or create an LandingPadInfo for the +/// specified MachineBasicBlock. +LandingPadInfo &MachineModuleInfo::getOrCreateLandingPadInfo +    (MachineBasicBlock *LandingPad) { +  unsigned N = LandingPads.size(); +  for (unsigned i = 0; i < N; ++i) { +    LandingPadInfo &UI = LandingPads[i]; +    if (UI.LandingPadBlock == LandingPad) +      return UI; +  } +   +  LandingPads.push_back(LandingPadInfo(LandingPad)); +  return LandingPads[N]; +} + +/// addInvoke - Provide the begin and end labels of an invoke style call and +/// associate it with a try landing pad block. +void MachineModuleInfo::addInvoke(MachineBasicBlock *LandingPad, +                                  unsigned BeginLabel, unsigned EndLabel) { +  LandingPadInfo &UI = getOrCreateLandingPadInfo(LandingPad); +  if (!UI.BeginLabel) UI.BeginLabel = BeginLabel;   +  UI.EndLabel = EndLabel;   +} + +/// addLandingPad - Provide the label of a try LandingPad block. +/// +unsigned MachineModuleInfo::addLandingPad(MachineBasicBlock *LandingPad) { +  unsigned LandingPadLabel = NextLabelID(); +  LandingPadInfo &UI = getOrCreateLandingPadInfo(LandingPad); +  UI.LandingPadLabel = LandingPadLabel;   +  return LandingPadLabel; +} + +/// addPersonality - Provide the personality function for the exception +/// information. +void MachineModuleInfo::addPersonality(MachineBasicBlock *LandingPad, +                                       Function *Personality) { +  LandingPadInfo &UI = getOrCreateLandingPadInfo(LandingPad); +  UI.Personality = Personality; +} + +/// addCatchTypeInfo - Provide the catch typeinfo for a landing pad. +/// +void MachineModuleInfo::addCatchTypeInfo(MachineBasicBlock *LandingPad, +                                        std::vector<GlobalVariable *> &TyInfo) { +  LandingPadInfo &UI = getOrCreateLandingPadInfo(LandingPad); +  for (unsigned N = TyInfo.size(); N; --N) +    UI.TypeIds.push_back(getTypeIDFor(TyInfo[N - 1])); +} +                         +/// TidyLandingPads - Remap landing pad labels and remove any deleted landing +/// pads. +void MachineModuleInfo::TidyLandingPads() { +  for (unsigned i = 0; i != LandingPads.size(); ) { +    LandingPadInfo &LandingPad = LandingPads[i]; +    LandingPad.BeginLabel = MappedLabel(LandingPad.BeginLabel); +    LandingPad.EndLabel = MappedLabel(LandingPad.EndLabel); +    LandingPad.LandingPadLabel = MappedLabel(LandingPad.LandingPadLabel); +     +    if (!LandingPad.BeginLabel || +        !LandingPad.EndLabel || +        !LandingPad.LandingPadLabel) { +      LandingPads.erase(LandingPads.begin() + i); +      continue; +    } +     +    ++i; +  } +} + +/// getTypeIDFor - Return the type id for the specified typeinfo.  This is  +/// function wide. +unsigned MachineModuleInfo::getTypeIDFor(GlobalVariable *TI) { +  for (unsigned i = 0, N = TypeInfos.size(); i != N; ++i) +    if (TypeInfos[i] == TI) return i + 1; + +  TypeInfos.push_back(TI); +  return TypeInfos.size(); +} + +/// getLandingPadInfos - Return a reference to the landing pad info for the +/// current function. +Function *MachineModuleInfo::getPersonality() const { +  return !LandingPads.empty() ? LandingPads[0].Personality : NULL; +} + +  //===----------------------------------------------------------------------===//  /// DebugLabelFolding pass - This pass prunes out redundant labels.  This allows  /// a info consumer to determine if the range of two labels is empty, by seeing  | 

