Jim Laskey | 6da1864 | 2007-01-26 21:38:26 +0000 | [diff] [blame] | 1 | //===-- llvm/CodeGen/MachineModuleInfo.cpp ----------------------*- C++ -*-===// |
Jim Laskey | 6af5681 | 2006-01-04 13:36:38 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 4ee451d | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Jim Laskey | 6af5681 | 2006-01-04 13:36:38 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
Jim Laskey | 6af5681 | 2006-01-04 13:36:38 +0000 | [diff] [blame] | 9 | |
Jim Laskey | 6da1864 | 2007-01-26 21:38:26 +0000 | [diff] [blame] | 10 | #include "llvm/CodeGen/MachineModuleInfo.h" |
Jim Laskey | 6af5681 | 2006-01-04 13:36:38 +0000 | [diff] [blame] | 11 | |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 12 | #include "llvm/Constants.h" |
Evan Cheng | 0ff39b3 | 2008-06-30 07:31:25 +0000 | [diff] [blame] | 13 | #include "llvm/Analysis/ValueTracking.h" |
Jim Laskey | 9d4209f | 2006-11-07 19:33:46 +0000 | [diff] [blame] | 14 | #include "llvm/CodeGen/MachineFunctionPass.h" |
| 15 | #include "llvm/CodeGen/MachineFunction.h" |
Evan Cheng | 8b56a90 | 2008-09-22 22:21:38 +0000 | [diff] [blame] | 16 | #include "llvm/CodeGen/Passes.h" |
Jim Laskey | 9d4209f | 2006-11-07 19:33:46 +0000 | [diff] [blame] | 17 | #include "llvm/Target/TargetInstrInfo.h" |
| 18 | #include "llvm/Target/TargetMachine.h" |
Jim Laskey | c1c47c3 | 2007-01-29 23:40:33 +0000 | [diff] [blame] | 19 | #include "llvm/Target/TargetOptions.h" |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 20 | #include "llvm/DerivedTypes.h" |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 21 | #include "llvm/GlobalVariable.h" |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 22 | #include "llvm/Intrinsics.h" |
| 23 | #include "llvm/Instructions.h" |
| 24 | #include "llvm/Module.h" |
| 25 | #include "llvm/Support/Dwarf.h" |
Torok Edwin | c25e758 | 2009-07-11 20:10:48 +0000 | [diff] [blame] | 26 | #include "llvm/Support/ErrorHandling.h" |
Jim Laskey | 6af5681 | 2006-01-04 13:36:38 +0000 | [diff] [blame] | 27 | using namespace llvm; |
Jim Laskey | 9c4447a | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 28 | using namespace llvm::dwarf; |
Jim Laskey | 6af5681 | 2006-01-04 13:36:38 +0000 | [diff] [blame] | 29 | |
| 30 | // Handle the Pass registration stuff necessary to use TargetData's. |
Dan Gohman | 844731a | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 31 | static RegisterPass<MachineModuleInfo> |
| 32 | X("machinemoduleinfo", "Module Information"); |
Devang Patel | 1997473 | 2007-05-03 01:11:54 +0000 | [diff] [blame] | 33 | char MachineModuleInfo::ID = 0; |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 34 | |
Chris Lattner | a70e2e3 | 2009-09-15 22:44:26 +0000 | [diff] [blame] | 35 | // Out of line virtual method. |
| 36 | MachineModuleInfoImpl::~MachineModuleInfoImpl() {} |
| 37 | |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 38 | //===----------------------------------------------------------------------===// |
Eric Christopher | cf29697 | 2009-08-26 21:27:09 +0000 | [diff] [blame] | 39 | |
Jim Laskey | 6da1864 | 2007-01-26 21:38:26 +0000 | [diff] [blame] | 40 | MachineModuleInfo::MachineModuleInfo() |
Dan Gohman | ae73dc1 | 2008-09-04 17:05:41 +0000 | [diff] [blame] | 41 | : ImmutablePass(&ID) |
Chris Lattner | f185455 | 2009-09-16 05:26:00 +0000 | [diff] [blame] | 42 | , ObjFileMMI(0) |
Bob Wilson | 5d48c6d | 2010-02-06 05:55:20 +0000 | [diff] [blame] | 43 | , CurCallSite(0) |
Anton Korobeynikov | 2365f51 | 2007-07-14 14:06:15 +0000 | [diff] [blame] | 44 | , CallsEHReturn(0) |
| 45 | , CallsUnwindInit(0) |
Chris Lattner | a70e2e3 | 2009-09-15 22:44:26 +0000 | [diff] [blame] | 46 | , DbgInfoAvailable(false) { |
Eric Christopher | d44fff7 | 2009-08-26 21:30:49 +0000 | [diff] [blame] | 47 | // Always emit some info, by default "no personality" info. |
Anton Korobeynikov | 8c7c173 | 2007-05-13 15:42:26 +0000 | [diff] [blame] | 48 | Personalities.push_back(NULL); |
| 49 | } |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 50 | |
Chris Lattner | a70e2e3 | 2009-09-15 22:44:26 +0000 | [diff] [blame] | 51 | MachineModuleInfo::~MachineModuleInfo() { |
Chris Lattner | f185455 | 2009-09-16 05:26:00 +0000 | [diff] [blame] | 52 | delete ObjFileMMI; |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 53 | } |
| 54 | |
Jim Laskey | 6da1864 | 2007-01-26 21:38:26 +0000 | [diff] [blame] | 55 | /// doInitialization - Initialize the state for a new module. |
Jim Laskey | b2efb85 | 2006-01-04 22:28:25 +0000 | [diff] [blame] | 56 | /// |
Jim Laskey | 6da1864 | 2007-01-26 21:38:26 +0000 | [diff] [blame] | 57 | bool MachineModuleInfo::doInitialization() { |
Jim Laskey | b2efb85 | 2006-01-04 22:28:25 +0000 | [diff] [blame] | 58 | return false; |
Jim Laskey | 6af5681 | 2006-01-04 13:36:38 +0000 | [diff] [blame] | 59 | } |
| 60 | |
Jim Laskey | 6da1864 | 2007-01-26 21:38:26 +0000 | [diff] [blame] | 61 | /// doFinalization - Tear down the state after completion of a module. |
Jim Laskey | b2efb85 | 2006-01-04 22:28:25 +0000 | [diff] [blame] | 62 | /// |
Jim Laskey | 6da1864 | 2007-01-26 21:38:26 +0000 | [diff] [blame] | 63 | bool MachineModuleInfo::doFinalization() { |
Jim Laskey | b2efb85 | 2006-01-04 22:28:25 +0000 | [diff] [blame] | 64 | return false; |
| 65 | } |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 66 | |
Jim Laskey | 6da1864 | 2007-01-26 21:38:26 +0000 | [diff] [blame] | 67 | /// EndFunction - Discard function meta information. |
Jim Laskey | 4188699 | 2006-04-07 16:34:46 +0000 | [diff] [blame] | 68 | /// |
Jim Laskey | 6da1864 | 2007-01-26 21:38:26 +0000 | [diff] [blame] | 69 | void MachineModuleInfo::EndFunction() { |
Jim Laskey | 4188699 | 2006-04-07 16:34:46 +0000 | [diff] [blame] | 70 | // Clean up frame info. |
Jim Laskey | 4188699 | 2006-04-07 16:34:46 +0000 | [diff] [blame] | 71 | FrameMoves.clear(); |
Eric Christopher | cf29697 | 2009-08-26 21:27:09 +0000 | [diff] [blame] | 72 | |
Jim Laskey | 59667fe | 2007-02-21 22:38:31 +0000 | [diff] [blame] | 73 | // Clean up exception info. |
| 74 | LandingPads.clear(); |
Jim Grosbach | ca752c9 | 2010-01-28 01:45:32 +0000 | [diff] [blame] | 75 | CallSiteMap.clear(); |
Jim Laskey | 59667fe | 2007-02-21 22:38:31 +0000 | [diff] [blame] | 76 | TypeInfos.clear(); |
Duncan Sands | 73ef58a | 2007-06-02 16:53:42 +0000 | [diff] [blame] | 77 | FilterIds.clear(); |
Duncan Sands | 14da32a | 2007-07-05 15:15:01 +0000 | [diff] [blame] | 78 | FilterEnds.clear(); |
Anton Korobeynikov | 2365f51 | 2007-07-14 14:06:15 +0000 | [diff] [blame] | 79 | CallsEHReturn = 0; |
| 80 | CallsUnwindInit = 0; |
Devang Patel | 85d29e2 | 2009-10-08 20:41:17 +0000 | [diff] [blame] | 81 | VariableDbgInfo.clear(); |
Jim Laskey | 4188699 | 2006-04-07 16:34:46 +0000 | [diff] [blame] | 82 | } |
| 83 | |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 84 | /// AnalyzeModule - Scan the module for global debug information. |
| 85 | /// |
Jim Laskey | 6da1864 | 2007-01-26 21:38:26 +0000 | [diff] [blame] | 86 | void MachineModuleInfo::AnalyzeModule(Module &M) { |
Chris Lattner | 401e10c | 2009-07-20 06:14:25 +0000 | [diff] [blame] | 87 | // Insert functions in the llvm.used array (but not llvm.compiler.used) into |
| 88 | // UsedFunctions. |
Dale Johannesen | 48ae02f | 2008-01-16 19:59:28 +0000 | [diff] [blame] | 89 | GlobalVariable *GV = M.getGlobalVariable("llvm.used"); |
| 90 | if (!GV || !GV->hasInitializer()) return; |
| 91 | |
| 92 | // Should be an array of 'i8*'. |
| 93 | ConstantArray *InitList = dyn_cast<ConstantArray>(GV->getInitializer()); |
| 94 | if (InitList == 0) return; |
| 95 | |
Chris Lattner | 1d5c493 | 2009-07-20 06:05:50 +0000 | [diff] [blame] | 96 | for (unsigned i = 0, e = InitList->getNumOperands(); i != e; ++i) |
| 97 | if (Function *F = |
| 98 | dyn_cast<Function>(InitList->getOperand(i)->stripPointerCasts())) |
| 99 | UsedFunctions.insert(F); |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 100 | } |
| 101 | |
Jim Laskey | 59667fe | 2007-02-21 22:38:31 +0000 | [diff] [blame] | 102 | //===-EH-------------------------------------------------------------------===// |
| 103 | |
| 104 | /// getOrCreateLandingPadInfo - Find or create an LandingPadInfo for the |
| 105 | /// specified MachineBasicBlock. |
Bill Wendling | 10fff60 | 2008-07-03 22:53:42 +0000 | [diff] [blame] | 106 | LandingPadInfo &MachineModuleInfo::getOrCreateLandingPadInfo |
| 107 | (MachineBasicBlock *LandingPad) { |
Jim Laskey | 59667fe | 2007-02-21 22:38:31 +0000 | [diff] [blame] | 108 | unsigned N = LandingPads.size(); |
| 109 | for (unsigned i = 0; i < N; ++i) { |
Jim Laskey | 59e8434 | 2007-03-01 20:25:32 +0000 | [diff] [blame] | 110 | LandingPadInfo &LP = LandingPads[i]; |
| 111 | if (LP.LandingPadBlock == LandingPad) |
| 112 | return LP; |
Jim Laskey | 59667fe | 2007-02-21 22:38:31 +0000 | [diff] [blame] | 113 | } |
Eric Christopher | cf29697 | 2009-08-26 21:27:09 +0000 | [diff] [blame] | 114 | |
Jim Laskey | 59667fe | 2007-02-21 22:38:31 +0000 | [diff] [blame] | 115 | LandingPads.push_back(LandingPadInfo(LandingPad)); |
| 116 | return LandingPads[N]; |
| 117 | } |
| 118 | |
| 119 | /// addInvoke - Provide the begin and end labels of an invoke style call and |
| 120 | /// associate it with a try landing pad block. |
| 121 | void MachineModuleInfo::addInvoke(MachineBasicBlock *LandingPad, |
| 122 | unsigned BeginLabel, unsigned EndLabel) { |
Jim Laskey | 59e8434 | 2007-03-01 20:25:32 +0000 | [diff] [blame] | 123 | LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad); |
Anton Korobeynikov | eeb37e0 | 2007-05-10 22:34:59 +0000 | [diff] [blame] | 124 | LP.BeginLabels.push_back(BeginLabel); |
| 125 | LP.EndLabels.push_back(EndLabel); |
Jim Laskey | 59667fe | 2007-02-21 22:38:31 +0000 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | /// addLandingPad - Provide the label of a try LandingPad block. |
| 129 | /// |
| 130 | unsigned MachineModuleInfo::addLandingPad(MachineBasicBlock *LandingPad) { |
| 131 | unsigned LandingPadLabel = NextLabelID(); |
Jim Laskey | 59e8434 | 2007-03-01 20:25:32 +0000 | [diff] [blame] | 132 | LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad); |
Eric Christopher | cf29697 | 2009-08-26 21:27:09 +0000 | [diff] [blame] | 133 | LP.LandingPadLabel = LandingPadLabel; |
Jim Laskey | 59667fe | 2007-02-21 22:38:31 +0000 | [diff] [blame] | 134 | return LandingPadLabel; |
| 135 | } |
| 136 | |
| 137 | /// addPersonality - Provide the personality function for the exception |
| 138 | /// information. |
| 139 | void MachineModuleInfo::addPersonality(MachineBasicBlock *LandingPad, |
Anton Korobeynikov | 8c7c173 | 2007-05-13 15:42:26 +0000 | [diff] [blame] | 140 | Function *Personality) { |
Jim Laskey | 59e8434 | 2007-03-01 20:25:32 +0000 | [diff] [blame] | 141 | LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad); |
Anton Korobeynikov | 8c7c173 | 2007-05-13 15:42:26 +0000 | [diff] [blame] | 142 | LP.Personality = Personality; |
Anton Korobeynikov | 0ff3ca4 | 2007-05-12 22:36:25 +0000 | [diff] [blame] | 143 | |
Bill Wendling | 10fff60 | 2008-07-03 22:53:42 +0000 | [diff] [blame] | 144 | for (unsigned i = 0; i < Personalities.size(); ++i) |
Anton Korobeynikov | 8c7c173 | 2007-05-13 15:42:26 +0000 | [diff] [blame] | 145 | if (Personalities[i] == Personality) |
| 146 | return; |
Eric Christopher | cf29697 | 2009-08-26 21:27:09 +0000 | [diff] [blame] | 147 | |
Eric Christopher | d44fff7 | 2009-08-26 21:30:49 +0000 | [diff] [blame] | 148 | // If this is the first personality we're adding go |
| 149 | // ahead and add it at the beginning. |
| 150 | if (Personalities[0] == NULL) |
| 151 | Personalities[0] = Personality; |
| 152 | else |
| 153 | Personalities.push_back(Personality); |
Jim Laskey | 59667fe | 2007-02-21 22:38:31 +0000 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | /// addCatchTypeInfo - Provide the catch typeinfo for a landing pad. |
| 157 | /// |
| 158 | void MachineModuleInfo::addCatchTypeInfo(MachineBasicBlock *LandingPad, |
| 159 | std::vector<GlobalVariable *> &TyInfo) { |
Jim Laskey | 59e8434 | 2007-03-01 20:25:32 +0000 | [diff] [blame] | 160 | LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad); |
Jim Laskey | 59667fe | 2007-02-21 22:38:31 +0000 | [diff] [blame] | 161 | for (unsigned N = TyInfo.size(); N; --N) |
Jim Laskey | 59e8434 | 2007-03-01 20:25:32 +0000 | [diff] [blame] | 162 | LP.TypeIds.push_back(getTypeIDFor(TyInfo[N - 1])); |
Jim Laskey | 59667fe | 2007-02-21 22:38:31 +0000 | [diff] [blame] | 163 | } |
Duncan Sands | 73ef58a | 2007-06-02 16:53:42 +0000 | [diff] [blame] | 164 | |
| 165 | /// addFilterTypeInfo - Provide the filter typeinfo for a landing pad. |
Jim Laskey | 59e8434 | 2007-03-01 20:25:32 +0000 | [diff] [blame] | 166 | /// |
Duncan Sands | 73ef58a | 2007-06-02 16:53:42 +0000 | [diff] [blame] | 167 | void MachineModuleInfo::addFilterTypeInfo(MachineBasicBlock *LandingPad, |
| 168 | std::vector<GlobalVariable *> &TyInfo) { |
Jim Laskey | 59e8434 | 2007-03-01 20:25:32 +0000 | [diff] [blame] | 169 | LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad); |
Bill Wendling | 4925567 | 2008-07-07 21:41:57 +0000 | [diff] [blame] | 170 | std::vector<unsigned> IdsInFilter(TyInfo.size()); |
Bill Wendling | 10fff60 | 2008-07-03 22:53:42 +0000 | [diff] [blame] | 171 | for (unsigned I = 0, E = TyInfo.size(); I != E; ++I) |
Duncan Sands | 73ef58a | 2007-06-02 16:53:42 +0000 | [diff] [blame] | 172 | IdsInFilter[I] = getTypeIDFor(TyInfo[I]); |
| 173 | LP.TypeIds.push_back(getFilterIDFor(IdsInFilter)); |
Jim Laskey | 59e8434 | 2007-03-01 20:25:32 +0000 | [diff] [blame] | 174 | } |
| 175 | |
Duncan Sands | 6590b04 | 2007-08-27 15:47:50 +0000 | [diff] [blame] | 176 | /// addCleanup - Add a cleanup action for a landing pad. |
| 177 | /// |
| 178 | void MachineModuleInfo::addCleanup(MachineBasicBlock *LandingPad) { |
| 179 | LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad); |
| 180 | LP.TypeIds.push_back(0); |
| 181 | } |
| 182 | |
Jim Laskey | 59667fe | 2007-02-21 22:38:31 +0000 | [diff] [blame] | 183 | /// TidyLandingPads - Remap landing pad labels and remove any deleted landing |
| 184 | /// pads. |
| 185 | void MachineModuleInfo::TidyLandingPads() { |
| 186 | for (unsigned i = 0; i != LandingPads.size(); ) { |
| 187 | LandingPadInfo &LandingPad = LandingPads[i]; |
Chris Lattner | a34ec229 | 2010-03-09 01:51:43 +0000 | [diff] [blame] | 188 | if (isLabelDeleted(LandingPad.LandingPadLabel)) |
| 189 | LandingPad.LandingPadLabel = 0; |
Anton Korobeynikov | eeb37e0 | 2007-05-10 22:34:59 +0000 | [diff] [blame] | 190 | |
Anton Korobeynikov | 070280e | 2007-05-23 11:08:31 +0000 | [diff] [blame] | 191 | // Special case: we *should* emit LPs with null LP MBB. This indicates |
Duncan Sands | 481dc72 | 2007-12-19 07:36:31 +0000 | [diff] [blame] | 192 | // "nounwind" case. |
Anton Korobeynikov | 070280e | 2007-05-23 11:08:31 +0000 | [diff] [blame] | 193 | if (!LandingPad.LandingPadLabel && LandingPad.LandingPadBlock) { |
Jim Laskey | 59667fe | 2007-02-21 22:38:31 +0000 | [diff] [blame] | 194 | LandingPads.erase(LandingPads.begin() + i); |
| 195 | continue; |
| 196 | } |
Duncan Sands | 57810cd | 2007-09-05 11:27:52 +0000 | [diff] [blame] | 197 | |
Bill Wendling | 10fff60 | 2008-07-03 22:53:42 +0000 | [diff] [blame] | 198 | for (unsigned j=0; j != LandingPads[i].BeginLabels.size(); ) { |
Chris Lattner | a34ec229 | 2010-03-09 01:51:43 +0000 | [diff] [blame] | 199 | unsigned BeginLabel = LandingPad.BeginLabels[j]; |
| 200 | unsigned EndLabel = LandingPad.EndLabels[j]; |
| 201 | if (isLabelDeleted(BeginLabel) || isLabelDeleted(EndLabel)) { |
Anton Korobeynikov | eeb37e0 | 2007-05-10 22:34:59 +0000 | [diff] [blame] | 202 | LandingPad.BeginLabels.erase(LandingPad.BeginLabels.begin() + j); |
| 203 | LandingPad.EndLabels.erase(LandingPad.EndLabels.begin() + j); |
| 204 | continue; |
| 205 | } |
| 206 | |
Anton Korobeynikov | eeb37e0 | 2007-05-10 22:34:59 +0000 | [diff] [blame] | 207 | ++j; |
| 208 | } |
Duncan Sands | 57810cd | 2007-09-05 11:27:52 +0000 | [diff] [blame] | 209 | |
| 210 | // Remove landing pads with no try-ranges. |
Dan Gohman | 3035959 | 2008-01-29 13:02:09 +0000 | [diff] [blame] | 211 | if (LandingPads[i].BeginLabels.empty()) { |
Duncan Sands | 57810cd | 2007-09-05 11:27:52 +0000 | [diff] [blame] | 212 | LandingPads.erase(LandingPads.begin() + i); |
| 213 | continue; |
| 214 | } |
| 215 | |
| 216 | // If there is no landing pad, ensure that the list of typeids is empty. |
| 217 | // If the only typeid is a cleanup, this is the same as having no typeids. |
| 218 | if (!LandingPad.LandingPadBlock || |
| 219 | (LandingPad.TypeIds.size() == 1 && !LandingPad.TypeIds[0])) |
| 220 | LandingPad.TypeIds.clear(); |
| 221 | |
Jim Laskey | 59667fe | 2007-02-21 22:38:31 +0000 | [diff] [blame] | 222 | ++i; |
| 223 | } |
| 224 | } |
| 225 | |
Eric Christopher | cf29697 | 2009-08-26 21:27:09 +0000 | [diff] [blame] | 226 | /// getTypeIDFor - Return the type id for the specified typeinfo. This is |
Jim Laskey | 59667fe | 2007-02-21 22:38:31 +0000 | [diff] [blame] | 227 | /// function wide. |
| 228 | unsigned MachineModuleInfo::getTypeIDFor(GlobalVariable *TI) { |
Bill Wendling | 10fff60 | 2008-07-03 22:53:42 +0000 | [diff] [blame] | 229 | for (unsigned i = 0, N = TypeInfos.size(); i != N; ++i) |
| 230 | if (TypeInfos[i] == TI) return i + 1; |
Jim Laskey | 59667fe | 2007-02-21 22:38:31 +0000 | [diff] [blame] | 231 | |
| 232 | TypeInfos.push_back(TI); |
| 233 | return TypeInfos.size(); |
| 234 | } |
| 235 | |
Duncan Sands | 73ef58a | 2007-06-02 16:53:42 +0000 | [diff] [blame] | 236 | /// getFilterIDFor - Return the filter id for the specified typeinfos. This is |
| 237 | /// function wide. |
Bill Wendling | 914c970 | 2008-06-27 01:27:56 +0000 | [diff] [blame] | 238 | int MachineModuleInfo::getFilterIDFor(std::vector<unsigned> &TyIds) { |
Duncan Sands | 14da32a | 2007-07-05 15:15:01 +0000 | [diff] [blame] | 239 | // If the new filter coincides with the tail of an existing filter, then |
| 240 | // re-use the existing filter. Folding filters more than this requires |
| 241 | // re-ordering filters and/or their elements - probably not worth it. |
| 242 | for (std::vector<unsigned>::iterator I = FilterEnds.begin(), |
| 243 | E = FilterEnds.end(); I != E; ++I) { |
Bill Wendling | 914c970 | 2008-06-27 01:27:56 +0000 | [diff] [blame] | 244 | unsigned i = *I, j = TyIds.size(); |
Duncan Sands | 14da32a | 2007-07-05 15:15:01 +0000 | [diff] [blame] | 245 | |
| 246 | while (i && j) |
| 247 | if (FilterIds[--i] != TyIds[--j]) |
| 248 | goto try_next; |
| 249 | |
| 250 | if (!j) |
| 251 | // The new filter coincides with range [i, end) of the existing filter. |
| 252 | return -(1 + i); |
Bill Wendling | 914c970 | 2008-06-27 01:27:56 +0000 | [diff] [blame] | 253 | |
Duncan Sands | 14da32a | 2007-07-05 15:15:01 +0000 | [diff] [blame] | 254 | try_next:; |
| 255 | } |
| 256 | |
| 257 | // Add the new filter. |
Bill Wendling | 914c970 | 2008-06-27 01:27:56 +0000 | [diff] [blame] | 258 | int FilterID = -(1 + FilterIds.size()); |
| 259 | FilterIds.reserve(FilterIds.size() + TyIds.size() + 1); |
| 260 | for (unsigned I = 0, N = TyIds.size(); I != N; ++I) |
Duncan Sands | 73ef58a | 2007-06-02 16:53:42 +0000 | [diff] [blame] | 261 | FilterIds.push_back(TyIds[I]); |
Bill Wendling | 914c970 | 2008-06-27 01:27:56 +0000 | [diff] [blame] | 262 | FilterEnds.push_back(FilterIds.size()); |
Duncan Sands | 73ef58a | 2007-06-02 16:53:42 +0000 | [diff] [blame] | 263 | FilterIds.push_back(0); // terminator |
| 264 | return FilterID; |
| 265 | } |
| 266 | |
Anton Korobeynikov | 8c7c173 | 2007-05-13 15:42:26 +0000 | [diff] [blame] | 267 | /// getPersonality - Return the personality function for the current function. |
Jim Laskey | 59667fe | 2007-02-21 22:38:31 +0000 | [diff] [blame] | 268 | Function *MachineModuleInfo::getPersonality() const { |
Anton Korobeynikov | 0ff3ca4 | 2007-05-12 22:36:25 +0000 | [diff] [blame] | 269 | // FIXME: Until PR1414 will be fixed, we're using 1 personality function per |
Anton Korobeynikov | 8c7c173 | 2007-05-13 15:42:26 +0000 | [diff] [blame] | 270 | // function |
| 271 | return !LandingPads.empty() ? LandingPads[0].Personality : NULL; |
Jim Laskey | 59667fe | 2007-02-21 22:38:31 +0000 | [diff] [blame] | 272 | } |
| 273 | |
Anton Korobeynikov | 8c7c173 | 2007-05-13 15:42:26 +0000 | [diff] [blame] | 274 | /// getPersonalityIndex - Return unique index for current personality |
Eric Christopher | 5e365e2 | 2009-08-26 21:44:57 +0000 | [diff] [blame] | 275 | /// function. NULL/first personality function should always get zero index. |
Anton Korobeynikov | 8c7c173 | 2007-05-13 15:42:26 +0000 | [diff] [blame] | 276 | unsigned MachineModuleInfo::getPersonalityIndex() const { |
Anton Korobeynikov | 070280e | 2007-05-23 11:08:31 +0000 | [diff] [blame] | 277 | const Function* Personality = NULL; |
Eric Christopher | cf29697 | 2009-08-26 21:27:09 +0000 | [diff] [blame] | 278 | |
Anton Korobeynikov | 070280e | 2007-05-23 11:08:31 +0000 | [diff] [blame] | 279 | // Scan landing pads. If there is at least one non-NULL personality - use it. |
Bill Wendling | 10fff60 | 2008-07-03 22:53:42 +0000 | [diff] [blame] | 280 | for (unsigned i = 0; i != LandingPads.size(); ++i) |
Anton Korobeynikov | 070280e | 2007-05-23 11:08:31 +0000 | [diff] [blame] | 281 | if (LandingPads[i].Personality) { |
| 282 | Personality = LandingPads[i].Personality; |
| 283 | break; |
| 284 | } |
Eric Christopher | cf29697 | 2009-08-26 21:27:09 +0000 | [diff] [blame] | 285 | |
Bill Wendling | 10fff60 | 2008-07-03 22:53:42 +0000 | [diff] [blame] | 286 | for (unsigned i = 0; i < Personalities.size(); ++i) { |
Anton Korobeynikov | 8c7c173 | 2007-05-13 15:42:26 +0000 | [diff] [blame] | 287 | if (Personalities[i] == Personality) |
| 288 | return i; |
Bill Wendling | 10fff60 | 2008-07-03 22:53:42 +0000 | [diff] [blame] | 289 | } |
Anton Korobeynikov | 8c7c173 | 2007-05-13 15:42:26 +0000 | [diff] [blame] | 290 | |
Eric Christopher | 5e365e2 | 2009-08-26 21:44:57 +0000 | [diff] [blame] | 291 | // This will happen if the current personality function is |
| 292 | // in the zero index. |
Anton Korobeynikov | 8c7c173 | 2007-05-13 15:42:26 +0000 | [diff] [blame] | 293 | return 0; |
| 294 | } |
Jim Laskey | 59667fe | 2007-02-21 22:38:31 +0000 | [diff] [blame] | 295 | |