Chris Lattner | a80ba71 | 2004-08-16 23:15:22 +0000 | [diff] [blame] | 1 | //===-- AsmPrinter.cpp - Common AsmPrinter code ---------------------------===// |
| 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. |
Chris Lattner | a80ba71 | 2004-08-16 23:15:22 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the AsmPrinter class. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Evan Cheng | 932f022 | 2006-03-03 02:04:29 +0000 | [diff] [blame] | 14 | #include "llvm/CodeGen/AsmPrinter.h" |
Evan Cheng | 246ae0d | 2006-03-01 22:18:09 +0000 | [diff] [blame] | 15 | #include "llvm/Assembly/Writer.h" |
Nate Begeman | 8cfa57b | 2005-12-06 06:18:55 +0000 | [diff] [blame] | 16 | #include "llvm/DerivedTypes.h" |
Chris Lattner | a80ba71 | 2004-08-16 23:15:22 +0000 | [diff] [blame] | 17 | #include "llvm/Constants.h" |
Chris Lattner | 450de39 | 2005-11-10 18:36:17 +0000 | [diff] [blame] | 18 | #include "llvm/Module.h" |
Gordon Henriksen | 5eca075 | 2008-08-17 18:44:35 +0000 | [diff] [blame] | 19 | #include "llvm/CodeGen/GCMetadataPrinter.h" |
Chris Lattner | 3b4fd32 | 2005-11-21 08:25:09 +0000 | [diff] [blame] | 20 | #include "llvm/CodeGen/MachineConstantPool.h" |
David Greene | fe37ab3 | 2009-08-18 19:22:55 +0000 | [diff] [blame] | 21 | #include "llvm/CodeGen/MachineFunction.h" |
Nate Begeman | 37efe67 | 2006-04-22 18:53:45 +0000 | [diff] [blame] | 22 | #include "llvm/CodeGen/MachineJumpTableInfo.h" |
David Greene | b71d1b2 | 2009-08-10 16:38:07 +0000 | [diff] [blame] | 23 | #include "llvm/CodeGen/MachineLoopInfo.h" |
Chris Lattner | 84bc542 | 2007-12-31 04:13:23 +0000 | [diff] [blame] | 24 | #include "llvm/CodeGen/MachineModuleInfo.h" |
Devang Patel | c48c550 | 2009-01-13 21:44:10 +0000 | [diff] [blame] | 25 | #include "llvm/CodeGen/DwarfWriter.h" |
Argyrios Kyrtzidis | cd76240 | 2009-05-07 13:55:51 +0000 | [diff] [blame] | 26 | #include "llvm/Analysis/DebugInfo.h" |
Chris Lattner | 2b2954f | 2009-07-27 21:28:04 +0000 | [diff] [blame] | 27 | #include "llvm/MC/MCContext.h" |
David Greene | 3ac1ab8 | 2009-07-16 22:24:20 +0000 | [diff] [blame] | 28 | #include "llvm/MC/MCInst.h" |
Chris Lattner | a87dea4 | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 29 | #include "llvm/MC/MCSection.h" |
| 30 | #include "llvm/MC/MCStreamer.h" |
Chris Lattner | 7cb384d | 2009-09-12 23:02:08 +0000 | [diff] [blame] | 31 | #include "llvm/MC/MCSymbol.h" |
Evan Cheng | 42bf74b | 2009-03-25 01:47:28 +0000 | [diff] [blame] | 32 | #include "llvm/Support/CommandLine.h" |
Torok Edwin | 7d696d8 | 2009-07-11 13:10:19 +0000 | [diff] [blame] | 33 | #include "llvm/Support/ErrorHandling.h" |
David Greene | 014700c | 2009-07-13 20:25:48 +0000 | [diff] [blame] | 34 | #include "llvm/Support/FormattedStream.h" |
Chris Lattner | a80ba71 | 2004-08-16 23:15:22 +0000 | [diff] [blame] | 35 | #include "llvm/Support/Mangler.h" |
Chris Lattner | af76e59 | 2009-08-22 20:48:53 +0000 | [diff] [blame] | 36 | #include "llvm/MC/MCAsmInfo.h" |
Owen Anderson | 07000c6 | 2006-05-12 06:33:49 +0000 | [diff] [blame] | 37 | #include "llvm/Target/TargetData.h" |
Chris Lattner | 0336fdb | 2006-10-06 22:50:56 +0000 | [diff] [blame] | 38 | #include "llvm/Target/TargetLowering.h" |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 39 | #include "llvm/Target/TargetLoweringObjectFile.h" |
Evan Cheng | 6547e40 | 2008-07-01 23:18:29 +0000 | [diff] [blame] | 40 | #include "llvm/Target/TargetOptions.h" |
Evan Cheng | da47e6e | 2008-03-15 00:03:38 +0000 | [diff] [blame] | 41 | #include "llvm/Target/TargetRegisterInfo.h" |
Evan Cheng | cc41586 | 2007-11-09 01:32:10 +0000 | [diff] [blame] | 42 | #include "llvm/ADT/SmallPtrSet.h" |
Chris Lattner | fad86b0 | 2008-08-17 07:19:36 +0000 | [diff] [blame] | 43 | #include "llvm/ADT/SmallString.h" |
Owen Anderson | cb37188 | 2008-08-21 00:14:44 +0000 | [diff] [blame] | 44 | #include "llvm/ADT/StringExtras.h" |
Chris Lattner | 6609913 | 2006-02-01 22:41:11 +0000 | [diff] [blame] | 45 | #include <cerrno> |
Chris Lattner | a80ba71 | 2004-08-16 23:15:22 +0000 | [diff] [blame] | 46 | using namespace llvm; |
| 47 | |
Evan Cheng | 42bf74b | 2009-03-25 01:47:28 +0000 | [diff] [blame] | 48 | static cl::opt<cl::boolOrDefault> |
| 49 | AsmVerbose("asm-verbose", cl::desc("Add comments to directives."), |
| 50 | cl::init(cl::BOU_UNSET)); |
| 51 | |
Devang Patel | 1997473 | 2007-05-03 01:11:54 +0000 | [diff] [blame] | 52 | char AsmPrinter::ID = 0; |
David Greene | 7184781 | 2009-07-14 20:18:05 +0000 | [diff] [blame] | 53 | AsmPrinter::AsmPrinter(formatted_raw_ostream &o, TargetMachine &tm, |
Chris Lattner | af76e59 | 2009-08-22 20:48:53 +0000 | [diff] [blame] | 54 | const MCAsmInfo *T, bool VDef) |
Daniel Dunbar | 5bcc8bd | 2009-07-01 01:48:54 +0000 | [diff] [blame] | 55 | : MachineFunctionPass(&ID), FunctionNumber(0), O(o), |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 56 | TM(tm), MAI(T), TRI(tm.getRegisterInfo()), |
Chris Lattner | 2b2954f | 2009-07-27 21:28:04 +0000 | [diff] [blame] | 57 | |
| 58 | OutContext(*new MCContext()), |
Chris Lattner | 90edac0 | 2009-09-14 03:02:37 +0000 | [diff] [blame] | 59 | // FIXME: Pass instprinter to streamer. |
| 60 | OutStreamer(*createAsmStreamer(OutContext, O, *T, 0)), |
Chris Lattner | 2b2954f | 2009-07-27 21:28:04 +0000 | [diff] [blame] | 61 | |
Chris Lattner | 290c2f5 | 2009-08-03 23:20:21 +0000 | [diff] [blame] | 62 | LastMI(0), LastFn(0), Counter(~0U), |
Devang Patel | a143404 | 2009-10-01 01:15:28 +0000 | [diff] [blame] | 63 | PrevDLT(0, 0, ~0U, ~0U) { |
Chris Lattner | 0de1fc4 | 2009-06-24 19:09:55 +0000 | [diff] [blame] | 64 | DW = 0; MMI = 0; |
Evan Cheng | 42bf74b | 2009-03-25 01:47:28 +0000 | [diff] [blame] | 65 | switch (AsmVerbose) { |
| 66 | case cl::BOU_UNSET: VerboseAsm = VDef; break; |
| 67 | case cl::BOU_TRUE: VerboseAsm = true; break; |
| 68 | case cl::BOU_FALSE: VerboseAsm = false; break; |
| 69 | } |
| 70 | } |
Chris Lattner | ed13893 | 2005-12-13 06:32:10 +0000 | [diff] [blame] | 71 | |
Gordon Henriksen | c317a60 | 2008-08-17 12:08:44 +0000 | [diff] [blame] | 72 | AsmPrinter::~AsmPrinter() { |
| 73 | for (gcp_iterator I = GCMetadataPrinters.begin(), |
| 74 | E = GCMetadataPrinters.end(); I != E; ++I) |
| 75 | delete I->second; |
Chris Lattner | 2b2954f | 2009-07-27 21:28:04 +0000 | [diff] [blame] | 76 | |
| 77 | delete &OutStreamer; |
| 78 | delete &OutContext; |
Gordon Henriksen | c317a60 | 2008-08-17 12:08:44 +0000 | [diff] [blame] | 79 | } |
Chris Lattner | ed13893 | 2005-12-13 06:32:10 +0000 | [diff] [blame] | 80 | |
Chris Lattner | 38c3988 | 2009-08-03 19:12:26 +0000 | [diff] [blame] | 81 | TargetLoweringObjectFile &AsmPrinter::getObjFileLowering() const { |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 82 | return TM.getTargetLowering()->getObjFileLowering(); |
| 83 | } |
| 84 | |
Chris Lattner | dabf07c | 2009-08-18 06:15:16 +0000 | [diff] [blame] | 85 | /// getCurrentSection() - Return the current section we are emitting to. |
| 86 | const MCSection *AsmPrinter::getCurrentSection() const { |
| 87 | return OutStreamer.getCurrentSection(); |
| 88 | } |
| 89 | |
| 90 | |
Gordon Henriksen | ce22477 | 2008-01-07 01:30:38 +0000 | [diff] [blame] | 91 | void AsmPrinter::getAnalysisUsage(AnalysisUsage &AU) const { |
Dan Gohman | 845012e | 2009-07-31 23:37:33 +0000 | [diff] [blame] | 92 | AU.setPreservesAll(); |
Gordon Henriksen | ce22477 | 2008-01-07 01:30:38 +0000 | [diff] [blame] | 93 | MachineFunctionPass::getAnalysisUsage(AU); |
Gordon Henriksen | 5eca075 | 2008-08-17 18:44:35 +0000 | [diff] [blame] | 94 | AU.addRequired<GCModuleInfo>(); |
David Greene | fe37ab3 | 2009-08-18 19:22:55 +0000 | [diff] [blame] | 95 | if (VerboseAsm) |
David Greene | b71d1b2 | 2009-08-10 16:38:07 +0000 | [diff] [blame] | 96 | AU.addRequired<MachineLoopInfo>(); |
Gordon Henriksen | ce22477 | 2008-01-07 01:30:38 +0000 | [diff] [blame] | 97 | } |
| 98 | |
Chris Lattner | a80ba71 | 2004-08-16 23:15:22 +0000 | [diff] [blame] | 99 | bool AsmPrinter::doInitialization(Module &M) { |
Chris Lattner | f26e03b | 2009-07-31 17:42:42 +0000 | [diff] [blame] | 100 | // Initialize TargetLoweringObjectFile. |
| 101 | const_cast<TargetLoweringObjectFile&>(getObjFileLowering()) |
| 102 | .Initialize(OutContext, TM); |
| 103 | |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 104 | Mang = new Mangler(M, MAI->getGlobalPrefix(), MAI->getPrivateGlobalPrefix(), |
| 105 | MAI->getLinkerPrivateGlobalPrefix()); |
Chris Lattner | 2c1b159 | 2006-01-23 23:47:53 +0000 | [diff] [blame] | 106 | |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 107 | if (MAI->doesAllowQuotesInName()) |
Chris Lattner | a93ca92 | 2009-06-18 23:41:35 +0000 | [diff] [blame] | 108 | Mang->setUseQuotes(true); |
Anton Korobeynikov | c6f729e | 2009-09-18 16:57:42 +0000 | [diff] [blame] | 109 | |
| 110 | if (MAI->doesAllowNameToStartWithDigit()) |
| 111 | Mang->setSymbolsCanStartWithDigit(true); |
Chris Lattner | a93ca92 | 2009-06-18 23:41:35 +0000 | [diff] [blame] | 112 | |
Bob Wilson | 812209a | 2009-09-30 22:06:26 +0000 | [diff] [blame] | 113 | // Allow the target to emit any magic that it wants at the start of the file. |
| 114 | EmitStartOfAsmFile(M); |
Rafael Espindola | 952b839 | 2008-12-03 11:01:37 +0000 | [diff] [blame] | 115 | |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 116 | if (MAI->hasSingleParameterDotFile()) { |
Rafael Espindola | 952b839 | 2008-12-03 11:01:37 +0000 | [diff] [blame] | 117 | /* Very minimal debug info. It is ignored if we emit actual |
Bob Wilson | bc9506f | 2009-09-30 21:26:13 +0000 | [diff] [blame] | 118 | debug info. If we don't, this at least helps the user find where |
Rafael Espindola | 952b839 | 2008-12-03 11:01:37 +0000 | [diff] [blame] | 119 | a function came from. */ |
| 120 | O << "\t.file\t\"" << M.getModuleIdentifier() << "\"\n"; |
| 121 | } |
| 122 | |
Bob Wilson | 812209a | 2009-09-30 22:06:26 +0000 | [diff] [blame] | 123 | GCModuleInfo *MI = getAnalysisIfAvailable<GCModuleInfo>(); |
| 124 | assert(MI && "AsmPrinter didn't require GCModuleInfo?"); |
Gordon Henriksen | 5eca075 | 2008-08-17 18:44:35 +0000 | [diff] [blame] | 125 | for (GCModuleInfo::iterator I = MI->begin(), E = MI->end(); I != E; ++I) |
| 126 | if (GCMetadataPrinter *MP = GetOrCreateGCPrinter(*I)) |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 127 | MP->beginAssembly(O, *this, *MAI); |
Gordon Henriksen | ce22477 | 2008-01-07 01:30:38 +0000 | [diff] [blame] | 128 | |
Chris Lattner | 3e2fa7a | 2006-01-24 04:16:34 +0000 | [diff] [blame] | 129 | if (!M.getModuleInlineAsm().empty()) |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 130 | O << MAI->getCommentString() << " Start of file scope inline assembly\n" |
Chris Lattner | 3e2fa7a | 2006-01-24 04:16:34 +0000 | [diff] [blame] | 131 | << M.getModuleInlineAsm() |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 132 | << '\n' << MAI->getCommentString() |
Jim Laskey | 563321a | 2006-09-06 18:34:40 +0000 | [diff] [blame] | 133 | << " End of file scope inline assembly\n"; |
Chris Lattner | 2c1b159 | 2006-01-23 23:47:53 +0000 | [diff] [blame] | 134 | |
Chris Lattner | b55e068 | 2009-09-24 05:44:53 +0000 | [diff] [blame] | 135 | MMI = getAnalysisIfAvailable<MachineModuleInfo>(); |
| 136 | if (MMI) |
| 137 | MMI->AnalyzeModule(M); |
| 138 | DW = getAnalysisIfAvailable<DwarfWriter>(); |
| 139 | if (DW) |
| 140 | DW->BeginModule(&M, MMI, O, this, MAI); |
Devang Patel | 14a55d9 | 2009-06-19 21:54:26 +0000 | [diff] [blame] | 141 | |
Chris Lattner | a80ba71 | 2004-08-16 23:15:22 +0000 | [diff] [blame] | 142 | return false; |
| 143 | } |
| 144 | |
| 145 | bool AsmPrinter::doFinalization(Module &M) { |
Chris Lattner | 40bbebd | 2009-07-21 18:38:57 +0000 | [diff] [blame] | 146 | // Emit global variables. |
| 147 | for (Module::const_global_iterator I = M.global_begin(), E = M.global_end(); |
| 148 | I != E; ++I) |
| 149 | PrintGlobalVariable(I); |
| 150 | |
Chris Lattner | 1f522fe | 2009-06-24 18:54:37 +0000 | [diff] [blame] | 151 | // Emit final debug information. |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 152 | if (MAI->doesSupportDebugInformation() || MAI->doesSupportExceptionHandling()) |
Chris Lattner | 1f522fe | 2009-06-24 18:54:37 +0000 | [diff] [blame] | 153 | DW->EndModule(); |
| 154 | |
Chris Lattner | 0a7befa | 2009-06-24 18:52:01 +0000 | [diff] [blame] | 155 | // If the target wants to know about weak references, print them all. |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 156 | if (MAI->getWeakRefDirective()) { |
Chris Lattner | 0a7befa | 2009-06-24 18:52:01 +0000 | [diff] [blame] | 157 | // FIXME: This is not lazy, it would be nice to only print weak references |
| 158 | // to stuff that is actually used. Note that doing so would require targets |
| 159 | // to notice uses in operands (due to constant exprs etc). This should |
| 160 | // happen with the MC stuff eventually. |
Rafael Espindola | 15404d0 | 2006-12-18 03:37:18 +0000 | [diff] [blame] | 161 | |
Chris Lattner | 0a7befa | 2009-06-24 18:52:01 +0000 | [diff] [blame] | 162 | // Print out module-level global variables here. |
| 163 | for (Module::const_global_iterator I = M.global_begin(), E = M.global_end(); |
| 164 | I != E; ++I) { |
| 165 | if (I->hasExternalWeakLinkage()) |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 166 | O << MAI->getWeakRefDirective() << Mang->getMangledName(I) << '\n'; |
Chris Lattner | 0a7befa | 2009-06-24 18:52:01 +0000 | [diff] [blame] | 167 | } |
| 168 | |
Chris Lattner | c6fdced | 2009-08-03 23:10:34 +0000 | [diff] [blame] | 169 | for (Module::const_iterator I = M.begin(), E = M.end(); I != E; ++I) { |
Chris Lattner | 0a7befa | 2009-06-24 18:52:01 +0000 | [diff] [blame] | 170 | if (I->hasExternalWeakLinkage()) |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 171 | O << MAI->getWeakRefDirective() << Mang->getMangledName(I) << '\n'; |
Chris Lattner | 0a7befa | 2009-06-24 18:52:01 +0000 | [diff] [blame] | 172 | } |
Rafael Espindola | 15404d0 | 2006-12-18 03:37:18 +0000 | [diff] [blame] | 173 | } |
| 174 | |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 175 | if (MAI->getSetDirective()) { |
Dan Gohman | d19a53b | 2008-06-30 22:03:41 +0000 | [diff] [blame] | 176 | O << '\n'; |
Anton Korobeynikov | 8b0a8c8 | 2007-04-25 14:27:10 +0000 | [diff] [blame] | 177 | for (Module::const_alias_iterator I = M.alias_begin(), E = M.alias_end(); |
Chris Lattner | 0a7befa | 2009-06-24 18:52:01 +0000 | [diff] [blame] | 178 | I != E; ++I) { |
Chris Lattner | b8158ac | 2009-07-14 18:17:16 +0000 | [diff] [blame] | 179 | std::string Name = Mang->getMangledName(I); |
Anton Korobeynikov | 325be7c | 2007-09-06 17:21:48 +0000 | [diff] [blame] | 180 | |
| 181 | const GlobalValue *GV = cast<GlobalValue>(I->getAliasedGlobal()); |
Chris Lattner | b8158ac | 2009-07-14 18:17:16 +0000 | [diff] [blame] | 182 | std::string Target = Mang->getMangledName(GV); |
Anton Korobeynikov | 541af7f | 2008-09-24 22:21:04 +0000 | [diff] [blame] | 183 | |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 184 | if (I->hasExternalLinkage() || !MAI->getWeakRefDirective()) |
Dan Gohman | d19a53b | 2008-06-30 22:03:41 +0000 | [diff] [blame] | 185 | O << "\t.globl\t" << Name << '\n'; |
Anton Korobeynikov | 8b0a8c8 | 2007-04-25 14:27:10 +0000 | [diff] [blame] | 186 | else if (I->hasWeakLinkage()) |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 187 | O << MAI->getWeakRefDirective() << Name << '\n'; |
Rafael Espindola | bb46f52 | 2009-01-15 20:18:42 +0000 | [diff] [blame] | 188 | else if (!I->hasLocalLinkage()) |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 189 | llvm_unreachable("Invalid alias linkage"); |
Anton Korobeynikov | 22c9e65 | 2008-03-11 21:41:14 +0000 | [diff] [blame] | 190 | |
Anton Korobeynikov | 541af7f | 2008-09-24 22:21:04 +0000 | [diff] [blame] | 191 | printVisibility(Name, I->getVisibility()); |
Anton Korobeynikov | 22c9e65 | 2008-03-11 21:41:14 +0000 | [diff] [blame] | 192 | |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 193 | O << MAI->getSetDirective() << ' ' << Name << ", " << Target << '\n'; |
Anton Korobeynikov | 8b0a8c8 | 2007-04-25 14:27:10 +0000 | [diff] [blame] | 194 | } |
| 195 | } |
| 196 | |
Duncan Sands | 1465d61 | 2009-01-28 13:14:17 +0000 | [diff] [blame] | 197 | GCModuleInfo *MI = getAnalysisIfAvailable<GCModuleInfo>(); |
Gordon Henriksen | 5eca075 | 2008-08-17 18:44:35 +0000 | [diff] [blame] | 198 | assert(MI && "AsmPrinter didn't require GCModuleInfo?"); |
| 199 | for (GCModuleInfo::iterator I = MI->end(), E = MI->begin(); I != E; ) |
| 200 | if (GCMetadataPrinter *MP = GetOrCreateGCPrinter(*--I)) |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 201 | MP->finishAssembly(O, *this, *MAI); |
Gordon Henriksen | ce22477 | 2008-01-07 01:30:38 +0000 | [diff] [blame] | 202 | |
Dan Gohman | a779a98 | 2008-05-05 00:28:39 +0000 | [diff] [blame] | 203 | // If we don't have any trampolines, then we don't require stack memory |
| 204 | // to be executable. Some targets have a directive to declare this. |
Chris Lattner | 0a7befa | 2009-06-24 18:52:01 +0000 | [diff] [blame] | 205 | Function *InitTrampolineIntrinsic = M.getFunction("llvm.init.trampoline"); |
Dan Gohman | a779a98 | 2008-05-05 00:28:39 +0000 | [diff] [blame] | 206 | if (!InitTrampolineIntrinsic || InitTrampolineIntrinsic->use_empty()) |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 207 | if (MAI->getNonexecutableStackDirective()) |
| 208 | O << MAI->getNonexecutableStackDirective() << '\n'; |
Dan Gohman | a779a98 | 2008-05-05 00:28:39 +0000 | [diff] [blame] | 209 | |
Chris Lattner | bd23d5f | 2009-09-18 20:17:03 +0000 | [diff] [blame] | 210 | |
| 211 | // Allow the target to emit any magic that it wants at the end of the file, |
| 212 | // after everything else has gone out. |
| 213 | EmitEndOfAsmFile(M); |
| 214 | |
Chris Lattner | a80ba71 | 2004-08-16 23:15:22 +0000 | [diff] [blame] | 215 | delete Mang; Mang = 0; |
Chris Lattner | 0de1fc4 | 2009-06-24 19:09:55 +0000 | [diff] [blame] | 216 | DW = 0; MMI = 0; |
Chris Lattner | 2b2954f | 2009-07-27 21:28:04 +0000 | [diff] [blame] | 217 | |
| 218 | OutStreamer.Finish(); |
Chris Lattner | a80ba71 | 2004-08-16 23:15:22 +0000 | [diff] [blame] | 219 | return false; |
| 220 | } |
| 221 | |
Chris Lattner | 25045bd | 2005-11-21 07:51:36 +0000 | [diff] [blame] | 222 | void AsmPrinter::SetupMachineFunction(MachineFunction &MF) { |
Chris Lattner | a80ba71 | 2004-08-16 23:15:22 +0000 | [diff] [blame] | 223 | // What's my mangled name? |
Chris Lattner | b8158ac | 2009-07-14 18:17:16 +0000 | [diff] [blame] | 224 | CurrentFnName = Mang->getMangledName(MF.getFunction()); |
Evan Cheng | 347d39f | 2007-10-14 05:57:21 +0000 | [diff] [blame] | 225 | IncrementFunctionNumber(); |
David Greene | b71d1b2 | 2009-08-10 16:38:07 +0000 | [diff] [blame] | 226 | |
Chris Lattner | 25d812b | 2009-09-16 00:35:39 +0000 | [diff] [blame] | 227 | if (VerboseAsm) |
David Greene | b71d1b2 | 2009-08-10 16:38:07 +0000 | [diff] [blame] | 228 | LI = &getAnalysis<MachineLoopInfo>(); |
Chris Lattner | a80ba71 | 2004-08-16 23:15:22 +0000 | [diff] [blame] | 229 | } |
| 230 | |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 231 | namespace { |
| 232 | // SectionCPs - Keep track the alignment, constpool entries per Section. |
| 233 | struct SectionCPs { |
Chris Lattner | a87dea4 | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 234 | const MCSection *S; |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 235 | unsigned Alignment; |
| 236 | SmallVector<unsigned, 4> CPEs; |
Chris Lattner | a87dea4 | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 237 | SectionCPs(const MCSection *s, unsigned a) : S(s), Alignment(a) {}; |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 238 | }; |
| 239 | } |
| 240 | |
Chris Lattner | 3b4fd32 | 2005-11-21 08:25:09 +0000 | [diff] [blame] | 241 | /// EmitConstantPool - Print to the current output stream assembly |
| 242 | /// representations of the constants in the constant pool MCP. This is |
| 243 | /// used to print out constants which have been "spilled to memory" by |
| 244 | /// the code generator. |
| 245 | /// |
| 246 | void AsmPrinter::EmitConstantPool(MachineConstantPool *MCP) { |
Chris Lattner | fa77d43 | 2006-02-09 04:22:52 +0000 | [diff] [blame] | 247 | const std::vector<MachineConstantPoolEntry> &CP = MCP->getConstants(); |
Chris Lattner | 3b4fd32 | 2005-11-21 08:25:09 +0000 | [diff] [blame] | 248 | if (CP.empty()) return; |
Evan Cheng | 2d2cec1 | 2006-06-29 00:26:09 +0000 | [diff] [blame] | 249 | |
Anton Korobeynikov | 088ae83 | 2008-09-24 22:17:59 +0000 | [diff] [blame] | 250 | // Calculate sections for constant pool entries. We collect entries to go into |
| 251 | // the same section together to reduce amount of section switch statements. |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 252 | SmallVector<SectionCPs, 4> CPSections; |
Chris Lattner | 3b4fd32 | 2005-11-21 08:25:09 +0000 | [diff] [blame] | 253 | for (unsigned i = 0, e = CP.size(); i != e; ++i) { |
Chris Lattner | 298414e | 2009-07-22 00:28:43 +0000 | [diff] [blame] | 254 | const MachineConstantPoolEntry &CPE = CP[i]; |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 255 | unsigned Align = CPE.getAlignment(); |
Chris Lattner | 5c2f789 | 2009-07-26 06:26:55 +0000 | [diff] [blame] | 256 | |
| 257 | SectionKind Kind; |
| 258 | switch (CPE.getRelocationInfo()) { |
| 259 | default: llvm_unreachable("Unknown section kind"); |
Chris Lattner | 2798119 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 260 | case 2: Kind = SectionKind::getReadOnlyWithRel(); break; |
Chris Lattner | 4c50922 | 2009-07-26 07:00:12 +0000 | [diff] [blame] | 261 | case 1: |
Chris Lattner | 2798119 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 262 | Kind = SectionKind::getReadOnlyWithRelLocal(); |
Chris Lattner | 4c50922 | 2009-07-26 07:00:12 +0000 | [diff] [blame] | 263 | break; |
Chris Lattner | 5c2f789 | 2009-07-26 06:26:55 +0000 | [diff] [blame] | 264 | case 0: |
Chris Lattner | 4c50922 | 2009-07-26 07:00:12 +0000 | [diff] [blame] | 265 | switch (TM.getTargetData()->getTypeAllocSize(CPE.getType())) { |
Chris Lattner | 2798119 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 266 | case 4: Kind = SectionKind::getMergeableConst4(); break; |
| 267 | case 8: Kind = SectionKind::getMergeableConst8(); break; |
| 268 | case 16: Kind = SectionKind::getMergeableConst16();break; |
| 269 | default: Kind = SectionKind::getMergeableConst(); break; |
Chris Lattner | 4c50922 | 2009-07-26 07:00:12 +0000 | [diff] [blame] | 270 | } |
Chris Lattner | 5c2f789 | 2009-07-26 06:26:55 +0000 | [diff] [blame] | 271 | } |
| 272 | |
Chris Lattner | 83d77fa | 2009-08-01 23:46:12 +0000 | [diff] [blame] | 273 | const MCSection *S = getObjFileLowering().getSectionForConstant(Kind); |
Chris Lattner | 298414e | 2009-07-22 00:28:43 +0000 | [diff] [blame] | 274 | |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 275 | // The number of sections are small, just do a linear search from the |
| 276 | // last section to the first. |
| 277 | bool Found = false; |
| 278 | unsigned SecIdx = CPSections.size(); |
| 279 | while (SecIdx != 0) { |
| 280 | if (CPSections[--SecIdx].S == S) { |
| 281 | Found = true; |
| 282 | break; |
| 283 | } |
| 284 | } |
| 285 | if (!Found) { |
| 286 | SecIdx = CPSections.size(); |
| 287 | CPSections.push_back(SectionCPs(S, Align)); |
| 288 | } |
| 289 | |
| 290 | if (Align > CPSections[SecIdx].Alignment) |
| 291 | CPSections[SecIdx].Alignment = Align; |
| 292 | CPSections[SecIdx].CPEs.push_back(i); |
Evan Cheng | 2d2cec1 | 2006-06-29 00:26:09 +0000 | [diff] [blame] | 293 | } |
| 294 | |
Anton Korobeynikov | 088ae83 | 2008-09-24 22:17:59 +0000 | [diff] [blame] | 295 | // Now print stuff into the calculated sections. |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 296 | for (unsigned i = 0, e = CPSections.size(); i != e; ++i) { |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 297 | OutStreamer.SwitchSection(CPSections[i].S); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 298 | EmitAlignment(Log2_32(CPSections[i].Alignment)); |
Evan Cheng | 2d2cec1 | 2006-06-29 00:26:09 +0000 | [diff] [blame] | 299 | |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 300 | unsigned Offset = 0; |
| 301 | for (unsigned j = 0, ee = CPSections[i].CPEs.size(); j != ee; ++j) { |
| 302 | unsigned CPI = CPSections[i].CPEs[j]; |
| 303 | MachineConstantPoolEntry CPE = CP[CPI]; |
Anton Korobeynikov | 088ae83 | 2008-09-24 22:17:59 +0000 | [diff] [blame] | 304 | |
Chris Lattner | 3029f92 | 2006-02-09 04:46:04 +0000 | [diff] [blame] | 305 | // Emit inter-object padding for alignment. |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 306 | unsigned AlignMask = CPE.getAlignment() - 1; |
| 307 | unsigned NewOffset = (Offset + AlignMask) & ~AlignMask; |
| 308 | EmitZeros(NewOffset - Offset); |
| 309 | |
| 310 | const Type *Ty = CPE.getType(); |
Duncan Sands | 777d230 | 2009-05-09 07:06:46 +0000 | [diff] [blame] | 311 | Offset = NewOffset + TM.getTargetData()->getTypeAllocSize(Ty); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 312 | |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 313 | O << MAI->getPrivateGlobalPrefix() << "CPI" << getFunctionNumber() << '_' |
Dan Gohman | a12e9d7 | 2009-08-12 18:32:22 +0000 | [diff] [blame] | 314 | << CPI << ':'; |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 315 | if (VerboseAsm) { |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 316 | O.PadToColumn(MAI->getCommentColumn()); |
| 317 | O << MAI->getCommentString() << " constant "; |
Dan Gohman | cf20ac4 | 2009-08-13 01:36:44 +0000 | [diff] [blame] | 318 | WriteTypeSymbolic(O, CPE.getType(), MF->getFunction()->getParent()); |
Anton Korobeynikov | 088ae83 | 2008-09-24 22:17:59 +0000 | [diff] [blame] | 319 | } |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 320 | O << '\n'; |
| 321 | if (CPE.isMachineConstantPoolEntry()) |
| 322 | EmitMachineConstantPoolValue(CPE.Val.MachineCPVal); |
| 323 | else |
| 324 | EmitGlobalConstant(CPE.Val.ConstVal); |
Chris Lattner | 3029f92 | 2006-02-09 04:46:04 +0000 | [diff] [blame] | 325 | } |
Chris Lattner | 3b4fd32 | 2005-11-21 08:25:09 +0000 | [diff] [blame] | 326 | } |
| 327 | } |
| 328 | |
Nate Begeman | 37efe67 | 2006-04-22 18:53:45 +0000 | [diff] [blame] | 329 | /// EmitJumpTableInfo - Print assembly representations of the jump tables used |
| 330 | /// by the current function to the current output stream. |
| 331 | /// |
Chris Lattner | 1da31ee | 2006-10-05 03:01:21 +0000 | [diff] [blame] | 332 | void AsmPrinter::EmitJumpTableInfo(MachineJumpTableInfo *MJTI, |
| 333 | MachineFunction &MF) { |
Nate Begeman | 37efe67 | 2006-04-22 18:53:45 +0000 | [diff] [blame] | 334 | const std::vector<MachineJumpTableEntry> &JT = MJTI->getJumpTables(); |
| 335 | if (JT.empty()) return; |
Anton Korobeynikov | 9de1934 | 2007-11-14 09:18:41 +0000 | [diff] [blame] | 336 | |
Jim Laskey | acd80ac | 2006-12-14 19:17:33 +0000 | [diff] [blame] | 337 | bool IsPic = TM.getRelocationModel() == Reloc::PIC_; |
Nate Begeman | 4d9bbdc | 2006-07-27 16:46:58 +0000 | [diff] [blame] | 338 | |
Nate Begeman | 2f1ae88 | 2006-07-27 01:13:04 +0000 | [diff] [blame] | 339 | // Pick the directive to use to print the jump table entries, and switch to |
| 340 | // the appropriate section. |
Jim Laskey | acd80ac | 2006-12-14 19:17:33 +0000 | [diff] [blame] | 341 | TargetLowering *LoweringInfo = TM.getTargetLowering(); |
Anton Korobeynikov | 24287dd | 2006-12-19 21:04:20 +0000 | [diff] [blame] | 342 | |
Anton Korobeynikov | e87f52d | 2008-07-09 13:27:16 +0000 | [diff] [blame] | 343 | const Function *F = MF.getFunction(); |
Evan Cheng | b13bafe | 2009-06-18 20:37:15 +0000 | [diff] [blame] | 344 | bool JTInDiffSection = false; |
Chris Lattner | 83d77fa | 2009-08-01 23:46:12 +0000 | [diff] [blame] | 345 | if (F->isWeakForLinker() || |
| 346 | (IsPic && !LoweringInfo->usesGlobalOffsetTable())) { |
Jim Laskey | acd80ac | 2006-12-14 19:17:33 +0000 | [diff] [blame] | 347 | // In PIC mode, we need to emit the jump table to the same section as the |
| 348 | // function body itself, otherwise the label differences won't make sense. |
Anton Korobeynikov | e87f52d | 2008-07-09 13:27:16 +0000 | [diff] [blame] | 349 | // We should also do if the section name is NULL or function is declared in |
| 350 | // discardable section. |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 351 | OutStreamer.SwitchSection(getObjFileLowering().SectionForGlobal(F, Mang, |
| 352 | TM)); |
Nate Begeman | 2f1ae88 | 2006-07-27 01:13:04 +0000 | [diff] [blame] | 353 | } else { |
Chris Lattner | 83d77fa | 2009-08-01 23:46:12 +0000 | [diff] [blame] | 354 | // Otherwise, drop it in the readonly section. |
| 355 | const MCSection *ReadOnlySection = |
Chris Lattner | 2798119 | 2009-08-01 23:57:16 +0000 | [diff] [blame] | 356 | getObjFileLowering().getSectionForConstant(SectionKind::getReadOnly()); |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 357 | OutStreamer.SwitchSection(ReadOnlySection); |
Evan Cheng | b13bafe | 2009-06-18 20:37:15 +0000 | [diff] [blame] | 358 | JTInDiffSection = true; |
Nate Begeman | 2f1ae88 | 2006-07-27 01:13:04 +0000 | [diff] [blame] | 359 | } |
Jim Laskey | acd80ac | 2006-12-14 19:17:33 +0000 | [diff] [blame] | 360 | |
| 361 | EmitAlignment(Log2_32(MJTI->getAlignment())); |
Chris Lattner | 0c4e678 | 2006-07-15 01:34:12 +0000 | [diff] [blame] | 362 | |
Nate Begeman | 37efe67 | 2006-04-22 18:53:45 +0000 | [diff] [blame] | 363 | for (unsigned i = 0, e = JT.size(); i != e; ++i) { |
Nate Begeman | 52a51e38 | 2006-08-12 21:29:52 +0000 | [diff] [blame] | 364 | const std::vector<MachineBasicBlock*> &JTBBs = JT[i].MBBs; |
Chris Lattner | 0737188 | 2006-10-28 18:10:06 +0000 | [diff] [blame] | 365 | |
| 366 | // If this jump table was deleted, ignore it. |
| 367 | if (JTBBs.empty()) continue; |
Nate Begeman | 52a51e38 | 2006-08-12 21:29:52 +0000 | [diff] [blame] | 368 | |
| 369 | // For PIC codegen, if possible we want to use the SetDirective to reduce |
| 370 | // the number of relocations the assembler will generate for the jump table. |
| 371 | // Set directives are all printed before the jump table itself. |
Evan Cheng | cc41586 | 2007-11-09 01:32:10 +0000 | [diff] [blame] | 372 | SmallPtrSet<MachineBasicBlock*, 16> EmittedSets; |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 373 | if (MAI->getSetDirective() && IsPic) |
Nate Begeman | 52a51e38 | 2006-08-12 21:29:52 +0000 | [diff] [blame] | 374 | for (unsigned ii = 0, ee = JTBBs.size(); ii != ee; ++ii) |
Evan Cheng | cc41586 | 2007-11-09 01:32:10 +0000 | [diff] [blame] | 375 | if (EmittedSets.insert(JTBBs[ii])) |
| 376 | printPICJumpTableSetLabel(i, JTBBs[ii]); |
Nate Begeman | 52a51e38 | 2006-08-12 21:29:52 +0000 | [diff] [blame] | 377 | |
Chris Lattner | 7c30191 | 2009-09-13 19:02:16 +0000 | [diff] [blame] | 378 | // On some targets (e.g. Darwin) we want to emit two consequtive labels |
Chris Lattner | 393a8ee | 2007-01-18 01:12:56 +0000 | [diff] [blame] | 379 | // before each jump table. The first label is never referenced, but tells |
| 380 | // the assembler and linker the extents of the jump table object. The |
| 381 | // second label is actually referenced by the code. |
Chris Lattner | 7c30191 | 2009-09-13 19:02:16 +0000 | [diff] [blame] | 382 | if (JTInDiffSection && MAI->getLinkerPrivateGlobalPrefix()[0]) { |
| 383 | O << MAI->getLinkerPrivateGlobalPrefix() |
| 384 | << "JTI" << getFunctionNumber() << '_' << i << ":\n"; |
Evan Cheng | b13bafe | 2009-06-18 20:37:15 +0000 | [diff] [blame] | 385 | } |
Chris Lattner | 393a8ee | 2007-01-18 01:12:56 +0000 | [diff] [blame] | 386 | |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 387 | O << MAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber() |
Evan Cheng | 347d39f | 2007-10-14 05:57:21 +0000 | [diff] [blame] | 388 | << '_' << i << ":\n"; |
Nate Begeman | 52a51e38 | 2006-08-12 21:29:52 +0000 | [diff] [blame] | 389 | |
Nate Begeman | 37efe67 | 2006-04-22 18:53:45 +0000 | [diff] [blame] | 390 | for (unsigned ii = 0, ee = JTBBs.size(); ii != ee; ++ii) { |
Anton Korobeynikov | 9de1934 | 2007-11-14 09:18:41 +0000 | [diff] [blame] | 391 | printPICJumpTableEntry(MJTI, JTBBs[ii], i); |
Nate Begeman | 37efe67 | 2006-04-22 18:53:45 +0000 | [diff] [blame] | 392 | O << '\n'; |
| 393 | } |
| 394 | } |
| 395 | } |
| 396 | |
Anton Korobeynikov | 9de1934 | 2007-11-14 09:18:41 +0000 | [diff] [blame] | 397 | void AsmPrinter::printPICJumpTableEntry(const MachineJumpTableInfo *MJTI, |
| 398 | const MachineBasicBlock *MBB, |
| 399 | unsigned uid) const { |
Chris Lattner | b3ac6e4 | 2009-08-11 20:29:57 +0000 | [diff] [blame] | 400 | bool isPIC = TM.getRelocationModel() == Reloc::PIC_; |
Anton Korobeynikov | 9de1934 | 2007-11-14 09:18:41 +0000 | [diff] [blame] | 401 | |
| 402 | // Use JumpTableDirective otherwise honor the entry size from the jump table |
| 403 | // info. |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 404 | const char *JTEntryDirective = MAI->getJumpTableDirective(isPIC); |
Anton Korobeynikov | 9de1934 | 2007-11-14 09:18:41 +0000 | [diff] [blame] | 405 | bool HadJTEntryDirective = JTEntryDirective != NULL; |
| 406 | if (!HadJTEntryDirective) { |
| 407 | JTEntryDirective = MJTI->getEntrySize() == 4 ? |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 408 | MAI->getData32bitsDirective() : MAI->getData64bitsDirective(); |
Anton Korobeynikov | 9de1934 | 2007-11-14 09:18:41 +0000 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | O << JTEntryDirective << ' '; |
| 412 | |
| 413 | // If we have emitted set directives for the jump table entries, print |
| 414 | // them rather than the entries themselves. If we're emitting PIC, then |
| 415 | // emit the table entries as differences between two text section labels. |
| 416 | // If we're emitting non-PIC code, then emit the entries as direct |
| 417 | // references to the target basic blocks. |
Chris Lattner | b3ac6e4 | 2009-08-11 20:29:57 +0000 | [diff] [blame] | 418 | if (!isPIC) { |
Chris Lattner | 325d3dc | 2009-09-13 17:14:04 +0000 | [diff] [blame] | 419 | GetMBBSymbol(MBB->getNumber())->print(O, MAI); |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 420 | } else if (MAI->getSetDirective()) { |
| 421 | O << MAI->getPrivateGlobalPrefix() << getFunctionNumber() |
Chris Lattner | b3ac6e4 | 2009-08-11 20:29:57 +0000 | [diff] [blame] | 422 | << '_' << uid << "_set_" << MBB->getNumber(); |
Anton Korobeynikov | 9de1934 | 2007-11-14 09:18:41 +0000 | [diff] [blame] | 423 | } else { |
Chris Lattner | 325d3dc | 2009-09-13 17:14:04 +0000 | [diff] [blame] | 424 | GetMBBSymbol(MBB->getNumber())->print(O, MAI); |
Chris Lattner | b3ac6e4 | 2009-08-11 20:29:57 +0000 | [diff] [blame] | 425 | // If the arch uses custom Jump Table directives, don't calc relative to |
| 426 | // JT |
| 427 | if (!HadJTEntryDirective) |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 428 | O << '-' << MAI->getPrivateGlobalPrefix() << "JTI" |
Chris Lattner | b3ac6e4 | 2009-08-11 20:29:57 +0000 | [diff] [blame] | 429 | << getFunctionNumber() << '_' << uid; |
Anton Korobeynikov | 9de1934 | 2007-11-14 09:18:41 +0000 | [diff] [blame] | 430 | } |
| 431 | } |
| 432 | |
| 433 | |
Chris Lattner | ed13893 | 2005-12-13 06:32:10 +0000 | [diff] [blame] | 434 | /// EmitSpecialLLVMGlobal - Check to see if the specified global is a |
| 435 | /// special global used by LLVM. If so, emit it and return true, otherwise |
| 436 | /// do nothing and return false. |
| 437 | bool AsmPrinter::EmitSpecialLLVMGlobal(const GlobalVariable *GV) { |
Daniel Dunbar | 03d7651 | 2009-07-25 23:55:21 +0000 | [diff] [blame] | 438 | if (GV->getName() == "llvm.used") { |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 439 | if (MAI->getUsedDirective() != 0) // No need to emit this at all. |
Andrew Lenharth | b753a9b | 2007-08-22 19:33:11 +0000 | [diff] [blame] | 440 | EmitLLVMUsedList(GV->getInitializer()); |
| 441 | return true; |
| 442 | } |
| 443 | |
Chris Lattner | 401e10c | 2009-07-20 06:14:25 +0000 | [diff] [blame] | 444 | // Ignore debug and non-emitted data. This handles llvm.compiler.used. |
Chris Lattner | 266c7bb | 2009-04-13 05:44:34 +0000 | [diff] [blame] | 445 | if (GV->getSection() == "llvm.metadata" || |
| 446 | GV->hasAvailableExternallyLinkage()) |
| 447 | return true; |
Jim Laskey | 7809811 | 2006-03-07 22:00:35 +0000 | [diff] [blame] | 448 | |
| 449 | if (!GV->hasAppendingLinkage()) return false; |
| 450 | |
| 451 | assert(GV->hasInitializer() && "Not a special LLVM global!"); |
Chris Lattner | ed13893 | 2005-12-13 06:32:10 +0000 | [diff] [blame] | 452 | |
Evan Cheng | 916d07c | 2007-06-04 20:39:18 +0000 | [diff] [blame] | 453 | const TargetData *TD = TM.getTargetData(); |
| 454 | unsigned Align = Log2_32(TD->getPointerPrefAlignment()); |
Chris Lattner | f231c07 | 2009-03-09 05:52:15 +0000 | [diff] [blame] | 455 | if (GV->getName() == "llvm.global_ctors") { |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 456 | OutStreamer.SwitchSection(getObjFileLowering().getStaticCtorSection()); |
Chris Lattner | ea3a9ff | 2009-03-09 08:18:48 +0000 | [diff] [blame] | 457 | EmitAlignment(Align, 0); |
| 458 | EmitXXStructorList(GV->getInitializer()); |
| 459 | return true; |
Chris Lattner | ed13893 | 2005-12-13 06:32:10 +0000 | [diff] [blame] | 460 | } |
| 461 | |
Chris Lattner | f231c07 | 2009-03-09 05:52:15 +0000 | [diff] [blame] | 462 | if (GV->getName() == "llvm.global_dtors") { |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 463 | OutStreamer.SwitchSection(getObjFileLowering().getStaticDtorSection()); |
Chris Lattner | ea3a9ff | 2009-03-09 08:18:48 +0000 | [diff] [blame] | 464 | EmitAlignment(Align, 0); |
| 465 | EmitXXStructorList(GV->getInitializer()); |
| 466 | return true; |
Chris Lattner | ed13893 | 2005-12-13 06:32:10 +0000 | [diff] [blame] | 467 | } |
| 468 | |
| 469 | return false; |
| 470 | } |
| 471 | |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 472 | /// EmitLLVMUsedList - For targets that define a MAI::UsedDirective, mark each |
Dale Johannesen | d2e51af | 2008-09-09 22:29:13 +0000 | [diff] [blame] | 473 | /// global in the specified llvm.used list for which emitUsedDirectiveFor |
| 474 | /// is true, as being used with this directive. |
Chris Lattner | cb05af8 | 2006-09-26 03:38:18 +0000 | [diff] [blame] | 475 | void AsmPrinter::EmitLLVMUsedList(Constant *List) { |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 476 | const char *Directive = MAI->getUsedDirective(); |
Chris Lattner | cb05af8 | 2006-09-26 03:38:18 +0000 | [diff] [blame] | 477 | |
Dan Gohman | a119de8 | 2009-06-14 23:30:43 +0000 | [diff] [blame] | 478 | // Should be an array of 'i8*'. |
Chris Lattner | cb05af8 | 2006-09-26 03:38:18 +0000 | [diff] [blame] | 479 | ConstantArray *InitList = dyn_cast<ConstantArray>(List); |
| 480 | if (InitList == 0) return; |
| 481 | |
| 482 | for (unsigned i = 0, e = InitList->getNumOperands(); i != e; ++i) { |
Chris Lattner | 16fe990 | 2009-07-17 22:00:23 +0000 | [diff] [blame] | 483 | const GlobalValue *GV = |
| 484 | dyn_cast<GlobalValue>(InitList->getOperand(i)->stripPointerCasts()); |
Chris Lattner | 26630c1 | 2009-07-31 20:52:39 +0000 | [diff] [blame] | 485 | if (GV && getObjFileLowering().shouldEmitUsedDirectiveFor(GV, Mang)) { |
Dale Johannesen | 61e6093 | 2008-09-03 20:34:58 +0000 | [diff] [blame] | 486 | O << Directive; |
| 487 | EmitConstantValueOnly(InitList->getOperand(i)); |
| 488 | O << '\n'; |
| 489 | } |
Chris Lattner | cb05af8 | 2006-09-26 03:38:18 +0000 | [diff] [blame] | 490 | } |
| 491 | } |
| 492 | |
Chris Lattner | ed13893 | 2005-12-13 06:32:10 +0000 | [diff] [blame] | 493 | /// EmitXXStructorList - Emit the ctor or dtor list. This just prints out the |
| 494 | /// function pointers, ignoring the init priority. |
| 495 | void AsmPrinter::EmitXXStructorList(Constant *List) { |
| 496 | // Should be an array of '{ int, void ()* }' structs. The first value is the |
| 497 | // init priority, which we ignore. |
| 498 | if (!isa<ConstantArray>(List)) return; |
| 499 | ConstantArray *InitList = cast<ConstantArray>(List); |
| 500 | for (unsigned i = 0, e = InitList->getNumOperands(); i != e; ++i) |
| 501 | if (ConstantStruct *CS = dyn_cast<ConstantStruct>(InitList->getOperand(i))){ |
| 502 | if (CS->getNumOperands() != 2) return; // Not array of 2-element structs. |
Chris Lattner | 8de324b | 2005-12-21 01:17:37 +0000 | [diff] [blame] | 503 | |
| 504 | if (CS->getOperand(1)->isNullValue()) |
| 505 | return; // Found a null terminator, exit printing. |
| 506 | // Emit the function pointer. |
Chris Lattner | ed13893 | 2005-12-13 06:32:10 +0000 | [diff] [blame] | 507 | EmitGlobalConstant(CS->getOperand(1)); |
| 508 | } |
| 509 | } |
Chris Lattner | 3b4fd32 | 2005-11-21 08:25:09 +0000 | [diff] [blame] | 510 | |
Jim Laskey | bda9b0e | 2007-02-21 22:47:38 +0000 | [diff] [blame] | 511 | |
Jim Laskey | f1cdea1 | 2007-01-25 15:12:02 +0000 | [diff] [blame] | 512 | //===----------------------------------------------------------------------===// |
| 513 | /// LEB 128 number encoding. |
| 514 | |
| 515 | /// PrintULEB128 - Print a series of hexidecimal values (separated by commas) |
| 516 | /// representing an unsigned leb128 value. |
| 517 | void AsmPrinter::PrintULEB128(unsigned Value) const { |
Chris Lattner | a64f463 | 2008-11-10 04:35:24 +0000 | [diff] [blame] | 518 | char Buffer[20]; |
Jim Laskey | f1cdea1 | 2007-01-25 15:12:02 +0000 | [diff] [blame] | 519 | do { |
Chris Lattner | a64f463 | 2008-11-10 04:35:24 +0000 | [diff] [blame] | 520 | unsigned char Byte = static_cast<unsigned char>(Value & 0x7f); |
Jim Laskey | f1cdea1 | 2007-01-25 15:12:02 +0000 | [diff] [blame] | 521 | Value >>= 7; |
| 522 | if (Value) Byte |= 0x80; |
Chris Lattner | a64f463 | 2008-11-10 04:35:24 +0000 | [diff] [blame] | 523 | O << "0x" << utohex_buffer(Byte, Buffer+20); |
Jim Laskey | f1cdea1 | 2007-01-25 15:12:02 +0000 | [diff] [blame] | 524 | if (Value) O << ", "; |
| 525 | } while (Value); |
| 526 | } |
| 527 | |
Jim Laskey | f1cdea1 | 2007-01-25 15:12:02 +0000 | [diff] [blame] | 528 | /// PrintSLEB128 - Print a series of hexidecimal values (separated by commas) |
| 529 | /// representing a signed leb128 value. |
| 530 | void AsmPrinter::PrintSLEB128(int Value) const { |
| 531 | int Sign = Value >> (8 * sizeof(Value) - 1); |
| 532 | bool IsMore; |
Chris Lattner | a64f463 | 2008-11-10 04:35:24 +0000 | [diff] [blame] | 533 | char Buffer[20]; |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 534 | |
Jim Laskey | f1cdea1 | 2007-01-25 15:12:02 +0000 | [diff] [blame] | 535 | do { |
Chris Lattner | a64f463 | 2008-11-10 04:35:24 +0000 | [diff] [blame] | 536 | unsigned char Byte = static_cast<unsigned char>(Value & 0x7f); |
Jim Laskey | f1cdea1 | 2007-01-25 15:12:02 +0000 | [diff] [blame] | 537 | Value >>= 7; |
| 538 | IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 0; |
| 539 | if (IsMore) Byte |= 0x80; |
Chris Lattner | a64f463 | 2008-11-10 04:35:24 +0000 | [diff] [blame] | 540 | O << "0x" << utohex_buffer(Byte, Buffer+20); |
Jim Laskey | f1cdea1 | 2007-01-25 15:12:02 +0000 | [diff] [blame] | 541 | if (IsMore) O << ", "; |
| 542 | } while (IsMore); |
| 543 | } |
| 544 | |
Jim Laskey | f1cdea1 | 2007-01-25 15:12:02 +0000 | [diff] [blame] | 545 | //===--------------------------------------------------------------------===// |
| 546 | // Emission and print routines |
| 547 | // |
| 548 | |
| 549 | /// PrintHex - Print a value as a hexidecimal value. |
| 550 | /// |
| 551 | void AsmPrinter::PrintHex(int Value) const { |
Chris Lattner | c6a1346 | 2008-11-10 04:30:26 +0000 | [diff] [blame] | 552 | char Buffer[20]; |
Chris Lattner | c6a1346 | 2008-11-10 04:30:26 +0000 | [diff] [blame] | 553 | O << "0x" << utohex_buffer(static_cast<unsigned>(Value), Buffer+20); |
Jim Laskey | f1cdea1 | 2007-01-25 15:12:02 +0000 | [diff] [blame] | 554 | } |
| 555 | |
| 556 | /// EOL - Print a newline character to asm stream. If a comment is present |
| 557 | /// then it will be printed first. Comments should not contain '\n'. |
Jim Laskey | bda9b0e | 2007-02-21 22:47:38 +0000 | [diff] [blame] | 558 | void AsmPrinter::EOL() const { |
Dan Gohman | d19a53b | 2008-06-30 22:03:41 +0000 | [diff] [blame] | 559 | O << '\n'; |
Jim Laskey | bda9b0e | 2007-02-21 22:47:38 +0000 | [diff] [blame] | 560 | } |
Owen Anderson | 2599509 | 2008-07-01 21:16:27 +0000 | [diff] [blame] | 561 | |
Jim Laskey | f1cdea1 | 2007-01-25 15:12:02 +0000 | [diff] [blame] | 562 | void AsmPrinter::EOL(const std::string &Comment) const { |
Evan Cheng | 6547e40 | 2008-07-01 23:18:29 +0000 | [diff] [blame] | 563 | if (VerboseAsm && !Comment.empty()) { |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 564 | O.PadToColumn(MAI->getCommentColumn()); |
| 565 | O << MAI->getCommentString() |
Dan Gohman | d19a53b | 2008-06-30 22:03:41 +0000 | [diff] [blame] | 566 | << ' ' |
Jim Laskey | f1cdea1 | 2007-01-25 15:12:02 +0000 | [diff] [blame] | 567 | << Comment; |
| 568 | } |
Dan Gohman | d19a53b | 2008-06-30 22:03:41 +0000 | [diff] [blame] | 569 | O << '\n'; |
Jim Laskey | f1cdea1 | 2007-01-25 15:12:02 +0000 | [diff] [blame] | 570 | } |
| 571 | |
Owen Anderson | 2599509 | 2008-07-01 21:16:27 +0000 | [diff] [blame] | 572 | void AsmPrinter::EOL(const char* Comment) const { |
Evan Cheng | 6547e40 | 2008-07-01 23:18:29 +0000 | [diff] [blame] | 573 | if (VerboseAsm && *Comment) { |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 574 | O.PadToColumn(MAI->getCommentColumn()); |
| 575 | O << MAI->getCommentString() |
Owen Anderson | 2599509 | 2008-07-01 21:16:27 +0000 | [diff] [blame] | 576 | << ' ' |
| 577 | << Comment; |
| 578 | } |
| 579 | O << '\n'; |
| 580 | } |
| 581 | |
Bill Wendling | b5abecd | 2009-08-29 12:17:53 +0000 | [diff] [blame] | 582 | static const char *DecodeDWARFEncoding(unsigned Encoding) { |
| 583 | switch (Encoding) { |
| 584 | case dwarf::DW_EH_PE_absptr: |
| 585 | return "absptr"; |
| 586 | case dwarf::DW_EH_PE_omit: |
| 587 | return "omit"; |
| 588 | case dwarf::DW_EH_PE_pcrel: |
| 589 | return "pcrel"; |
Bill Wendling | 0734d35 | 2009-09-09 21:26:19 +0000 | [diff] [blame] | 590 | case dwarf::DW_EH_PE_udata4: |
| 591 | return "udata4"; |
| 592 | case dwarf::DW_EH_PE_udata8: |
| 593 | return "udata8"; |
| 594 | case dwarf::DW_EH_PE_sdata4: |
| 595 | return "sdata4"; |
| 596 | case dwarf::DW_EH_PE_sdata8: |
| 597 | return "sdata8"; |
Bill Wendling | b5abecd | 2009-08-29 12:17:53 +0000 | [diff] [blame] | 598 | case dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata4: |
| 599 | return "pcrel udata4"; |
| 600 | case dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4: |
| 601 | return "pcrel sdata4"; |
| 602 | case dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8: |
| 603 | return "pcrel udata8"; |
| 604 | case dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata8: |
| 605 | return "pcrel sdata8"; |
| 606 | case dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |dwarf::DW_EH_PE_udata4: |
| 607 | return "indirect pcrel udata4"; |
| 608 | case dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |dwarf::DW_EH_PE_sdata4: |
| 609 | return "indirect pcrel sdata4"; |
| 610 | case dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |dwarf::DW_EH_PE_udata8: |
| 611 | return "indirect pcrel udata8"; |
| 612 | case dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |dwarf::DW_EH_PE_sdata8: |
| 613 | return "indirect pcrel sdata8"; |
| 614 | } |
| 615 | |
| 616 | return 0; |
| 617 | } |
| 618 | |
Bill Wendling | b5abecd | 2009-08-29 12:17:53 +0000 | [diff] [blame] | 619 | void AsmPrinter::EOL(const char *Comment, unsigned Encoding) const { |
| 620 | if (VerboseAsm && *Comment) { |
| 621 | O.PadToColumn(MAI->getCommentColumn()); |
| 622 | O << MAI->getCommentString() |
| 623 | << ' ' |
| 624 | << Comment; |
| 625 | |
| 626 | if (const char *EncStr = DecodeDWARFEncoding(Encoding)) |
| 627 | O << " (" << EncStr << ')'; |
| 628 | } |
| 629 | O << '\n'; |
| 630 | } |
| 631 | |
Jim Laskey | f1cdea1 | 2007-01-25 15:12:02 +0000 | [diff] [blame] | 632 | /// EmitULEB128Bytes - Emit an assembler byte data directive to compose an |
| 633 | /// unsigned leb128 value. |
| 634 | void AsmPrinter::EmitULEB128Bytes(unsigned Value) const { |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 635 | if (MAI->hasLEB128()) { |
Jim Laskey | f1cdea1 | 2007-01-25 15:12:02 +0000 | [diff] [blame] | 636 | O << "\t.uleb128\t" |
| 637 | << Value; |
| 638 | } else { |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 639 | O << MAI->getData8bitsDirective(); |
Jim Laskey | f1cdea1 | 2007-01-25 15:12:02 +0000 | [diff] [blame] | 640 | PrintULEB128(Value); |
| 641 | } |
| 642 | } |
| 643 | |
| 644 | /// EmitSLEB128Bytes - print an assembler byte data directive to compose a |
| 645 | /// signed leb128 value. |
| 646 | void AsmPrinter::EmitSLEB128Bytes(int Value) const { |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 647 | if (MAI->hasLEB128()) { |
Jim Laskey | f1cdea1 | 2007-01-25 15:12:02 +0000 | [diff] [blame] | 648 | O << "\t.sleb128\t" |
| 649 | << Value; |
| 650 | } else { |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 651 | O << MAI->getData8bitsDirective(); |
Jim Laskey | f1cdea1 | 2007-01-25 15:12:02 +0000 | [diff] [blame] | 652 | PrintSLEB128(Value); |
| 653 | } |
| 654 | } |
| 655 | |
| 656 | /// EmitInt8 - Emit a byte directive and value. |
| 657 | /// |
| 658 | void AsmPrinter::EmitInt8(int Value) const { |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 659 | O << MAI->getData8bitsDirective(); |
Jim Laskey | f1cdea1 | 2007-01-25 15:12:02 +0000 | [diff] [blame] | 660 | PrintHex(Value & 0xFF); |
| 661 | } |
| 662 | |
| 663 | /// EmitInt16 - Emit a short directive and value. |
| 664 | /// |
| 665 | void AsmPrinter::EmitInt16(int Value) const { |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 666 | O << MAI->getData16bitsDirective(); |
Jim Laskey | f1cdea1 | 2007-01-25 15:12:02 +0000 | [diff] [blame] | 667 | PrintHex(Value & 0xFFFF); |
| 668 | } |
| 669 | |
| 670 | /// EmitInt32 - Emit a long directive and value. |
| 671 | /// |
| 672 | void AsmPrinter::EmitInt32(int Value) const { |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 673 | O << MAI->getData32bitsDirective(); |
Jim Laskey | f1cdea1 | 2007-01-25 15:12:02 +0000 | [diff] [blame] | 674 | PrintHex(Value); |
| 675 | } |
| 676 | |
| 677 | /// EmitInt64 - Emit a long long directive and value. |
| 678 | /// |
| 679 | void AsmPrinter::EmitInt64(uint64_t Value) const { |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 680 | if (MAI->getData64bitsDirective()) { |
| 681 | O << MAI->getData64bitsDirective(); |
Jim Laskey | f1cdea1 | 2007-01-25 15:12:02 +0000 | [diff] [blame] | 682 | PrintHex(Value); |
| 683 | } else { |
| 684 | if (TM.getTargetData()->isBigEndian()) { |
Dan Gohman | d19a53b | 2008-06-30 22:03:41 +0000 | [diff] [blame] | 685 | EmitInt32(unsigned(Value >> 32)); O << '\n'; |
Jim Laskey | f1cdea1 | 2007-01-25 15:12:02 +0000 | [diff] [blame] | 686 | EmitInt32(unsigned(Value)); |
| 687 | } else { |
Dan Gohman | d19a53b | 2008-06-30 22:03:41 +0000 | [diff] [blame] | 688 | EmitInt32(unsigned(Value)); O << '\n'; |
Jim Laskey | f1cdea1 | 2007-01-25 15:12:02 +0000 | [diff] [blame] | 689 | EmitInt32(unsigned(Value >> 32)); |
| 690 | } |
| 691 | } |
| 692 | } |
| 693 | |
| 694 | /// toOctal - Convert the low order bits of X into an octal digit. |
| 695 | /// |
| 696 | static inline char toOctal(int X) { |
| 697 | return (X&7)+'0'; |
| 698 | } |
| 699 | |
| 700 | /// printStringChar - Print a char, escaped if necessary. |
| 701 | /// |
David Greene | 7184781 | 2009-07-14 20:18:05 +0000 | [diff] [blame] | 702 | static void printStringChar(formatted_raw_ostream &O, unsigned char C) { |
Jim Laskey | f1cdea1 | 2007-01-25 15:12:02 +0000 | [diff] [blame] | 703 | if (C == '"') { |
| 704 | O << "\\\""; |
| 705 | } else if (C == '\\') { |
| 706 | O << "\\\\"; |
Chris Lattner | bbfa244 | 2009-01-22 23:38:45 +0000 | [diff] [blame] | 707 | } else if (isprint((unsigned char)C)) { |
Jim Laskey | f1cdea1 | 2007-01-25 15:12:02 +0000 | [diff] [blame] | 708 | O << C; |
| 709 | } else { |
| 710 | switch(C) { |
| 711 | case '\b': O << "\\b"; break; |
| 712 | case '\f': O << "\\f"; break; |
| 713 | case '\n': O << "\\n"; break; |
| 714 | case '\r': O << "\\r"; break; |
| 715 | case '\t': O << "\\t"; break; |
| 716 | default: |
| 717 | O << '\\'; |
| 718 | O << toOctal(C >> 6); |
| 719 | O << toOctal(C >> 3); |
| 720 | O << toOctal(C >> 0); |
| 721 | break; |
| 722 | } |
| 723 | } |
| 724 | } |
| 725 | |
| 726 | /// EmitString - Emit a string with quotes and a null terminator. |
| 727 | /// Special characters are emitted properly. |
| 728 | /// \literal (Eg. '\t') \endliteral |
| 729 | void AsmPrinter::EmitString(const std::string &String) const { |
Bill Wendling | f34be82 | 2009-04-09 23:51:31 +0000 | [diff] [blame] | 730 | EmitString(String.c_str(), String.size()); |
| 731 | } |
| 732 | |
| 733 | void AsmPrinter::EmitString(const char *String, unsigned Size) const { |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 734 | const char* AscizDirective = MAI->getAscizDirective(); |
Anton Korobeynikov | fb269cf | 2007-03-06 19:25:02 +0000 | [diff] [blame] | 735 | if (AscizDirective) |
| 736 | O << AscizDirective; |
| 737 | else |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 738 | O << MAI->getAsciiDirective(); |
Dan Gohman | d19a53b | 2008-06-30 22:03:41 +0000 | [diff] [blame] | 739 | O << '\"'; |
Bill Wendling | f34be82 | 2009-04-09 23:51:31 +0000 | [diff] [blame] | 740 | for (unsigned i = 0; i < Size; ++i) |
Chris Lattner | a118c2e | 2009-04-08 00:28:38 +0000 | [diff] [blame] | 741 | printStringChar(O, String[i]); |
Anton Korobeynikov | fb269cf | 2007-03-06 19:25:02 +0000 | [diff] [blame] | 742 | if (AscizDirective) |
Dan Gohman | d19a53b | 2008-06-30 22:03:41 +0000 | [diff] [blame] | 743 | O << '\"'; |
Anton Korobeynikov | fb269cf | 2007-03-06 19:25:02 +0000 | [diff] [blame] | 744 | else |
| 745 | O << "\\0\""; |
Jim Laskey | f1cdea1 | 2007-01-25 15:12:02 +0000 | [diff] [blame] | 746 | } |
| 747 | |
| 748 | |
Dan Gohman | 189f80d | 2007-09-24 20:58:13 +0000 | [diff] [blame] | 749 | /// EmitFile - Emit a .file directive. |
| 750 | void AsmPrinter::EmitFile(unsigned Number, const std::string &Name) const { |
| 751 | O << "\t.file\t" << Number << " \""; |
Chris Lattner | a118c2e | 2009-04-08 00:28:38 +0000 | [diff] [blame] | 752 | for (unsigned i = 0, N = Name.size(); i < N; ++i) |
| 753 | printStringChar(O, Name[i]); |
Dan Gohman | d19a53b | 2008-06-30 22:03:41 +0000 | [diff] [blame] | 754 | O << '\"'; |
Dan Gohman | 189f80d | 2007-09-24 20:58:13 +0000 | [diff] [blame] | 755 | } |
| 756 | |
| 757 | |
Jim Laskey | f1cdea1 | 2007-01-25 15:12:02 +0000 | [diff] [blame] | 758 | //===----------------------------------------------------------------------===// |
| 759 | |
Chris Lattner | 3a42053 | 2007-05-31 18:57:45 +0000 | [diff] [blame] | 760 | // EmitAlignment - Emit an alignment directive to the specified power of |
| 761 | // two boundary. For example, if you pass in 3 here, you will get an 8 |
| 762 | // byte alignment. If a global value is specified, and if that global has |
| 763 | // an explicit alignment requested, it will unconditionally override the |
| 764 | // alignment request. However, if ForcedAlignBits is specified, this value |
| 765 | // has final say: the ultimate alignment will be the max of ForcedAlignBits |
| 766 | // and the alignment computed with NumBits and the global. |
| 767 | // |
| 768 | // The algorithm is: |
| 769 | // Align = NumBits; |
| 770 | // if (GV && GV->hasalignment) Align = GV->getalignment(); |
| 771 | // Align = std::max(Align, ForcedAlignBits); |
| 772 | // |
| 773 | void AsmPrinter::EmitAlignment(unsigned NumBits, const GlobalValue *GV, |
Evan Cheng | 05548eb | 2008-02-29 19:36:59 +0000 | [diff] [blame] | 774 | unsigned ForcedAlignBits, |
| 775 | bool UseFillExpr) const { |
Dale Johannesen | 00d56b9 | 2007-04-23 23:33:31 +0000 | [diff] [blame] | 776 | if (GV && GV->getAlignment()) |
Chris Lattner | 3a42053 | 2007-05-31 18:57:45 +0000 | [diff] [blame] | 777 | NumBits = Log2_32(GV->getAlignment()); |
| 778 | NumBits = std::max(NumBits, ForcedAlignBits); |
| 779 | |
Chris Lattner | 2a21c6e | 2005-11-10 18:09:27 +0000 | [diff] [blame] | 780 | if (NumBits == 0) return; // No need to emit alignment. |
Chris Lattner | 663c2d2 | 2009-08-19 06:12:02 +0000 | [diff] [blame] | 781 | |
| 782 | unsigned FillValue = 0; |
Chris Lattner | dabf07c | 2009-08-18 06:15:16 +0000 | [diff] [blame] | 783 | if (getCurrentSection()->getKind().isText()) |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 784 | FillValue = MAI->getTextAlignFillValue(); |
Chris Lattner | 663c2d2 | 2009-08-19 06:12:02 +0000 | [diff] [blame] | 785 | |
| 786 | OutStreamer.EmitValueToAlignment(1 << NumBits, FillValue, 1, 0); |
Chris Lattner | bfddc20 | 2004-08-17 19:14:29 +0000 | [diff] [blame] | 787 | } |
David Greene | a5bb59f | 2009-08-05 21:00:52 +0000 | [diff] [blame] | 788 | |
Chris Lattner | 25045bd | 2005-11-21 07:51:36 +0000 | [diff] [blame] | 789 | /// EmitZeros - Emit a block of zeros. |
Chris Lattner | 7d057a3 | 2004-08-17 21:38:40 +0000 | [diff] [blame] | 790 | /// |
Sanjiv Gupta | c8d7bc8 | 2009-01-30 04:25:10 +0000 | [diff] [blame] | 791 | void AsmPrinter::EmitZeros(uint64_t NumZeros, unsigned AddrSpace) const { |
Chris Lattner | 7d057a3 | 2004-08-17 21:38:40 +0000 | [diff] [blame] | 792 | if (NumZeros) { |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 793 | if (MAI->getZeroDirective()) { |
| 794 | O << MAI->getZeroDirective() << NumZeros; |
| 795 | if (MAI->getZeroDirectiveSuffix()) |
| 796 | O << MAI->getZeroDirectiveSuffix(); |
Dan Gohman | d19a53b | 2008-06-30 22:03:41 +0000 | [diff] [blame] | 797 | O << '\n'; |
Jeff Cohen | c6a057b | 2006-05-02 03:46:13 +0000 | [diff] [blame] | 798 | } else { |
Chris Lattner | 7d057a3 | 2004-08-17 21:38:40 +0000 | [diff] [blame] | 799 | for (; NumZeros; --NumZeros) |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 800 | O << MAI->getData8bitsDirective(AddrSpace) << "0\n"; |
Chris Lattner | 7d057a3 | 2004-08-17 21:38:40 +0000 | [diff] [blame] | 801 | } |
| 802 | } |
| 803 | } |
| 804 | |
Chris Lattner | a80ba71 | 2004-08-16 23:15:22 +0000 | [diff] [blame] | 805 | // Print out the specified constant, without a storage class. Only the |
| 806 | // constants valid in constant expressions can occur here. |
Chris Lattner | 25045bd | 2005-11-21 07:51:36 +0000 | [diff] [blame] | 807 | void AsmPrinter::EmitConstantValueOnly(const Constant *CV) { |
Chris Lattner | bd1d382 | 2004-10-16 18:19:26 +0000 | [diff] [blame] | 808 | if (CV->isNullValue() || isa<UndefValue>(CV)) |
Dan Gohman | d19a53b | 2008-06-30 22:03:41 +0000 | [diff] [blame] | 809 | O << '0'; |
Zhou Sheng | 6b6b6ef | 2007-01-11 12:24:14 +0000 | [diff] [blame] | 810 | else if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) { |
Scott Michel | 4315eee | 2008-06-03 06:18:19 +0000 | [diff] [blame] | 811 | O << CI->getZExtValue(); |
Reid Spencer | b83eb64 | 2006-10-20 07:07:24 +0000 | [diff] [blame] | 812 | } else if (const GlobalValue *GV = dyn_cast<GlobalValue>(CV)) { |
Duraid Madina | 855a519 | 2005-04-02 12:21:51 +0000 | [diff] [blame] | 813 | // This is a constant address for a global variable or function. Use the |
Chris Lattner | bfd1e50 | 2009-09-15 23:11:32 +0000 | [diff] [blame] | 814 | // name of the variable or function as the address value. |
| 815 | O << Mang->getMangledName(GV); |
Duraid Madina | 855a519 | 2005-04-02 12:21:51 +0000 | [diff] [blame] | 816 | } else if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(CV)) { |
Owen Anderson | a69571c | 2006-05-03 01:29:57 +0000 | [diff] [blame] | 817 | const TargetData *TD = TM.getTargetData(); |
Anton Korobeynikov | 13b7d3d | 2007-02-04 23:27:42 +0000 | [diff] [blame] | 818 | unsigned Opcode = CE->getOpcode(); |
| 819 | switch (Opcode) { |
Chris Lattner | c19ee61 | 2009-08-01 22:25:12 +0000 | [diff] [blame] | 820 | case Instruction::Trunc: |
| 821 | case Instruction::ZExt: |
| 822 | case Instruction::SExt: |
| 823 | case Instruction::FPTrunc: |
| 824 | case Instruction::FPExt: |
| 825 | case Instruction::UIToFP: |
| 826 | case Instruction::SIToFP: |
| 827 | case Instruction::FPToUI: |
| 828 | case Instruction::FPToSI: |
| 829 | llvm_unreachable("FIXME: Don't support this constant cast expr"); |
Chris Lattner | a80ba71 | 2004-08-16 23:15:22 +0000 | [diff] [blame] | 830 | case Instruction::GetElementPtr: { |
| 831 | // generate a symbolic expression for the byte address |
| 832 | const Constant *ptrVal = CE->getOperand(0); |
Chris Lattner | 7f6b9d2 | 2007-02-10 20:31:59 +0000 | [diff] [blame] | 833 | SmallVector<Value*, 8> idxVec(CE->op_begin()+1, CE->op_end()); |
| 834 | if (int64_t Offset = TD->getIndexedOffset(ptrVal->getType(), &idxVec[0], |
| 835 | idxVec.size())) { |
Chris Lattner | 4798bbe | 2009-02-05 06:55:21 +0000 | [diff] [blame] | 836 | // Truncate/sext the offset to the pointer size. |
| 837 | if (TD->getPointerSizeInBits() != 64) { |
| 838 | int SExtAmount = 64-TD->getPointerSizeInBits(); |
| 839 | Offset = (Offset << SExtAmount) >> SExtAmount; |
| 840 | } |
| 841 | |
Chris Lattner | 27e1921 | 2005-02-14 21:40:26 +0000 | [diff] [blame] | 842 | if (Offset) |
Dan Gohman | d19a53b | 2008-06-30 22:03:41 +0000 | [diff] [blame] | 843 | O << '('; |
Chris Lattner | 25045bd | 2005-11-21 07:51:36 +0000 | [diff] [blame] | 844 | EmitConstantValueOnly(ptrVal); |
Chris Lattner | 27e1921 | 2005-02-14 21:40:26 +0000 | [diff] [blame] | 845 | if (Offset > 0) |
| 846 | O << ") + " << Offset; |
| 847 | else if (Offset < 0) |
| 848 | O << ") - " << -Offset; |
Chris Lattner | a80ba71 | 2004-08-16 23:15:22 +0000 | [diff] [blame] | 849 | } else { |
Chris Lattner | 25045bd | 2005-11-21 07:51:36 +0000 | [diff] [blame] | 850 | EmitConstantValueOnly(ptrVal); |
Chris Lattner | a80ba71 | 2004-08-16 23:15:22 +0000 | [diff] [blame] | 851 | } |
| 852 | break; |
| 853 | } |
Chris Lattner | cb0a681 | 2006-12-12 05:14:13 +0000 | [diff] [blame] | 854 | case Instruction::BitCast: |
| 855 | return EmitConstantValueOnly(CE->getOperand(0)); |
| 856 | |
Chris Lattner | ddc9401 | 2006-12-12 05:18:19 +0000 | [diff] [blame] | 857 | case Instruction::IntToPtr: { |
| 858 | // Handle casts to pointers by changing them into casts to the appropriate |
| 859 | // integer type. This promotes constant folding and simplifies this code. |
| 860 | Constant *Op = CE->getOperand(0); |
Owen Anderson | 1d0be15 | 2009-08-13 21:58:54 +0000 | [diff] [blame] | 861 | Op = ConstantExpr::getIntegerCast(Op, TD->getIntPtrType(CV->getContext()), |
| 862 | false/*ZExt*/); |
Chris Lattner | ddc9401 | 2006-12-12 05:18:19 +0000 | [diff] [blame] | 863 | return EmitConstantValueOnly(Op); |
| 864 | } |
| 865 | |
| 866 | |
| 867 | case Instruction::PtrToInt: { |
Chris Lattner | 4a6bd33 | 2006-07-29 01:57:19 +0000 | [diff] [blame] | 868 | // Support only foldable casts to/from pointers that can be eliminated by |
| 869 | // changing the pointer to the appropriately sized integer type. |
Chris Lattner | a80ba71 | 2004-08-16 23:15:22 +0000 | [diff] [blame] | 870 | Constant *Op = CE->getOperand(0); |
Chris Lattner | ddc9401 | 2006-12-12 05:18:19 +0000 | [diff] [blame] | 871 | const Type *Ty = CE->getType(); |
Chris Lattner | a80ba71 | 2004-08-16 23:15:22 +0000 | [diff] [blame] | 872 | |
Chris Lattner | ddc9401 | 2006-12-12 05:18:19 +0000 | [diff] [blame] | 873 | // We can emit the pointer value into this slot if the slot is an |
| 874 | // integer slot greater or equal to the size of the pointer. |
Chris Lattner | c19ee61 | 2009-08-01 22:25:12 +0000 | [diff] [blame] | 875 | if (TD->getTypeAllocSize(Ty) == TD->getTypeAllocSize(Op->getType())) |
Chris Lattner | 4a6bd33 | 2006-07-29 01:57:19 +0000 | [diff] [blame] | 876 | return EmitConstantValueOnly(Op); |
Nick Lewycky | d622738 | 2008-08-08 06:34:07 +0000 | [diff] [blame] | 877 | |
| 878 | O << "(("; |
Chris Lattner | 25045bd | 2005-11-21 07:51:36 +0000 | [diff] [blame] | 879 | EmitConstantValueOnly(Op); |
Chris Lattner | c19ee61 | 2009-08-01 22:25:12 +0000 | [diff] [blame] | 880 | APInt ptrMask = |
| 881 | APInt::getAllOnesValue(TD->getTypeAllocSizeInBits(Op->getType())); |
Chris Lattner | fad86b0 | 2008-08-17 07:19:36 +0000 | [diff] [blame] | 882 | |
| 883 | SmallString<40> S; |
| 884 | ptrMask.toStringUnsigned(S); |
Daniel Dunbar | dddfd34 | 2009-08-19 20:07:03 +0000 | [diff] [blame] | 885 | O << ") & " << S.str() << ')'; |
Chris Lattner | a80ba71 | 2004-08-16 23:15:22 +0000 | [diff] [blame] | 886 | break; |
| 887 | } |
| 888 | case Instruction::Add: |
Anton Korobeynikov | 13b7d3d | 2007-02-04 23:27:42 +0000 | [diff] [blame] | 889 | case Instruction::Sub: |
Anton Korobeynikov | feb8893 | 2007-12-18 20:53:41 +0000 | [diff] [blame] | 890 | case Instruction::And: |
| 891 | case Instruction::Or: |
| 892 | case Instruction::Xor: |
Dan Gohman | d19a53b | 2008-06-30 22:03:41 +0000 | [diff] [blame] | 893 | O << '('; |
Chris Lattner | 25045bd | 2005-11-21 07:51:36 +0000 | [diff] [blame] | 894 | EmitConstantValueOnly(CE->getOperand(0)); |
Dan Gohman | d19a53b | 2008-06-30 22:03:41 +0000 | [diff] [blame] | 895 | O << ')'; |
Anton Korobeynikov | feb8893 | 2007-12-18 20:53:41 +0000 | [diff] [blame] | 896 | switch (Opcode) { |
| 897 | case Instruction::Add: |
| 898 | O << " + "; |
| 899 | break; |
| 900 | case Instruction::Sub: |
| 901 | O << " - "; |
| 902 | break; |
| 903 | case Instruction::And: |
| 904 | O << " & "; |
| 905 | break; |
| 906 | case Instruction::Or: |
| 907 | O << " | "; |
| 908 | break; |
| 909 | case Instruction::Xor: |
| 910 | O << " ^ "; |
| 911 | break; |
| 912 | default: |
| 913 | break; |
| 914 | } |
Dan Gohman | d19a53b | 2008-06-30 22:03:41 +0000 | [diff] [blame] | 915 | O << '('; |
Chris Lattner | 25045bd | 2005-11-21 07:51:36 +0000 | [diff] [blame] | 916 | EmitConstantValueOnly(CE->getOperand(1)); |
Dan Gohman | d19a53b | 2008-06-30 22:03:41 +0000 | [diff] [blame] | 917 | O << ')'; |
Chris Lattner | a80ba71 | 2004-08-16 23:15:22 +0000 | [diff] [blame] | 918 | break; |
| 919 | default: |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 920 | llvm_unreachable("Unsupported operator!"); |
Chris Lattner | a80ba71 | 2004-08-16 23:15:22 +0000 | [diff] [blame] | 921 | } |
Dan Gohman | 6a55e62 | 2009-10-30 01:45:18 +0000 | [diff] [blame] | 922 | } else if (const BlockAddress *BA = dyn_cast<BlockAddress>(CV)) { |
| 923 | GetBlockAddressSymbol(BA)->print(O, MAI); |
Chris Lattner | a80ba71 | 2004-08-16 23:15:22 +0000 | [diff] [blame] | 924 | } else { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 925 | llvm_unreachable("Unknown constant value!"); |
Chris Lattner | a80ba71 | 2004-08-16 23:15:22 +0000 | [diff] [blame] | 926 | } |
| 927 | } |
Chris Lattner | 1b7e235 | 2004-08-17 06:36:49 +0000 | [diff] [blame] | 928 | |
Chris Lattner | 2980cef | 2005-11-10 18:06:33 +0000 | [diff] [blame] | 929 | /// printAsCString - Print the specified array as a C compatible string, only if |
Chris Lattner | 1b7e235 | 2004-08-17 06:36:49 +0000 | [diff] [blame] | 930 | /// the predicate isString is true. |
| 931 | /// |
David Greene | 7184781 | 2009-07-14 20:18:05 +0000 | [diff] [blame] | 932 | static void printAsCString(formatted_raw_ostream &O, const ConstantArray *CVA, |
Chris Lattner | 2980cef | 2005-11-10 18:06:33 +0000 | [diff] [blame] | 933 | unsigned LastElt) { |
Chris Lattner | 1b7e235 | 2004-08-17 06:36:49 +0000 | [diff] [blame] | 934 | assert(CVA->isString() && "Array is not string compatible!"); |
| 935 | |
Dan Gohman | d19a53b | 2008-06-30 22:03:41 +0000 | [diff] [blame] | 936 | O << '\"'; |
Chris Lattner | 2980cef | 2005-11-10 18:06:33 +0000 | [diff] [blame] | 937 | for (unsigned i = 0; i != LastElt; ++i) { |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 938 | unsigned char C = |
Reid Spencer | b83eb64 | 2006-10-20 07:07:24 +0000 | [diff] [blame] | 939 | (unsigned char)cast<ConstantInt>(CVA->getOperand(i))->getZExtValue(); |
Jim Laskey | f1cdea1 | 2007-01-25 15:12:02 +0000 | [diff] [blame] | 940 | printStringChar(O, C); |
Chris Lattner | 1b7e235 | 2004-08-17 06:36:49 +0000 | [diff] [blame] | 941 | } |
Dan Gohman | d19a53b | 2008-06-30 22:03:41 +0000 | [diff] [blame] | 942 | O << '\"'; |
Chris Lattner | 1b7e235 | 2004-08-17 06:36:49 +0000 | [diff] [blame] | 943 | } |
| 944 | |
Jeff Cohen | c884db4 | 2006-05-02 01:16:28 +0000 | [diff] [blame] | 945 | /// EmitString - Emit a zero-byte-terminated string constant. |
| 946 | /// |
| 947 | void AsmPrinter::EmitString(const ConstantArray *CVA) const { |
| 948 | unsigned NumElts = CVA->getNumOperands(); |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 949 | if (MAI->getAscizDirective() && NumElts && |
Reid Spencer | b83eb64 | 2006-10-20 07:07:24 +0000 | [diff] [blame] | 950 | cast<ConstantInt>(CVA->getOperand(NumElts-1))->getZExtValue() == 0) { |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 951 | O << MAI->getAscizDirective(); |
Jeff Cohen | c884db4 | 2006-05-02 01:16:28 +0000 | [diff] [blame] | 952 | printAsCString(O, CVA, NumElts-1); |
| 953 | } else { |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 954 | O << MAI->getAsciiDirective(); |
Jeff Cohen | c884db4 | 2006-05-02 01:16:28 +0000 | [diff] [blame] | 955 | printAsCString(O, CVA, NumElts); |
| 956 | } |
Dan Gohman | d19a53b | 2008-06-30 22:03:41 +0000 | [diff] [blame] | 957 | O << '\n'; |
Jeff Cohen | c884db4 | 2006-05-02 01:16:28 +0000 | [diff] [blame] | 958 | } |
| 959 | |
Sanjiv Gupta | d3d9657 | 2009-04-28 16:34:20 +0000 | [diff] [blame] | 960 | void AsmPrinter::EmitGlobalConstantArray(const ConstantArray *CVA, |
| 961 | unsigned AddrSpace) { |
Dan Gohman | 00d448a | 2008-12-22 21:14:27 +0000 | [diff] [blame] | 962 | if (CVA->isString()) { |
| 963 | EmitString(CVA); |
| 964 | } else { // Not a string. Print the values in successive locations |
| 965 | for (unsigned i = 0, e = CVA->getNumOperands(); i != e; ++i) |
Sanjiv Gupta | d3d9657 | 2009-04-28 16:34:20 +0000 | [diff] [blame] | 966 | EmitGlobalConstant(CVA->getOperand(i), AddrSpace); |
Dan Gohman | 00d448a | 2008-12-22 21:14:27 +0000 | [diff] [blame] | 967 | } |
| 968 | } |
| 969 | |
| 970 | void AsmPrinter::EmitGlobalConstantVector(const ConstantVector *CP) { |
| 971 | const VectorType *PTy = CP->getType(); |
| 972 | |
| 973 | for (unsigned I = 0, E = PTy->getNumElements(); I < E; ++I) |
| 974 | EmitGlobalConstant(CP->getOperand(I)); |
| 975 | } |
| 976 | |
Sanjiv Gupta | c8d7bc8 | 2009-01-30 04:25:10 +0000 | [diff] [blame] | 977 | void AsmPrinter::EmitGlobalConstantStruct(const ConstantStruct *CVS, |
| 978 | unsigned AddrSpace) { |
Dan Gohman | 00d448a | 2008-12-22 21:14:27 +0000 | [diff] [blame] | 979 | // Print the fields in successive locations. Pad to align if needed! |
| 980 | const TargetData *TD = TM.getTargetData(); |
Duncan Sands | 777d230 | 2009-05-09 07:06:46 +0000 | [diff] [blame] | 981 | unsigned Size = TD->getTypeAllocSize(CVS->getType()); |
Dan Gohman | 00d448a | 2008-12-22 21:14:27 +0000 | [diff] [blame] | 982 | const StructLayout *cvsLayout = TD->getStructLayout(CVS->getType()); |
| 983 | uint64_t sizeSoFar = 0; |
| 984 | for (unsigned i = 0, e = CVS->getNumOperands(); i != e; ++i) { |
| 985 | const Constant* field = CVS->getOperand(i); |
| 986 | |
| 987 | // Check if padding is needed and insert one or more 0s. |
Duncan Sands | 777d230 | 2009-05-09 07:06:46 +0000 | [diff] [blame] | 988 | uint64_t fieldSize = TD->getTypeAllocSize(field->getType()); |
Dan Gohman | 00d448a | 2008-12-22 21:14:27 +0000 | [diff] [blame] | 989 | uint64_t padSize = ((i == e-1 ? Size : cvsLayout->getElementOffset(i+1)) |
| 990 | - cvsLayout->getElementOffset(i)) - fieldSize; |
| 991 | sizeSoFar += fieldSize + padSize; |
| 992 | |
| 993 | // Now print the actual field value. |
Sanjiv Gupta | c8d7bc8 | 2009-01-30 04:25:10 +0000 | [diff] [blame] | 994 | EmitGlobalConstant(field, AddrSpace); |
Dan Gohman | 00d448a | 2008-12-22 21:14:27 +0000 | [diff] [blame] | 995 | |
| 996 | // Insert padding - this may include padding to increase the size of the |
| 997 | // current field up to the ABI size (if the struct is not packed) as well |
| 998 | // as padding to ensure that the next field starts at the right offset. |
Sanjiv Gupta | c8d7bc8 | 2009-01-30 04:25:10 +0000 | [diff] [blame] | 999 | EmitZeros(padSize, AddrSpace); |
Dan Gohman | 00d448a | 2008-12-22 21:14:27 +0000 | [diff] [blame] | 1000 | } |
| 1001 | assert(sizeSoFar == cvsLayout->getSizeInBytes() && |
| 1002 | "Layout of constant struct may be incorrect!"); |
| 1003 | } |
| 1004 | |
Sanjiv Gupta | c8d7bc8 | 2009-01-30 04:25:10 +0000 | [diff] [blame] | 1005 | void AsmPrinter::EmitGlobalConstantFP(const ConstantFP *CFP, |
| 1006 | unsigned AddrSpace) { |
Dan Gohman | 00d448a | 2008-12-22 21:14:27 +0000 | [diff] [blame] | 1007 | // FP Constants are printed as integer constants to avoid losing |
| 1008 | // precision... |
Owen Anderson | 1d0be15 | 2009-08-13 21:58:54 +0000 | [diff] [blame] | 1009 | LLVMContext &Context = CFP->getContext(); |
Dan Gohman | 00d448a | 2008-12-22 21:14:27 +0000 | [diff] [blame] | 1010 | const TargetData *TD = TM.getTargetData(); |
Chris Lattner | cf0fe8d | 2009-10-05 05:54:46 +0000 | [diff] [blame] | 1011 | if (CFP->getType()->isDoubleTy()) { |
Dan Gohman | 00d448a | 2008-12-22 21:14:27 +0000 | [diff] [blame] | 1012 | double Val = CFP->getValueAPF().convertToDouble(); // for comment only |
| 1013 | uint64_t i = CFP->getValueAPF().bitcastToAPInt().getZExtValue(); |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1014 | if (MAI->getData64bitsDirective(AddrSpace)) { |
| 1015 | O << MAI->getData64bitsDirective(AddrSpace) << i; |
Dan Gohman | a12e9d7 | 2009-08-12 18:32:22 +0000 | [diff] [blame] | 1016 | if (VerboseAsm) { |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1017 | O.PadToColumn(MAI->getCommentColumn()); |
| 1018 | O << MAI->getCommentString() << " double " << Val; |
Dan Gohman | a12e9d7 | 2009-08-12 18:32:22 +0000 | [diff] [blame] | 1019 | } |
Evan Cheng | f1c0ae9 | 2009-03-24 00:17:40 +0000 | [diff] [blame] | 1020 | O << '\n'; |
| 1021 | } else if (TD->isBigEndian()) { |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1022 | O << MAI->getData32bitsDirective(AddrSpace) << unsigned(i >> 32); |
Dan Gohman | a12e9d7 | 2009-08-12 18:32:22 +0000 | [diff] [blame] | 1023 | if (VerboseAsm) { |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1024 | O.PadToColumn(MAI->getCommentColumn()); |
| 1025 | O << MAI->getCommentString() |
Dan Gohman | cf20ac4 | 2009-08-13 01:36:44 +0000 | [diff] [blame] | 1026 | << " most significant word of double " << Val; |
Dan Gohman | a12e9d7 | 2009-08-12 18:32:22 +0000 | [diff] [blame] | 1027 | } |
Evan Cheng | f1c0ae9 | 2009-03-24 00:17:40 +0000 | [diff] [blame] | 1028 | O << '\n'; |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1029 | O << MAI->getData32bitsDirective(AddrSpace) << unsigned(i); |
Dan Gohman | a12e9d7 | 2009-08-12 18:32:22 +0000 | [diff] [blame] | 1030 | if (VerboseAsm) { |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1031 | O.PadToColumn(MAI->getCommentColumn()); |
| 1032 | O << MAI->getCommentString() |
Dan Gohman | cf20ac4 | 2009-08-13 01:36:44 +0000 | [diff] [blame] | 1033 | << " least significant word of double " << Val; |
Dan Gohman | a12e9d7 | 2009-08-12 18:32:22 +0000 | [diff] [blame] | 1034 | } |
Evan Cheng | f1c0ae9 | 2009-03-24 00:17:40 +0000 | [diff] [blame] | 1035 | O << '\n'; |
Dan Gohman | 00d448a | 2008-12-22 21:14:27 +0000 | [diff] [blame] | 1036 | } else { |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1037 | O << MAI->getData32bitsDirective(AddrSpace) << unsigned(i); |
Dan Gohman | a12e9d7 | 2009-08-12 18:32:22 +0000 | [diff] [blame] | 1038 | if (VerboseAsm) { |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1039 | O.PadToColumn(MAI->getCommentColumn()); |
| 1040 | O << MAI->getCommentString() |
Dan Gohman | cf20ac4 | 2009-08-13 01:36:44 +0000 | [diff] [blame] | 1041 | << " least significant word of double " << Val; |
Dan Gohman | a12e9d7 | 2009-08-12 18:32:22 +0000 | [diff] [blame] | 1042 | } |
Evan Cheng | f1c0ae9 | 2009-03-24 00:17:40 +0000 | [diff] [blame] | 1043 | O << '\n'; |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1044 | O << MAI->getData32bitsDirective(AddrSpace) << unsigned(i >> 32); |
Dan Gohman | a12e9d7 | 2009-08-12 18:32:22 +0000 | [diff] [blame] | 1045 | if (VerboseAsm) { |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1046 | O.PadToColumn(MAI->getCommentColumn()); |
| 1047 | O << MAI->getCommentString() |
Dan Gohman | cf20ac4 | 2009-08-13 01:36:44 +0000 | [diff] [blame] | 1048 | << " most significant word of double " << Val; |
Dan Gohman | a12e9d7 | 2009-08-12 18:32:22 +0000 | [diff] [blame] | 1049 | } |
Evan Cheng | f1c0ae9 | 2009-03-24 00:17:40 +0000 | [diff] [blame] | 1050 | O << '\n'; |
Dan Gohman | 00d448a | 2008-12-22 21:14:27 +0000 | [diff] [blame] | 1051 | } |
| 1052 | return; |
Chris Lattner | cf0fe8d | 2009-10-05 05:54:46 +0000 | [diff] [blame] | 1053 | } |
| 1054 | |
| 1055 | if (CFP->getType()->isFloatTy()) { |
Dan Gohman | 00d448a | 2008-12-22 21:14:27 +0000 | [diff] [blame] | 1056 | float Val = CFP->getValueAPF().convertToFloat(); // for comment only |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1057 | O << MAI->getData32bitsDirective(AddrSpace) |
Evan Cheng | f1c0ae9 | 2009-03-24 00:17:40 +0000 | [diff] [blame] | 1058 | << CFP->getValueAPF().bitcastToAPInt().getZExtValue(); |
Dan Gohman | a12e9d7 | 2009-08-12 18:32:22 +0000 | [diff] [blame] | 1059 | if (VerboseAsm) { |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1060 | O.PadToColumn(MAI->getCommentColumn()); |
| 1061 | O << MAI->getCommentString() << " float " << Val; |
Dan Gohman | a12e9d7 | 2009-08-12 18:32:22 +0000 | [diff] [blame] | 1062 | } |
Evan Cheng | f1c0ae9 | 2009-03-24 00:17:40 +0000 | [diff] [blame] | 1063 | O << '\n'; |
Dan Gohman | 00d448a | 2008-12-22 21:14:27 +0000 | [diff] [blame] | 1064 | return; |
Chris Lattner | cf0fe8d | 2009-10-05 05:54:46 +0000 | [diff] [blame] | 1065 | } |
| 1066 | |
| 1067 | if (CFP->getType()->isX86_FP80Ty()) { |
Dan Gohman | 00d448a | 2008-12-22 21:14:27 +0000 | [diff] [blame] | 1068 | // all long double variants are printed as hex |
| 1069 | // api needed to prevent premature destruction |
| 1070 | APInt api = CFP->getValueAPF().bitcastToAPInt(); |
| 1071 | const uint64_t *p = api.getRawData(); |
| 1072 | // Convert to double so we can print the approximate val as a comment. |
| 1073 | APFloat DoubleVal = CFP->getValueAPF(); |
| 1074 | bool ignored; |
| 1075 | DoubleVal.convert(APFloat::IEEEdouble, APFloat::rmNearestTiesToEven, |
| 1076 | &ignored); |
| 1077 | if (TD->isBigEndian()) { |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1078 | O << MAI->getData16bitsDirective(AddrSpace) << uint16_t(p[1]); |
Dan Gohman | a12e9d7 | 2009-08-12 18:32:22 +0000 | [diff] [blame] | 1079 | if (VerboseAsm) { |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1080 | O.PadToColumn(MAI->getCommentColumn()); |
| 1081 | O << MAI->getCommentString() |
Dan Gohman | cf20ac4 | 2009-08-13 01:36:44 +0000 | [diff] [blame] | 1082 | << " most significant halfword of x86_fp80 ~" |
Evan Cheng | f1c0ae9 | 2009-03-24 00:17:40 +0000 | [diff] [blame] | 1083 | << DoubleVal.convertToDouble(); |
Dan Gohman | a12e9d7 | 2009-08-12 18:32:22 +0000 | [diff] [blame] | 1084 | } |
Evan Cheng | f1c0ae9 | 2009-03-24 00:17:40 +0000 | [diff] [blame] | 1085 | O << '\n'; |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1086 | O << MAI->getData16bitsDirective(AddrSpace) << uint16_t(p[0] >> 48); |
Dan Gohman | a12e9d7 | 2009-08-12 18:32:22 +0000 | [diff] [blame] | 1087 | if (VerboseAsm) { |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1088 | O.PadToColumn(MAI->getCommentColumn()); |
| 1089 | O << MAI->getCommentString() << " next halfword"; |
Dan Gohman | a12e9d7 | 2009-08-12 18:32:22 +0000 | [diff] [blame] | 1090 | } |
Evan Cheng | f1c0ae9 | 2009-03-24 00:17:40 +0000 | [diff] [blame] | 1091 | O << '\n'; |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1092 | O << MAI->getData16bitsDirective(AddrSpace) << uint16_t(p[0] >> 32); |
Dan Gohman | a12e9d7 | 2009-08-12 18:32:22 +0000 | [diff] [blame] | 1093 | if (VerboseAsm) { |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1094 | O.PadToColumn(MAI->getCommentColumn()); |
| 1095 | O << MAI->getCommentString() << " next halfword"; |
Dan Gohman | a12e9d7 | 2009-08-12 18:32:22 +0000 | [diff] [blame] | 1096 | } |
Evan Cheng | f1c0ae9 | 2009-03-24 00:17:40 +0000 | [diff] [blame] | 1097 | O << '\n'; |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1098 | O << MAI->getData16bitsDirective(AddrSpace) << uint16_t(p[0] >> 16); |
Dan Gohman | a12e9d7 | 2009-08-12 18:32:22 +0000 | [diff] [blame] | 1099 | if (VerboseAsm) { |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1100 | O.PadToColumn(MAI->getCommentColumn()); |
| 1101 | O << MAI->getCommentString() << " next halfword"; |
Dan Gohman | a12e9d7 | 2009-08-12 18:32:22 +0000 | [diff] [blame] | 1102 | } |
Evan Cheng | f1c0ae9 | 2009-03-24 00:17:40 +0000 | [diff] [blame] | 1103 | O << '\n'; |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1104 | O << MAI->getData16bitsDirective(AddrSpace) << uint16_t(p[0]); |
Dan Gohman | a12e9d7 | 2009-08-12 18:32:22 +0000 | [diff] [blame] | 1105 | if (VerboseAsm) { |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1106 | O.PadToColumn(MAI->getCommentColumn()); |
| 1107 | O << MAI->getCommentString() |
Dan Gohman | cf20ac4 | 2009-08-13 01:36:44 +0000 | [diff] [blame] | 1108 | << " least significant halfword"; |
Dan Gohman | a12e9d7 | 2009-08-12 18:32:22 +0000 | [diff] [blame] | 1109 | } |
Evan Cheng | f1c0ae9 | 2009-03-24 00:17:40 +0000 | [diff] [blame] | 1110 | O << '\n'; |
Dan Gohman | 00d448a | 2008-12-22 21:14:27 +0000 | [diff] [blame] | 1111 | } else { |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1112 | O << MAI->getData16bitsDirective(AddrSpace) << uint16_t(p[0]); |
Dan Gohman | a12e9d7 | 2009-08-12 18:32:22 +0000 | [diff] [blame] | 1113 | if (VerboseAsm) { |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1114 | O.PadToColumn(MAI->getCommentColumn()); |
| 1115 | O << MAI->getCommentString() |
Dan Gohman | cf20ac4 | 2009-08-13 01:36:44 +0000 | [diff] [blame] | 1116 | << " least significant halfword of x86_fp80 ~" |
Evan Cheng | f1c0ae9 | 2009-03-24 00:17:40 +0000 | [diff] [blame] | 1117 | << DoubleVal.convertToDouble(); |
Dan Gohman | a12e9d7 | 2009-08-12 18:32:22 +0000 | [diff] [blame] | 1118 | } |
Evan Cheng | f1c0ae9 | 2009-03-24 00:17:40 +0000 | [diff] [blame] | 1119 | O << '\n'; |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1120 | O << MAI->getData16bitsDirective(AddrSpace) << uint16_t(p[0] >> 16); |
Dan Gohman | a12e9d7 | 2009-08-12 18:32:22 +0000 | [diff] [blame] | 1121 | if (VerboseAsm) { |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1122 | O.PadToColumn(MAI->getCommentColumn()); |
| 1123 | O << MAI->getCommentString() |
Dan Gohman | cf20ac4 | 2009-08-13 01:36:44 +0000 | [diff] [blame] | 1124 | << " next halfword"; |
Dan Gohman | a12e9d7 | 2009-08-12 18:32:22 +0000 | [diff] [blame] | 1125 | } |
Evan Cheng | f1c0ae9 | 2009-03-24 00:17:40 +0000 | [diff] [blame] | 1126 | O << '\n'; |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1127 | O << MAI->getData16bitsDirective(AddrSpace) << uint16_t(p[0] >> 32); |
Dan Gohman | a12e9d7 | 2009-08-12 18:32:22 +0000 | [diff] [blame] | 1128 | if (VerboseAsm) { |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1129 | O.PadToColumn(MAI->getCommentColumn()); |
| 1130 | O << MAI->getCommentString() |
Dan Gohman | cf20ac4 | 2009-08-13 01:36:44 +0000 | [diff] [blame] | 1131 | << " next halfword"; |
Dan Gohman | a12e9d7 | 2009-08-12 18:32:22 +0000 | [diff] [blame] | 1132 | } |
Evan Cheng | f1c0ae9 | 2009-03-24 00:17:40 +0000 | [diff] [blame] | 1133 | O << '\n'; |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1134 | O << MAI->getData16bitsDirective(AddrSpace) << uint16_t(p[0] >> 48); |
Dan Gohman | a12e9d7 | 2009-08-12 18:32:22 +0000 | [diff] [blame] | 1135 | if (VerboseAsm) { |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1136 | O.PadToColumn(MAI->getCommentColumn()); |
| 1137 | O << MAI->getCommentString() |
Dan Gohman | cf20ac4 | 2009-08-13 01:36:44 +0000 | [diff] [blame] | 1138 | << " next halfword"; |
Dan Gohman | a12e9d7 | 2009-08-12 18:32:22 +0000 | [diff] [blame] | 1139 | } |
Evan Cheng | f1c0ae9 | 2009-03-24 00:17:40 +0000 | [diff] [blame] | 1140 | O << '\n'; |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1141 | O << MAI->getData16bitsDirective(AddrSpace) << uint16_t(p[1]); |
Dan Gohman | a12e9d7 | 2009-08-12 18:32:22 +0000 | [diff] [blame] | 1142 | if (VerboseAsm) { |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1143 | O.PadToColumn(MAI->getCommentColumn()); |
| 1144 | O << MAI->getCommentString() |
Dan Gohman | cf20ac4 | 2009-08-13 01:36:44 +0000 | [diff] [blame] | 1145 | << " most significant halfword"; |
Dan Gohman | a12e9d7 | 2009-08-12 18:32:22 +0000 | [diff] [blame] | 1146 | } |
Evan Cheng | f1c0ae9 | 2009-03-24 00:17:40 +0000 | [diff] [blame] | 1147 | O << '\n'; |
Dan Gohman | 00d448a | 2008-12-22 21:14:27 +0000 | [diff] [blame] | 1148 | } |
Owen Anderson | 1d0be15 | 2009-08-13 21:58:54 +0000 | [diff] [blame] | 1149 | EmitZeros(TD->getTypeAllocSize(Type::getX86_FP80Ty(Context)) - |
| 1150 | TD->getTypeStoreSize(Type::getX86_FP80Ty(Context)), AddrSpace); |
Dan Gohman | 00d448a | 2008-12-22 21:14:27 +0000 | [diff] [blame] | 1151 | return; |
Chris Lattner | cf0fe8d | 2009-10-05 05:54:46 +0000 | [diff] [blame] | 1152 | } |
| 1153 | |
| 1154 | if (CFP->getType()->isPPC_FP128Ty()) { |
Dan Gohman | 00d448a | 2008-12-22 21:14:27 +0000 | [diff] [blame] | 1155 | // all long double variants are printed as hex |
| 1156 | // api needed to prevent premature destruction |
| 1157 | APInt api = CFP->getValueAPF().bitcastToAPInt(); |
| 1158 | const uint64_t *p = api.getRawData(); |
| 1159 | if (TD->isBigEndian()) { |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1160 | O << MAI->getData32bitsDirective(AddrSpace) << uint32_t(p[0] >> 32); |
Dan Gohman | a12e9d7 | 2009-08-12 18:32:22 +0000 | [diff] [blame] | 1161 | if (VerboseAsm) { |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1162 | O.PadToColumn(MAI->getCommentColumn()); |
| 1163 | O << MAI->getCommentString() |
Dan Gohman | cf20ac4 | 2009-08-13 01:36:44 +0000 | [diff] [blame] | 1164 | << " most significant word of ppc_fp128"; |
Dan Gohman | a12e9d7 | 2009-08-12 18:32:22 +0000 | [diff] [blame] | 1165 | } |
Evan Cheng | f1c0ae9 | 2009-03-24 00:17:40 +0000 | [diff] [blame] | 1166 | O << '\n'; |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1167 | O << MAI->getData32bitsDirective(AddrSpace) << uint32_t(p[0]); |
Dan Gohman | a12e9d7 | 2009-08-12 18:32:22 +0000 | [diff] [blame] | 1168 | if (VerboseAsm) { |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1169 | O.PadToColumn(MAI->getCommentColumn()); |
| 1170 | O << MAI->getCommentString() |
Dan Gohman | cf20ac4 | 2009-08-13 01:36:44 +0000 | [diff] [blame] | 1171 | << " next word"; |
Dan Gohman | a12e9d7 | 2009-08-12 18:32:22 +0000 | [diff] [blame] | 1172 | } |
Evan Cheng | f1c0ae9 | 2009-03-24 00:17:40 +0000 | [diff] [blame] | 1173 | O << '\n'; |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1174 | O << MAI->getData32bitsDirective(AddrSpace) << uint32_t(p[1] >> 32); |
Dan Gohman | a12e9d7 | 2009-08-12 18:32:22 +0000 | [diff] [blame] | 1175 | if (VerboseAsm) { |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1176 | O.PadToColumn(MAI->getCommentColumn()); |
| 1177 | O << MAI->getCommentString() |
Dan Gohman | cf20ac4 | 2009-08-13 01:36:44 +0000 | [diff] [blame] | 1178 | << " next word"; |
Dan Gohman | a12e9d7 | 2009-08-12 18:32:22 +0000 | [diff] [blame] | 1179 | } |
Evan Cheng | f1c0ae9 | 2009-03-24 00:17:40 +0000 | [diff] [blame] | 1180 | O << '\n'; |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1181 | O << MAI->getData32bitsDirective(AddrSpace) << uint32_t(p[1]); |
Dan Gohman | a12e9d7 | 2009-08-12 18:32:22 +0000 | [diff] [blame] | 1182 | if (VerboseAsm) { |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1183 | O.PadToColumn(MAI->getCommentColumn()); |
| 1184 | O << MAI->getCommentString() |
Dan Gohman | cf20ac4 | 2009-08-13 01:36:44 +0000 | [diff] [blame] | 1185 | << " least significant word"; |
Dan Gohman | a12e9d7 | 2009-08-12 18:32:22 +0000 | [diff] [blame] | 1186 | } |
Evan Cheng | f1c0ae9 | 2009-03-24 00:17:40 +0000 | [diff] [blame] | 1187 | O << '\n'; |
Dan Gohman | 00d448a | 2008-12-22 21:14:27 +0000 | [diff] [blame] | 1188 | } else { |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1189 | O << MAI->getData32bitsDirective(AddrSpace) << uint32_t(p[1]); |
Dan Gohman | a12e9d7 | 2009-08-12 18:32:22 +0000 | [diff] [blame] | 1190 | if (VerboseAsm) { |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1191 | O.PadToColumn(MAI->getCommentColumn()); |
| 1192 | O << MAI->getCommentString() |
Dan Gohman | cf20ac4 | 2009-08-13 01:36:44 +0000 | [diff] [blame] | 1193 | << " least significant word of ppc_fp128"; |
Dan Gohman | a12e9d7 | 2009-08-12 18:32:22 +0000 | [diff] [blame] | 1194 | } |
Evan Cheng | f1c0ae9 | 2009-03-24 00:17:40 +0000 | [diff] [blame] | 1195 | O << '\n'; |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1196 | O << MAI->getData32bitsDirective(AddrSpace) << uint32_t(p[1] >> 32); |
Dan Gohman | a12e9d7 | 2009-08-12 18:32:22 +0000 | [diff] [blame] | 1197 | if (VerboseAsm) { |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1198 | O.PadToColumn(MAI->getCommentColumn()); |
| 1199 | O << MAI->getCommentString() |
Dan Gohman | cf20ac4 | 2009-08-13 01:36:44 +0000 | [diff] [blame] | 1200 | << " next word"; |
Dan Gohman | a12e9d7 | 2009-08-12 18:32:22 +0000 | [diff] [blame] | 1201 | } |
Evan Cheng | f1c0ae9 | 2009-03-24 00:17:40 +0000 | [diff] [blame] | 1202 | O << '\n'; |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1203 | O << MAI->getData32bitsDirective(AddrSpace) << uint32_t(p[0]); |
Dan Gohman | a12e9d7 | 2009-08-12 18:32:22 +0000 | [diff] [blame] | 1204 | if (VerboseAsm) { |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1205 | O.PadToColumn(MAI->getCommentColumn()); |
| 1206 | O << MAI->getCommentString() |
Dan Gohman | cf20ac4 | 2009-08-13 01:36:44 +0000 | [diff] [blame] | 1207 | << " next word"; |
Dan Gohman | a12e9d7 | 2009-08-12 18:32:22 +0000 | [diff] [blame] | 1208 | } |
Evan Cheng | f1c0ae9 | 2009-03-24 00:17:40 +0000 | [diff] [blame] | 1209 | O << '\n'; |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1210 | O << MAI->getData32bitsDirective(AddrSpace) << uint32_t(p[0] >> 32); |
Dan Gohman | a12e9d7 | 2009-08-12 18:32:22 +0000 | [diff] [blame] | 1211 | if (VerboseAsm) { |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1212 | O.PadToColumn(MAI->getCommentColumn()); |
| 1213 | O << MAI->getCommentString() |
Dan Gohman | cf20ac4 | 2009-08-13 01:36:44 +0000 | [diff] [blame] | 1214 | << " most significant word"; |
Dan Gohman | a12e9d7 | 2009-08-12 18:32:22 +0000 | [diff] [blame] | 1215 | } |
Evan Cheng | f1c0ae9 | 2009-03-24 00:17:40 +0000 | [diff] [blame] | 1216 | O << '\n'; |
Dan Gohman | 00d448a | 2008-12-22 21:14:27 +0000 | [diff] [blame] | 1217 | } |
| 1218 | return; |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1219 | } else llvm_unreachable("Floating point constant type not handled"); |
Dan Gohman | 00d448a | 2008-12-22 21:14:27 +0000 | [diff] [blame] | 1220 | } |
| 1221 | |
Sanjiv Gupta | c8d7bc8 | 2009-01-30 04:25:10 +0000 | [diff] [blame] | 1222 | void AsmPrinter::EmitGlobalConstantLargeInt(const ConstantInt *CI, |
| 1223 | unsigned AddrSpace) { |
Dan Gohman | 00d448a | 2008-12-22 21:14:27 +0000 | [diff] [blame] | 1224 | const TargetData *TD = TM.getTargetData(); |
| 1225 | unsigned BitWidth = CI->getBitWidth(); |
| 1226 | assert(isPowerOf2_32(BitWidth) && |
| 1227 | "Non-power-of-2-sized integers not handled!"); |
| 1228 | |
| 1229 | // We don't expect assemblers to support integer data directives |
| 1230 | // for more than 64 bits, so we emit the data in at most 64-bit |
| 1231 | // quantities at a time. |
| 1232 | const uint64_t *RawData = CI->getValue().getRawData(); |
| 1233 | for (unsigned i = 0, e = BitWidth / 64; i != e; ++i) { |
| 1234 | uint64_t Val; |
| 1235 | if (TD->isBigEndian()) |
| 1236 | Val = RawData[e - i - 1]; |
| 1237 | else |
| 1238 | Val = RawData[i]; |
| 1239 | |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1240 | if (MAI->getData64bitsDirective(AddrSpace)) |
| 1241 | O << MAI->getData64bitsDirective(AddrSpace) << Val << '\n'; |
Dan Gohman | 00d448a | 2008-12-22 21:14:27 +0000 | [diff] [blame] | 1242 | else if (TD->isBigEndian()) { |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1243 | O << MAI->getData32bitsDirective(AddrSpace) << unsigned(Val >> 32); |
Dan Gohman | a12e9d7 | 2009-08-12 18:32:22 +0000 | [diff] [blame] | 1244 | if (VerboseAsm) { |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1245 | O.PadToColumn(MAI->getCommentColumn()); |
| 1246 | O << MAI->getCommentString() |
Dan Gohman | cf20ac4 | 2009-08-13 01:36:44 +0000 | [diff] [blame] | 1247 | << " most significant half of i64 " << Val; |
Dan Gohman | a12e9d7 | 2009-08-12 18:32:22 +0000 | [diff] [blame] | 1248 | } |
Evan Cheng | f1c0ae9 | 2009-03-24 00:17:40 +0000 | [diff] [blame] | 1249 | O << '\n'; |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1250 | O << MAI->getData32bitsDirective(AddrSpace) << unsigned(Val); |
Dan Gohman | a12e9d7 | 2009-08-12 18:32:22 +0000 | [diff] [blame] | 1251 | if (VerboseAsm) { |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1252 | O.PadToColumn(MAI->getCommentColumn()); |
| 1253 | O << MAI->getCommentString() |
Dan Gohman | cf20ac4 | 2009-08-13 01:36:44 +0000 | [diff] [blame] | 1254 | << " least significant half of i64 " << Val; |
Dan Gohman | a12e9d7 | 2009-08-12 18:32:22 +0000 | [diff] [blame] | 1255 | } |
Evan Cheng | f1c0ae9 | 2009-03-24 00:17:40 +0000 | [diff] [blame] | 1256 | O << '\n'; |
Dan Gohman | 00d448a | 2008-12-22 21:14:27 +0000 | [diff] [blame] | 1257 | } else { |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1258 | O << MAI->getData32bitsDirective(AddrSpace) << unsigned(Val); |
Dan Gohman | a12e9d7 | 2009-08-12 18:32:22 +0000 | [diff] [blame] | 1259 | if (VerboseAsm) { |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1260 | O.PadToColumn(MAI->getCommentColumn()); |
| 1261 | O << MAI->getCommentString() |
Dan Gohman | cf20ac4 | 2009-08-13 01:36:44 +0000 | [diff] [blame] | 1262 | << " least significant half of i64 " << Val; |
Dan Gohman | a12e9d7 | 2009-08-12 18:32:22 +0000 | [diff] [blame] | 1263 | } |
Evan Cheng | f1c0ae9 | 2009-03-24 00:17:40 +0000 | [diff] [blame] | 1264 | O << '\n'; |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1265 | O << MAI->getData32bitsDirective(AddrSpace) << unsigned(Val >> 32); |
Dan Gohman | a12e9d7 | 2009-08-12 18:32:22 +0000 | [diff] [blame] | 1266 | if (VerboseAsm) { |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1267 | O.PadToColumn(MAI->getCommentColumn()); |
| 1268 | O << MAI->getCommentString() |
Dan Gohman | cf20ac4 | 2009-08-13 01:36:44 +0000 | [diff] [blame] | 1269 | << " most significant half of i64 " << Val; |
Dan Gohman | a12e9d7 | 2009-08-12 18:32:22 +0000 | [diff] [blame] | 1270 | } |
Evan Cheng | f1c0ae9 | 2009-03-24 00:17:40 +0000 | [diff] [blame] | 1271 | O << '\n'; |
Dan Gohman | 00d448a | 2008-12-22 21:14:27 +0000 | [diff] [blame] | 1272 | } |
| 1273 | } |
| 1274 | } |
| 1275 | |
Chris Lattner | 25045bd | 2005-11-21 07:51:36 +0000 | [diff] [blame] | 1276 | /// EmitGlobalConstant - Print a general LLVM constant to the .s file. |
Sanjiv Gupta | c8d7bc8 | 2009-01-30 04:25:10 +0000 | [diff] [blame] | 1277 | void AsmPrinter::EmitGlobalConstant(const Constant *CV, unsigned AddrSpace) { |
Owen Anderson | a69571c | 2006-05-03 01:29:57 +0000 | [diff] [blame] | 1278 | const TargetData *TD = TM.getTargetData(); |
Dan Gohman | 00d448a | 2008-12-22 21:14:27 +0000 | [diff] [blame] | 1279 | const Type *type = CV->getType(); |
Duncan Sands | 777d230 | 2009-05-09 07:06:46 +0000 | [diff] [blame] | 1280 | unsigned Size = TD->getTypeAllocSize(type); |
Chris Lattner | 1b7e235 | 2004-08-17 06:36:49 +0000 | [diff] [blame] | 1281 | |
Chris Lattner | bd1d382 | 2004-10-16 18:19:26 +0000 | [diff] [blame] | 1282 | if (CV->isNullValue() || isa<UndefValue>(CV)) { |
Sanjiv Gupta | c8d7bc8 | 2009-01-30 04:25:10 +0000 | [diff] [blame] | 1283 | EmitZeros(Size, AddrSpace); |
Chris Lattner | 1b7e235 | 2004-08-17 06:36:49 +0000 | [diff] [blame] | 1284 | return; |
| 1285 | } else if (const ConstantArray *CVA = dyn_cast<ConstantArray>(CV)) { |
Sanjiv Gupta | d3d9657 | 2009-04-28 16:34:20 +0000 | [diff] [blame] | 1286 | EmitGlobalConstantArray(CVA , AddrSpace); |
Chris Lattner | 1b7e235 | 2004-08-17 06:36:49 +0000 | [diff] [blame] | 1287 | return; |
| 1288 | } else if (const ConstantStruct *CVS = dyn_cast<ConstantStruct>(CV)) { |
Sanjiv Gupta | c8d7bc8 | 2009-01-30 04:25:10 +0000 | [diff] [blame] | 1289 | EmitGlobalConstantStruct(CVS, AddrSpace); |
Chris Lattner | 1b7e235 | 2004-08-17 06:36:49 +0000 | [diff] [blame] | 1290 | return; |
| 1291 | } else if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CV)) { |
Sanjiv Gupta | c8d7bc8 | 2009-01-30 04:25:10 +0000 | [diff] [blame] | 1292 | EmitGlobalConstantFP(CFP, AddrSpace); |
Dan Gohman | 00d448a | 2008-12-22 21:14:27 +0000 | [diff] [blame] | 1293 | return; |
| 1294 | } else if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) { |
| 1295 | // Small integers are handled below; large integers are handled here. |
| 1296 | if (Size > 4) { |
Sanjiv Gupta | c8d7bc8 | 2009-01-30 04:25:10 +0000 | [diff] [blame] | 1297 | EmitGlobalConstantLargeInt(CI, AddrSpace); |
Chris Lattner | 1b7e235 | 2004-08-17 06:36:49 +0000 | [diff] [blame] | 1298 | return; |
| 1299 | } |
Reid Spencer | 9d6565a | 2007-02-15 02:26:10 +0000 | [diff] [blame] | 1300 | } else if (const ConstantVector *CP = dyn_cast<ConstantVector>(CV)) { |
Dan Gohman | 00d448a | 2008-12-22 21:14:27 +0000 | [diff] [blame] | 1301 | EmitGlobalConstantVector(CP); |
Nate Begeman | 8cfa57b | 2005-12-06 06:18:55 +0000 | [diff] [blame] | 1302 | return; |
Chris Lattner | 1b7e235 | 2004-08-17 06:36:49 +0000 | [diff] [blame] | 1303 | } |
| 1304 | |
Sanjiv Gupta | c8d7bc8 | 2009-01-30 04:25:10 +0000 | [diff] [blame] | 1305 | printDataDirective(type, AddrSpace); |
Chris Lattner | 25045bd | 2005-11-21 07:51:36 +0000 | [diff] [blame] | 1306 | EmitConstantValueOnly(CV); |
Evan Cheng | f1c0ae9 | 2009-03-24 00:17:40 +0000 | [diff] [blame] | 1307 | if (VerboseAsm) { |
| 1308 | if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) { |
| 1309 | SmallString<40> S; |
| 1310 | CI->getValue().toStringUnsigned(S, 16); |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1311 | O.PadToColumn(MAI->getCommentColumn()); |
| 1312 | O << MAI->getCommentString() << " 0x" << S.str(); |
Evan Cheng | f1c0ae9 | 2009-03-24 00:17:40 +0000 | [diff] [blame] | 1313 | } |
Scott Michel | eefc845 | 2008-06-03 15:39:51 +0000 | [diff] [blame] | 1314 | } |
Dan Gohman | d19a53b | 2008-06-30 22:03:41 +0000 | [diff] [blame] | 1315 | O << '\n'; |
Chris Lattner | 1b7e235 | 2004-08-17 06:36:49 +0000 | [diff] [blame] | 1316 | } |
Chris Lattner | 0264d1a | 2006-01-27 02:10:10 +0000 | [diff] [blame] | 1317 | |
Chris Lattner | fad86b0 | 2008-08-17 07:19:36 +0000 | [diff] [blame] | 1318 | void AsmPrinter::EmitMachineConstantPoolValue(MachineConstantPoolValue *MCPV) { |
Evan Cheng | d6594ae | 2006-09-12 21:00:35 +0000 | [diff] [blame] | 1319 | // Target doesn't support this yet! |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1320 | llvm_unreachable("Target does not support EmitMachineConstantPoolValue"); |
Evan Cheng | d6594ae | 2006-09-12 21:00:35 +0000 | [diff] [blame] | 1321 | } |
| 1322 | |
Chris Lattner | 3ce9b67 | 2006-09-26 23:59:50 +0000 | [diff] [blame] | 1323 | /// PrintSpecial - Print information related to the specified machine instr |
| 1324 | /// that is independent of the operand, and may be independent of the instr |
| 1325 | /// itself. This can be useful for portably encoding the comment character |
| 1326 | /// or other bits of target-specific knowledge into the asmstrings. The |
| 1327 | /// syntax used is ${:comment}. Targets can override this to add support |
| 1328 | /// for their own strange codes. |
Chris Lattner | 3e0cc26 | 2009-03-10 05:37:13 +0000 | [diff] [blame] | 1329 | void AsmPrinter::PrintSpecial(const MachineInstr *MI, const char *Code) const { |
Chris Lattner | bae02cf | 2006-09-27 00:06:07 +0000 | [diff] [blame] | 1330 | if (!strcmp(Code, "private")) { |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1331 | O << MAI->getPrivateGlobalPrefix(); |
Chris Lattner | bae02cf | 2006-09-27 00:06:07 +0000 | [diff] [blame] | 1332 | } else if (!strcmp(Code, "comment")) { |
Evan Cheng | f1c0ae9 | 2009-03-24 00:17:40 +0000 | [diff] [blame] | 1333 | if (VerboseAsm) |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1334 | O << MAI->getCommentString(); |
Chris Lattner | 3ce9b67 | 2006-09-26 23:59:50 +0000 | [diff] [blame] | 1335 | } else if (!strcmp(Code, "uid")) { |
Chris Lattner | b6a24bf | 2007-02-05 21:23:52 +0000 | [diff] [blame] | 1336 | // Comparing the address of MI isn't sufficient, because machineinstrs may |
| 1337 | // be allocated to the same address across functions. |
| 1338 | const Function *ThisF = MI->getParent()->getParent()->getFunction(); |
| 1339 | |
Owen Anderson | bd58edf | 2009-06-24 22:28:12 +0000 | [diff] [blame] | 1340 | // If this is a new LastFn instruction, bump the counter. |
| 1341 | if (LastMI != MI || LastFn != ThisF) { |
Chris Lattner | b6a24bf | 2007-02-05 21:23:52 +0000 | [diff] [blame] | 1342 | ++Counter; |
| 1343 | LastMI = MI; |
Owen Anderson | bd58edf | 2009-06-24 22:28:12 +0000 | [diff] [blame] | 1344 | LastFn = ThisF; |
Chris Lattner | b6a24bf | 2007-02-05 21:23:52 +0000 | [diff] [blame] | 1345 | } |
Chris Lattner | 3ce9b67 | 2006-09-26 23:59:50 +0000 | [diff] [blame] | 1346 | O << Counter; |
| 1347 | } else { |
Torok Edwin | 7d696d8 | 2009-07-11 13:10:19 +0000 | [diff] [blame] | 1348 | std::string msg; |
| 1349 | raw_string_ostream Msg(msg); |
| 1350 | Msg << "Unknown special formatter '" << Code |
Bill Wendling | e815619 | 2006-12-07 01:30:32 +0000 | [diff] [blame] | 1351 | << "' for machine instr: " << *MI; |
Torok Edwin | 7d696d8 | 2009-07-11 13:10:19 +0000 | [diff] [blame] | 1352 | llvm_report_error(Msg.str()); |
Chris Lattner | 3ce9b67 | 2006-09-26 23:59:50 +0000 | [diff] [blame] | 1353 | } |
| 1354 | } |
| 1355 | |
Argyrios Kyrtzidis | cd76240 | 2009-05-07 13:55:51 +0000 | [diff] [blame] | 1356 | /// processDebugLoc - Processes the debug information of each machine |
| 1357 | /// instruction's DebugLoc. |
Devang Patel | af0e272 | 2009-10-06 02:19:11 +0000 | [diff] [blame] | 1358 | void AsmPrinter::processDebugLoc(const MachineInstr *MI, |
| 1359 | bool BeforePrintingInsn) { |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1360 | if (!MAI || !DW) |
Chris Lattner | d250329 | 2009-08-05 04:09:18 +0000 | [diff] [blame] | 1361 | return; |
Devang Patel | b0fdedb | 2009-09-30 23:12:50 +0000 | [diff] [blame] | 1362 | DebugLoc DL = MI->getDebugLoc(); |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1363 | if (MAI->doesSupportDebugInformation() && DW->ShouldEmitDwarfDebug()) { |
Argyrios Kyrtzidis | cd76240 | 2009-05-07 13:55:51 +0000 | [diff] [blame] | 1364 | if (!DL.isUnknown()) { |
Argyrios Kyrtzidis | cd76240 | 2009-05-07 13:55:51 +0000 | [diff] [blame] | 1365 | DebugLocTuple CurDLT = MF->getDebugLocTuple(DL); |
Devang Patel | af0e272 | 2009-10-06 02:19:11 +0000 | [diff] [blame] | 1366 | if (BeforePrintingInsn) { |
Devang Patel | 1619dc3 | 2009-10-13 23:28:53 +0000 | [diff] [blame] | 1367 | if (CurDLT.Scope != 0 && PrevDLT != CurDLT) { |
Devang Patel | 60b35bd | 2009-10-06 18:37:31 +0000 | [diff] [blame] | 1368 | unsigned L = DW->RecordSourceLine(CurDLT.Line, CurDLT.Col, |
Devang Patel | 1619dc3 | 2009-10-13 23:28:53 +0000 | [diff] [blame] | 1369 | CurDLT.Scope); |
Devang Patel | 60b35bd | 2009-10-06 18:37:31 +0000 | [diff] [blame] | 1370 | printLabel(L); |
Dan Gohman | b953c94 | 2009-10-31 20:59:09 +0000 | [diff] [blame] | 1371 | O << '\n'; |
Devang Patel | 60b35bd | 2009-10-06 18:37:31 +0000 | [diff] [blame] | 1372 | #ifdef ATTACH_DEBUG_INFO_TO_AN_INSN |
| 1373 | DW->SetDbgScopeBeginLabels(MI, L); |
| 1374 | #endif |
| 1375 | } else { |
| 1376 | #ifdef ATTACH_DEBUG_INFO_TO_AN_INSN |
| 1377 | DW->SetDbgScopeEndLabels(MI, 0); |
| 1378 | #endif |
Devang Patel | af0e272 | 2009-10-06 02:19:11 +0000 | [diff] [blame] | 1379 | } |
Devang Patel | 60b35bd | 2009-10-06 18:37:31 +0000 | [diff] [blame] | 1380 | } |
Argyrios Kyrtzidis | cd76240 | 2009-05-07 13:55:51 +0000 | [diff] [blame] | 1381 | PrevDLT = CurDLT; |
| 1382 | } |
| 1383 | } |
| 1384 | } |
Chris Lattner | 3ce9b67 | 2006-09-26 23:59:50 +0000 | [diff] [blame] | 1385 | |
Chris Lattner | 0264d1a | 2006-01-27 02:10:10 +0000 | [diff] [blame] | 1386 | /// printInlineAsm - This method formats and prints the specified machine |
| 1387 | /// instruction that is an inline asm. |
| 1388 | void AsmPrinter::printInlineAsm(const MachineInstr *MI) const { |
Chris Lattner | f2b67cf | 2006-01-30 23:00:08 +0000 | [diff] [blame] | 1389 | unsigned NumOperands = MI->getNumOperands(); |
| 1390 | |
| 1391 | // Count the number of register definitions. |
| 1392 | unsigned NumDefs = 0; |
Dan Gohman | d735b80 | 2008-10-03 15:45:36 +0000 | [diff] [blame] | 1393 | for (; MI->getOperand(NumDefs).isReg() && MI->getOperand(NumDefs).isDef(); |
Chris Lattner | 67942f5 | 2006-09-05 20:02:51 +0000 | [diff] [blame] | 1394 | ++NumDefs) |
Chris Lattner | f2b67cf | 2006-01-30 23:00:08 +0000 | [diff] [blame] | 1395 | assert(NumDefs != NumOperands-1 && "No asm string?"); |
| 1396 | |
Dan Gohman | d735b80 | 2008-10-03 15:45:36 +0000 | [diff] [blame] | 1397 | assert(MI->getOperand(NumDefs).isSymbol() && "No asm string?"); |
Chris Lattner | 6609913 | 2006-02-01 22:41:11 +0000 | [diff] [blame] | 1398 | |
| 1399 | // Disassemble the AsmStr, printing out the literal pieces, the operands, etc. |
Chris Lattner | f2b67cf | 2006-01-30 23:00:08 +0000 | [diff] [blame] | 1400 | const char *AsmStr = MI->getOperand(NumDefs).getSymbolName(); |
Chris Lattner | 6609913 | 2006-02-01 22:41:11 +0000 | [diff] [blame] | 1401 | |
Dale Johannesen | ba2a0b9 | 2008-01-29 02:21:21 +0000 | [diff] [blame] | 1402 | // If this asmstr is empty, just print the #APP/#NOAPP markers. |
| 1403 | // These are useful to see where empty asm's wound up. |
Chris Lattner | f26f5dd | 2006-07-28 00:17:20 +0000 | [diff] [blame] | 1404 | if (AsmStr[0] == 0) { |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1405 | O << MAI->getCommentString() << MAI->getInlineAsmStart() << "\n\t"; |
| 1406 | O << MAI->getCommentString() << MAI->getInlineAsmEnd() << '\n'; |
Chris Lattner | f26f5dd | 2006-07-28 00:17:20 +0000 | [diff] [blame] | 1407 | return; |
| 1408 | } |
| 1409 | |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1410 | O << MAI->getCommentString() << MAI->getInlineAsmStart() << "\n\t"; |
Chris Lattner | f26f5dd | 2006-07-28 00:17:20 +0000 | [diff] [blame] | 1411 | |
Bill Wendling | eb9a42c | 2007-01-16 03:42:04 +0000 | [diff] [blame] | 1412 | // The variant of the current asmprinter. |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1413 | int AsmPrinterVariant = MAI->getAssemblerDialect(); |
Bill Wendling | eb9a42c | 2007-01-16 03:42:04 +0000 | [diff] [blame] | 1414 | |
Chris Lattner | 6609913 | 2006-02-01 22:41:11 +0000 | [diff] [blame] | 1415 | int CurVariant = -1; // The number of the {.|.|.} region we are in. |
| 1416 | const char *LastEmitted = AsmStr; // One past the last character emitted. |
Chris Lattner | 2cc2f66 | 2006-02-01 01:28:23 +0000 | [diff] [blame] | 1417 | |
Chris Lattner | 6609913 | 2006-02-01 22:41:11 +0000 | [diff] [blame] | 1418 | while (*LastEmitted) { |
| 1419 | switch (*LastEmitted) { |
| 1420 | default: { |
| 1421 | // Not a special case, emit the string section literally. |
| 1422 | const char *LiteralEnd = LastEmitted+1; |
| 1423 | while (*LiteralEnd && *LiteralEnd != '{' && *LiteralEnd != '|' && |
Chris Lattner | 1c05997 | 2006-05-05 21:47:05 +0000 | [diff] [blame] | 1424 | *LiteralEnd != '}' && *LiteralEnd != '$' && *LiteralEnd != '\n') |
Chris Lattner | 6609913 | 2006-02-01 22:41:11 +0000 | [diff] [blame] | 1425 | ++LiteralEnd; |
| 1426 | if (CurVariant == -1 || CurVariant == AsmPrinterVariant) |
| 1427 | O.write(LastEmitted, LiteralEnd-LastEmitted); |
| 1428 | LastEmitted = LiteralEnd; |
| 1429 | break; |
| 1430 | } |
Chris Lattner | 1c05997 | 2006-05-05 21:47:05 +0000 | [diff] [blame] | 1431 | case '\n': |
| 1432 | ++LastEmitted; // Consume newline character. |
Dan Gohman | d19a53b | 2008-06-30 22:03:41 +0000 | [diff] [blame] | 1433 | O << '\n'; // Indent code with newline. |
Chris Lattner | 1c05997 | 2006-05-05 21:47:05 +0000 | [diff] [blame] | 1434 | break; |
Chris Lattner | 6609913 | 2006-02-01 22:41:11 +0000 | [diff] [blame] | 1435 | case '$': { |
| 1436 | ++LastEmitted; // Consume '$' character. |
Chris Lattner | faf1dae | 2006-10-03 23:27:09 +0000 | [diff] [blame] | 1437 | bool Done = true; |
| 1438 | |
| 1439 | // Handle escapes. |
| 1440 | switch (*LastEmitted) { |
| 1441 | default: Done = false; break; |
| 1442 | case '$': // $$ -> $ |
Chris Lattner | 6609913 | 2006-02-01 22:41:11 +0000 | [diff] [blame] | 1443 | if (CurVariant == -1 || CurVariant == AsmPrinterVariant) |
| 1444 | O << '$'; |
| 1445 | ++LastEmitted; // Consume second '$' character. |
| 1446 | break; |
Chris Lattner | faf1dae | 2006-10-03 23:27:09 +0000 | [diff] [blame] | 1447 | case '(': // $( -> same as GCC's { character. |
| 1448 | ++LastEmitted; // Consume '(' character. |
| 1449 | if (CurVariant != -1) { |
Torok Edwin | 7d696d8 | 2009-07-11 13:10:19 +0000 | [diff] [blame] | 1450 | llvm_report_error("Nested variants found in inline asm string: '" |
| 1451 | + std::string(AsmStr) + "'"); |
Chris Lattner | faf1dae | 2006-10-03 23:27:09 +0000 | [diff] [blame] | 1452 | } |
| 1453 | CurVariant = 0; // We're in the first variant now. |
| 1454 | break; |
| 1455 | case '|': |
| 1456 | ++LastEmitted; // consume '|' character. |
Dale Johannesen | 8b1e054 | 2008-10-10 21:04:42 +0000 | [diff] [blame] | 1457 | if (CurVariant == -1) |
| 1458 | O << '|'; // this is gcc's behavior for | outside a variant |
| 1459 | else |
| 1460 | ++CurVariant; // We're in the next variant. |
Chris Lattner | faf1dae | 2006-10-03 23:27:09 +0000 | [diff] [blame] | 1461 | break; |
| 1462 | case ')': // $) -> same as GCC's } char. |
| 1463 | ++LastEmitted; // consume ')' character. |
Dale Johannesen | 8b1e054 | 2008-10-10 21:04:42 +0000 | [diff] [blame] | 1464 | if (CurVariant == -1) |
| 1465 | O << '}'; // this is gcc's behavior for } outside a variant |
| 1466 | else |
| 1467 | CurVariant = -1; |
Chris Lattner | faf1dae | 2006-10-03 23:27:09 +0000 | [diff] [blame] | 1468 | break; |
Chris Lattner | 6609913 | 2006-02-01 22:41:11 +0000 | [diff] [blame] | 1469 | } |
Chris Lattner | faf1dae | 2006-10-03 23:27:09 +0000 | [diff] [blame] | 1470 | if (Done) break; |
Chris Lattner | 6609913 | 2006-02-01 22:41:11 +0000 | [diff] [blame] | 1471 | |
| 1472 | bool HasCurlyBraces = false; |
| 1473 | if (*LastEmitted == '{') { // ${variable} |
| 1474 | ++LastEmitted; // Consume '{' character. |
| 1475 | HasCurlyBraces = true; |
| 1476 | } |
| 1477 | |
Chris Lattner | 3e0cc26 | 2009-03-10 05:37:13 +0000 | [diff] [blame] | 1478 | // If we have ${:foo}, then this is not a real operand reference, it is a |
| 1479 | // "magic" string reference, just like in .td files. Arrange to call |
| 1480 | // PrintSpecial. |
| 1481 | if (HasCurlyBraces && *LastEmitted == ':') { |
| 1482 | ++LastEmitted; |
| 1483 | const char *StrStart = LastEmitted; |
| 1484 | const char *StrEnd = strchr(StrStart, '}'); |
| 1485 | if (StrEnd == 0) { |
Torok Edwin | 7d696d8 | 2009-07-11 13:10:19 +0000 | [diff] [blame] | 1486 | llvm_report_error("Unterminated ${:foo} operand in inline asm string: '" |
| 1487 | + std::string(AsmStr) + "'"); |
Chris Lattner | 3e0cc26 | 2009-03-10 05:37:13 +0000 | [diff] [blame] | 1488 | } |
| 1489 | |
| 1490 | std::string Val(StrStart, StrEnd); |
| 1491 | PrintSpecial(MI, Val.c_str()); |
| 1492 | LastEmitted = StrEnd+1; |
| 1493 | break; |
| 1494 | } |
| 1495 | |
Chris Lattner | 6609913 | 2006-02-01 22:41:11 +0000 | [diff] [blame] | 1496 | const char *IDStart = LastEmitted; |
| 1497 | char *IDEnd; |
Chris Lattner | fad2912 | 2007-01-23 00:36:17 +0000 | [diff] [blame] | 1498 | errno = 0; |
Chris Lattner | 6609913 | 2006-02-01 22:41:11 +0000 | [diff] [blame] | 1499 | long Val = strtol(IDStart, &IDEnd, 10); // We only accept numbers for IDs. |
| 1500 | if (!isdigit(*IDStart) || (Val == 0 && errno == EINVAL)) { |
Torok Edwin | 7d696d8 | 2009-07-11 13:10:19 +0000 | [diff] [blame] | 1501 | llvm_report_error("Bad $ operand number in inline asm string: '" |
| 1502 | + std::string(AsmStr) + "'"); |
Chris Lattner | 6609913 | 2006-02-01 22:41:11 +0000 | [diff] [blame] | 1503 | } |
| 1504 | LastEmitted = IDEnd; |
| 1505 | |
Chris Lattner | a36cb0a | 2006-02-06 22:17:23 +0000 | [diff] [blame] | 1506 | char Modifier[2] = { 0, 0 }; |
| 1507 | |
Chris Lattner | 6609913 | 2006-02-01 22:41:11 +0000 | [diff] [blame] | 1508 | if (HasCurlyBraces) { |
Chris Lattner | a36cb0a | 2006-02-06 22:17:23 +0000 | [diff] [blame] | 1509 | // If we have curly braces, check for a modifier character. This |
| 1510 | // supports syntax like ${0:u}, which correspond to "%u0" in GCC asm. |
| 1511 | if (*LastEmitted == ':') { |
| 1512 | ++LastEmitted; // Consume ':' character. |
| 1513 | if (*LastEmitted == 0) { |
Torok Edwin | 7d696d8 | 2009-07-11 13:10:19 +0000 | [diff] [blame] | 1514 | llvm_report_error("Bad ${:} expression in inline asm string: '" |
| 1515 | + std::string(AsmStr) + "'"); |
Chris Lattner | a36cb0a | 2006-02-06 22:17:23 +0000 | [diff] [blame] | 1516 | } |
| 1517 | |
| 1518 | Modifier[0] = *LastEmitted; |
| 1519 | ++LastEmitted; // Consume modifier character. |
| 1520 | } |
| 1521 | |
Chris Lattner | 6609913 | 2006-02-01 22:41:11 +0000 | [diff] [blame] | 1522 | if (*LastEmitted != '}') { |
Torok Edwin | 7d696d8 | 2009-07-11 13:10:19 +0000 | [diff] [blame] | 1523 | llvm_report_error("Bad ${} expression in inline asm string: '" |
| 1524 | + std::string(AsmStr) + "'"); |
Chris Lattner | 6609913 | 2006-02-01 22:41:11 +0000 | [diff] [blame] | 1525 | } |
| 1526 | ++LastEmitted; // Consume '}' character. |
| 1527 | } |
| 1528 | |
| 1529 | if ((unsigned)Val >= NumOperands-1) { |
Torok Edwin | 7d696d8 | 2009-07-11 13:10:19 +0000 | [diff] [blame] | 1530 | llvm_report_error("Invalid $ operand number in inline asm string: '" |
| 1531 | + std::string(AsmStr) + "'"); |
Chris Lattner | 6609913 | 2006-02-01 22:41:11 +0000 | [diff] [blame] | 1532 | } |
| 1533 | |
Chris Lattner | c3a9f8d | 2006-02-23 19:21:04 +0000 | [diff] [blame] | 1534 | // Okay, we finally have a value number. Ask the target to print this |
Chris Lattner | 6609913 | 2006-02-01 22:41:11 +0000 | [diff] [blame] | 1535 | // operand! |
Chris Lattner | c3a9f8d | 2006-02-23 19:21:04 +0000 | [diff] [blame] | 1536 | if (CurVariant == -1 || CurVariant == AsmPrinterVariant) { |
| 1537 | unsigned OpNo = 1; |
Chris Lattner | fd561cd | 2006-06-08 18:00:47 +0000 | [diff] [blame] | 1538 | |
| 1539 | bool Error = false; |
| 1540 | |
Chris Lattner | c3a9f8d | 2006-02-23 19:21:04 +0000 | [diff] [blame] | 1541 | // Scan to find the machine operand number for the operand. |
Chris Lattner | daf6bc6 | 2006-02-24 19:50:58 +0000 | [diff] [blame] | 1542 | for (; Val; --Val) { |
Chris Lattner | fd561cd | 2006-06-08 18:00:47 +0000 | [diff] [blame] | 1543 | if (OpNo >= MI->getNumOperands()) break; |
Chris Lattner | 9e33049 | 2007-12-30 20:50:28 +0000 | [diff] [blame] | 1544 | unsigned OpFlags = MI->getOperand(OpNo).getImm(); |
Evan Cheng | 697cbbf | 2009-03-20 18:03:34 +0000 | [diff] [blame] | 1545 | OpNo += InlineAsm::getNumOperandRegisters(OpFlags) + 1; |
Chris Lattner | daf6bc6 | 2006-02-24 19:50:58 +0000 | [diff] [blame] | 1546 | } |
Chris Lattner | dd26033 | 2006-02-24 20:21:58 +0000 | [diff] [blame] | 1547 | |
Chris Lattner | fd561cd | 2006-06-08 18:00:47 +0000 | [diff] [blame] | 1548 | if (OpNo >= MI->getNumOperands()) { |
| 1549 | Error = true; |
Chris Lattner | dd26033 | 2006-02-24 20:21:58 +0000 | [diff] [blame] | 1550 | } else { |
Chris Lattner | 9e33049 | 2007-12-30 20:50:28 +0000 | [diff] [blame] | 1551 | unsigned OpFlags = MI->getOperand(OpNo).getImm(); |
Chris Lattner | fd561cd | 2006-06-08 18:00:47 +0000 | [diff] [blame] | 1552 | ++OpNo; // Skip over the ID number. |
| 1553 | |
Dale Johannesen | eb57ea7 | 2007-11-05 21:20:28 +0000 | [diff] [blame] | 1554 | if (Modifier[0]=='l') // labels are target independent |
Chris Lattner | 325d3dc | 2009-09-13 17:14:04 +0000 | [diff] [blame] | 1555 | GetMBBSymbol(MI->getOperand(OpNo).getMBB() |
| 1556 | ->getNumber())->print(O, MAI); |
Dale Johannesen | eb57ea7 | 2007-11-05 21:20:28 +0000 | [diff] [blame] | 1557 | else { |
| 1558 | AsmPrinter *AP = const_cast<AsmPrinter*>(this); |
Dale Johannesen | 86b49f8 | 2008-09-24 01:07:17 +0000 | [diff] [blame] | 1559 | if ((OpFlags & 7) == 4) { |
Dale Johannesen | eb57ea7 | 2007-11-05 21:20:28 +0000 | [diff] [blame] | 1560 | Error = AP->PrintAsmMemoryOperand(MI, OpNo, AsmPrinterVariant, |
| 1561 | Modifier[0] ? Modifier : 0); |
| 1562 | } else { |
| 1563 | Error = AP->PrintAsmOperand(MI, OpNo, AsmPrinterVariant, |
| 1564 | Modifier[0] ? Modifier : 0); |
| 1565 | } |
Chris Lattner | fd561cd | 2006-06-08 18:00:47 +0000 | [diff] [blame] | 1566 | } |
Chris Lattner | dd26033 | 2006-02-24 20:21:58 +0000 | [diff] [blame] | 1567 | } |
| 1568 | if (Error) { |
Torok Edwin | 7d696d8 | 2009-07-11 13:10:19 +0000 | [diff] [blame] | 1569 | std::string msg; |
| 1570 | raw_string_ostream Msg(msg); |
| 1571 | Msg << "Invalid operand found in inline asm: '" |
Bill Wendling | e815619 | 2006-12-07 01:30:32 +0000 | [diff] [blame] | 1572 | << AsmStr << "'\n"; |
Torok Edwin | 7d696d8 | 2009-07-11 13:10:19 +0000 | [diff] [blame] | 1573 | MI->print(Msg); |
| 1574 | llvm_report_error(Msg.str()); |
Chris Lattner | 6609913 | 2006-02-01 22:41:11 +0000 | [diff] [blame] | 1575 | } |
Chris Lattner | c3a9f8d | 2006-02-23 19:21:04 +0000 | [diff] [blame] | 1576 | } |
Chris Lattner | 6609913 | 2006-02-01 22:41:11 +0000 | [diff] [blame] | 1577 | break; |
| 1578 | } |
Chris Lattner | 6609913 | 2006-02-01 22:41:11 +0000 | [diff] [blame] | 1579 | } |
| 1580 | } |
Chris Lattner | c5ea263 | 2009-09-09 23:14:36 +0000 | [diff] [blame] | 1581 | O << "\n\t" << MAI->getCommentString() << MAI->getInlineAsmEnd(); |
Chris Lattner | 6609913 | 2006-02-01 22:41:11 +0000 | [diff] [blame] | 1582 | } |
| 1583 | |
Evan Cheng | da47e6e | 2008-03-15 00:03:38 +0000 | [diff] [blame] | 1584 | /// printImplicitDef - This method prints the specified machine instruction |
| 1585 | /// that is an implicit def. |
| 1586 | void AsmPrinter::printImplicitDef(const MachineInstr *MI) const { |
Chris Lattner | c5ea263 | 2009-09-09 23:14:36 +0000 | [diff] [blame] | 1587 | if (!VerboseAsm) return; |
| 1588 | O.PadToColumn(MAI->getCommentColumn()); |
| 1589 | O << MAI->getCommentString() << " implicit-def: " |
Chris Lattner | f806c23 | 2009-09-13 19:48:37 +0000 | [diff] [blame] | 1590 | << TRI->getName(MI->getOperand(0).getReg()); |
Evan Cheng | da47e6e | 2008-03-15 00:03:38 +0000 | [diff] [blame] | 1591 | } |
| 1592 | |
Jakob Stoklund Olesen | ad68264 | 2009-11-04 19:24:37 +0000 | [diff] [blame^] | 1593 | void AsmPrinter::printKill(const MachineInstr *MI) const { |
| 1594 | if (!VerboseAsm) return; |
| 1595 | O.PadToColumn(MAI->getCommentColumn()); |
| 1596 | O << MAI->getCommentString() << " kill:"; |
| 1597 | for (unsigned n = 0, e = MI->getNumOperands(); n != e; ++n) { |
| 1598 | const MachineOperand &op = MI->getOperand(n); |
| 1599 | assert(op.isReg() && "KILL instruction must have only register operands"); |
| 1600 | O << ' ' << TRI->getName(op.getReg()) << (op.isDef() ? "<def>" : "<kill>"); |
| 1601 | } |
| 1602 | } |
| 1603 | |
Jim Laskey | 1ee2925 | 2007-01-26 14:34:52 +0000 | [diff] [blame] | 1604 | /// printLabel - This method prints a local label used by debug and |
| 1605 | /// exception handling tables. |
| 1606 | void AsmPrinter::printLabel(const MachineInstr *MI) const { |
Dan Gohman | 528bc02 | 2008-07-01 00:16:26 +0000 | [diff] [blame] | 1607 | printLabel(MI->getOperand(0).getImm()); |
Jim Laskey | 1ee2925 | 2007-01-26 14:34:52 +0000 | [diff] [blame] | 1608 | } |
| 1609 | |
Evan Cheng | 1b08bbc | 2008-02-01 09:10:45 +0000 | [diff] [blame] | 1610 | void AsmPrinter::printLabel(unsigned Id) const { |
Chris Lattner | c5ea263 | 2009-09-09 23:14:36 +0000 | [diff] [blame] | 1611 | O << MAI->getPrivateGlobalPrefix() << "label" << Id << ':'; |
Evan Cheng | 1b08bbc | 2008-02-01 09:10:45 +0000 | [diff] [blame] | 1612 | } |
| 1613 | |
Chris Lattner | 6609913 | 2006-02-01 22:41:11 +0000 | [diff] [blame] | 1614 | /// PrintAsmOperand - Print the specified operand of MI, an INLINEASM |
| 1615 | /// instruction, using the specified assembler variant. Targets should |
| 1616 | /// overried this to format as appropriate. |
| 1617 | bool AsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, |
Chris Lattner | a36cb0a | 2006-02-06 22:17:23 +0000 | [diff] [blame] | 1618 | unsigned AsmVariant, const char *ExtraCode) { |
Chris Lattner | 6609913 | 2006-02-01 22:41:11 +0000 | [diff] [blame] | 1619 | // Target doesn't support this yet! |
| 1620 | return true; |
Chris Lattner | 0264d1a | 2006-01-27 02:10:10 +0000 | [diff] [blame] | 1621 | } |
Chris Lattner | dd26033 | 2006-02-24 20:21:58 +0000 | [diff] [blame] | 1622 | |
| 1623 | bool AsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo, |
| 1624 | unsigned AsmVariant, |
| 1625 | const char *ExtraCode) { |
| 1626 | // Target doesn't support this yet! |
| 1627 | return true; |
| 1628 | } |
Nate Begeman | 37efe67 | 2006-04-22 18:53:45 +0000 | [diff] [blame] | 1629 | |
Dan Gohman | 8c2b525 | 2009-10-30 01:27:03 +0000 | [diff] [blame] | 1630 | MCSymbol *AsmPrinter::GetBlockAddressSymbol(const BlockAddress *BA) const { |
| 1631 | return GetBlockAddressSymbol(BA->getFunction(), BA->getBasicBlock()); |
| 1632 | } |
| 1633 | |
| 1634 | MCSymbol *AsmPrinter::GetBlockAddressSymbol(const Function *F, |
| 1635 | const BasicBlock *BB) const { |
| 1636 | assert(BB->hasName() && |
| 1637 | "Address of anonymous basic block not supported yet!"); |
| 1638 | |
Dan Gohman | 6ae5b32 | 2009-10-30 01:38:20 +0000 | [diff] [blame] | 1639 | // FIXME: This isn't guaranteed to produce a unique name even if the |
| 1640 | // block and function have a name. |
Dan Gohman | 8c2b525 | 2009-10-30 01:27:03 +0000 | [diff] [blame] | 1641 | std::string Mangled = |
| 1642 | Mang->getMangledName(F, Mang->makeNameProper(BB->getName()).c_str(), |
| 1643 | /*ForcePrivate=*/true); |
| 1644 | |
| 1645 | return OutContext.GetOrCreateSymbol(StringRef(Mangled)); |
| 1646 | } |
| 1647 | |
Chris Lattner | 7cb384d | 2009-09-12 23:02:08 +0000 | [diff] [blame] | 1648 | MCSymbol *AsmPrinter::GetMBBSymbol(unsigned MBBID) const { |
| 1649 | SmallString<60> Name; |
| 1650 | raw_svector_ostream(Name) << MAI->getPrivateGlobalPrefix() << "BB" |
| 1651 | << getFunctionNumber() << '_' << MBBID; |
| 1652 | |
| 1653 | return OutContext.GetOrCreateSymbol(Name.str()); |
| 1654 | } |
| 1655 | |
| 1656 | |
Chris Lattner | 70a54c0 | 2009-09-13 18:25:37 +0000 | [diff] [blame] | 1657 | /// EmitBasicBlockStart - This method prints the label for the specified |
| 1658 | /// MachineBasicBlock, an alignment (if present) and a comment describing |
| 1659 | /// it if appropriate. |
Chris Lattner | 662316c | 2009-09-14 03:15:54 +0000 | [diff] [blame] | 1660 | void AsmPrinter::EmitBasicBlockStart(const MachineBasicBlock *MBB) const { |
Dan Gohman | b1cac33 | 2009-10-30 01:34:35 +0000 | [diff] [blame] | 1661 | // Emit an alignment directive for this block, if needed. |
Chris Lattner | 70a54c0 | 2009-09-13 18:25:37 +0000 | [diff] [blame] | 1662 | if (unsigned Align = MBB->getAlignment()) |
| 1663 | EmitAlignment(Log2_32(Align)); |
Evan Cheng | fb8075d | 2008-02-28 00:43:03 +0000 | [diff] [blame] | 1664 | |
Dan Gohman | b1cac33 | 2009-10-30 01:34:35 +0000 | [diff] [blame] | 1665 | // If the block has its address taken, emit a special label to satisfy |
| 1666 | // references to the block. This is done so that we don't need to |
| 1667 | // remember the number of this label, and so that we can make |
| 1668 | // forward references to labels without knowing what their numbers |
| 1669 | // will be. |
Dan Gohman | 8c2b525 | 2009-10-30 01:27:03 +0000 | [diff] [blame] | 1670 | if (MBB->hasAddressTaken()) { |
| 1671 | GetBlockAddressSymbol(MBB->getBasicBlock()->getParent(), |
| 1672 | MBB->getBasicBlock())->print(O, MAI); |
| 1673 | O << ':'; |
| 1674 | if (VerboseAsm) { |
| 1675 | O.PadToColumn(MAI->getCommentColumn()); |
| 1676 | O << MAI->getCommentString() << " Address Taken"; |
| 1677 | } |
| 1678 | O << '\n'; |
| 1679 | } |
| 1680 | |
Dan Gohman | b1cac33 | 2009-10-30 01:34:35 +0000 | [diff] [blame] | 1681 | // Print the main label for the block. |
Dan Gohman | e3cc3f3 | 2009-10-06 17:38:38 +0000 | [diff] [blame] | 1682 | if (MBB->pred_empty() || MBB->isOnlyReachableByFallthrough()) { |
| 1683 | if (VerboseAsm) |
| 1684 | O << MAI->getCommentString() << " BB#" << MBB->getNumber() << ':'; |
| 1685 | } else { |
| 1686 | GetMBBSymbol(MBB->getNumber())->print(O, MAI); |
| 1687 | O << ':'; |
| 1688 | if (!VerboseAsm) |
| 1689 | O << '\n'; |
| 1690 | } |
Chris Lattner | 70a54c0 | 2009-09-13 18:25:37 +0000 | [diff] [blame] | 1691 | |
Dan Gohman | b1cac33 | 2009-10-30 01:34:35 +0000 | [diff] [blame] | 1692 | // Print some comments to accompany the label. |
Chris Lattner | 70a54c0 | 2009-09-13 18:25:37 +0000 | [diff] [blame] | 1693 | if (VerboseAsm) { |
Dan Gohman | e45da0d | 2009-08-12 18:47:05 +0000 | [diff] [blame] | 1694 | if (const BasicBlock *BB = MBB->getBasicBlock()) |
| 1695 | if (BB->hasName()) { |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1696 | O.PadToColumn(MAI->getCommentColumn()); |
| 1697 | O << MAI->getCommentString() << ' '; |
Dan Gohman | 46d5056 | 2009-08-12 20:56:56 +0000 | [diff] [blame] | 1698 | WriteAsOperand(O, BB, /*PrintType=*/false); |
Dan Gohman | e45da0d | 2009-08-12 18:47:05 +0000 | [diff] [blame] | 1699 | } |
David Greene | b71d1b2 | 2009-08-10 16:38:07 +0000 | [diff] [blame] | 1700 | |
Chris Lattner | 70a54c0 | 2009-09-13 18:25:37 +0000 | [diff] [blame] | 1701 | EmitComments(*MBB); |
Dan Gohman | e3cc3f3 | 2009-10-06 17:38:38 +0000 | [diff] [blame] | 1702 | O << '\n'; |
David Greene | b71d1b2 | 2009-08-10 16:38:07 +0000 | [diff] [blame] | 1703 | } |
Nate Begeman | 37efe67 | 2006-04-22 18:53:45 +0000 | [diff] [blame] | 1704 | } |
Nate Begeman | 52a51e38 | 2006-08-12 21:29:52 +0000 | [diff] [blame] | 1705 | |
Evan Cheng | cc41586 | 2007-11-09 01:32:10 +0000 | [diff] [blame] | 1706 | /// printPICJumpTableSetLabel - This method prints a set label for the |
| 1707 | /// specified MachineBasicBlock for a jumptable entry. |
| 1708 | void AsmPrinter::printPICJumpTableSetLabel(unsigned uid, |
| 1709 | const MachineBasicBlock *MBB) const { |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1710 | if (!MAI->getSetDirective()) |
Nate Begeman | 52a51e38 | 2006-08-12 21:29:52 +0000 | [diff] [blame] | 1711 | return; |
| 1712 | |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1713 | O << MAI->getSetDirective() << ' ' << MAI->getPrivateGlobalPrefix() |
Evan Cheng | 347d39f | 2007-10-14 05:57:21 +0000 | [diff] [blame] | 1714 | << getFunctionNumber() << '_' << uid << "_set_" << MBB->getNumber() << ','; |
Chris Lattner | 325d3dc | 2009-09-13 17:14:04 +0000 | [diff] [blame] | 1715 | GetMBBSymbol(MBB->getNumber())->print(O, MAI); |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1716 | O << '-' << MAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber() |
Evan Cheng | 347d39f | 2007-10-14 05:57:21 +0000 | [diff] [blame] | 1717 | << '_' << uid << '\n'; |
Nate Begeman | 52a51e38 | 2006-08-12 21:29:52 +0000 | [diff] [blame] | 1718 | } |
Evan Cheng | d6594ae | 2006-09-12 21:00:35 +0000 | [diff] [blame] | 1719 | |
Evan Cheng | cc41586 | 2007-11-09 01:32:10 +0000 | [diff] [blame] | 1720 | void AsmPrinter::printPICJumpTableSetLabel(unsigned uid, unsigned uid2, |
| 1721 | const MachineBasicBlock *MBB) const { |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1722 | if (!MAI->getSetDirective()) |
Evan Cheng | 41349c1 | 2006-11-01 09:23:08 +0000 | [diff] [blame] | 1723 | return; |
| 1724 | |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1725 | O << MAI->getSetDirective() << ' ' << MAI->getPrivateGlobalPrefix() |
Evan Cheng | 347d39f | 2007-10-14 05:57:21 +0000 | [diff] [blame] | 1726 | << getFunctionNumber() << '_' << uid << '_' << uid2 |
| 1727 | << "_set_" << MBB->getNumber() << ','; |
Chris Lattner | 325d3dc | 2009-09-13 17:14:04 +0000 | [diff] [blame] | 1728 | GetMBBSymbol(MBB->getNumber())->print(O, MAI); |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1729 | O << '-' << MAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber() |
Evan Cheng | 347d39f | 2007-10-14 05:57:21 +0000 | [diff] [blame] | 1730 | << '_' << uid << '_' << uid2 << '\n'; |
Evan Cheng | 41349c1 | 2006-11-01 09:23:08 +0000 | [diff] [blame] | 1731 | } |
| 1732 | |
Evan Cheng | d6594ae | 2006-09-12 21:00:35 +0000 | [diff] [blame] | 1733 | /// printDataDirective - This method prints the asm directive for the |
| 1734 | /// specified type. |
Sanjiv Gupta | c8d7bc8 | 2009-01-30 04:25:10 +0000 | [diff] [blame] | 1735 | void AsmPrinter::printDataDirective(const Type *type, unsigned AddrSpace) { |
Evan Cheng | d6594ae | 2006-09-12 21:00:35 +0000 | [diff] [blame] | 1736 | const TargetData *TD = TM.getTargetData(); |
| 1737 | switch (type->getTypeID()) { |
Chris Lattner | f1cfea2 | 2009-07-15 04:42:49 +0000 | [diff] [blame] | 1738 | case Type::FloatTyID: case Type::DoubleTyID: |
| 1739 | case Type::X86_FP80TyID: case Type::FP128TyID: case Type::PPC_FP128TyID: |
| 1740 | assert(0 && "Should have already output floating point constant."); |
| 1741 | default: |
| 1742 | assert(0 && "Can't handle printing this type of thing"); |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1743 | case Type::IntegerTyID: { |
| 1744 | unsigned BitWidth = cast<IntegerType>(type)->getBitWidth(); |
| 1745 | if (BitWidth <= 8) |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1746 | O << MAI->getData8bitsDirective(AddrSpace); |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1747 | else if (BitWidth <= 16) |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1748 | O << MAI->getData16bitsDirective(AddrSpace); |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1749 | else if (BitWidth <= 32) |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1750 | O << MAI->getData32bitsDirective(AddrSpace); |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1751 | else if (BitWidth <= 64) { |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1752 | assert(MAI->getData64bitsDirective(AddrSpace) && |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1753 | "Target cannot handle 64-bit constant exprs!"); |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1754 | O << MAI->getData64bitsDirective(AddrSpace); |
Dan Gohman | 82f94f1 | 2008-09-08 16:40:13 +0000 | [diff] [blame] | 1755 | } else { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1756 | llvm_unreachable("Target cannot handle given data directive width!"); |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1757 | } |
Evan Cheng | d6594ae | 2006-09-12 21:00:35 +0000 | [diff] [blame] | 1758 | break; |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1759 | } |
Evan Cheng | d6594ae | 2006-09-12 21:00:35 +0000 | [diff] [blame] | 1760 | case Type::PointerTyID: |
| 1761 | if (TD->getPointerSize() == 8) { |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1762 | assert(MAI->getData64bitsDirective(AddrSpace) && |
Evan Cheng | d6594ae | 2006-09-12 21:00:35 +0000 | [diff] [blame] | 1763 | "Target cannot handle 64-bit pointer exprs!"); |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1764 | O << MAI->getData64bitsDirective(AddrSpace); |
Sanjiv Gupta | fcc6f15 | 2009-01-22 10:14:21 +0000 | [diff] [blame] | 1765 | } else if (TD->getPointerSize() == 2) { |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1766 | O << MAI->getData16bitsDirective(AddrSpace); |
Sanjiv Gupta | fcc6f15 | 2009-01-22 10:14:21 +0000 | [diff] [blame] | 1767 | } else if (TD->getPointerSize() == 1) { |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1768 | O << MAI->getData8bitsDirective(AddrSpace); |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 1769 | } else { |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1770 | O << MAI->getData32bitsDirective(AddrSpace); |
Evan Cheng | d6594ae | 2006-09-12 21:00:35 +0000 | [diff] [blame] | 1771 | } |
Evan Cheng | d6594ae | 2006-09-12 21:00:35 +0000 | [diff] [blame] | 1772 | break; |
Evan Cheng | d6594ae | 2006-09-12 21:00:35 +0000 | [diff] [blame] | 1773 | } |
| 1774 | } |
Dale Johannesen | 4c3a5f8 | 2007-02-16 01:54:53 +0000 | [diff] [blame] | 1775 | |
Anton Korobeynikov | f5b6a47 | 2008-08-08 18:25:07 +0000 | [diff] [blame] | 1776 | void AsmPrinter::printVisibility(const std::string& Name, |
| 1777 | unsigned Visibility) const { |
| 1778 | if (Visibility == GlobalValue::HiddenVisibility) { |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1779 | if (const char *Directive = MAI->getHiddenDirective()) |
Anton Korobeynikov | f5b6a47 | 2008-08-08 18:25:07 +0000 | [diff] [blame] | 1780 | O << Directive << Name << '\n'; |
| 1781 | } else if (Visibility == GlobalValue::ProtectedVisibility) { |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1782 | if (const char *Directive = MAI->getProtectedDirective()) |
Anton Korobeynikov | f5b6a47 | 2008-08-08 18:25:07 +0000 | [diff] [blame] | 1783 | O << Directive << Name << '\n'; |
| 1784 | } |
| 1785 | } |
Gordon Henriksen | c317a60 | 2008-08-17 12:08:44 +0000 | [diff] [blame] | 1786 | |
Anton Korobeynikov | 7751ad9 | 2008-11-22 16:15:34 +0000 | [diff] [blame] | 1787 | void AsmPrinter::printOffset(int64_t Offset) const { |
| 1788 | if (Offset > 0) |
| 1789 | O << '+' << Offset; |
| 1790 | else if (Offset < 0) |
| 1791 | O << Offset; |
| 1792 | } |
| 1793 | |
Gordon Henriksen | 5eca075 | 2008-08-17 18:44:35 +0000 | [diff] [blame] | 1794 | GCMetadataPrinter *AsmPrinter::GetOrCreateGCPrinter(GCStrategy *S) { |
| 1795 | if (!S->usesMetadata()) |
Gordon Henriksen | c317a60 | 2008-08-17 12:08:44 +0000 | [diff] [blame] | 1796 | return 0; |
| 1797 | |
Gordon Henriksen | 5eca075 | 2008-08-17 18:44:35 +0000 | [diff] [blame] | 1798 | gcp_iterator GCPI = GCMetadataPrinters.find(S); |
Gordon Henriksen | c317a60 | 2008-08-17 12:08:44 +0000 | [diff] [blame] | 1799 | if (GCPI != GCMetadataPrinters.end()) |
| 1800 | return GCPI->second; |
| 1801 | |
Gordon Henriksen | 5eca075 | 2008-08-17 18:44:35 +0000 | [diff] [blame] | 1802 | const char *Name = S->getName().c_str(); |
Gordon Henriksen | c317a60 | 2008-08-17 12:08:44 +0000 | [diff] [blame] | 1803 | |
| 1804 | for (GCMetadataPrinterRegistry::iterator |
| 1805 | I = GCMetadataPrinterRegistry::begin(), |
| 1806 | E = GCMetadataPrinterRegistry::end(); I != E; ++I) |
| 1807 | if (strcmp(Name, I->getName()) == 0) { |
Gordon Henriksen | 5eca075 | 2008-08-17 18:44:35 +0000 | [diff] [blame] | 1808 | GCMetadataPrinter *GMP = I->instantiate(); |
| 1809 | GMP->S = S; |
| 1810 | GCMetadataPrinters.insert(std::make_pair(S, GMP)); |
| 1811 | return GMP; |
Gordon Henriksen | c317a60 | 2008-08-17 12:08:44 +0000 | [diff] [blame] | 1812 | } |
| 1813 | |
Chris Lattner | 103289e | 2009-08-23 07:19:13 +0000 | [diff] [blame] | 1814 | errs() << "no GCMetadataPrinter registered for GC: " << Name << "\n"; |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1815 | llvm_unreachable(0); |
Gordon Henriksen | c317a60 | 2008-08-17 12:08:44 +0000 | [diff] [blame] | 1816 | } |
David Greene | 014700c | 2009-07-13 20:25:48 +0000 | [diff] [blame] | 1817 | |
| 1818 | /// EmitComments - Pretty-print comments for instructions |
Chris Lattner | 5f51cd0 | 2009-08-07 23:42:01 +0000 | [diff] [blame] | 1819 | void AsmPrinter::EmitComments(const MachineInstr &MI) const { |
Chris Lattner | c5ea263 | 2009-09-09 23:14:36 +0000 | [diff] [blame] | 1820 | assert(VerboseAsm && !MI.getDebugLoc().isUnknown()); |
Chris Lattner | 5f51cd0 | 2009-08-07 23:42:01 +0000 | [diff] [blame] | 1821 | |
| 1822 | DebugLocTuple DLT = MF->getDebugLocTuple(MI.getDebugLoc()); |
David Greene | 3ac1ab8 | 2009-07-16 22:24:20 +0000 | [diff] [blame] | 1823 | |
Chris Lattner | 8f4b1ec | 2009-08-17 15:48:08 +0000 | [diff] [blame] | 1824 | // Print source line info. |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1825 | O.PadToColumn(MAI->getCommentColumn()); |
| 1826 | O << MAI->getCommentString() << " SrcLine "; |
Devang Patel | 1619dc3 | 2009-10-13 23:28:53 +0000 | [diff] [blame] | 1827 | if (DLT.Scope) { |
| 1828 | DICompileUnit CU(DLT.Scope); |
| 1829 | if (!CU.isNull()) |
| 1830 | O << CU.getFilename() << " "; |
David Greene | 3ac1ab8 | 2009-07-16 22:24:20 +0000 | [diff] [blame] | 1831 | } |
Chris Lattner | 5f51cd0 | 2009-08-07 23:42:01 +0000 | [diff] [blame] | 1832 | O << DLT.Line; |
| 1833 | if (DLT.Col != 0) |
| 1834 | O << ":" << DLT.Col; |
David Greene | 014700c | 2009-07-13 20:25:48 +0000 | [diff] [blame] | 1835 | } |
| 1836 | |
David Greene | fe37ab3 | 2009-08-18 19:22:55 +0000 | [diff] [blame] | 1837 | /// PrintChildLoopComment - Print comments about child loops within |
| 1838 | /// the loop for this basic block, with nesting. |
| 1839 | /// |
| 1840 | static void PrintChildLoopComment(formatted_raw_ostream &O, |
| 1841 | const MachineLoop *loop, |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1842 | const MCAsmInfo *MAI, |
David Greene | fe37ab3 | 2009-08-18 19:22:55 +0000 | [diff] [blame] | 1843 | int FunctionNumber) { |
| 1844 | // Add child loop information |
| 1845 | for(MachineLoop::iterator cl = loop->begin(), |
| 1846 | clend = loop->end(); |
| 1847 | cl != clend; |
| 1848 | ++cl) { |
| 1849 | MachineBasicBlock *Header = (*cl)->getHeader(); |
| 1850 | assert(Header && "No header for loop"); |
| 1851 | |
| 1852 | O << '\n'; |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1853 | O.PadToColumn(MAI->getCommentColumn()); |
David Greene | fe37ab3 | 2009-08-18 19:22:55 +0000 | [diff] [blame] | 1854 | |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1855 | O << MAI->getCommentString(); |
Chris Lattner | c281de1 | 2009-08-23 00:51:00 +0000 | [diff] [blame] | 1856 | O.indent(((*cl)->getLoopDepth()-1)*2) |
David Greene | fe37ab3 | 2009-08-18 19:22:55 +0000 | [diff] [blame] | 1857 | << " Child Loop BB" << FunctionNumber << "_" |
| 1858 | << Header->getNumber() << " Depth " << (*cl)->getLoopDepth(); |
| 1859 | |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1860 | PrintChildLoopComment(O, *cl, MAI, FunctionNumber); |
David Greene | fe37ab3 | 2009-08-18 19:22:55 +0000 | [diff] [blame] | 1861 | } |
| 1862 | } |
| 1863 | |
David Greene | b71d1b2 | 2009-08-10 16:38:07 +0000 | [diff] [blame] | 1864 | /// EmitComments - Pretty-print comments for basic blocks |
| 1865 | void AsmPrinter::EmitComments(const MachineBasicBlock &MBB) const |
| 1866 | { |
David Greene | fe37ab3 | 2009-08-18 19:22:55 +0000 | [diff] [blame] | 1867 | if (VerboseAsm) { |
David Greene | b71d1b2 | 2009-08-10 16:38:07 +0000 | [diff] [blame] | 1868 | // Add loop depth information |
| 1869 | const MachineLoop *loop = LI->getLoopFor(&MBB); |
| 1870 | |
| 1871 | if (loop) { |
| 1872 | // Print a newline after bb# annotation. |
| 1873 | O << "\n"; |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1874 | O.PadToColumn(MAI->getCommentColumn()); |
| 1875 | O << MAI->getCommentString() << " Loop Depth " << loop->getLoopDepth() |
David Greene | b71d1b2 | 2009-08-10 16:38:07 +0000 | [diff] [blame] | 1876 | << '\n'; |
| 1877 | |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1878 | O.PadToColumn(MAI->getCommentColumn()); |
David Greene | b71d1b2 | 2009-08-10 16:38:07 +0000 | [diff] [blame] | 1879 | |
| 1880 | MachineBasicBlock *Header = loop->getHeader(); |
| 1881 | assert(Header && "No header for loop"); |
| 1882 | |
| 1883 | if (Header == &MBB) { |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1884 | O << MAI->getCommentString() << " Loop Header"; |
| 1885 | PrintChildLoopComment(O, loop, MAI, getFunctionNumber()); |
David Greene | b71d1b2 | 2009-08-10 16:38:07 +0000 | [diff] [blame] | 1886 | } |
| 1887 | else { |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1888 | O << MAI->getCommentString() << " Loop Header is BB" |
David Greene | b71d1b2 | 2009-08-10 16:38:07 +0000 | [diff] [blame] | 1889 | << getFunctionNumber() << "_" << loop->getHeader()->getNumber(); |
| 1890 | } |
| 1891 | |
| 1892 | if (loop->empty()) { |
| 1893 | O << '\n'; |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1894 | O.PadToColumn(MAI->getCommentColumn()); |
| 1895 | O << MAI->getCommentString() << " Inner Loop"; |
David Greene | b71d1b2 | 2009-08-10 16:38:07 +0000 | [diff] [blame] | 1896 | } |
| 1897 | |
| 1898 | // Add parent loop information |
| 1899 | for (const MachineLoop *CurLoop = loop->getParentLoop(); |
| 1900 | CurLoop; |
| 1901 | CurLoop = CurLoop->getParentLoop()) { |
| 1902 | MachineBasicBlock *Header = CurLoop->getHeader(); |
| 1903 | assert(Header && "No header for loop"); |
| 1904 | |
| 1905 | O << '\n'; |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1906 | O.PadToColumn(MAI->getCommentColumn()); |
| 1907 | O << MAI->getCommentString(); |
Chris Lattner | c281de1 | 2009-08-23 00:51:00 +0000 | [diff] [blame] | 1908 | O.indent((CurLoop->getLoopDepth()-1)*2) |
David Greene | fe37ab3 | 2009-08-18 19:22:55 +0000 | [diff] [blame] | 1909 | << " Inside Loop BB" << getFunctionNumber() << "_" |
David Greene | b71d1b2 | 2009-08-10 16:38:07 +0000 | [diff] [blame] | 1910 | << Header->getNumber() << " Depth " << CurLoop->getLoopDepth(); |
| 1911 | } |
| 1912 | } |
| 1913 | } |
| 1914 | } |