| OLD | NEW |
| 1 //===-- AsmPrinter.cpp - Common AsmPrinter code ---------------------------===// | 1 //===-- AsmPrinter.cpp - Common AsmPrinter code ---------------------------===// |
| 2 // | 2 // |
| 3 // The LLVM Compiler Infrastructure | 3 // The LLVM Compiler Infrastructure |
| 4 // | 4 // |
| 5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
| 6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
| 7 // | 7 // |
| 8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
| 9 // | 9 // |
| 10 // This file implements the AsmPrinter class. | 10 // This file implements the AsmPrinter class. |
| (...skipping 742 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 753 | 753 |
| 754 if (isVerbose()) | 754 if (isVerbose()) |
| 755 emitComments(MI, OutStreamer.GetCommentOS()); | 755 emitComments(MI, OutStreamer.GetCommentOS()); |
| 756 | 756 |
| 757 switch (MI.getOpcode()) { | 757 switch (MI.getOpcode()) { |
| 758 case TargetOpcode::CFI_INSTRUCTION: | 758 case TargetOpcode::CFI_INSTRUCTION: |
| 759 emitCFIInstruction(MI); | 759 emitCFIInstruction(MI); |
| 760 break; | 760 break; |
| 761 | 761 |
| 762 case TargetOpcode::EH_LABEL: | 762 case TargetOpcode::EH_LABEL: |
| 763 case TargetOpcode::GC_LABEL: | 763 case TargetOpcode::GC_LABEL: { |
| 764 // @LOCALMOD-START |
| 765 if (unsigned LabelAlign = GetTargetLabelAlign(&MI)) |
| 766 EmitAlignment(LabelAlign); |
| 767 // @LOCALMOD-END |
| 764 OutStreamer.EmitLabel(MI.getOperand(0).getMCSymbol()); | 768 OutStreamer.EmitLabel(MI.getOperand(0).getMCSymbol()); |
| 765 break; | 769 break; |
| 770 } |
| 766 case TargetOpcode::INLINEASM: | 771 case TargetOpcode::INLINEASM: |
| 767 EmitInlineAsm(&MI); | 772 EmitInlineAsm(&MI); |
| 768 break; | 773 break; |
| 769 case TargetOpcode::DBG_VALUE: | 774 case TargetOpcode::DBG_VALUE: |
| 770 if (isVerbose()) { | 775 if (isVerbose()) { |
| 771 if (!emitDebugValueComment(&MI, *this)) | 776 if (!emitDebugValueComment(&MI, *this)) |
| 772 EmitInstruction(&MI); | 777 EmitInstruction(&MI); |
| 773 } | 778 } |
| 774 break; | 779 break; |
| 775 case TargetOpcode::IMPLICIT_DEF: | 780 case TargetOpcode::IMPLICIT_DEF: |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1120 const std::vector<MachineJumpTableEntry> &JT = MJTI->getJumpTables(); | 1125 const std::vector<MachineJumpTableEntry> &JT = MJTI->getJumpTables(); |
| 1121 if (JT.empty()) return; | 1126 if (JT.empty()) return; |
| 1122 | 1127 |
| 1123 // Pick the directive to use to print the jump table entries, and switch to | 1128 // Pick the directive to use to print the jump table entries, and switch to |
| 1124 // the appropriate section. | 1129 // the appropriate section. |
| 1125 const Function *F = MF->getFunction(); | 1130 const Function *F = MF->getFunction(); |
| 1126 bool JTInDiffSection = false; | 1131 bool JTInDiffSection = false; |
| 1127 if (// In PIC mode, we need to emit the jump table to the same section as the | 1132 if (// In PIC mode, we need to emit the jump table to the same section as the |
| 1128 // function body itself, otherwise the label differences won't make sense. | 1133 // function body itself, otherwise the label differences won't make sense. |
| 1129 // FIXME: Need a better predicate for this: what about custom entries? | 1134 // FIXME: Need a better predicate for this: what about custom entries? |
| 1130 MJTI->getEntryKind() == MachineJumpTableInfo::EK_LabelDifference32 || | 1135 (MJTI->getEntryKind() == MachineJumpTableInfo::EK_LabelDifference32 || |
| 1131 // We should also do if the section name is NULL or function is declared | 1136 // We should also do if the section name is NULL or function is declared |
| 1132 // in discardable section | 1137 // in discardable section |
| 1133 // FIXME: this isn't the right predicate, should be based on the MCSection | 1138 // FIXME: this isn't the right predicate, should be based on the MCSection |
| 1134 // for the function. | 1139 // for the function. |
| 1135 F->isWeakForLinker()) { | 1140 // @LOCALMOD-START |
| 1141 // the original code is a hack |
| 1142 // jumptables usually end up in .rodata |
| 1143 // but for functions with weak linkage there is a chance that the are |
| 1144 // not needed. So in order to be discard the function AND the jumptable |
| 1145 // they keep them both in .text. This fix only works if we never discard |
| 1146 // weak functions. This is guaranteed because the bitcode linker already |
| 1147 // throws out unused ones. |
| 1148 // TODO: Investigate the other case of concern -- PIC code. |
| 1149 // Concern is about jumptables being in a different section: can the |
| 1150 // rodata and text be too far apart for a RIP-relative offset? |
| 1151 F->isWeakForLinker()) |
| 1152 && !UseReadOnlyJumpTables()) { |
| 1136 OutStreamer.SwitchSection( | 1153 OutStreamer.SwitchSection( |
| 1137 getObjFileLowering().SectionForGlobal(F, *Mang, TM)); | 1154 getObjFileLowering().SectionForGlobal(F, *Mang, TM)); |
| 1138 } else { | 1155 } else { |
| 1139 // Otherwise, drop it in the readonly section. | 1156 // Otherwise, drop it in the readonly section. |
| 1157 // (localmod: pick a readonly section based on the properties of F, which |
| 1158 // means a unique readonly section if F gets a unique text section) |
| 1140 const MCSection *ReadOnlySection = | 1159 const MCSection *ReadOnlySection = |
| 1141 getObjFileLowering().getSectionForConstant(SectionKind::getReadOnly(), | 1160 getObjFileLowering().SectionForGlobal( |
| 1142 /*C=*/nullptr); | 1161 F, SectionKind::getReadOnly(), *Mang, TM); |
| 1162 // @LOCALMOD-END |
| 1143 OutStreamer.SwitchSection(ReadOnlySection); | 1163 OutStreamer.SwitchSection(ReadOnlySection); |
| 1144 JTInDiffSection = true; | 1164 JTInDiffSection = true; |
| 1145 } | 1165 } |
| 1146 | 1166 |
| 1147 EmitAlignment(Log2_32( | 1167 EmitAlignment(Log2_32( |
| 1148 MJTI->getEntryAlignment(*TM.getSubtargetImpl()->getDataLayout()))); | 1168 MJTI->getEntryAlignment(*TM.getSubtargetImpl()->getDataLayout()))); |
| 1149 | 1169 |
| 1150 // Jump tables in code sections are marked with a data_region directive | 1170 // Jump tables in code sections are marked with a data_region directive |
| 1151 // where that's supported. | 1171 // where that's supported. |
| 1152 if (!JTInDiffSection) | 1172 if (!JTInDiffSection) |
| 1153 OutStreamer.EmitDataRegion(MCDR_DataRegionJT32); | 1173 OutStreamer.EmitDataRegion(MCDR_DataRegionJT32); |
| 1154 | 1174 |
| 1155 for (unsigned JTI = 0, e = JT.size(); JTI != e; ++JTI) { | 1175 for (unsigned JTI = 0, e = JT.size(); JTI != e; ++JTI) { |
| 1156 const std::vector<MachineBasicBlock*> &JTBBs = JT[JTI].MBBs; | 1176 const std::vector<MachineBasicBlock*> &JTBBs = JT[JTI].MBBs; |
| 1157 | 1177 |
| 1158 // If this jump table was deleted, ignore it. | 1178 // If this jump table was deleted, ignore it. |
| 1159 if (JTBBs.empty()) continue; | 1179 if (JTBBs.empty()) continue; |
| 1160 | 1180 |
| 1161 // For the EK_LabelDifference32 entry, if using .set avoids a relocation, | 1181 // For the EK_LabelDifference32 entry, if using .set avoids a relocation, |
| 1162 /// emit a .set directive for each unique entry. | 1182 /// emit a .set directive for each unique entry. |
| 1163 if (MJTI->getEntryKind() == MachineJumpTableInfo::EK_LabelDifference32 && | 1183 if (MJTI->getEntryKind() == MachineJumpTableInfo::EK_LabelDifference32 && |
| 1164 MAI->doesSetDirectiveSuppressesReloc()) { | 1184 MAI->doesSetDirectiveSuppressesReloc() && |
| 1185 !UseReadOnlyJumpTables()) { // @LOCALMOD |
| 1165 SmallPtrSet<const MachineBasicBlock*, 16> EmittedSets; | 1186 SmallPtrSet<const MachineBasicBlock*, 16> EmittedSets; |
| 1166 const TargetLowering *TLI = TM.getSubtargetImpl()->getTargetLowering(); | 1187 const TargetLowering *TLI = TM.getSubtargetImpl()->getTargetLowering(); |
| 1167 const MCExpr *Base = TLI->getPICJumpTableRelocBaseExpr(MF,JTI,OutContext); | 1188 const MCExpr *Base = TLI->getPICJumpTableRelocBaseExpr(MF,JTI,OutContext); |
| 1168 for (unsigned ii = 0, ee = JTBBs.size(); ii != ee; ++ii) { | 1189 for (unsigned ii = 0, ee = JTBBs.size(); ii != ee; ++ii) { |
| 1169 const MachineBasicBlock *MBB = JTBBs[ii]; | 1190 const MachineBasicBlock *MBB = JTBBs[ii]; |
| 1170 if (!EmittedSets.insert(MBB).second) | 1191 if (!EmittedSets.insert(MBB).second) |
| 1171 continue; | 1192 continue; |
| 1172 | 1193 |
| 1173 // .set LJTSet, LBB32-base | 1194 // .set LJTSet, LBB32-base |
| 1174 const MCExpr *LHS = | 1195 const MCExpr *LHS = |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1235 } | 1256 } |
| 1236 | 1257 |
| 1237 case MachineJumpTableInfo::EK_LabelDifference32: { | 1258 case MachineJumpTableInfo::EK_LabelDifference32: { |
| 1238 // Each entry is the address of the block minus the address of the jump | 1259 // Each entry is the address of the block minus the address of the jump |
| 1239 // table. This is used for PIC jump tables where gprel32 is not supported. | 1260 // table. This is used for PIC jump tables where gprel32 is not supported. |
| 1240 // e.g.: | 1261 // e.g.: |
| 1241 // .word LBB123 - LJTI1_2 | 1262 // .word LBB123 - LJTI1_2 |
| 1242 // If the .set directive avoids relocations, this is emitted as: | 1263 // If the .set directive avoids relocations, this is emitted as: |
| 1243 // .set L4_5_set_123, LBB123 - LJTI1_2 | 1264 // .set L4_5_set_123, LBB123 - LJTI1_2 |
| 1244 // .word L4_5_set_123 | 1265 // .word L4_5_set_123 |
| 1245 if (MAI->doesSetDirectiveSuppressesReloc()) { | 1266 if (MAI->doesSetDirectiveSuppressesReloc() && |
| 1267 !UseReadOnlyJumpTables()) { // @LOCALMOD |
| 1246 Value = MCSymbolRefExpr::Create(GetJTSetSymbol(UID, MBB->getNumber()), | 1268 Value = MCSymbolRefExpr::Create(GetJTSetSymbol(UID, MBB->getNumber()), |
| 1247 OutContext); | 1269 OutContext); |
| 1248 break; | 1270 break; |
| 1249 } | 1271 } |
| 1250 Value = MCSymbolRefExpr::Create(MBB->getSymbol(), OutContext); | 1272 Value = MCSymbolRefExpr::Create(MBB->getSymbol(), OutContext); |
| 1251 const TargetLowering *TLI = TM.getSubtargetImpl()->getTargetLowering(); | 1273 const TargetLowering *TLI = TM.getSubtargetImpl()->getTargetLowering(); |
| 1252 const MCExpr *Base = TLI->getPICJumpTableRelocBaseExpr(MF, UID, OutContext); | 1274 const MCExpr *Base = TLI->getPICJumpTableRelocBaseExpr(MF, UID, OutContext); |
| 1253 Value = MCBinaryExpr::CreateSub(Value, Base, OutContext); | 1275 Value = MCBinaryExpr::CreateSub(Value, Base, OutContext); |
| 1254 break; | 1276 break; |
| 1255 } | 1277 } |
| (...skipping 1011 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2267 GMP->S = &S; | 2289 GMP->S = &S; |
| 2268 auto IterBool = GCMap.insert(std::make_pair(&S, std::move(GMP))); | 2290 auto IterBool = GCMap.insert(std::make_pair(&S, std::move(GMP))); |
| 2269 return IterBool.first->second.get(); | 2291 return IterBool.first->second.get(); |
| 2270 } | 2292 } |
| 2271 | 2293 |
| 2272 report_fatal_error("no GCMetadataPrinter registered for GC: " + Twine(Name)); | 2294 report_fatal_error("no GCMetadataPrinter registered for GC: " + Twine(Name)); |
| 2273 } | 2295 } |
| 2274 | 2296 |
| 2275 /// Pin vtable to this file. | 2297 /// Pin vtable to this file. |
| 2276 AsmPrinterHandler::~AsmPrinterHandler() {} | 2298 AsmPrinterHandler::~AsmPrinterHandler() {} |
| OLD | NEW |