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