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