blob: a228d2a0b4db95ab02a736e2d781f2277b515433 [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001//===-- ARMAsmPrinter.cpp - ARM LLVM assembly writer ----------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner081ce942007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file contains a printer that converts from our internal representation
11// of machine-dependent LLVM code to GAS-format ARM assembly language.
12//
13//===----------------------------------------------------------------------===//
14
15#define DEBUG_TYPE "asm-printer"
16#include "ARM.h"
Anton Korobeynikova229f0b2009-05-23 19:51:20 +000017#include "ARMBuildAttrs.h"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000018#include "ARMTargetMachine.h"
19#include "ARMAddressingModes.h"
20#include "ARMConstantPoolValue.h"
21#include "ARMMachineFunctionInfo.h"
22#include "llvm/Constants.h"
23#include "llvm/Module.h"
Devang Patelf667ab42009-06-25 00:47:42 +000024#include "llvm/MDNode.h"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000025#include "llvm/CodeGen/AsmPrinter.h"
26#include "llvm/CodeGen/DwarfWriter.h"
27#include "llvm/CodeGen/MachineModuleInfo.h"
28#include "llvm/CodeGen/MachineFunctionPass.h"
29#include "llvm/CodeGen/MachineJumpTableInfo.h"
30#include "llvm/Target/TargetAsmInfo.h"
31#include "llvm/Target/TargetData.h"
32#include "llvm/Target/TargetMachine.h"
33#include "llvm/Target/TargetOptions.h"
34#include "llvm/ADT/Statistic.h"
35#include "llvm/ADT/StringExtras.h"
Evan Chenga65854f2008-12-05 01:06:39 +000036#include "llvm/ADT/StringSet.h"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000037#include "llvm/Support/Compiler.h"
Edwin Török26cb0252009-07-08 20:55:50 +000038#include "llvm/Support/ErrorHandling.h"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000039#include "llvm/Support/Mangler.h"
40#include "llvm/Support/MathExtras.h"
Owen Anderson847b99b2008-08-21 00:14:44 +000041#include "llvm/Support/raw_ostream.h"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000042#include <cctype>
43using namespace llvm;
44
45STATISTIC(EmittedInsts, "Number of machine instrs printed");
46
47namespace {
Bill Wendling4f405312009-02-24 08:30:20 +000048 class VISIBILITY_HIDDEN ARMAsmPrinter : public AsmPrinter {
Devang Patelaa1e8432009-01-08 23:40:34 +000049 DwarfWriter *DW;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000050
51 /// Subtarget - Keep a pointer to the ARMSubtarget around so that we can
52 /// make the right decision when printing asm code for different targets.
53 const ARMSubtarget *Subtarget;
54
55 /// AFI - Keep a pointer to ARMFunctionInfo for the current
Evan Chenge6c61622008-09-18 07:27:23 +000056 /// MachineFunction.
Dan Gohmanf17a25c2007-07-18 16:29:46 +000057 ARMFunctionInfo *AFI;
58
Evan Chenge6c61622008-09-18 07:27:23 +000059 /// MCP - Keep a pointer to constantpool entries of the current
60 /// MachineFunction.
61 const MachineConstantPool *MCP;
62
Dan Gohmanf17a25c2007-07-18 16:29:46 +000063 /// We name each basic block in a Function with a unique number, so
64 /// that we can consistently refer to them later. This is cleared
65 /// at the beginning of each call to runOnMachineFunction().
66 ///
67 typedef std::map<const Value *, unsigned> ValueMapTy;
68 ValueMapTy NumberForBB;
69
Evan Chengf1012ce2008-08-08 06:56:16 +000070 /// GVNonLazyPtrs - Keeps the set of GlobalValues that require
71 /// non-lazy-pointers for indirect access.
Evan Chenga65854f2008-12-05 01:06:39 +000072 StringSet<> GVNonLazyPtrs;
73
74 /// HiddenGVNonLazyPtrs - Keeps the set of GlobalValues with hidden
75 /// visibility that require non-lazy-pointers for indirect access.
76 StringSet<> HiddenGVNonLazyPtrs;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000077
Evan Chengf1012ce2008-08-08 06:56:16 +000078 /// FnStubs - Keeps the set of external function GlobalAddresses that the
79 /// asm printer should generate stubs for.
Evan Chenga65854f2008-12-05 01:06:39 +000080 StringSet<> FnStubs;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000081
82 /// True if asm printer is printing a series of CONSTPOOL_ENTRY.
83 bool InCPMode;
Bill Wendling4f405312009-02-24 08:30:20 +000084 public:
Bill Wendling58ed5d22009-04-29 00:15:41 +000085 explicit ARMAsmPrinter(raw_ostream &O, TargetMachine &TM,
Daniel Dunbarb10d2222009-07-01 01:48:54 +000086 const TargetAsmInfo *T, bool V)
87 : AsmPrinter(O, TM, T, V), DW(0), AFI(NULL), MCP(NULL),
Bill Wendling4f405312009-02-24 08:30:20 +000088 InCPMode(false) {
89 Subtarget = &TM.getSubtarget<ARMSubtarget>();
90 }
91
Dan Gohmanf17a25c2007-07-18 16:29:46 +000092 virtual const char *getPassName() const {
93 return "ARM Assembly Printer";
94 }
95
Evan Cheng532cdc52009-06-29 07:51:04 +000096 void printOperand(const MachineInstr *MI, int OpNum,
Dan Gohmanf17a25c2007-07-18 16:29:46 +000097 const char *Modifier = 0);
Evan Cheng532cdc52009-06-29 07:51:04 +000098 void printSOImmOperand(const MachineInstr *MI, int OpNum);
99 void printSOImm2PartOperand(const MachineInstr *MI, int OpNum);
100 void printSORegOperand(const MachineInstr *MI, int OpNum);
101 void printAddrMode2Operand(const MachineInstr *MI, int OpNum);
102 void printAddrMode2OffsetOperand(const MachineInstr *MI, int OpNum);
103 void printAddrMode3Operand(const MachineInstr *MI, int OpNum);
104 void printAddrMode3OffsetOperand(const MachineInstr *MI, int OpNum);
105 void printAddrMode4Operand(const MachineInstr *MI, int OpNum,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000106 const char *Modifier = 0);
Evan Cheng532cdc52009-06-29 07:51:04 +0000107 void printAddrMode5Operand(const MachineInstr *MI, int OpNum,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000108 const char *Modifier = 0);
Bob Wilson970a10d2009-07-01 23:16:05 +0000109 void printAddrMode6Operand(const MachineInstr *MI, int OpNum);
Evan Cheng532cdc52009-06-29 07:51:04 +0000110 void printAddrModePCOperand(const MachineInstr *MI, int OpNum,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000111 const char *Modifier = 0);
Evan Cheng532cdc52009-06-29 07:51:04 +0000112 void printBitfieldInvMaskImmOperand (const MachineInstr *MI, int OpNum);
Evan Cheng19bb7c72009-06-27 02:26:13 +0000113
Evan Cheng532cdc52009-06-29 07:51:04 +0000114 void printThumbAddrModeRROperand(const MachineInstr *MI, int OpNum);
115 void printThumbAddrModeRI5Operand(const MachineInstr *MI, int OpNum,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000116 unsigned Scale);
Evan Cheng532cdc52009-06-29 07:51:04 +0000117 void printThumbAddrModeS1Operand(const MachineInstr *MI, int OpNum);
118 void printThumbAddrModeS2Operand(const MachineInstr *MI, int OpNum);
119 void printThumbAddrModeS4Operand(const MachineInstr *MI, int OpNum);
120 void printThumbAddrModeSPOperand(const MachineInstr *MI, int OpNum);
Evan Cheng19bb7c72009-06-27 02:26:13 +0000121
Evan Cheng19bb7c72009-06-27 02:26:13 +0000122 void printT2SOOperand(const MachineInstr *MI, int OpNum);
Evan Cheng532cdc52009-06-29 07:51:04 +0000123 void printT2AddrModeImm12Operand(const MachineInstr *MI, int OpNum);
124 void printT2AddrModeImm8Operand(const MachineInstr *MI, int OpNum);
Evan Chenga90942e2009-07-02 07:28:31 +0000125 void printT2AddrModeImm8OffsetOperand(const MachineInstr *MI, int OpNum);
Evan Cheng532cdc52009-06-29 07:51:04 +0000126 void printT2AddrModeSoRegOperand(const MachineInstr *MI, int OpNum);
Evan Cheng19bb7c72009-06-27 02:26:13 +0000127
Evan Cheng532cdc52009-06-29 07:51:04 +0000128 void printPredicateOperand(const MachineInstr *MI, int OpNum);
129 void printSBitModifierOperand(const MachineInstr *MI, int OpNum);
130 void printPCLabel(const MachineInstr *MI, int OpNum);
131 void printRegisterList(const MachineInstr *MI, int OpNum);
132 void printCPInstOperand(const MachineInstr *MI, int OpNum,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000133 const char *Modifier);
Evan Cheng532cdc52009-06-29 07:51:04 +0000134 void printJTBlockOperand(const MachineInstr *MI, int OpNum);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000135
Evan Cheng532cdc52009-06-29 07:51:04 +0000136 virtual bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNum,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000137 unsigned AsmVariant, const char *ExtraCode);
Evan Cheng532cdc52009-06-29 07:51:04 +0000138 virtual bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNum,
Bob Wilson6c982bb2009-05-19 05:53:42 +0000139 unsigned AsmVariant,
140 const char *ExtraCode);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000141
Anton Korobeynikov3cc6efa2008-08-07 09:54:23 +0000142 void printModuleLevelGV(const GlobalVariable* GVar);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000143 bool printInstruction(const MachineInstr *MI); // autogenerated.
144 void printMachineInstruction(const MachineInstr *MI);
145 bool runOnMachineFunction(MachineFunction &F);
146 bool doInitialization(Module &M);
147 bool doFinalization(Module &M);
148
Evan Chengf1012ce2008-08-08 06:56:16 +0000149 /// EmitMachineConstantPoolValue - Print a machine constantpool value to
150 /// the .s file.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000151 virtual void EmitMachineConstantPoolValue(MachineConstantPoolValue *MCPV) {
152 printDataDirective(MCPV->getType());
153
Evan Chengf1012ce2008-08-08 06:56:16 +0000154 ARMConstantPoolValue *ACPV = static_cast<ARMConstantPoolValue*>(MCPV);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000155 GlobalValue *GV = ACPV->getGV();
156 std::string Name = GV ? Mang->getValueName(GV) : TAI->getGlobalPrefix();
157 if (!GV)
158 Name += ACPV->getSymbol();
159 if (ACPV->isNonLazyPointer()) {
Evan Chenga65854f2008-12-05 01:06:39 +0000160 if (GV->hasHiddenVisibility())
161 HiddenGVNonLazyPtrs.insert(Name);
162 else
163 GVNonLazyPtrs.insert(Name);
Dale Johannesena21b5202008-05-19 21:38:18 +0000164 printSuffixedName(Name, "$non_lazy_ptr");
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000165 } else if (ACPV->isStub()) {
166 FnStubs.insert(Name);
Dale Johannesena21b5202008-05-19 21:38:18 +0000167 printSuffixedName(Name, "$stub");
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000168 } else
169 O << Name;
170 if (ACPV->hasModifier()) O << "(" << ACPV->getModifier() << ")";
171 if (ACPV->getPCAdjustment() != 0) {
172 O << "-(" << TAI->getPrivateGlobalPrefix() << "PC"
173 << utostr(ACPV->getLabelId())
174 << "+" << (unsigned)ACPV->getPCAdjustment();
175 if (ACPV->mustAddCurrentAddress())
176 O << "-.";
177 O << ")";
178 }
179 O << "\n";
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000180 }
181
182 void getAnalysisUsage(AnalysisUsage &AU) const {
Gordon Henriksen76e4b612007-09-30 13:39:29 +0000183 AsmPrinter::getAnalysisUsage(AU);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000184 AU.setPreservesAll();
185 AU.addRequired<MachineModuleInfo>();
Devang Patelaa1e8432009-01-08 23:40:34 +0000186 AU.addRequired<DwarfWriter>();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000187 }
188 };
189} // end of anonymous namespace
190
191#include "ARMGenAsmWriter.inc"
192
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000193/// runOnMachineFunction - This uses the printInstruction()
194/// method to print assembly for each instruction.
195///
196bool ARMAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
Bill Wendling4f405312009-02-24 08:30:20 +0000197 this->MF = &MF;
198
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000199 AFI = MF.getInfo<ARMFunctionInfo>();
Evan Chenge6c61622008-09-18 07:27:23 +0000200 MCP = MF.getConstantPool();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000201
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000202 SetupMachineFunction(MF);
203 O << "\n";
204
205 // NOTE: we don't print out constant pools here, they are handled as
206 // instructions.
207
208 O << "\n";
209 // Print out labels for the function.
210 const Function *F = MF.getFunction();
211 switch (F->getLinkage()) {
Edwin Török26cb0252009-07-08 20:55:50 +0000212 default: LLVM_UNREACHABLE("Unknown linkage type!");
Rafael Espindolaa168fc92009-01-15 20:18:42 +0000213 case Function::PrivateLinkage:
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000214 case Function::InternalLinkage:
215 SwitchToTextSection("\t.text", F);
216 break;
217 case Function::ExternalLinkage:
218 SwitchToTextSection("\t.text", F);
219 O << "\t.globl\t" << CurrentFnName << "\n";
220 break;
Duncan Sands19d161f2009-03-07 15:45:40 +0000221 case Function::WeakAnyLinkage:
222 case Function::WeakODRLinkage:
223 case Function::LinkOnceAnyLinkage:
224 case Function::LinkOnceODRLinkage:
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000225 if (Subtarget->isTargetDarwin()) {
226 SwitchToTextSection(
227 ".section __TEXT,__textcoal_nt,coalesced,pure_instructions", F);
228 O << "\t.globl\t" << CurrentFnName << "\n";
229 O << "\t.weak_definition\t" << CurrentFnName << "\n";
230 } else {
231 O << TAI->getWeakRefDirective() << CurrentFnName << "\n";
232 }
233 break;
234 }
235
Anton Korobeynikov78d69aa2008-08-08 18:25:07 +0000236 printVisibility(CurrentFnName, F->getVisibility());
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000237
238 if (AFI->isThumbFunction()) {
Bill Wendling25a8ae32009-06-30 22:38:32 +0000239 EmitAlignment(MF.getAlignment(), F, AFI->getAlign());
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000240 O << "\t.code\t16\n";
241 O << "\t.thumb_func";
242 if (Subtarget->isTargetDarwin())
243 O << "\t" << CurrentFnName;
244 O << "\n";
245 InCPMode = false;
Bill Wendling25a8ae32009-06-30 22:38:32 +0000246 } else {
247 EmitAlignment(MF.getAlignment(), F);
248 }
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000249
250 O << CurrentFnName << ":\n";
251 // Emit pre-function debug information.
Devang Patelaa1e8432009-01-08 23:40:34 +0000252 DW->BeginFunction(&MF);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000253
Bill Wendling43a78162008-01-28 09:15:03 +0000254 if (Subtarget->isTargetDarwin()) {
255 // If the function is empty, then we need to emit *something*. Otherwise,
256 // the function's label might be associated with something that it wasn't
257 // meant to be associated with. We emit a noop in this situation.
258 MachineFunction::iterator I = MF.begin();
259
260 if (++I == MF.end() && MF.front().empty())
261 O << "\tnop\n";
262 }
263
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000264 // Print out code for the function.
265 for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
266 I != E; ++I) {
267 // Print a label for the basic block.
268 if (I != MF.begin()) {
Evan Cheng11db8142009-03-24 00:17:40 +0000269 printBasicBlockLabel(I, true, true, VerboseAsm);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000270 O << '\n';
271 }
272 for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end();
273 II != E; ++II) {
274 // Print the assembly for the instruction.
275 printMachineInstruction(II);
276 }
277 }
278
279 if (TAI->hasDotTypeDotSizeDirective())
280 O << "\t.size " << CurrentFnName << ", .-" << CurrentFnName << "\n";
281
282 // Emit post-function debug information.
Devang Patelaa1e8432009-01-08 23:40:34 +0000283 DW->EndFunction(&MF);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000284
Dan Gohmaneb94abd2008-11-07 19:49:17 +0000285 O.flush();
286
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000287 return false;
288}
289
Evan Cheng532cdc52009-06-29 07:51:04 +0000290void ARMAsmPrinter::printOperand(const MachineInstr *MI, int OpNum,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000291 const char *Modifier) {
Evan Cheng532cdc52009-06-29 07:51:04 +0000292 const MachineOperand &MO = MI->getOperand(OpNum);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000293 switch (MO.getType()) {
Bob Wilsone60fee02009-06-22 23:27:02 +0000294 case MachineOperand::MO_Register: {
295 unsigned Reg = MO.getReg();
296 if (TargetRegisterInfo::isPhysicalRegister(Reg)) {
297 if (Modifier && strcmp(Modifier, "dregpair") == 0) {
298 unsigned DRegLo = TRI->getSubReg(Reg, 5); // arm_dsubreg_0
299 unsigned DRegHi = TRI->getSubReg(Reg, 6); // arm_dsubreg_1
300 O << '{'
Bob Wilsoned592c02009-07-08 18:11:30 +0000301 << TRI->getAsmName(DRegLo) << ',' << TRI->getAsmName(DRegHi)
Bob Wilsone60fee02009-06-22 23:27:02 +0000302 << '}';
Bob Wilsoned592c02009-07-08 18:11:30 +0000303 } else if (Modifier && strcmp(Modifier, "dregsingle") == 0) {
304 O << '{' << TRI->getAsmName(Reg) << '}';
Bob Wilsone60fee02009-06-22 23:27:02 +0000305 } else {
306 O << TRI->getAsmName(Reg);
307 }
308 } else
Edwin Török26cb0252009-07-08 20:55:50 +0000309 LLVM_UNREACHABLE("not implemented");
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000310 break;
Bob Wilsone60fee02009-06-22 23:27:02 +0000311 }
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000312 case MachineOperand::MO_Immediate: {
313 if (!Modifier || strcmp(Modifier, "no_hash") != 0)
314 O << "#";
315
Bob Wilsonbc2f9e72009-05-19 21:27:57 +0000316 O << MO.getImm();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000317 break;
318 }
319 case MachineOperand::MO_MachineBasicBlock:
Chris Lattner6017d482007-12-30 23:10:15 +0000320 printBasicBlockLabel(MO.getMBB());
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000321 return;
322 case MachineOperand::MO_GlobalAddress: {
323 bool isCallOp = Modifier && !strcmp(Modifier, "call");
324 GlobalValue *GV = MO.getGlobal();
325 std::string Name = Mang->getValueName(GV);
326 bool isExt = (GV->isDeclaration() || GV->hasWeakLinkage() ||
327 GV->hasLinkOnceLinkage());
328 if (isExt && isCallOp && Subtarget->isTargetDarwin() &&
329 TM.getRelocationModel() != Reloc::Static) {
Dale Johannesena21b5202008-05-19 21:38:18 +0000330 printSuffixedName(Name, "$stub");
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000331 FnStubs.insert(Name);
332 } else
333 O << Name;
Anton Korobeynikov440f23d2008-11-22 16:15:34 +0000334
335 printOffset(MO.getOffset());
336
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000337 if (isCallOp && Subtarget->isTargetELF() &&
338 TM.getRelocationModel() == Reloc::PIC_)
339 O << "(PLT)";
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000340 break;
341 }
342 case MachineOperand::MO_ExternalSymbol: {
343 bool isCallOp = Modifier && !strcmp(Modifier, "call");
344 std::string Name(TAI->getGlobalPrefix());
345 Name += MO.getSymbolName();
346 if (isCallOp && Subtarget->isTargetDarwin() &&
347 TM.getRelocationModel() != Reloc::Static) {
Dale Johannesena21b5202008-05-19 21:38:18 +0000348 printSuffixedName(Name, "$stub");
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000349 FnStubs.insert(Name);
350 } else
351 O << Name;
352 if (isCallOp && Subtarget->isTargetELF() &&
353 TM.getRelocationModel() == Reloc::PIC_)
354 O << "(PLT)";
355 break;
356 }
357 case MachineOperand::MO_ConstantPoolIndex:
Evan Cheng477013c2007-10-14 05:57:21 +0000358 O << TAI->getPrivateGlobalPrefix() << "CPI" << getFunctionNumber()
Chris Lattner6017d482007-12-30 23:10:15 +0000359 << '_' << MO.getIndex();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000360 break;
361 case MachineOperand::MO_JumpTableIndex:
Evan Cheng477013c2007-10-14 05:57:21 +0000362 O << TAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber()
Chris Lattner6017d482007-12-30 23:10:15 +0000363 << '_' << MO.getIndex();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000364 break;
365 default:
366 O << "<unknown operand type>"; abort (); break;
367 }
368}
369
Evan Cheng42ceb472009-03-25 01:47:28 +0000370static void printSOImm(raw_ostream &O, int64_t V, bool VerboseAsm,
371 const TargetAsmInfo *TAI) {
Evan Cheng8be2a5b2009-07-08 21:03:57 +0000372 // Break it up into two parts that make up a shifter immediate.
373 V = ARM_AM::getSOImmVal(V);
374 assert(V != -1 && "Not a valid so_imm value!");
375
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000376 unsigned Imm = ARM_AM::getSOImmValImm(V);
377 unsigned Rot = ARM_AM::getSOImmValRot(V);
Anton Korobeynikov440f23d2008-11-22 16:15:34 +0000378
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000379 // Print low-level immediate formation info, per
380 // A5.1.3: "Data-processing operands - Immediate".
381 if (Rot) {
382 O << "#" << Imm << ", " << Rot;
383 // Pretty printed version.
Evan Cheng11db8142009-03-24 00:17:40 +0000384 if (VerboseAsm)
385 O << ' ' << TAI->getCommentString()
386 << ' ' << (int)ARM_AM::rotr32(Imm, Rot);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000387 } else {
388 O << "#" << Imm;
389 }
390}
391
392/// printSOImmOperand - SOImm is 4-bit rotate amount in bits 8-11 with 8-bit
393/// immediate in bits 0-7.
394void ARMAsmPrinter::printSOImmOperand(const MachineInstr *MI, int OpNum) {
395 const MachineOperand &MO = MI->getOperand(OpNum);
Dan Gohmanb9f4fa72008-10-03 15:45:36 +0000396 assert(MO.isImm() && "Not a valid so_imm value!");
Evan Cheng42ceb472009-03-25 01:47:28 +0000397 printSOImm(O, MO.getImm(), VerboseAsm, TAI);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000398}
399
Evan Cheng7cd4acb2008-11-06 02:25:39 +0000400/// printSOImm2PartOperand - SOImm is broken into two pieces using a 'mov'
401/// followed by an 'orr' to materialize.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000402void ARMAsmPrinter::printSOImm2PartOperand(const MachineInstr *MI, int OpNum) {
403 const MachineOperand &MO = MI->getOperand(OpNum);
Dan Gohmanb9f4fa72008-10-03 15:45:36 +0000404 assert(MO.isImm() && "Not a valid so_imm value!");
Chris Lattnera96056a2007-12-30 20:49:49 +0000405 unsigned V1 = ARM_AM::getSOImmTwoPartFirst(MO.getImm());
406 unsigned V2 = ARM_AM::getSOImmTwoPartSecond(MO.getImm());
Evan Cheng8be2a5b2009-07-08 21:03:57 +0000407 printSOImm(O, V1, VerboseAsm, TAI);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000408 O << "\n\torr";
409 printPredicateOperand(MI, 2);
410 O << " ";
411 printOperand(MI, 0);
412 O << ", ";
413 printOperand(MI, 0);
414 O << ", ";
Evan Cheng8be2a5b2009-07-08 21:03:57 +0000415 printSOImm(O, V2, VerboseAsm, TAI);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000416}
417
418// so_reg is a 4-operand unit corresponding to register forms of the A5.1
419// "Addressing Mode 1 - Data-processing operands" forms. This includes:
Evan Cheng19bb7c72009-06-27 02:26:13 +0000420// REG 0 0 - e.g. R5
421// REG REG 0,SH_OPC - e.g. R5, ROR R3
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000422// REG 0 IMM,SH_OPC - e.g. R5, LSL #3
423void ARMAsmPrinter::printSORegOperand(const MachineInstr *MI, int Op) {
424 const MachineOperand &MO1 = MI->getOperand(Op);
425 const MachineOperand &MO2 = MI->getOperand(Op+1);
426 const MachineOperand &MO3 = MI->getOperand(Op+2);
427
Dan Gohman1e57df32008-02-10 18:45:23 +0000428 assert(TargetRegisterInfo::isPhysicalRegister(MO1.getReg()));
Bill Wendling8eeb9792008-02-26 21:11:01 +0000429 O << TM.getRegisterInfo()->get(MO1.getReg()).AsmName;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000430
431 // Print the shift opc.
432 O << ", "
Chris Lattnera96056a2007-12-30 20:49:49 +0000433 << ARM_AM::getShiftOpcStr(ARM_AM::getSORegShOp(MO3.getImm()))
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000434 << " ";
435
436 if (MO2.getReg()) {
Dan Gohman1e57df32008-02-10 18:45:23 +0000437 assert(TargetRegisterInfo::isPhysicalRegister(MO2.getReg()));
Bill Wendling8eeb9792008-02-26 21:11:01 +0000438 O << TM.getRegisterInfo()->get(MO2.getReg()).AsmName;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000439 assert(ARM_AM::getSORegOffset(MO3.getImm()) == 0);
440 } else {
441 O << "#" << ARM_AM::getSORegOffset(MO3.getImm());
442 }
443}
444
445void ARMAsmPrinter::printAddrMode2Operand(const MachineInstr *MI, int Op) {
446 const MachineOperand &MO1 = MI->getOperand(Op);
447 const MachineOperand &MO2 = MI->getOperand(Op+1);
448 const MachineOperand &MO3 = MI->getOperand(Op+2);
449
Dan Gohmanb9f4fa72008-10-03 15:45:36 +0000450 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000451 printOperand(MI, Op);
452 return;
453 }
454
Bill Wendling8eeb9792008-02-26 21:11:01 +0000455 O << "[" << TM.getRegisterInfo()->get(MO1.getReg()).AsmName;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000456
457 if (!MO2.getReg()) {
458 if (ARM_AM::getAM2Offset(MO3.getImm())) // Don't print +0.
459 O << ", #"
460 << (char)ARM_AM::getAM2Op(MO3.getImm())
461 << ARM_AM::getAM2Offset(MO3.getImm());
462 O << "]";
463 return;
464 }
465
466 O << ", "
467 << (char)ARM_AM::getAM2Op(MO3.getImm())
Bill Wendling8eeb9792008-02-26 21:11:01 +0000468 << TM.getRegisterInfo()->get(MO2.getReg()).AsmName;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000469
470 if (unsigned ShImm = ARM_AM::getAM2Offset(MO3.getImm()))
471 O << ", "
Chris Lattnera96056a2007-12-30 20:49:49 +0000472 << ARM_AM::getShiftOpcStr(ARM_AM::getAM2ShiftOpc(MO3.getImm()))
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000473 << " #" << ShImm;
474 O << "]";
475}
476
477void ARMAsmPrinter::printAddrMode2OffsetOperand(const MachineInstr *MI, int Op){
478 const MachineOperand &MO1 = MI->getOperand(Op);
479 const MachineOperand &MO2 = MI->getOperand(Op+1);
480
481 if (!MO1.getReg()) {
482 unsigned ImmOffs = ARM_AM::getAM2Offset(MO2.getImm());
483 assert(ImmOffs && "Malformed indexed load / store!");
484 O << "#"
485 << (char)ARM_AM::getAM2Op(MO2.getImm())
486 << ImmOffs;
487 return;
488 }
489
490 O << (char)ARM_AM::getAM2Op(MO2.getImm())
Bill Wendling8eeb9792008-02-26 21:11:01 +0000491 << TM.getRegisterInfo()->get(MO1.getReg()).AsmName;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000492
493 if (unsigned ShImm = ARM_AM::getAM2Offset(MO2.getImm()))
494 O << ", "
Chris Lattnera96056a2007-12-30 20:49:49 +0000495 << ARM_AM::getShiftOpcStr(ARM_AM::getAM2ShiftOpc(MO2.getImm()))
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000496 << " #" << ShImm;
497}
498
499void ARMAsmPrinter::printAddrMode3Operand(const MachineInstr *MI, int Op) {
500 const MachineOperand &MO1 = MI->getOperand(Op);
501 const MachineOperand &MO2 = MI->getOperand(Op+1);
502 const MachineOperand &MO3 = MI->getOperand(Op+2);
503
Dan Gohman1e57df32008-02-10 18:45:23 +0000504 assert(TargetRegisterInfo::isPhysicalRegister(MO1.getReg()));
Bill Wendling8eeb9792008-02-26 21:11:01 +0000505 O << "[" << TM.getRegisterInfo()->get(MO1.getReg()).AsmName;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000506
507 if (MO2.getReg()) {
508 O << ", "
509 << (char)ARM_AM::getAM3Op(MO3.getImm())
Bill Wendling8eeb9792008-02-26 21:11:01 +0000510 << TM.getRegisterInfo()->get(MO2.getReg()).AsmName
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000511 << "]";
512 return;
513 }
514
515 if (unsigned ImmOffs = ARM_AM::getAM3Offset(MO3.getImm()))
516 O << ", #"
517 << (char)ARM_AM::getAM3Op(MO3.getImm())
518 << ImmOffs;
519 O << "]";
520}
521
522void ARMAsmPrinter::printAddrMode3OffsetOperand(const MachineInstr *MI, int Op){
523 const MachineOperand &MO1 = MI->getOperand(Op);
524 const MachineOperand &MO2 = MI->getOperand(Op+1);
525
526 if (MO1.getReg()) {
527 O << (char)ARM_AM::getAM3Op(MO2.getImm())
Bill Wendling8eeb9792008-02-26 21:11:01 +0000528 << TM.getRegisterInfo()->get(MO1.getReg()).AsmName;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000529 return;
530 }
531
532 unsigned ImmOffs = ARM_AM::getAM3Offset(MO2.getImm());
533 assert(ImmOffs && "Malformed indexed load / store!");
534 O << "#"
535 << (char)ARM_AM::getAM3Op(MO2.getImm())
536 << ImmOffs;
537}
538
539void ARMAsmPrinter::printAddrMode4Operand(const MachineInstr *MI, int Op,
540 const char *Modifier) {
541 const MachineOperand &MO1 = MI->getOperand(Op);
542 const MachineOperand &MO2 = MI->getOperand(Op+1);
543 ARM_AM::AMSubMode Mode = ARM_AM::getAM4SubMode(MO2.getImm());
544 if (Modifier && strcmp(Modifier, "submode") == 0) {
545 if (MO1.getReg() == ARM::SP) {
546 bool isLDM = (MI->getOpcode() == ARM::LDM ||
547 MI->getOpcode() == ARM::LDM_RET);
548 O << ARM_AM::getAMSubModeAltStr(Mode, isLDM);
549 } else
550 O << ARM_AM::getAMSubModeStr(Mode);
551 } else {
552 printOperand(MI, Op);
553 if (ARM_AM::getAM4WBFlag(MO2.getImm()))
554 O << "!";
555 }
556}
557
558void ARMAsmPrinter::printAddrMode5Operand(const MachineInstr *MI, int Op,
559 const char *Modifier) {
560 const MachineOperand &MO1 = MI->getOperand(Op);
561 const MachineOperand &MO2 = MI->getOperand(Op+1);
562
Dan Gohmanb9f4fa72008-10-03 15:45:36 +0000563 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000564 printOperand(MI, Op);
565 return;
566 }
567
Dan Gohman1e57df32008-02-10 18:45:23 +0000568 assert(TargetRegisterInfo::isPhysicalRegister(MO1.getReg()));
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000569
570 if (Modifier && strcmp(Modifier, "submode") == 0) {
571 ARM_AM::AMSubMode Mode = ARM_AM::getAM5SubMode(MO2.getImm());
572 if (MO1.getReg() == ARM::SP) {
573 bool isFLDM = (MI->getOpcode() == ARM::FLDMD ||
574 MI->getOpcode() == ARM::FLDMS);
575 O << ARM_AM::getAMSubModeAltStr(Mode, isFLDM);
576 } else
577 O << ARM_AM::getAMSubModeStr(Mode);
578 return;
579 } else if (Modifier && strcmp(Modifier, "base") == 0) {
580 // Used for FSTM{D|S} and LSTM{D|S} operations.
Bill Wendling8eeb9792008-02-26 21:11:01 +0000581 O << TM.getRegisterInfo()->get(MO1.getReg()).AsmName;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000582 if (ARM_AM::getAM5WBFlag(MO2.getImm()))
583 O << "!";
584 return;
585 }
586
Bill Wendling8eeb9792008-02-26 21:11:01 +0000587 O << "[" << TM.getRegisterInfo()->get(MO1.getReg()).AsmName;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000588
589 if (unsigned ImmOffs = ARM_AM::getAM5Offset(MO2.getImm())) {
590 O << ", #"
591 << (char)ARM_AM::getAM5Op(MO2.getImm())
592 << ImmOffs*4;
593 }
594 O << "]";
595}
596
Bob Wilson970a10d2009-07-01 23:16:05 +0000597void ARMAsmPrinter::printAddrMode6Operand(const MachineInstr *MI, int Op) {
598 const MachineOperand &MO1 = MI->getOperand(Op);
599 const MachineOperand &MO2 = MI->getOperand(Op+1);
600 const MachineOperand &MO3 = MI->getOperand(Op+2);
601
602 // FIXME: No support yet for specifying alignment.
603 O << "[" << TM.getRegisterInfo()->get(MO1.getReg()).AsmName << "]";
604
605 if (ARM_AM::getAM6WBFlag(MO3.getImm())) {
606 if (MO2.getReg() == 0)
607 O << "!";
608 else
609 O << ", " << TM.getRegisterInfo()->get(MO2.getReg()).AsmName;
610 }
611}
612
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000613void ARMAsmPrinter::printAddrModePCOperand(const MachineInstr *MI, int Op,
614 const char *Modifier) {
615 if (Modifier && strcmp(Modifier, "label") == 0) {
616 printPCLabel(MI, Op+1);
617 return;
618 }
619
620 const MachineOperand &MO1 = MI->getOperand(Op);
Dan Gohman1e57df32008-02-10 18:45:23 +0000621 assert(TargetRegisterInfo::isPhysicalRegister(MO1.getReg()));
Bill Wendling8eeb9792008-02-26 21:11:01 +0000622 O << "[pc, +" << TM.getRegisterInfo()->get(MO1.getReg()).AsmName << "]";
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000623}
624
625void
Evan Cheng36173712009-06-23 17:48:47 +0000626ARMAsmPrinter::printBitfieldInvMaskImmOperand(const MachineInstr *MI, int Op) {
627 const MachineOperand &MO = MI->getOperand(Op);
628 uint32_t v = ~MO.getImm();
Evan Cheng23057682009-06-25 22:04:44 +0000629 int32_t lsb = CountTrailingZeros_32(v);
Nick Lewyckyd2e271b2009-06-24 01:08:42 +0000630 int32_t width = (32 - CountLeadingZeros_32 (v)) - lsb;
Evan Cheng36173712009-06-23 17:48:47 +0000631 assert(MO.isImm() && "Not a valid bf_inv_mask_imm value!");
632 O << "#" << lsb << ", #" << width;
633}
634
Evan Cheng532cdc52009-06-29 07:51:04 +0000635//===--------------------------------------------------------------------===//
636
Evan Cheng36173712009-06-23 17:48:47 +0000637void
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000638ARMAsmPrinter::printThumbAddrModeRROperand(const MachineInstr *MI, int Op) {
639 const MachineOperand &MO1 = MI->getOperand(Op);
640 const MachineOperand &MO2 = MI->getOperand(Op+1);
Bill Wendling8eeb9792008-02-26 21:11:01 +0000641 O << "[" << TM.getRegisterInfo()->get(MO1.getReg()).AsmName;
642 O << ", " << TM.getRegisterInfo()->get(MO2.getReg()).AsmName << "]";
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000643}
644
645void
646ARMAsmPrinter::printThumbAddrModeRI5Operand(const MachineInstr *MI, int Op,
647 unsigned Scale) {
648 const MachineOperand &MO1 = MI->getOperand(Op);
649 const MachineOperand &MO2 = MI->getOperand(Op+1);
650 const MachineOperand &MO3 = MI->getOperand(Op+2);
651
Dan Gohmanb9f4fa72008-10-03 15:45:36 +0000652 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000653 printOperand(MI, Op);
654 return;
655 }
656
Bill Wendling8eeb9792008-02-26 21:11:01 +0000657 O << "[" << TM.getRegisterInfo()->get(MO1.getReg()).AsmName;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000658 if (MO3.getReg())
Bill Wendling8eeb9792008-02-26 21:11:01 +0000659 O << ", " << TM.getRegisterInfo()->get(MO3.getReg()).AsmName;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000660 else if (unsigned ImmOffs = MO2.getImm()) {
661 O << ", #" << ImmOffs;
662 if (Scale > 1)
663 O << " * " << Scale;
664 }
665 O << "]";
666}
667
668void
669ARMAsmPrinter::printThumbAddrModeS1Operand(const MachineInstr *MI, int Op) {
670 printThumbAddrModeRI5Operand(MI, Op, 1);
671}
672void
673ARMAsmPrinter::printThumbAddrModeS2Operand(const MachineInstr *MI, int Op) {
674 printThumbAddrModeRI5Operand(MI, Op, 2);
675}
676void
677ARMAsmPrinter::printThumbAddrModeS4Operand(const MachineInstr *MI, int Op) {
678 printThumbAddrModeRI5Operand(MI, Op, 4);
679}
680
681void ARMAsmPrinter::printThumbAddrModeSPOperand(const MachineInstr *MI,int Op) {
682 const MachineOperand &MO1 = MI->getOperand(Op);
683 const MachineOperand &MO2 = MI->getOperand(Op+1);
Bill Wendling8eeb9792008-02-26 21:11:01 +0000684 O << "[" << TM.getRegisterInfo()->get(MO1.getReg()).AsmName;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000685 if (unsigned ImmOffs = MO2.getImm())
686 O << ", #" << ImmOffs << " * 4";
687 O << "]";
688}
689
Evan Cheng532cdc52009-06-29 07:51:04 +0000690//===--------------------------------------------------------------------===//
691
Evan Cheng19bb7c72009-06-27 02:26:13 +0000692// Constant shifts t2_so_reg is a 2-operand unit corresponding to the Thumb2
693// register with shift forms.
694// REG 0 0 - e.g. R5
695// REG IMM, SH_OPC - e.g. R5, LSL #3
696void ARMAsmPrinter::printT2SOOperand(const MachineInstr *MI, int OpNum) {
697 const MachineOperand &MO1 = MI->getOperand(OpNum);
698 const MachineOperand &MO2 = MI->getOperand(OpNum+1);
699
700 unsigned Reg = MO1.getReg();
701 assert(TargetRegisterInfo::isPhysicalRegister(Reg));
702 O << TM.getRegisterInfo()->getAsmName(Reg);
703
704 // Print the shift opc.
705 O << ", "
706 << ARM_AM::getShiftOpcStr(ARM_AM::getSORegShOp(MO2.getImm()))
707 << " ";
708
709 assert(MO2.isImm() && "Not a valid t2_so_reg value!");
710 O << "#" << ARM_AM::getSORegOffset(MO2.getImm());
711}
712
Evan Cheng532cdc52009-06-29 07:51:04 +0000713void ARMAsmPrinter::printT2AddrModeImm12Operand(const MachineInstr *MI,
714 int OpNum) {
715 const MachineOperand &MO1 = MI->getOperand(OpNum);
716 const MachineOperand &MO2 = MI->getOperand(OpNum+1);
Evan Cheng19bb7c72009-06-27 02:26:13 +0000717
Evan Cheng532cdc52009-06-29 07:51:04 +0000718 O << "[" << TM.getRegisterInfo()->get(MO1.getReg()).AsmName;
719
720 unsigned OffImm = MO2.getImm();
721 if (OffImm) // Don't print +0.
722 O << ", #+" << OffImm;
723 O << "]";
724}
725
726void ARMAsmPrinter::printT2AddrModeImm8Operand(const MachineInstr *MI,
727 int OpNum) {
728 const MachineOperand &MO1 = MI->getOperand(OpNum);
729 const MachineOperand &MO2 = MI->getOperand(OpNum+1);
730
731 O << "[" << TM.getRegisterInfo()->get(MO1.getReg()).AsmName;
732
733 int32_t OffImm = (int32_t)MO2.getImm();
734 // Don't print +0.
735 if (OffImm < 0)
736 O << ", #-" << -OffImm;
737 else if (OffImm > 0)
738 O << ", #+" << OffImm;
739 O << "]";
740}
741
Evan Chenga90942e2009-07-02 07:28:31 +0000742void ARMAsmPrinter::printT2AddrModeImm8OffsetOperand(const MachineInstr *MI,
743 int OpNum) {
744 const MachineOperand &MO1 = MI->getOperand(OpNum);
745 int32_t OffImm = (int32_t)MO1.getImm();
746 // Don't print +0.
747 if (OffImm < 0)
748 O << "#-" << -OffImm;
749 else if (OffImm > 0)
750 O << "#+" << OffImm;
751}
752
Evan Cheng532cdc52009-06-29 07:51:04 +0000753void ARMAsmPrinter::printT2AddrModeSoRegOperand(const MachineInstr *MI,
754 int OpNum) {
755 const MachineOperand &MO1 = MI->getOperand(OpNum);
756 const MachineOperand &MO2 = MI->getOperand(OpNum+1);
757 const MachineOperand &MO3 = MI->getOperand(OpNum+2);
758
759 O << "[" << TM.getRegisterInfo()->get(MO1.getReg()).AsmName;
760
761 if (MO2.getReg()) {
762 O << ", +"
763 << TM.getRegisterInfo()->get(MO2.getReg()).AsmName;
764
765 unsigned ShAmt = MO3.getImm();
766 if (ShAmt) {
767 assert(ShAmt <= 3 && "Not a valid Thumb2 addressing mode!");
768 O << ", lsl #" << ShAmt;
769 }
770 }
771 O << "]";
772}
773
774
775//===--------------------------------------------------------------------===//
776
777void ARMAsmPrinter::printPredicateOperand(const MachineInstr *MI, int OpNum) {
778 ARMCC::CondCodes CC = (ARMCC::CondCodes)MI->getOperand(OpNum).getImm();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000779 if (CC != ARMCC::AL)
780 O << ARMCondCodeToString(CC);
781}
782
Evan Cheng532cdc52009-06-29 07:51:04 +0000783void ARMAsmPrinter::printSBitModifierOperand(const MachineInstr *MI, int OpNum){
784 unsigned Reg = MI->getOperand(OpNum).getReg();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000785 if (Reg) {
786 assert(Reg == ARM::CPSR && "Expect ARM CPSR register!");
787 O << 's';
788 }
789}
790
Evan Cheng532cdc52009-06-29 07:51:04 +0000791void ARMAsmPrinter::printPCLabel(const MachineInstr *MI, int OpNum) {
792 int Id = (int)MI->getOperand(OpNum).getImm();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000793 O << TAI->getPrivateGlobalPrefix() << "PC" << Id;
794}
795
Evan Cheng532cdc52009-06-29 07:51:04 +0000796void ARMAsmPrinter::printRegisterList(const MachineInstr *MI, int OpNum) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000797 O << "{";
Evan Cheng532cdc52009-06-29 07:51:04 +0000798 for (unsigned i = OpNum, e = MI->getNumOperands(); i != e; ++i) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000799 printOperand(MI, i);
800 if (i != e-1) O << ", ";
801 }
802 O << "}";
803}
804
Evan Cheng532cdc52009-06-29 07:51:04 +0000805void ARMAsmPrinter::printCPInstOperand(const MachineInstr *MI, int OpNum,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000806 const char *Modifier) {
807 assert(Modifier && "This operand only works with a modifier!");
808 // There are two aspects to a CONSTANTPOOL_ENTRY operand, the label and the
809 // data itself.
810 if (!strcmp(Modifier, "label")) {
Evan Cheng532cdc52009-06-29 07:51:04 +0000811 unsigned ID = MI->getOperand(OpNum).getImm();
Evan Cheng477013c2007-10-14 05:57:21 +0000812 O << TAI->getPrivateGlobalPrefix() << "CPI" << getFunctionNumber()
813 << '_' << ID << ":\n";
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000814 } else {
815 assert(!strcmp(Modifier, "cpentry") && "Unknown modifier for CPE");
Evan Cheng532cdc52009-06-29 07:51:04 +0000816 unsigned CPI = MI->getOperand(OpNum).getIndex();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000817
Evan Chenge6c61622008-09-18 07:27:23 +0000818 const MachineConstantPoolEntry &MCPE = MCP->getConstants()[CPI];
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000819
Evan Chengf1012ce2008-08-08 06:56:16 +0000820 if (MCPE.isMachineConstantPoolEntry()) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000821 EmitMachineConstantPoolValue(MCPE.Val.MachineCPVal);
Evan Chengf1012ce2008-08-08 06:56:16 +0000822 } else {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000823 EmitGlobalConstant(MCPE.Val.ConstVal);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000824 }
825 }
826}
827
Evan Cheng532cdc52009-06-29 07:51:04 +0000828void ARMAsmPrinter::printJTBlockOperand(const MachineInstr *MI, int OpNum) {
829 const MachineOperand &MO1 = MI->getOperand(OpNum);
830 const MachineOperand &MO2 = MI->getOperand(OpNum+1); // Unique Id
Chris Lattner6017d482007-12-30 23:10:15 +0000831 unsigned JTI = MO1.getIndex();
Evan Cheng477013c2007-10-14 05:57:21 +0000832 O << TAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber()
Chris Lattnera96056a2007-12-30 20:49:49 +0000833 << '_' << JTI << '_' << MO2.getImm() << ":\n";
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000834
835 const char *JTEntryDirective = TAI->getJumpTableDirective();
836 if (!JTEntryDirective)
837 JTEntryDirective = TAI->getData32bitsDirective();
838
839 const MachineFunction *MF = MI->getParent()->getParent();
Dan Gohmane4da6412008-07-07 20:06:06 +0000840 const MachineJumpTableInfo *MJTI = MF->getJumpTableInfo();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000841 const std::vector<MachineJumpTableEntry> &JT = MJTI->getJumpTables();
842 const std::vector<MachineBasicBlock*> &JTBBs = JT[JTI].MBBs;
843 bool UseSet= TAI->getSetDirective() && TM.getRelocationModel() == Reloc::PIC_;
844 std::set<MachineBasicBlock*> JTSets;
845 for (unsigned i = 0, e = JTBBs.size(); i != e; ++i) {
846 MachineBasicBlock *MBB = JTBBs[i];
847 if (UseSet && JTSets.insert(MBB).second)
Chris Lattnera96056a2007-12-30 20:49:49 +0000848 printPICJumpTableSetLabel(JTI, MO2.getImm(), MBB);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000849
850 O << JTEntryDirective << ' ';
851 if (UseSet)
Evan Cheng477013c2007-10-14 05:57:21 +0000852 O << TAI->getPrivateGlobalPrefix() << getFunctionNumber()
Chris Lattnera96056a2007-12-30 20:49:49 +0000853 << '_' << JTI << '_' << MO2.getImm()
Evan Cheng477013c2007-10-14 05:57:21 +0000854 << "_set_" << MBB->getNumber();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000855 else if (TM.getRelocationModel() == Reloc::PIC_) {
Evan Cheng45c1edb2008-02-28 00:43:03 +0000856 printBasicBlockLabel(MBB, false, false, false);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000857 // If the arch uses custom Jump Table directives, don't calc relative to JT
858 if (!TAI->getJumpTableDirective())
859 O << '-' << TAI->getPrivateGlobalPrefix() << "JTI"
Chris Lattnera96056a2007-12-30 20:49:49 +0000860 << getFunctionNumber() << '_' << JTI << '_' << MO2.getImm();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000861 } else
Evan Cheng45c1edb2008-02-28 00:43:03 +0000862 printBasicBlockLabel(MBB, false, false, false);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000863 if (i != e-1)
864 O << '\n';
865 }
866}
867
868
Evan Cheng532cdc52009-06-29 07:51:04 +0000869bool ARMAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNum,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000870 unsigned AsmVariant, const char *ExtraCode){
871 // Does this asm operand have a single letter operand modifier?
872 if (ExtraCode && ExtraCode[0]) {
873 if (ExtraCode[1] != 0) return true; // Unknown modifier.
874
875 switch (ExtraCode[0]) {
876 default: return true; // Unknown modifier.
Bob Wilson5260c4c2009-04-06 21:46:51 +0000877 case 'a': // Don't print "#" before a global var name or constant.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000878 case 'c': // Don't print "$" before a global var name or constant.
Evan Cheng532cdc52009-06-29 07:51:04 +0000879 printOperand(MI, OpNum, "no_hash");
Bob Wilson5260c4c2009-04-06 21:46:51 +0000880 return false;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000881 case 'P': // Print a VFP double precision register.
Evan Cheng532cdc52009-06-29 07:51:04 +0000882 printOperand(MI, OpNum);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000883 return false;
884 case 'Q':
885 if (TM.getTargetData()->isLittleEndian())
886 break;
887 // Fallthrough
888 case 'R':
889 if (TM.getTargetData()->isBigEndian())
890 break;
891 // Fallthrough
892 case 'H': // Write second word of DI / DF reference.
893 // Verify that this operand has two consecutive registers.
Evan Cheng532cdc52009-06-29 07:51:04 +0000894 if (!MI->getOperand(OpNum).isReg() ||
895 OpNum+1 == MI->getNumOperands() ||
896 !MI->getOperand(OpNum+1).isReg())
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000897 return true;
Evan Cheng532cdc52009-06-29 07:51:04 +0000898 ++OpNum; // Return the high-part.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000899 }
900 }
901
Evan Cheng532cdc52009-06-29 07:51:04 +0000902 printOperand(MI, OpNum);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000903 return false;
904}
905
Bob Wilson6c982bb2009-05-19 05:53:42 +0000906bool ARMAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,
Evan Cheng532cdc52009-06-29 07:51:04 +0000907 unsigned OpNum, unsigned AsmVariant,
Bob Wilson6c982bb2009-05-19 05:53:42 +0000908 const char *ExtraCode) {
909 if (ExtraCode && ExtraCode[0])
910 return true; // Unknown modifier.
Evan Cheng532cdc52009-06-29 07:51:04 +0000911 printAddrMode2Operand(MI, OpNum);
Bob Wilson6c982bb2009-05-19 05:53:42 +0000912 return false;
913}
914
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000915void ARMAsmPrinter::printMachineInstruction(const MachineInstr *MI) {
916 ++EmittedInsts;
917
918 int Opc = MI->getOpcode();
919 switch (Opc) {
920 case ARM::CONSTPOOL_ENTRY:
921 if (!InCPMode && AFI->isThumbFunction()) {
922 EmitAlignment(2);
923 InCPMode = true;
924 }
925 break;
926 default: {
927 if (InCPMode && AFI->isThumbFunction())
928 InCPMode = false;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000929 }}
930
931 // Call the autogenerated instruction printer routines.
932 printInstruction(MI);
933}
934
935bool ARMAsmPrinter::doInitialization(Module &M) {
Evan Chenge4428082008-12-10 21:54:21 +0000936
Dan Gohman4a558a32007-07-25 19:33:14 +0000937 bool Result = AsmPrinter::doInitialization(M);
Duncan Sands4e0d6a72009-01-28 13:14:17 +0000938 DW = getAnalysisIfAvailable<DwarfWriter>();
Dale Johannesen2f85df12008-07-09 21:20:54 +0000939
Anton Korobeynikov9a2d2302009-06-17 23:43:18 +0000940 // Thumb-2 instructions are supported only in unified assembler syntax mode.
Bob Wilsond7afe4f2009-06-18 00:36:17 +0000941 if (Subtarget->hasThumb2())
Anton Korobeynikov9a2d2302009-06-17 23:43:18 +0000942 O << "\t.syntax unified\n";
943
Anton Korobeynikova229f0b2009-05-23 19:51:20 +0000944 // Emit ARM Build Attributes
945 if (Subtarget->isTargetELF()) {
946 // CPU Type
Anton Korobeynikov84529082009-06-01 19:03:17 +0000947 std::string CPUString = Subtarget->getCPUString();
948 if (CPUString != "generic")
949 O << "\t.cpu " << CPUString << '\n';
Anton Korobeynikova229f0b2009-05-23 19:51:20 +0000950
951 // FIXME: Emit FPU type
952 if (Subtarget->hasVFP2())
953 O << "\t.eabi_attribute " << ARMBuildAttrs::VFP_arch << ", 2\n";
954
955 // Signal various FP modes.
956 if (!UnsafeFPMath)
957 O << "\t.eabi_attribute " << ARMBuildAttrs::ABI_FP_denormal << ", 1\n"
958 << "\t.eabi_attribute " << ARMBuildAttrs::ABI_FP_exceptions << ", 1\n";
959
960 if (FiniteOnlyFPMath())
961 O << "\t.eabi_attribute " << ARMBuildAttrs::ABI_FP_number_model << ", 1\n";
962 else
963 O << "\t.eabi_attribute " << ARMBuildAttrs::ABI_FP_number_model << ", 3\n";
964
965 // 8-bytes alignment stuff.
966 O << "\t.eabi_attribute " << ARMBuildAttrs::ABI_align8_needed << ", 1\n"
967 << "\t.eabi_attribute " << ARMBuildAttrs::ABI_align8_preserved << ", 1\n";
968
969 // FIXME: Should we signal R9 usage?
970 }
971
Dan Gohman4a558a32007-07-25 19:33:14 +0000972 return Result;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000973}
974
Chris Lattner2b638a72008-02-15 19:04:54 +0000975/// PrintUnmangledNameSafely - Print out the printable characters in the name.
Dan Gohman8387bb32009-03-03 02:55:14 +0000976/// Don't print things like \\n or \\0.
Owen Anderson847b99b2008-08-21 00:14:44 +0000977static void PrintUnmangledNameSafely(const Value *V, raw_ostream &OS) {
Chris Lattner2b638a72008-02-15 19:04:54 +0000978 for (const char *Name = V->getNameStart(), *E = Name+V->getNameLen();
979 Name != E; ++Name)
980 if (isprint(*Name))
981 OS << *Name;
982}
983
Anton Korobeynikov3cc6efa2008-08-07 09:54:23 +0000984void ARMAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000985 const TargetData *TD = TM.getTargetData();
986
Anton Korobeynikov3cc6efa2008-08-07 09:54:23 +0000987 if (!GVar->hasInitializer()) // External global require no code
988 return;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000989
Anton Korobeynikov3cc6efa2008-08-07 09:54:23 +0000990 // Check to see if this is a special global used by LLVM, if so, emit it.
991
992 if (EmitSpecialLLVMGlobal(GVar)) {
993 if (Subtarget->isTargetDarwin() &&
994 TM.getRelocationModel() == Reloc::Static) {
995 if (GVar->getName() == "llvm.global_ctors")
996 O << ".reference .constructors_used\n";
997 else if (GVar->getName() == "llvm.global_dtors")
998 O << ".reference .destructors_used\n";
999 }
1000 return;
1001 }
1002
Anton Korobeynikov3cc6efa2008-08-07 09:54:23 +00001003 std::string name = Mang->getValueName(GVar);
1004 Constant *C = GVar->getInitializer();
Devang Patel880595f2009-06-26 02:26:12 +00001005 if (isa<MDNode>(C) || isa<MDString>(C))
Devang Patelf667ab42009-06-25 00:47:42 +00001006 return;
Anton Korobeynikov3cc6efa2008-08-07 09:54:23 +00001007 const Type *Type = C->getType();
Duncan Sandsec4f97d2009-05-09 07:06:46 +00001008 unsigned Size = TD->getTypeAllocSize(Type);
Anton Korobeynikov3cc6efa2008-08-07 09:54:23 +00001009 unsigned Align = TD->getPreferredAlignmentLog(GVar);
Evan Cheng43f73c62008-12-06 02:00:55 +00001010 bool isDarwin = Subtarget->isTargetDarwin();
Anton Korobeynikov3cc6efa2008-08-07 09:54:23 +00001011
Anton Korobeynikov78d69aa2008-08-08 18:25:07 +00001012 printVisibility(name, GVar->getVisibility());
Anton Korobeynikov3cc6efa2008-08-07 09:54:23 +00001013
1014 if (Subtarget->isTargetELF())
1015 O << "\t.type " << name << ",%object\n";
1016
Evan Chengcf84b142009-02-18 02:19:52 +00001017 if (C->isNullValue() && !GVar->hasSection() && !GVar->isThreadLocal() &&
1018 !(isDarwin &&
1019 TAI->SectionKindForGlobal(GVar) == SectionKind::RODataMergeStr)) {
Anton Korobeynikov3cc6efa2008-08-07 09:54:23 +00001020 // FIXME: This seems to be pretty darwin-specific
1021
1022 if (GVar->hasExternalLinkage()) {
Evan Cheng43f73c62008-12-06 02:00:55 +00001023 SwitchToSection(TAI->SectionForGlobal(GVar));
Anton Korobeynikov3cc6efa2008-08-07 09:54:23 +00001024 if (const char *Directive = TAI->getZeroFillDirective()) {
1025 O << "\t.globl\t" << name << "\n";
1026 O << Directive << "__DATA, __common, " << name << ", "
1027 << Size << ", " << Align << "\n";
1028 return;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001029 }
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001030 }
1031
Duncan Sands19d161f2009-03-07 15:45:40 +00001032 if (GVar->hasLocalLinkage() || GVar->isWeakForLinker()) {
Anton Korobeynikov3cc6efa2008-08-07 09:54:23 +00001033 if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001034
Evan Cheng43f73c62008-12-06 02:00:55 +00001035 if (isDarwin) {
Rafael Espindolaa168fc92009-01-15 20:18:42 +00001036 if (GVar->hasLocalLinkage()) {
Evan Cheng43f73c62008-12-06 02:00:55 +00001037 O << TAI->getLCOMMDirective() << name << "," << Size
1038 << ',' << Align;
1039 } else if (GVar->hasCommonLinkage()) {
1040 O << TAI->getCOMMDirective() << name << "," << Size
1041 << ',' << Align;
1042 } else {
1043 SwitchToSection(TAI->SectionForGlobal(GVar));
1044 O << "\t.globl " << name << '\n'
1045 << TAI->getWeakDefDirective() << name << '\n';
1046 EmitAlignment(Align, GVar);
Evan Cheng11db8142009-03-24 00:17:40 +00001047 O << name << ":";
1048 if (VerboseAsm) {
1049 O << "\t\t\t\t" << TAI->getCommentString() << ' ';
1050 PrintUnmangledNameSafely(GVar, O);
1051 }
Evan Cheng43f73c62008-12-06 02:00:55 +00001052 O << '\n';
1053 EmitGlobalConstant(C);
1054 return;
1055 }
1056 } else if (TAI->getLCOMMDirective() != NULL) {
Rafael Espindolaa168fc92009-01-15 20:18:42 +00001057 if (GVar->hasLocalLinkage()) {
Anton Korobeynikov3cc6efa2008-08-07 09:54:23 +00001058 O << TAI->getLCOMMDirective() << name << "," << Size;
Evan Cheng43f73c62008-12-06 02:00:55 +00001059 } else {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001060 O << TAI->getCOMMDirective() << name << "," << Size;
Evan Cheng43f73c62008-12-06 02:00:55 +00001061 if (TAI->getCOMMDirectiveTakesAlignment())
1062 O << ',' << (TAI->getAlignmentIsInBytes() ? (1 << Align) : Align);
1063 }
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001064 } else {
Evan Cheng43f73c62008-12-06 02:00:55 +00001065 SwitchToSection(TAI->SectionForGlobal(GVar));
Rafael Espindolaa168fc92009-01-15 20:18:42 +00001066 if (GVar->hasLocalLinkage())
Anton Korobeynikov3cc6efa2008-08-07 09:54:23 +00001067 O << "\t.local\t" << name << "\n";
1068 O << TAI->getCOMMDirective() << name << "," << Size;
1069 if (TAI->getCOMMDirectiveTakesAlignment())
1070 O << "," << (TAI->getAlignmentIsInBytes() ? (1 << Align) : Align);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001071 }
Evan Cheng11db8142009-03-24 00:17:40 +00001072 if (VerboseAsm) {
1073 O << "\t\t" << TAI->getCommentString() << " ";
1074 PrintUnmangledNameSafely(GVar, O);
1075 }
Anton Korobeynikov3cc6efa2008-08-07 09:54:23 +00001076 O << "\n";
1077 return;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001078 }
Anton Korobeynikov3cc6efa2008-08-07 09:54:23 +00001079 }
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001080
Evan Cheng43f73c62008-12-06 02:00:55 +00001081 SwitchToSection(TAI->SectionForGlobal(GVar));
Anton Korobeynikov3cc6efa2008-08-07 09:54:23 +00001082 switch (GVar->getLinkage()) {
Duncan Sandsb95df792009-03-11 20:14:15 +00001083 case GlobalValue::CommonLinkage:
Duncan Sands19d161f2009-03-07 15:45:40 +00001084 case GlobalValue::LinkOnceAnyLinkage:
1085 case GlobalValue::LinkOnceODRLinkage:
1086 case GlobalValue::WeakAnyLinkage:
1087 case GlobalValue::WeakODRLinkage:
Evan Cheng43f73c62008-12-06 02:00:55 +00001088 if (isDarwin) {
Anton Korobeynikov3cc6efa2008-08-07 09:54:23 +00001089 O << "\t.globl " << name << "\n"
1090 << "\t.weak_definition " << name << "\n";
1091 } else {
1092 O << "\t.weak " << name << "\n";
1093 }
1094 break;
1095 case GlobalValue::AppendingLinkage:
1096 // FIXME: appending linkage variables should go into a section of
1097 // their name or something. For now, just emit them as external.
1098 case GlobalValue::ExternalLinkage:
1099 O << "\t.globl " << name << "\n";
1100 // FALL THROUGH
Rafael Espindolaa168fc92009-01-15 20:18:42 +00001101 case GlobalValue::PrivateLinkage:
Anton Korobeynikov3cc6efa2008-08-07 09:54:23 +00001102 case GlobalValue::InternalLinkage:
1103 break;
1104 default:
Edwin Török26cb0252009-07-08 20:55:50 +00001105 LLVM_UNREACHABLE("Unknown linkage type!");
Anton Korobeynikov3cc6efa2008-08-07 09:54:23 +00001106 }
1107
1108 EmitAlignment(Align, GVar);
Evan Cheng11db8142009-03-24 00:17:40 +00001109 O << name << ":";
1110 if (VerboseAsm) {
1111 O << "\t\t\t\t" << TAI->getCommentString() << " ";
1112 PrintUnmangledNameSafely(GVar, O);
1113 }
Anton Korobeynikov3cc6efa2008-08-07 09:54:23 +00001114 O << "\n";
1115 if (TAI->hasDotTypeDotSizeDirective())
1116 O << "\t.size " << name << ", " << Size << "\n";
1117
Anton Korobeynikov3cc6efa2008-08-07 09:54:23 +00001118 EmitGlobalConstant(C);
1119 O << '\n';
1120}
1121
1122
1123bool ARMAsmPrinter::doFinalization(Module &M) {
1124 for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
1125 I != E; ++I)
1126 printModuleLevelGV(I);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001127
1128 if (Subtarget->isTargetDarwin()) {
1129 SwitchToDataSection("");
1130
1131 // Output stubs for dynamically-linked functions
Evan Chenga65854f2008-12-05 01:06:39 +00001132 for (StringSet<>::iterator i = FnStubs.begin(), e = FnStubs.end();
1133 i != e; ++i) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001134 if (TM.getRelocationModel() == Reloc::PIC_)
1135 SwitchToTextSection(".section __TEXT,__picsymbolstub4,symbol_stubs,"
1136 "none,16", 0);
1137 else
1138 SwitchToTextSection(".section __TEXT,__symbol_stub4,symbol_stubs,"
1139 "none,12", 0);
1140
1141 EmitAlignment(2);
1142 O << "\t.code\t32\n";
1143
Evan Chenga65854f2008-12-05 01:06:39 +00001144 const char *p = i->getKeyData();
Dale Johannesena21b5202008-05-19 21:38:18 +00001145 printSuffixedName(p, "$stub");
1146 O << ":\n";
Evan Chenga65854f2008-12-05 01:06:39 +00001147 O << "\t.indirect_symbol " << p << "\n";
Dale Johannesena21b5202008-05-19 21:38:18 +00001148 O << "\tldr ip, ";
1149 printSuffixedName(p, "$slp");
1150 O << "\n";
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001151 if (TM.getRelocationModel() == Reloc::PIC_) {
Dale Johannesena21b5202008-05-19 21:38:18 +00001152 printSuffixedName(p, "$scv");
1153 O << ":\n";
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001154 O << "\tadd ip, pc, ip\n";
1155 }
1156 O << "\tldr pc, [ip, #0]\n";
Dale Johannesena21b5202008-05-19 21:38:18 +00001157 printSuffixedName(p, "$slp");
1158 O << ":\n";
1159 O << "\t.long\t";
1160 printSuffixedName(p, "$lazy_ptr");
1161 if (TM.getRelocationModel() == Reloc::PIC_) {
1162 O << "-(";
1163 printSuffixedName(p, "$scv");
1164 O << "+8)\n";
1165 } else
1166 O << "\n";
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001167 SwitchToDataSection(".lazy_symbol_pointer", 0);
Dale Johannesena21b5202008-05-19 21:38:18 +00001168 printSuffixedName(p, "$lazy_ptr");
1169 O << ":\n";
Evan Chenga65854f2008-12-05 01:06:39 +00001170 O << "\t.indirect_symbol " << p << "\n";
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001171 O << "\t.long\tdyld_stub_binding_helper\n";
1172 }
1173 O << "\n";
1174
1175 // Output non-lazy-pointers for external and common global variables.
Evan Chenga65854f2008-12-05 01:06:39 +00001176 if (!GVNonLazyPtrs.empty()) {
Evan Cheng43f73c62008-12-06 02:00:55 +00001177 SwitchToDataSection("\t.non_lazy_symbol_pointer", 0);
Evan Chenga65854f2008-12-05 01:06:39 +00001178 for (StringSet<>::iterator i = GVNonLazyPtrs.begin(),
1179 e = GVNonLazyPtrs.end(); i != e; ++i) {
1180 const char *p = i->getKeyData();
1181 printSuffixedName(p, "$non_lazy_ptr");
1182 O << ":\n";
1183 O << "\t.indirect_symbol " << p << "\n";
1184 O << "\t.long\t0\n";
1185 }
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001186 }
1187
Evan Chenga65854f2008-12-05 01:06:39 +00001188 if (!HiddenGVNonLazyPtrs.empty()) {
1189 SwitchToSection(TAI->getDataSection());
1190 for (StringSet<>::iterator i = HiddenGVNonLazyPtrs.begin(),
1191 e = HiddenGVNonLazyPtrs.end(); i != e; ++i) {
1192 const char *p = i->getKeyData();
1193 EmitAlignment(2);
1194 printSuffixedName(p, "$non_lazy_ptr");
1195 O << ":\n";
1196 O << "\t.long " << p << "\n";
1197 }
1198 }
1199
1200
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001201 // Funny Darwin hack: This flag tells the linker that no global symbols
1202 // contain code that falls through to other global symbols (e.g. the obvious
1203 // implementation of multiple entry points). If this doesn't occur, the
1204 // linker can safely perform dead code stripping. Since LLVM never
1205 // generates code that does this, it is always safe to set.
1206 O << "\t.subsections_via_symbols\n";
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001207 }
1208
Dan Gohman4a558a32007-07-25 19:33:14 +00001209 return AsmPrinter::doFinalization(M);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001210}
Anton Korobeynikov74b114b2008-08-17 13:55:10 +00001211
1212/// createARMCodePrinterPass - Returns a pass that prints the ARM
1213/// assembly code for a MachineFunction to the given output stream,
1214/// using the given target machine description. This should work
1215/// regardless of whether the function is in SSA form.
1216///
Owen Anderson847b99b2008-08-21 00:14:44 +00001217FunctionPass *llvm::createARMCodePrinterPass(raw_ostream &o,
Anton Korobeynikov65d16ea2009-06-26 21:28:53 +00001218 ARMBaseTargetMachine &tm,
Bill Wendling5ed22ac2009-04-29 23:29:43 +00001219 bool verbose) {
Daniel Dunbarb10d2222009-07-01 01:48:54 +00001220 return new ARMAsmPrinter(o, tm, tm.getTargetAsmInfo(), verbose);
Anton Korobeynikov74b114b2008-08-17 13:55:10 +00001221}
1222
1223namespace {
1224 static struct Register {
1225 Register() {
Anton Korobeynikov65d16ea2009-06-26 21:28:53 +00001226 ARMBaseTargetMachine::registerAsmPrinter(createARMCodePrinterPass);
Anton Korobeynikov74b114b2008-08-17 13:55:10 +00001227 }
1228 } Registrator;
1229}
Douglas Gregor1dc5ff42009-06-16 20:12:29 +00001230
Bob Wilsonebbc1c42009-06-23 23:59:40 +00001231// Force static initialization.
1232extern "C" void LLVMInitializeARMAsmPrinter() { }