Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1 | //===-- llvm/CodeGen/MachineModuleInfo.cpp ----------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 081ce94 | 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. |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "llvm/CodeGen/MachineModuleInfo.h" |
| 11 | |
| 12 | #include "llvm/Constants.h" |
Evan Cheng | 833501d | 2008-06-30 07:31:25 +0000 | [diff] [blame] | 13 | #include "llvm/Analysis/ValueTracking.h" |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 14 | #include "llvm/CodeGen/MachineFunctionPass.h" |
| 15 | #include "llvm/CodeGen/MachineFunction.h" |
Evan Cheng | 1b42ac1 | 2008-09-22 22:21:38 +0000 | [diff] [blame] | 16 | #include "llvm/CodeGen/Passes.h" |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 17 | #include "llvm/Target/TargetInstrInfo.h" |
| 18 | #include "llvm/Target/TargetMachine.h" |
| 19 | #include "llvm/Target/TargetOptions.h" |
| 20 | #include "llvm/DerivedTypes.h" |
| 21 | #include "llvm/GlobalVariable.h" |
| 22 | #include "llvm/Intrinsics.h" |
| 23 | #include "llvm/Instructions.h" |
| 24 | #include "llvm/Module.h" |
| 25 | #include "llvm/Support/Dwarf.h" |
Edwin Török | 675d562 | 2009-07-11 20:10:48 +0000 | [diff] [blame^] | 26 | #include "llvm/Support/ErrorHandling.h" |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 27 | #include "llvm/Support/Streams.h" |
| 28 | using namespace llvm; |
| 29 | using namespace llvm::dwarf; |
| 30 | |
| 31 | // Handle the Pass registration stuff necessary to use TargetData's. |
Dan Gohman | 089efff | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 32 | static RegisterPass<MachineModuleInfo> |
| 33 | X("machinemoduleinfo", "Module Information"); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 34 | char MachineModuleInfo::ID = 0; |
| 35 | |
| 36 | //===----------------------------------------------------------------------===// |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 37 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 38 | MachineModuleInfo::MachineModuleInfo() |
Dan Gohman | 26f8c27 | 2008-09-04 17:05:41 +0000 | [diff] [blame] | 39 | : ImmutablePass(&ID) |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 40 | , LabelIDList() |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 41 | , FrameMoves() |
| 42 | , LandingPads() |
| 43 | , Personalities() |
| 44 | , CallsEHReturn(0) |
| 45 | , CallsUnwindInit(0) |
Devang Patel | 86cfa40 | 2009-01-13 23:02:17 +0000 | [diff] [blame] | 46 | , DbgInfoAvailable(false) |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 47 | { |
| 48 | // Always emit "no personality" info |
| 49 | Personalities.push_back(NULL); |
| 50 | } |
| 51 | MachineModuleInfo::~MachineModuleInfo() { |
| 52 | |
| 53 | } |
| 54 | |
| 55 | /// doInitialization - Initialize the state for a new module. |
| 56 | /// |
| 57 | bool MachineModuleInfo::doInitialization() { |
| 58 | return false; |
| 59 | } |
| 60 | |
| 61 | /// doFinalization - Tear down the state after completion of a module. |
| 62 | /// |
| 63 | bool MachineModuleInfo::doFinalization() { |
| 64 | return false; |
| 65 | } |
| 66 | |
| 67 | /// BeginFunction - Begin gathering function meta information. |
| 68 | /// |
| 69 | void MachineModuleInfo::BeginFunction(MachineFunction *MF) { |
| 70 | // Coming soon. |
| 71 | } |
| 72 | |
| 73 | /// EndFunction - Discard function meta information. |
| 74 | /// |
| 75 | void MachineModuleInfo::EndFunction() { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 76 | // Clean up frame info. |
| 77 | FrameMoves.clear(); |
| 78 | |
| 79 | // Clean up exception info. |
| 80 | LandingPads.clear(); |
| 81 | TypeInfos.clear(); |
| 82 | FilterIds.clear(); |
| 83 | FilterEnds.clear(); |
| 84 | CallsEHReturn = 0; |
| 85 | CallsUnwindInit = 0; |
| 86 | } |
| 87 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 88 | /// AnalyzeModule - Scan the module for global debug information. |
| 89 | /// |
| 90 | void MachineModuleInfo::AnalyzeModule(Module &M) { |
Dale Johannesen | 3dadeb3 | 2008-01-16 19:59:28 +0000 | [diff] [blame] | 91 | // Insert functions in the llvm.used array into UsedFunctions. |
| 92 | GlobalVariable *GV = M.getGlobalVariable("llvm.used"); |
| 93 | if (!GV || !GV->hasInitializer()) return; |
| 94 | |
| 95 | // Should be an array of 'i8*'. |
| 96 | ConstantArray *InitList = dyn_cast<ConstantArray>(GV->getInitializer()); |
| 97 | if (InitList == 0) return; |
| 98 | |
| 99 | for (unsigned i = 0, e = InitList->getNumOperands(); i != e; ++i) { |
| 100 | if (ConstantExpr *CE = dyn_cast<ConstantExpr>(InitList->getOperand(i))) |
| 101 | if (CE->getOpcode() == Instruction::BitCast) |
| 102 | if (Function *F = dyn_cast<Function>(CE->getOperand(0))) |
| 103 | UsedFunctions.insert(F); |
| 104 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 105 | } |
| 106 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 107 | //===-EH-------------------------------------------------------------------===// |
| 108 | |
| 109 | /// getOrCreateLandingPadInfo - Find or create an LandingPadInfo for the |
| 110 | /// specified MachineBasicBlock. |
Bill Wendling | 4de8de5 | 2008-07-03 22:53:42 +0000 | [diff] [blame] | 111 | LandingPadInfo &MachineModuleInfo::getOrCreateLandingPadInfo |
| 112 | (MachineBasicBlock *LandingPad) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 113 | unsigned N = LandingPads.size(); |
| 114 | for (unsigned i = 0; i < N; ++i) { |
| 115 | LandingPadInfo &LP = LandingPads[i]; |
| 116 | if (LP.LandingPadBlock == LandingPad) |
| 117 | return LP; |
| 118 | } |
| 119 | |
| 120 | LandingPads.push_back(LandingPadInfo(LandingPad)); |
| 121 | return LandingPads[N]; |
| 122 | } |
| 123 | |
| 124 | /// addInvoke - Provide the begin and end labels of an invoke style call and |
| 125 | /// associate it with a try landing pad block. |
| 126 | void MachineModuleInfo::addInvoke(MachineBasicBlock *LandingPad, |
| 127 | unsigned BeginLabel, unsigned EndLabel) { |
| 128 | LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad); |
| 129 | LP.BeginLabels.push_back(BeginLabel); |
| 130 | LP.EndLabels.push_back(EndLabel); |
| 131 | } |
| 132 | |
| 133 | /// addLandingPad - Provide the label of a try LandingPad block. |
| 134 | /// |
| 135 | unsigned MachineModuleInfo::addLandingPad(MachineBasicBlock *LandingPad) { |
| 136 | unsigned LandingPadLabel = NextLabelID(); |
| 137 | LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad); |
| 138 | LP.LandingPadLabel = LandingPadLabel; |
| 139 | return LandingPadLabel; |
| 140 | } |
| 141 | |
| 142 | /// addPersonality - Provide the personality function for the exception |
| 143 | /// information. |
| 144 | void MachineModuleInfo::addPersonality(MachineBasicBlock *LandingPad, |
| 145 | Function *Personality) { |
| 146 | LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad); |
| 147 | LP.Personality = Personality; |
| 148 | |
Bill Wendling | 4de8de5 | 2008-07-03 22:53:42 +0000 | [diff] [blame] | 149 | for (unsigned i = 0; i < Personalities.size(); ++i) |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 150 | if (Personalities[i] == Personality) |
| 151 | return; |
| 152 | |
| 153 | Personalities.push_back(Personality); |
| 154 | } |
| 155 | |
| 156 | /// addCatchTypeInfo - Provide the catch typeinfo for a landing pad. |
| 157 | /// |
| 158 | void MachineModuleInfo::addCatchTypeInfo(MachineBasicBlock *LandingPad, |
| 159 | std::vector<GlobalVariable *> &TyInfo) { |
| 160 | LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad); |
| 161 | for (unsigned N = TyInfo.size(); N; --N) |
| 162 | LP.TypeIds.push_back(getTypeIDFor(TyInfo[N - 1])); |
| 163 | } |
| 164 | |
| 165 | /// addFilterTypeInfo - Provide the filter typeinfo for a landing pad. |
| 166 | /// |
| 167 | void MachineModuleInfo::addFilterTypeInfo(MachineBasicBlock *LandingPad, |
| 168 | std::vector<GlobalVariable *> &TyInfo) { |
| 169 | LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad); |
Bill Wendling | 993b3dd | 2008-07-07 21:41:57 +0000 | [diff] [blame] | 170 | std::vector<unsigned> IdsInFilter(TyInfo.size()); |
Bill Wendling | 4de8de5 | 2008-07-03 22:53:42 +0000 | [diff] [blame] | 171 | for (unsigned I = 0, E = TyInfo.size(); I != E; ++I) |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 172 | IdsInFilter[I] = getTypeIDFor(TyInfo[I]); |
| 173 | LP.TypeIds.push_back(getFilterIDFor(IdsInFilter)); |
| 174 | } |
| 175 | |
Duncan Sands | 923fdb1 | 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 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +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]; |
| 188 | LandingPad.LandingPadLabel = MappedLabel(LandingPad.LandingPadLabel); |
| 189 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 190 | // Special case: we *should* emit LPs with null LP MBB. This indicates |
Duncan Sands | 4ff179f | 2007-12-19 07:36:31 +0000 | [diff] [blame] | 191 | // "nounwind" case. |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 192 | if (!LandingPad.LandingPadLabel && LandingPad.LandingPadBlock) { |
| 193 | LandingPads.erase(LandingPads.begin() + i); |
| 194 | continue; |
| 195 | } |
Duncan Sands | 241a0c9 | 2007-09-05 11:27:52 +0000 | [diff] [blame] | 196 | |
Bill Wendling | 4de8de5 | 2008-07-03 22:53:42 +0000 | [diff] [blame] | 197 | for (unsigned j=0; j != LandingPads[i].BeginLabels.size(); ) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 198 | unsigned BeginLabel = MappedLabel(LandingPad.BeginLabels[j]); |
| 199 | unsigned EndLabel = MappedLabel(LandingPad.EndLabels[j]); |
Duncan Sands | 241a0c9 | 2007-09-05 11:27:52 +0000 | [diff] [blame] | 200 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 201 | if (!BeginLabel || !EndLabel) { |
| 202 | LandingPad.BeginLabels.erase(LandingPad.BeginLabels.begin() + j); |
| 203 | LandingPad.EndLabels.erase(LandingPad.EndLabels.begin() + j); |
| 204 | continue; |
| 205 | } |
| 206 | |
| 207 | LandingPad.BeginLabels[j] = BeginLabel; |
| 208 | LandingPad.EndLabels[j] = EndLabel; |
| 209 | ++j; |
| 210 | } |
Duncan Sands | 241a0c9 | 2007-09-05 11:27:52 +0000 | [diff] [blame] | 211 | |
| 212 | // Remove landing pads with no try-ranges. |
Dan Gohman | 301f405 | 2008-01-29 13:02:09 +0000 | [diff] [blame] | 213 | if (LandingPads[i].BeginLabels.empty()) { |
Duncan Sands | 241a0c9 | 2007-09-05 11:27:52 +0000 | [diff] [blame] | 214 | LandingPads.erase(LandingPads.begin() + i); |
| 215 | continue; |
| 216 | } |
| 217 | |
| 218 | // If there is no landing pad, ensure that the list of typeids is empty. |
| 219 | // If the only typeid is a cleanup, this is the same as having no typeids. |
| 220 | if (!LandingPad.LandingPadBlock || |
| 221 | (LandingPad.TypeIds.size() == 1 && !LandingPad.TypeIds[0])) |
| 222 | LandingPad.TypeIds.clear(); |
| 223 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 224 | ++i; |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | /// getTypeIDFor - Return the type id for the specified typeinfo. This is |
| 229 | /// function wide. |
| 230 | unsigned MachineModuleInfo::getTypeIDFor(GlobalVariable *TI) { |
Bill Wendling | 4de8de5 | 2008-07-03 22:53:42 +0000 | [diff] [blame] | 231 | for (unsigned i = 0, N = TypeInfos.size(); i != N; ++i) |
| 232 | if (TypeInfos[i] == TI) return i + 1; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 233 | |
| 234 | TypeInfos.push_back(TI); |
| 235 | return TypeInfos.size(); |
| 236 | } |
| 237 | |
| 238 | /// getFilterIDFor - Return the filter id for the specified typeinfos. This is |
| 239 | /// function wide. |
Bill Wendling | 0e679b8 | 2008-06-27 01:27:56 +0000 | [diff] [blame] | 240 | int MachineModuleInfo::getFilterIDFor(std::vector<unsigned> &TyIds) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 241 | // If the new filter coincides with the tail of an existing filter, then |
| 242 | // re-use the existing filter. Folding filters more than this requires |
| 243 | // re-ordering filters and/or their elements - probably not worth it. |
| 244 | for (std::vector<unsigned>::iterator I = FilterEnds.begin(), |
| 245 | E = FilterEnds.end(); I != E; ++I) { |
Bill Wendling | 0e679b8 | 2008-06-27 01:27:56 +0000 | [diff] [blame] | 246 | unsigned i = *I, j = TyIds.size(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 247 | |
| 248 | while (i && j) |
| 249 | if (FilterIds[--i] != TyIds[--j]) |
| 250 | goto try_next; |
| 251 | |
| 252 | if (!j) |
| 253 | // The new filter coincides with range [i, end) of the existing filter. |
| 254 | return -(1 + i); |
Bill Wendling | 0e679b8 | 2008-06-27 01:27:56 +0000 | [diff] [blame] | 255 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 256 | try_next:; |
| 257 | } |
| 258 | |
| 259 | // Add the new filter. |
Bill Wendling | 0e679b8 | 2008-06-27 01:27:56 +0000 | [diff] [blame] | 260 | int FilterID = -(1 + FilterIds.size()); |
| 261 | FilterIds.reserve(FilterIds.size() + TyIds.size() + 1); |
| 262 | for (unsigned I = 0, N = TyIds.size(); I != N; ++I) |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 263 | FilterIds.push_back(TyIds[I]); |
Bill Wendling | 0e679b8 | 2008-06-27 01:27:56 +0000 | [diff] [blame] | 264 | FilterEnds.push_back(FilterIds.size()); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 265 | FilterIds.push_back(0); // terminator |
| 266 | return FilterID; |
| 267 | } |
| 268 | |
| 269 | /// getPersonality - Return the personality function for the current function. |
| 270 | Function *MachineModuleInfo::getPersonality() const { |
| 271 | // FIXME: Until PR1414 will be fixed, we're using 1 personality function per |
| 272 | // function |
| 273 | return !LandingPads.empty() ? LandingPads[0].Personality : NULL; |
| 274 | } |
| 275 | |
| 276 | /// getPersonalityIndex - Return unique index for current personality |
| 277 | /// function. NULL personality function should always get zero index. |
| 278 | unsigned MachineModuleInfo::getPersonalityIndex() const { |
| 279 | const Function* Personality = NULL; |
| 280 | |
| 281 | // Scan landing pads. If there is at least one non-NULL personality - use it. |
Bill Wendling | 4de8de5 | 2008-07-03 22:53:42 +0000 | [diff] [blame] | 282 | for (unsigned i = 0; i != LandingPads.size(); ++i) |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 283 | if (LandingPads[i].Personality) { |
| 284 | Personality = LandingPads[i].Personality; |
| 285 | break; |
| 286 | } |
| 287 | |
Bill Wendling | 4de8de5 | 2008-07-03 22:53:42 +0000 | [diff] [blame] | 288 | for (unsigned i = 0; i < Personalities.size(); ++i) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 289 | if (Personalities[i] == Personality) |
| 290 | return i; |
Bill Wendling | 4de8de5 | 2008-07-03 22:53:42 +0000 | [diff] [blame] | 291 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 292 | |
| 293 | // This should never happen |
Edwin Török | 675d562 | 2009-07-11 20:10:48 +0000 | [diff] [blame^] | 294 | LLVM_UNREACHABLE("Personality function should be set!"); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 295 | return 0; |
| 296 | } |
| 297 | |
| 298 | //===----------------------------------------------------------------------===// |
| 299 | /// DebugLabelFolding pass - This pass prunes out redundant labels. This allows |
| 300 | /// a info consumer to determine if the range of two labels is empty, by seeing |
| 301 | /// if the labels map to the same reduced label. |
| 302 | |
| 303 | namespace llvm { |
| 304 | |
| 305 | struct DebugLabelFolder : public MachineFunctionPass { |
| 306 | static char ID; |
Dan Gohman | 26f8c27 | 2008-09-04 17:05:41 +0000 | [diff] [blame] | 307 | DebugLabelFolder() : MachineFunctionPass(&ID) {} |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 308 | |
Evan Cheng | 465a66e | 2008-09-22 20:58:04 +0000 | [diff] [blame] | 309 | virtual void getAnalysisUsage(AnalysisUsage &AU) const { |
Evan Cheng | 1b42ac1 | 2008-09-22 22:21:38 +0000 | [diff] [blame] | 310 | AU.addPreservedID(MachineLoopInfoID); |
| 311 | AU.addPreservedID(MachineDominatorsID); |
Evan Cheng | 465a66e | 2008-09-22 20:58:04 +0000 | [diff] [blame] | 312 | MachineFunctionPass::getAnalysisUsage(AU); |
| 313 | } |
| 314 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 315 | virtual bool runOnMachineFunction(MachineFunction &MF); |
| 316 | virtual const char *getPassName() const { return "Label Folder"; } |
| 317 | }; |
| 318 | |
| 319 | char DebugLabelFolder::ID = 0; |
| 320 | |
| 321 | bool DebugLabelFolder::runOnMachineFunction(MachineFunction &MF) { |
| 322 | // Get machine module info. |
Duncan Sands | 4e0d6a7 | 2009-01-28 13:14:17 +0000 | [diff] [blame] | 323 | MachineModuleInfo *MMI = getAnalysisIfAvailable<MachineModuleInfo>(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 324 | if (!MMI) return false; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 325 | |
| 326 | // Track if change is made. |
| 327 | bool MadeChange = false; |
| 328 | // No prior label to begin. |
| 329 | unsigned PriorLabel = 0; |
| 330 | |
| 331 | // Iterate through basic blocks. |
| 332 | for (MachineFunction::iterator BB = MF.begin(), E = MF.end(); |
| 333 | BB != E; ++BB) { |
| 334 | // Iterate through instructions. |
| 335 | for (MachineBasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ) { |
| 336 | // Is it a label. |
Devang Patel | 9a72741 | 2009-04-10 18:58:59 +0000 | [diff] [blame] | 337 | if (I->isDebugLabel() && !MMI->isDbgLabelUsed(I->getOperand(0).getImm())){ |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 338 | // The label ID # is always operand #0, an immediate. |
| 339 | unsigned NextLabel = I->getOperand(0).getImm(); |
| 340 | |
| 341 | // If there was an immediate prior label. |
| 342 | if (PriorLabel) { |
| 343 | // Remap the current label to prior label. |
| 344 | MMI->RemapLabel(NextLabel, PriorLabel); |
| 345 | // Delete the current label. |
| 346 | I = BB->erase(I); |
| 347 | // Indicate a change has been made. |
| 348 | MadeChange = true; |
| 349 | continue; |
| 350 | } else { |
| 351 | // Start a new round. |
| 352 | PriorLabel = NextLabel; |
| 353 | } |
| 354 | } else { |
| 355 | // No consecutive labels. |
| 356 | PriorLabel = 0; |
| 357 | } |
| 358 | |
| 359 | ++I; |
| 360 | } |
| 361 | } |
| 362 | |
| 363 | return MadeChange; |
| 364 | } |
| 365 | |
| 366 | FunctionPass *createDebugLabelFoldingPass() { return new DebugLabelFolder(); } |
| 367 | |
| 368 | } |
Bill Wendling | 4de8de5 | 2008-07-03 22:53:42 +0000 | [diff] [blame] | 369 | |