blob: 24c3b61b0109df788e90d4ae9e40726363fb43ba [file] [log] [blame]
Jia Liu9f610112012-02-17 08:55:11 +00001//===-- MipsAsmPrinter.cpp - Mips LLVM Assembly Printer -------------------===//
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +00007//
Akira Hatanakae2489122011-04-15 21:51:11 +00008//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +00009//
10// This file contains a printer that converts from our internal representation
11// of machine-dependent LLVM code to GAS-format MIPS assembly language.
12//
Akira Hatanakae2489122011-04-15 21:51:11 +000013//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000014
15#define DEBUG_TYPE "mips-asm-printer"
Akira Hatanaka9c6028f2011-07-07 23:56:50 +000016#include "InstPrinter/MipsInstPrinter.h"
Bruno Cardoso Lopesc85e3ff2011-11-11 22:58:42 +000017#include "MCTargetDesc/MipsBaseInfo.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000018#include "Mips.h"
Jack Carterc1b17ed2013-01-18 21:20:38 +000019#include "MipsAsmPrinter.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000020#include "MipsInstrInfo.h"
21#include "MipsMCInstLower.h"
Rafael Espindolaa17151a2013-10-08 13:08:17 +000022#include "MipsTargetStreamer.h"
Bruno Cardoso Lopesd5edb382011-11-08 22:26:47 +000023#include "llvm/ADT/SmallString.h"
24#include "llvm/ADT/StringExtras.h"
25#include "llvm/ADT/Twine.h"
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000026#include "llvm/CodeGen/MachineConstantPool.h"
Bruno Cardoso Lopesbcda5e22007-07-11 23:24:41 +000027#include "llvm/CodeGen/MachineFrameInfo.h"
Jack Carterb2af5122012-07-05 23:58:21 +000028#include "llvm/CodeGen/MachineFunctionPass.h"
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000029#include "llvm/CodeGen/MachineInstr.h"
Akira Hatanaka2fcc1cf2011-08-12 21:30:06 +000030#include "llvm/CodeGen/MachineMemOperand.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000031#include "llvm/IR/BasicBlock.h"
32#include "llvm/IR/DataLayout.h"
33#include "llvm/IR/InlineAsm.h"
34#include "llvm/IR/Instructions.h"
Rafael Espindola894843c2014-01-07 21:19:40 +000035#include "llvm/IR/Mangler.h"
Chris Lattner7b26fce2009-08-22 20:48:53 +000036#include "llvm/MC/MCAsmInfo.h"
Rafael Espindolaac4ad252013-10-05 16:42:21 +000037#include "llvm/MC/MCELFStreamer.h"
Akira Hatanaka9c6028f2011-07-07 23:56:50 +000038#include "llvm/MC/MCInst.h"
Chris Lattner4cd44982009-09-13 17:14:04 +000039#include "llvm/MC/MCSymbol.h"
Jack Carterab3cb422013-02-19 22:04:37 +000040#include "llvm/Support/ELF.h"
Jack Carterb2af5122012-07-05 23:58:21 +000041#include "llvm/Support/TargetRegistry.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000042#include "llvm/Support/raw_ostream.h"
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +000043#include "llvm/Target/TargetLoweringObjectFile.h"
Bruno Cardoso Lopesb4391322007-11-12 19:49:57 +000044#include "llvm/Target/TargetOptions.h"
Akira Hatanakaf2bcad92011-07-01 01:04:43 +000045
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000046using namespace llvm;
47
Rafael Espindolaa17151a2013-10-08 13:08:17 +000048MipsTargetStreamer &MipsAsmPrinter::getTargetStreamer() {
Rafael Espindola4a1a3602014-01-14 01:21:46 +000049 return static_cast<MipsTargetStreamer &>(*OutStreamer.getTargetStreamer());
Rafael Espindolaa17151a2013-10-08 13:08:17 +000050}
51
Akira Hatanaka34ee3ff2012-03-28 00:22:50 +000052bool MipsAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
Reed Kotler1595f362013-04-09 19:46:01 +000053 // Initialize TargetLoweringObjectFile.
54 if (Subtarget->allowMixed16_32())
55 const_cast<TargetLoweringObjectFile&>(getObjFileLowering())
56 .Initialize(OutContext, TM);
Akira Hatanaka34ee3ff2012-03-28 00:22:50 +000057 MipsFI = MF.getInfo<MipsFunctionInfo>();
Reed Kotler91ae9822013-10-27 21:57:36 +000058 MCP = MF.getConstantPool();
Akira Hatanaka34ee3ff2012-03-28 00:22:50 +000059 AsmPrinter::runOnMachineFunction(MF);
60 return true;
Bruno Cardoso Lopesd5edb382011-11-08 22:26:47 +000061}
62
Akira Hatanaka42a35242012-09-27 01:59:07 +000063bool MipsAsmPrinter::lowerOperand(const MachineOperand &MO, MCOperand &MCOp) {
64 MCOp = MCInstLowering.LowerOperand(MO);
65 return MCOp.isValid();
66}
67
68#include "MipsGenMCPseudoLowering.inc"
69
Akira Hatanakaddd12652011-07-07 20:10:52 +000070void MipsAsmPrinter::EmitInstruction(const MachineInstr *MI) {
Akira Hatanakaddd12652011-07-07 20:10:52 +000071 if (MI->isDebugValue()) {
Bruno Cardoso Lopescd1d4472011-12-30 21:09:41 +000072 SmallString<128> Str;
73 raw_svector_ostream OS(Str);
74
Akira Hatanakaddd12652011-07-07 20:10:52 +000075 PrintDebugValueComment(MI, OS);
76 return;
77 }
78
Reed Kotler91ae9822013-10-27 21:57:36 +000079 // If we just ended a constant pool, mark it as such.
80 if (InConstantPool && MI->getOpcode() != Mips::CONSTPOOL_ENTRY) {
81 OutStreamer.EmitDataRegion(MCDR_DataRegionEnd);
82 InConstantPool = false;
83 }
84 if (MI->getOpcode() == Mips::CONSTPOOL_ENTRY) {
85 // CONSTPOOL_ENTRY - This instruction represents a floating
86 //constant pool in the function. The first operand is the ID#
87 // for this instruction, the second is the index into the
88 // MachineConstantPool that this is, the third is the size in
89 // bytes of this constant pool entry.
90 // The required alignment is specified on the basic block holding this MI.
91 //
92 unsigned LabelId = (unsigned)MI->getOperand(0).getImm();
93 unsigned CPIdx = (unsigned)MI->getOperand(1).getIndex();
94
95 // If this is the first entry of the pool, mark it.
96 if (!InConstantPool) {
97 OutStreamer.EmitDataRegion(MCDR_DataRegion);
98 InConstantPool = true;
99 }
100
101 OutStreamer.EmitLabel(GetCPISymbol(LabelId));
102
103 const MachineConstantPoolEntry &MCPE = MCP->getConstants()[CPIdx];
104 if (MCPE.isMachineConstantPoolEntry())
105 EmitMachineConstantPoolValue(MCPE.Val.MachineCPVal);
106 else
107 EmitGlobalConstant(MCPE.Val.ConstVal);
108 return;
109 }
110
Akira Hatanaka5ac78682012-06-13 23:25:52 +0000111 MachineBasicBlock::const_instr_iterator I = MI;
112 MachineBasicBlock::const_instr_iterator E = MI->getParent()->instr_end();
113
114 do {
Akira Hatanaka556135d2013-02-06 21:50:15 +0000115 // Do any auto-generated pseudo lowerings.
116 if (emitPseudoExpansionLowering(OutStreamer, &*I))
117 continue;
Jack Carterc20a21b2012-08-28 19:07:39 +0000118
Reed Kotler76c9bcd2013-02-15 21:05:58 +0000119 // The inMips16Mode() test is not permanent.
120 // Some instructions are marked as pseudo right now which
121 // would make the test fail for the wrong reason but
122 // that will be fixed soon. We need this here because we are
123 // removing another test for this situation downstream in the
124 // callchain.
125 //
126 if (I->isPseudo() && !Subtarget->inMips16Mode())
127 llvm_unreachable("Pseudo opcode found in EmitInstruction()");
128
Akira Hatanaka556135d2013-02-06 21:50:15 +0000129 MCInst TmpInst0;
130 MCInstLowering.Lower(I, TmpInst0);
Akira Hatanaka5ac78682012-06-13 23:25:52 +0000131 OutStreamer.EmitInstruction(TmpInst0);
Akira Hatanaka556135d2013-02-06 21:50:15 +0000132 } while ((++I != E) && I->isInsideBundle()); // Delay slot check
Akira Hatanakaddd12652011-07-07 20:10:52 +0000133}
134
Akira Hatanakae2489122011-04-15 21:51:11 +0000135//===----------------------------------------------------------------------===//
Bruno Cardoso Lopescfd16382007-08-28 05:06:17 +0000136//
137// Mips Asm Directives
138//
139// -- Frame directive "frame Stackpointer, Stacksize, RARegister"
140// Describe the stack frame.
141//
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +0000142// -- Mask directives "(f)mask bitmask, offset"
Bruno Cardoso Lopescfd16382007-08-28 05:06:17 +0000143// Tells the assembler which registers are saved and where.
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +0000144// bitmask - contain a little endian bitset indicating which registers are
145// saved on function prologue (e.g. with a 0x80000000 mask, the
Bruno Cardoso Lopescfd16382007-08-28 05:06:17 +0000146// assembler knows the register 31 (RA) is saved at prologue.
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +0000147// offset - the position before stack pointer subtraction indicating where
Bruno Cardoso Lopescfd16382007-08-28 05:06:17 +0000148// the first saved register on prologue is located. (e.g. with a
149//
150// Consider the following function prologue:
151//
Bill Wendling97925ec2008-02-27 06:33:05 +0000152// .frame $fp,48,$ra
153// .mask 0xc0000000,-8
154// addiu $sp, $sp, -48
155// sw $ra, 40($sp)
156// sw $fp, 36($sp)
Bruno Cardoso Lopescfd16382007-08-28 05:06:17 +0000157//
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +0000158// With a 0xc0000000 mask, the assembler knows the register 31 (RA) and
159// 30 (FP) are saved at prologue. As the save order on prologue is from
160// left to right, RA is saved first. A -8 offset means that after the
Bruno Cardoso Lopescfd16382007-08-28 05:06:17 +0000161// stack pointer subtration, the first register in the mask (RA) will be
162// saved at address 48-8=40.
163//
Akira Hatanakae2489122011-04-15 21:51:11 +0000164//===----------------------------------------------------------------------===//
Bruno Cardoso Lopescfd16382007-08-28 05:06:17 +0000165
Akira Hatanakae2489122011-04-15 21:51:11 +0000166//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes80ab8f92008-07-14 14:42:54 +0000167// Mask directives
Akira Hatanakae2489122011-04-15 21:51:11 +0000168//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes80ab8f92008-07-14 14:42:54 +0000169
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +0000170// Create a bitmask with all callee saved registers for CPU or Floating Point
Bruno Cardoso Lopes4659aad2008-08-06 06:14:43 +0000171// registers. For CPU registers consider RA, GP and FP for saving if necessary.
Chris Lattner76c564b2010-04-04 04:47:45 +0000172void MipsAsmPrinter::printSavedRegsBitmask(raw_ostream &O) {
Bruno Cardoso Lopes4659aad2008-08-06 06:14:43 +0000173 // CPU and FPU Saved Registers Bitmasks
Akira Hatanaka90d96f42011-05-23 20:34:30 +0000174 unsigned CPUBitmask = 0, FPUBitmask = 0;
175 int CPUTopSavedRegOff, FPUTopSavedRegOff;
Bruno Cardoso Lopescfd16382007-08-28 05:06:17 +0000176
Bruno Cardoso Lopes4659aad2008-08-06 06:14:43 +0000177 // Set the CPU and FPU Bitmasks
Chris Lattnercc9a6f02010-01-28 06:22:43 +0000178 const MachineFrameInfo *MFI = MF->getFrameInfo();
Bruno Cardoso Lopescfd16382007-08-28 05:06:17 +0000179 const std::vector<CalleeSavedInfo> &CSI = MFI->getCalleeSavedInfo();
Akira Hatanaka90d96f42011-05-23 20:34:30 +0000180 // size of stack area to which FP callee-saved regs are saved.
Akira Hatanaka13e6ccf2013-08-06 23:08:38 +0000181 unsigned CPURegSize = Mips::GPR32RegClass.getSize();
Craig Topperc7242e02012-04-20 07:30:17 +0000182 unsigned FGR32RegSize = Mips::FGR32RegClass.getSize();
183 unsigned AFGR64RegSize = Mips::AFGR64RegClass.getSize();
Akira Hatanaka90d96f42011-05-23 20:34:30 +0000184 bool HasAFGR64Reg = false;
185 unsigned CSFPRegsSize = 0;
186 unsigned i, e = CSI.size();
187
188 // Set FPU Bitmask.
189 for (i = 0; i != e; ++i) {
Rafael Espindolaf2dffce2010-06-02 20:02:30 +0000190 unsigned Reg = CSI[i].getReg();
Akira Hatanaka13e6ccf2013-08-06 23:08:38 +0000191 if (Mips::GPR32RegClass.contains(Reg))
Akira Hatanaka90d96f42011-05-23 20:34:30 +0000192 break;
193
Akira Hatanaka5d6faed2012-12-10 20:04:40 +0000194 unsigned RegNum = TM.getRegisterInfo()->getEncodingValue(Reg);
Craig Topperc7242e02012-04-20 07:30:17 +0000195 if (Mips::AFGR64RegClass.contains(Reg)) {
Akira Hatanaka90d96f42011-05-23 20:34:30 +0000196 FPUBitmask |= (3 << RegNum);
197 CSFPRegsSize += AFGR64RegSize;
198 HasAFGR64Reg = true;
199 continue;
200 }
201
202 FPUBitmask |= (1 << RegNum);
203 CSFPRegsSize += FGR32RegSize;
Bruno Cardoso Lopes4659aad2008-08-06 06:14:43 +0000204 }
Bruno Cardoso Lopescfd16382007-08-28 05:06:17 +0000205
Akira Hatanaka90d96f42011-05-23 20:34:30 +0000206 // Set CPU Bitmask.
207 for (; i != e; ++i) {
208 unsigned Reg = CSI[i].getReg();
Akira Hatanaka5d6faed2012-12-10 20:04:40 +0000209 unsigned RegNum = TM.getRegisterInfo()->getEncodingValue(Reg);
Akira Hatanaka90d96f42011-05-23 20:34:30 +0000210 CPUBitmask |= (1 << RegNum);
211 }
Anton Korobeynikov0eecf5d2010-11-18 21:19:35 +0000212
Akira Hatanaka90d96f42011-05-23 20:34:30 +0000213 // FP Regs are saved right below where the virtual frame pointer points to.
214 FPUTopSavedRegOff = FPUBitmask ?
215 (HasAFGR64Reg ? -AFGR64RegSize : -FGR32RegSize) : 0;
216
217 // CPU Regs are saved below FP Regs.
218 CPUTopSavedRegOff = CPUBitmask ? -CSFPRegsSize - CPURegSize : 0;
Bruno Cardoso Lopescfd16382007-08-28 05:06:17 +0000219
Bruno Cardoso Lopes4659aad2008-08-06 06:14:43 +0000220 // Print CPUBitmask
Chris Lattner76c564b2010-04-04 04:47:45 +0000221 O << "\t.mask \t"; printHex32(CPUBitmask, O);
Akira Hatanaka90d96f42011-05-23 20:34:30 +0000222 O << ',' << CPUTopSavedRegOff << '\n';
Bruno Cardoso Lopes4659aad2008-08-06 06:14:43 +0000223
224 // Print FPUBitmask
Akira Hatanaka90d96f42011-05-23 20:34:30 +0000225 O << "\t.fmask\t"; printHex32(FPUBitmask, O);
226 O << "," << FPUTopSavedRegOff << '\n';
Bruno Cardoso Lopescfd16382007-08-28 05:06:17 +0000227}
228
229// Print a 32 bit hex number with all numbers.
Chris Lattner76c564b2010-04-04 04:47:45 +0000230void MipsAsmPrinter::printHex32(unsigned Value, raw_ostream &O) {
Owen Anderson93719642008-08-21 00:14:44 +0000231 O << "0x";
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +0000232 for (int i = 7; i >= 0; i--)
Benjamin Kramer20baffb2011-11-06 20:37:06 +0000233 O.write_hex((Value & (0xF << (i*4))) >> (i*4));
Bruno Cardoso Lopesbcda5e22007-07-11 23:24:41 +0000234}
235
Akira Hatanakae2489122011-04-15 21:51:11 +0000236//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes80ab8f92008-07-14 14:42:54 +0000237// Frame and Set directives
Akira Hatanakae2489122011-04-15 21:51:11 +0000238//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes80ab8f92008-07-14 14:42:54 +0000239
240/// Frame Directive
Chris Lattner5e596182010-04-04 07:05:53 +0000241void MipsAsmPrinter::emitFrameDirective() {
Bruno Cardoso Lopes80ab8f92008-07-14 14:42:54 +0000242 const TargetRegisterInfo &RI = *TM.getRegisterInfo();
243
Chris Lattnercc9a6f02010-01-28 06:22:43 +0000244 unsigned stackReg = RI.getFrameRegister(*MF);
Bruno Cardoso Lopes80ab8f92008-07-14 14:42:54 +0000245 unsigned returnReg = RI.getRARegister();
Chris Lattnercc9a6f02010-01-28 06:22:43 +0000246 unsigned stackSize = MF->getFrameInfo()->getStackSize();
Bruno Cardoso Lopes80ab8f92008-07-14 14:42:54 +0000247
Jia Liuf54f60f2012-02-28 07:46:26 +0000248 if (OutStreamer.hasRawTextSupport())
Bruno Cardoso Lopesd5edb382011-11-08 22:26:47 +0000249 OutStreamer.EmitRawText("\t.frame\t$" +
Benjamin Kramer20baffb2011-11-06 20:37:06 +0000250 StringRef(MipsInstPrinter::getRegisterName(stackReg)).lower() +
Akira Hatanaka9c6028f2011-07-07 23:56:50 +0000251 "," + Twine(stackSize) + ",$" +
Benjamin Kramer20baffb2011-11-06 20:37:06 +0000252 StringRef(MipsInstPrinter::getRegisterName(returnReg)).lower());
Bruno Cardoso Lopes80ab8f92008-07-14 14:42:54 +0000253}
254
255/// Emit Set directives.
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +0000256const char *MipsAsmPrinter::getCurrentABIString() const {
Chris Lattner5e596182010-04-04 07:05:53 +0000257 switch (Subtarget->getTargetABI()) {
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +0000258 case MipsSubtarget::O32: return "abi32";
Chris Lattner5e596182010-04-04 07:05:53 +0000259 case MipsSubtarget::N32: return "abiN32";
260 case MipsSubtarget::N64: return "abi64";
261 case MipsSubtarget::EABI: return "eabi32"; // TODO: handle eabi64
Dmitri Gribenkoca1e27b2012-09-10 21:26:47 +0000262 default: llvm_unreachable("Unknown Mips ABI");
Bruno Cardoso Lopes80ab8f92008-07-14 14:42:54 +0000263 }
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +0000264}
Bruno Cardoso Lopes80ab8f92008-07-14 14:42:54 +0000265
Chris Lattner5d9fb4b2010-01-27 23:23:58 +0000266void MipsAsmPrinter::EmitFunctionEntryLabel() {
Rafael Espindola6633d572014-01-14 18:57:12 +0000267 MipsTargetStreamer &TS = getTargetStreamer();
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000268 if (Subtarget->inMicroMipsMode())
Rafael Espindola6633d572014-01-14 18:57:12 +0000269 TS.emitDirectiveSetMicroMips();
270 // leave out until FSF available gas has micromips changes
271 // else
272 // TS.emitDirectiveSetNoMicroMips();
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000273
Rafael Espindola6633d572014-01-14 18:57:12 +0000274 if (Subtarget->inMips16Mode())
275 TS.emitDirectiveSetMips16();
276 else
277 TS.emitDirectiveSetNoMips16();
Jack Carterab3cb422013-02-19 22:04:37 +0000278
Rafael Espindola6633d572014-01-14 18:57:12 +0000279 TS.emitDirectiveEnt(*CurrentFnSym);
Chris Lattner5d9fb4b2010-01-27 23:23:58 +0000280 OutStreamer.EmitLabel(CurrentFnSym);
281}
282
Chris Lattnercc9a6f02010-01-28 06:22:43 +0000283/// EmitFunctionBodyStart - Targets can override this to emit stuff before
284/// the first basic block in the function.
285void MipsAsmPrinter::EmitFunctionBodyStart() {
Rafael Espindola7d78b2a2013-10-29 16:24:21 +0000286 MCInstLowering.Initialize(&MF->getContext());
Akira Hatanaka34ee3ff2012-03-28 00:22:50 +0000287
Reed Kotler0f2b10e2013-05-03 23:17:24 +0000288 bool IsNakedFunction =
289 MF->getFunction()->
290 getAttributes().hasAttribute(AttributeSet::FunctionIndex,
291 Attribute::Naked);
292 if (!IsNakedFunction)
293 emitFrameDirective();
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +0000294
Bruno Cardoso Lopesd5edb382011-11-08 22:26:47 +0000295 if (OutStreamer.hasRawTextSupport()) {
296 SmallString<128> Str;
297 raw_svector_ostream OS(Str);
Reed Kotler0f2b10e2013-05-03 23:17:24 +0000298 if (!IsNakedFunction)
299 printSavedRegsBitmask(OS);
Bruno Cardoso Lopesd5edb382011-11-08 22:26:47 +0000300 OutStreamer.EmitRawText(OS.str());
Reed Kotlerf0221472013-02-15 01:04:38 +0000301 if (!Subtarget->inMips16Mode()) {
302 OutStreamer.EmitRawText(StringRef("\t.set\tnoreorder"));
303 OutStreamer.EmitRawText(StringRef("\t.set\tnomacro"));
304 OutStreamer.EmitRawText(StringRef("\t.set\tnoat"));
305 }
Akira Hatanaka8f3573032012-05-12 00:48:43 +0000306 }
Chris Lattnercc9a6f02010-01-28 06:22:43 +0000307}
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000308
Chris Lattnercc9a6f02010-01-28 06:22:43 +0000309/// EmitFunctionBodyEnd - Targets can override this to emit stuff after
310/// the last basic block in the function.
311void MipsAsmPrinter::EmitFunctionBodyEnd() {
Chris Lattnerfd97a332010-01-28 01:48:52 +0000312 // There are instruction for this macros, but they must
313 // always be at the function end, and we can't emit and
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +0000314 // break with BB logic.
Bruno Cardoso Lopesd5edb382011-11-08 22:26:47 +0000315 if (OutStreamer.hasRawTextSupport()) {
Reed Kotlerf0221472013-02-15 01:04:38 +0000316 if (!Subtarget->inMips16Mode()) {
317 OutStreamer.EmitRawText(StringRef("\t.set\tat"));
318 OutStreamer.EmitRawText(StringRef("\t.set\tmacro"));
319 OutStreamer.EmitRawText(StringRef("\t.set\treorder"));
320 }
Bruno Cardoso Lopesd5edb382011-11-08 22:26:47 +0000321 OutStreamer.EmitRawText("\t.end\t" + Twine(CurrentFnSym->getName()));
322 }
Reed Kotler91ae9822013-10-27 21:57:36 +0000323 // Make sure to terminate any constant pools that were at the end
324 // of the function.
325 if (!InConstantPool)
326 return;
327 InConstantPool = false;
328 OutStreamer.EmitDataRegion(MCDR_DataRegionEnd);
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000329}
330
Bruno Cardoso Lopes160695f2010-07-20 08:37:04 +0000331/// isBlockOnlyReachableByFallthough - Return true if the basic block has
332/// exactly one predecessor and the control transfer mechanism between
333/// the predecessor and this block is a fall-through.
Akira Hatanakae2489122011-04-15 21:51:11 +0000334bool MipsAsmPrinter::isBlockOnlyReachableByFallthrough(const MachineBasicBlock*
335 MBB) const {
Bruno Cardoso Lopes160695f2010-07-20 08:37:04 +0000336 // The predecessor has to be immediately before this block.
337 const MachineBasicBlock *Pred = *MBB->pred_begin();
338
339 // If the predecessor is a switch statement, assume a jump table
340 // implementation, so it is not a fall through.
341 if (const BasicBlock *bb = Pred->getBasicBlock())
342 if (isa<SwitchInst>(bb->getTerminator()))
343 return false;
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +0000344
Akira Hatanakae625ba42011-04-01 18:57:38 +0000345 // If this is a landing pad, it isn't a fall through. If it has no preds,
346 // then nothing falls through to it.
347 if (MBB->isLandingPad() || MBB->pred_empty())
348 return false;
349
350 // If there isn't exactly one predecessor, it can't be a fall through.
351 MachineBasicBlock::const_pred_iterator PI = MBB->pred_begin(), PI2 = PI;
352 ++PI2;
Jia Liuf54f60f2012-02-28 07:46:26 +0000353
Akira Hatanakae625ba42011-04-01 18:57:38 +0000354 if (PI2 != MBB->pred_end())
Jia Liuf54f60f2012-02-28 07:46:26 +0000355 return false;
Akira Hatanakae625ba42011-04-01 18:57:38 +0000356
357 // The predecessor has to be immediately before this block.
358 if (!Pred->isLayoutSuccessor(MBB))
359 return false;
Jia Liuf54f60f2012-02-28 07:46:26 +0000360
Akira Hatanakae625ba42011-04-01 18:57:38 +0000361 // If the block is completely empty, then it definitely does fall through.
362 if (Pred->empty())
363 return true;
Jia Liuf54f60f2012-02-28 07:46:26 +0000364
Akira Hatanakae625ba42011-04-01 18:57:38 +0000365 // Otherwise, check the last instruction.
366 // Check if the last terminator is an unconditional branch.
367 MachineBasicBlock::const_iterator I = Pred->end();
Evan Cheng7f8e5632011-12-07 07:15:52 +0000368 while (I != Pred->begin() && !(--I)->isTerminator()) ;
Akira Hatanakae625ba42011-04-01 18:57:38 +0000369
Evan Cheng7f8e5632011-12-07 07:15:52 +0000370 return !I->isBarrier();
Bruno Cardoso Lopes160695f2010-07-20 08:37:04 +0000371}
372
Bruno Cardoso Lopes3d4bdcc2008-08-02 19:42:36 +0000373// Print out an operand for an inline asm expression.
Eric Christophered51b9e2012-05-10 21:48:22 +0000374bool MipsAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNum,
Chris Lattner3bb09762010-04-04 05:29:35 +0000375 unsigned AsmVariant,const char *ExtraCode,
376 raw_ostream &O) {
Bruno Cardoso Lopes3d4bdcc2008-08-02 19:42:36 +0000377 // Does this asm operand have a single letter operand modifier?
Eric Christophered51b9e2012-05-10 21:48:22 +0000378 if (ExtraCode && ExtraCode[0]) {
379 if (ExtraCode[1] != 0) return true; // Unknown modifier.
Bruno Cardoso Lopes3d4bdcc2008-08-02 19:42:36 +0000380
Eric Christophered51b9e2012-05-10 21:48:22 +0000381 const MachineOperand &MO = MI->getOperand(OpNum);
382 switch (ExtraCode[0]) {
Eric Christopherbc5d2492012-05-19 00:51:56 +0000383 default:
Jack Carterb2fd5f62012-06-21 17:14:46 +0000384 // See if this is a generic print operand
385 return AsmPrinter::PrintAsmOperand(MI,OpNum,AsmVariant,ExtraCode,O);
Eric Christopherbc5d2492012-05-19 00:51:56 +0000386 case 'X': // hex const int
387 if ((MO.getType()) != MachineOperand::MO_Immediate)
388 return true;
389 O << "0x" << StringRef(utohexstr(MO.getImm())).lower();
390 return false;
391 case 'x': // hex const int (low 16 bits)
392 if ((MO.getType()) != MachineOperand::MO_Immediate)
393 return true;
394 O << "0x" << StringRef(utohexstr(MO.getImm() & 0xffff)).lower();
395 return false;
396 case 'd': // decimal const int
397 if ((MO.getType()) != MachineOperand::MO_Immediate)
398 return true;
399 O << MO.getImm();
400 return false;
Eric Christopherf481ab32012-05-30 19:05:19 +0000401 case 'm': // decimal const int minus 1
402 if ((MO.getType()) != MachineOperand::MO_Immediate)
403 return true;
404 O << MO.getImm() - 1;
405 return false;
Jack Carter27747b52012-06-28 20:46:26 +0000406 case 'z': {
407 // $0 if zero, regular printing otherwise
Jack Carter6c0bc0b2012-06-28 01:33:40 +0000408 if (MO.getType() != MachineOperand::MO_Immediate)
409 return true;
410 int64_t Val = MO.getImm();
411 if (Val)
412 O << Val;
413 else
414 O << "$0";
415 return false;
416 }
Jack Cartere8cb2fc2012-07-10 22:41:20 +0000417 case 'D': // Second part of a double word register operand
418 case 'L': // Low order register of a double word register operand
Jack Cartera62ba822012-07-18 06:41:36 +0000419 case 'M': // High order register of a double word register operand
Jack Cartere8cb2fc2012-07-10 22:41:20 +0000420 {
Jack Carterb2af5122012-07-05 23:58:21 +0000421 if (OpNum == 0)
422 return true;
423 const MachineOperand &FlagsOP = MI->getOperand(OpNum - 1);
424 if (!FlagsOP.isImm())
425 return true;
426 unsigned Flags = FlagsOP.getImm();
427 unsigned NumVals = InlineAsm::getNumOperandRegisters(Flags);
Jack Carter2ab73b12012-07-06 02:44:22 +0000428 // Number of registers represented by this operand. We are looking
429 // for 2 for 32 bit mode and 1 for 64 bit mode.
Jack Carterb2af5122012-07-05 23:58:21 +0000430 if (NumVals != 2) {
Jack Carter2ab73b12012-07-06 02:44:22 +0000431 if (Subtarget->isGP64bit() && NumVals == 1 && MO.isReg()) {
Jack Carterb2af5122012-07-05 23:58:21 +0000432 unsigned Reg = MO.getReg();
433 O << '$' << MipsInstPrinter::getRegisterName(Reg);
434 return false;
435 }
436 return true;
437 }
Jack Carter42ebf982012-07-11 21:41:49 +0000438
439 unsigned RegOp = OpNum;
440 if (!Subtarget->isGP64bit()){
Jack Cartere8cb2fc2012-07-10 22:41:20 +0000441 // Endianess reverses which register holds the high or low value
Jack Cartera62ba822012-07-18 06:41:36 +0000442 // between M and L.
Jack Cartere8cb2fc2012-07-10 22:41:20 +0000443 switch(ExtraCode[0]) {
Jack Cartera62ba822012-07-18 06:41:36 +0000444 case 'M':
445 RegOp = (Subtarget->isLittle()) ? OpNum + 1 : OpNum;
Jack Cartere8cb2fc2012-07-10 22:41:20 +0000446 break;
447 case 'L':
Jack Cartera62ba822012-07-18 06:41:36 +0000448 RegOp = (Subtarget->isLittle()) ? OpNum : OpNum + 1;
449 break;
450 case 'D': // Always the second part
451 RegOp = OpNum + 1;
Jack Cartere8cb2fc2012-07-10 22:41:20 +0000452 }
453 if (RegOp >= MI->getNumOperands())
454 return true;
455 const MachineOperand &MO = MI->getOperand(RegOp);
456 if (!MO.isReg())
457 return true;
458 unsigned Reg = MO.getReg();
459 O << '$' << MipsInstPrinter::getRegisterName(Reg);
460 return false;
Jack Carterb2af5122012-07-05 23:58:21 +0000461 }
Eric Christophered51b9e2012-05-10 21:48:22 +0000462 }
Daniel Sanders8b59af12013-11-12 12:56:01 +0000463 case 'w':
464 // Print MSA registers for the 'f' constraint
465 // In LLVM, the 'w' modifier doesn't need to do anything.
466 // We can just call printOperand as normal.
467 break;
Jack Carter2ab73b12012-07-06 02:44:22 +0000468 }
469 }
Eric Christophered51b9e2012-05-10 21:48:22 +0000470
471 printOperand(MI, OpNum, O);
Bruno Cardoso Lopes3d4bdcc2008-08-02 19:42:36 +0000472 return false;
473}
474
Akira Hatanaka4c406e72011-06-21 00:40:49 +0000475bool MipsAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,
476 unsigned OpNum, unsigned AsmVariant,
477 const char *ExtraCode,
478 raw_ostream &O) {
Jack Carterb04e3572013-04-09 23:19:50 +0000479 int Offset = 0;
480 // Currently we are expecting either no ExtraCode or 'D'
481 if (ExtraCode) {
482 if (ExtraCode[0] == 'D')
483 Offset = 4;
484 else
485 return true; // Unknown modifier.
486 }
Jia Liuf54f60f2012-02-28 07:46:26 +0000487
Akira Hatanaka4c406e72011-06-21 00:40:49 +0000488 const MachineOperand &MO = MI->getOperand(OpNum);
489 assert(MO.isReg() && "unexpected inline asm memory operand");
Jack Carterb04e3572013-04-09 23:19:50 +0000490 O << Offset << "($" << MipsInstPrinter::getRegisterName(MO.getReg()) << ")";
Jack Carter6c0bc0b2012-06-28 01:33:40 +0000491
Akira Hatanaka4c406e72011-06-21 00:40:49 +0000492 return false;
493}
494
Chris Lattner76c564b2010-04-04 04:47:45 +0000495void MipsAsmPrinter::printOperand(const MachineInstr *MI, int opNum,
496 raw_ostream &O) {
Rafael Espindola58873562014-01-03 19:21:54 +0000497 const DataLayout *DL = TM.getDataLayout();
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000498 const MachineOperand &MO = MI->getOperand(opNum);
Bruno Cardoso Lopes3e0d0302007-11-05 03:02:32 +0000499 bool closeP = false;
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000500
Bruno Cardoso Lopes0f20a5b2009-09-01 17:27:58 +0000501 if (MO.getTargetFlags())
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000502 closeP = true;
Bruno Cardoso Lopes0f20a5b2009-09-01 17:27:58 +0000503
504 switch(MO.getTargetFlags()) {
505 case MipsII::MO_GPREL: O << "%gp_rel("; break;
506 case MipsII::MO_GOT_CALL: O << "%call16("; break;
Akira Hatanaka56d9ef52011-04-01 21:41:06 +0000507 case MipsII::MO_GOT: O << "%got("; break;
508 case MipsII::MO_ABS_HI: O << "%hi("; break;
509 case MipsII::MO_ABS_LO: O << "%lo("; break;
Bruno Cardoso Lopesbf3c1252011-05-31 02:53:58 +0000510 case MipsII::MO_TLSGD: O << "%tlsgd("; break;
511 case MipsII::MO_GOTTPREL: O << "%gottprel("; break;
512 case MipsII::MO_TPREL_HI: O << "%tprel_hi("; break;
513 case MipsII::MO_TPREL_LO: O << "%tprel_lo("; break;
Akira Hatanaka25ce3642011-09-22 03:09:07 +0000514 case MipsII::MO_GPOFF_HI: O << "%hi(%neg(%gp_rel("; break;
515 case MipsII::MO_GPOFF_LO: O << "%lo(%neg(%gp_rel("; break;
516 case MipsII::MO_GOT_DISP: O << "%got_disp("; break;
517 case MipsII::MO_GOT_PAGE: O << "%got_page("; break;
518 case MipsII::MO_GOT_OFST: O << "%got_ofst("; break;
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000519 }
Bruno Cardoso Lopes0f20a5b2009-09-01 17:27:58 +0000520
Chris Lattnereb2cc682009-09-13 20:31:40 +0000521 switch (MO.getType()) {
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000522 case MachineOperand::MO_Register:
Akira Hatanaka9c6028f2011-07-07 23:56:50 +0000523 O << '$'
Benjamin Kramer20baffb2011-11-06 20:37:06 +0000524 << StringRef(MipsInstPrinter::getRegisterName(MO.getReg())).lower();
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000525 break;
526
527 case MachineOperand::MO_Immediate:
Akira Hatanaka2db176c2011-05-24 21:22:21 +0000528 O << MO.getImm();
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000529 break;
530
531 case MachineOperand::MO_MachineBasicBlock:
Chris Lattner29bdac42010-03-13 21:04:28 +0000532 O << *MO.getMBB()->getSymbol();
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000533 return;
534
535 case MachineOperand::MO_GlobalAddress:
Rafael Espindola79858aa2013-10-29 17:07:16 +0000536 O << *getSymbol(MO.getGlobal());
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000537 break;
538
Bruno Cardoso Lopesf8198e42011-03-04 20:01:52 +0000539 case MachineOperand::MO_BlockAddress: {
Akira Hatanaka5fd22482012-06-14 21:10:56 +0000540 MCSymbol *BA = GetBlockAddressSymbol(MO.getBlockAddress());
Bruno Cardoso Lopesf8198e42011-03-04 20:01:52 +0000541 O << BA->getName();
542 break;
543 }
544
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000545 case MachineOperand::MO_ConstantPoolIndex:
Rafael Espindola58873562014-01-03 19:21:54 +0000546 O << DL->getPrivateGlobalPrefix() << "CPI"
Chris Lattnera5bb3702007-12-30 23:10:15 +0000547 << getFunctionNumber() << "_" << MO.getIndex();
Bruno Cardoso Lopes4713b282009-11-19 06:06:13 +0000548 if (MO.getOffset())
549 O << "+" << MO.getOffset();
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000550 break;
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +0000551
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000552 default:
Torok Edwinfbcc6632009-07-14 16:55:14 +0000553 llvm_unreachable("<unknown operand type>");
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000554 }
555
556 if (closeP) O << ")";
557}
558
Chris Lattner76c564b2010-04-04 04:47:45 +0000559void MipsAsmPrinter::printUnsignedImm(const MachineInstr *MI, int opNum,
560 raw_ostream &O) {
Bruno Cardoso Lopes92c64ae2008-08-13 07:13:40 +0000561 const MachineOperand &MO = MI->getOperand(opNum);
Devang Patel12f68552010-04-27 22:24:37 +0000562 if (MO.isImm())
Bruno Cardoso Lopes92c64ae2008-08-13 07:13:40 +0000563 O << (unsigned short int)MO.getImm();
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +0000564 else
Chris Lattner76c564b2010-04-04 04:47:45 +0000565 printOperand(MI, opNum, O);
Bruno Cardoso Lopes92c64ae2008-08-13 07:13:40 +0000566}
567
Daniel Sanders3f6eb542013-11-12 10:45:18 +0000568void MipsAsmPrinter::printUnsignedImm8(const MachineInstr *MI, int opNum,
569 raw_ostream &O) {
570 const MachineOperand &MO = MI->getOperand(opNum);
571 if (MO.isImm())
572 O << (unsigned short int)(unsigned char)MO.getImm();
573 else
574 printOperand(MI, opNum, O);
575}
576
Bruno Cardoso Lopes92c64ae2008-08-13 07:13:40 +0000577void MipsAsmPrinter::
Akira Hatanaka9f6f6f62011-07-07 20:54:20 +0000578printMemOperand(const MachineInstr *MI, int opNum, raw_ostream &O) {
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +0000579 // Load/Store memory operands -- imm($reg)
580 // If PIC target the target is loaded as the
Bruno Cardoso Lopes3e0d0302007-11-05 03:02:32 +0000581 // pattern lw $25,%call16($28)
Chris Lattner76c564b2010-04-04 04:47:45 +0000582 printOperand(MI, opNum+1, O);
Akira Hatanaka2e766ed2011-07-07 18:57:00 +0000583 O << "(";
584 printOperand(MI, opNum, O);
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000585 O << ")";
586}
587
Bruno Cardoso Lopesc9c3f492008-07-05 19:05:21 +0000588void MipsAsmPrinter::
Akira Hatanaka9f6f6f62011-07-07 20:54:20 +0000589printMemOperandEA(const MachineInstr *MI, int opNum, raw_ostream &O) {
590 // when using stack locations for not load/store instructions
591 // print the same way as all normal 3 operand instructions.
592 printOperand(MI, opNum, O);
593 O << ", ";
594 printOperand(MI, opNum+1, O);
595 return;
596}
597
598void MipsAsmPrinter::
Chris Lattner76c564b2010-04-04 04:47:45 +0000599printFCCOperand(const MachineInstr *MI, int opNum, raw_ostream &O,
600 const char *Modifier) {
Akira Hatanaka5fd22482012-06-14 21:10:56 +0000601 const MachineOperand &MO = MI->getOperand(opNum);
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +0000602 O << Mips::MipsFCCToString((Mips::CondCode)MO.getImm());
Bruno Cardoso Lopesc9c3f492008-07-05 19:05:21 +0000603}
604
Bob Wilsonb633d7a2009-09-30 22:06:26 +0000605void MipsAsmPrinter::EmitStartOfAsmFile(Module &M) {
Chris Lattner4b7dadb2009-08-19 05:49:37 +0000606 // FIXME: Use SwitchSection.
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +0000607
Jack Carterf9f753c2013-06-18 19:47:15 +0000608 // TODO: Need to add -mabicalls and -mno-abicalls flags.
609 // Currently we assume that -mabicalls is the default.
Jack Carter0cd3c192014-01-06 23:27:31 +0000610 getTargetStreamer().emitDirectiveAbiCalls();
611 Reloc::Model RM = Subtarget->getRelocationModel();
612 if (RM == Reloc::Static && !Subtarget->hasMips64())
613 getTargetStreamer().emitDirectiveOptionPic0();
Jack Carterf9f753c2013-06-18 19:47:15 +0000614
Bruno Cardoso Lopes80ab8f92008-07-14 14:42:54 +0000615 // Tell the assembler which ABI we are using
Bruno Cardoso Lopesd5edb382011-11-08 22:26:47 +0000616 if (OutStreamer.hasRawTextSupport())
Akira Hatanaka9e1d3692011-12-19 19:52:25 +0000617 OutStreamer.EmitRawText("\t.section .mdebug." +
618 Twine(getCurrentABIString()));
Bruno Cardoso Lopes80ab8f92008-07-14 14:42:54 +0000619
620 // TODO: handle O64 ABI
Bruno Cardoso Lopesd5edb382011-11-08 22:26:47 +0000621 if (OutStreamer.hasRawTextSupport()) {
622 if (Subtarget->isABI_EABI()) {
623 if (Subtarget->isGP32bit())
624 OutStreamer.EmitRawText(StringRef("\t.section .gcc_compiled_long32"));
625 else
626 OutStreamer.EmitRawText(StringRef("\t.section .gcc_compiled_long64"));
627 }
Benjamin Kramer0151d7b2010-04-05 10:17:15 +0000628 }
Bruno Cardoso Lopes80ab8f92008-07-14 14:42:54 +0000629
630 // return to previous section
Bruno Cardoso Lopesd5edb382011-11-08 22:26:47 +0000631 if (OutStreamer.hasRawTextSupport())
632 OutStreamer.EmitRawText(StringRef("\t.previous"));
Jack Carterc1b17ed2013-01-18 21:20:38 +0000633
634}
635
Jack Carterca2ae492014-01-25 00:24:07 +0000636void MipsAsmPrinter::processInitialEFlags() {
637 // Not having this check would work too, but would have us chew through
638 // code that it doesn't use for RawText.
639 if (OutStreamer.hasRawTextSupport())
640 return;
641
Rafael Espindolaac4ad252013-10-05 16:42:21 +0000642 // Update e_header flags
643 unsigned EFlags = 0;
644
645 // TODO: Need to add -mabicalls and -mno-abicalls flags.
646 // Currently we assume that -mabicalls is the default.
647 EFlags |= ELF::EF_MIPS_CPIC;
648
Jack Carterca2ae492014-01-25 00:24:07 +0000649 if (Subtarget->inMips16Mode())
Rafael Espindolaac4ad252013-10-05 16:42:21 +0000650 EFlags |= ELF::EF_MIPS_ARCH_ASE_M16;
651 else
652 EFlags |= ELF::EF_MIPS_NOREORDER;
653
654 // Architecture
Jack Carterca2ae492014-01-25 00:24:07 +0000655 if (Subtarget->hasMips64r2())
Rafael Espindolaac4ad252013-10-05 16:42:21 +0000656 EFlags |= ELF::EF_MIPS_ARCH_64R2;
Jack Carterca2ae492014-01-25 00:24:07 +0000657 else if (Subtarget->hasMips64())
Rafael Espindolaac4ad252013-10-05 16:42:21 +0000658 EFlags |= ELF::EF_MIPS_ARCH_64;
Jack Carterca2ae492014-01-25 00:24:07 +0000659 else if (Subtarget->hasMips32r2())
Rafael Espindolaac4ad252013-10-05 16:42:21 +0000660 EFlags |= ELF::EF_MIPS_ARCH_32R2;
661 else
662 EFlags |= ELF::EF_MIPS_ARCH_32;
663
Jack Carterca2ae492014-01-25 00:24:07 +0000664 if (Subtarget->inMicroMipsMode())
Rafael Espindolaac4ad252013-10-05 16:42:21 +0000665 EFlags |= ELF::EF_MIPS_MICROMIPS;
666
667 // ABI
Jack Carterca2ae492014-01-25 00:24:07 +0000668 if (Subtarget->isABI_O32())
Rafael Espindolaac4ad252013-10-05 16:42:21 +0000669 EFlags |= ELF::EF_MIPS_ABI_O32;
670
671 // Relocation Model
Jack Carterca2ae492014-01-25 00:24:07 +0000672 Reloc::Model RM = Subtarget->getRelocationModel();
Rafael Espindolaac4ad252013-10-05 16:42:21 +0000673 if (RM == Reloc::PIC_ || RM == Reloc::Default)
674 EFlags |= ELF::EF_MIPS_PIC;
675 else if (RM == Reloc::Static)
676 ; // Do nothing for Reloc::Static
677 else
678 llvm_unreachable("Unsupported relocation model for e_flags");
679
Jack Carterca2ae492014-01-25 00:24:07 +0000680 getTargetStreamer().emitMipsELFFlags(EFlags);
Rafael Espindolaac4ad252013-10-05 16:42:21 +0000681}
682
Jack Carterc1b17ed2013-01-18 21:20:38 +0000683void MipsAsmPrinter::EmitEndOfAsmFile(Module &M) {
Jack Carterc1b17ed2013-01-18 21:20:38 +0000684 // Emit Mips ELF register info
685 Subtarget->getMReginfo().emitMipsReginfoSectionCG(
686 OutStreamer, getObjFileLowering(), *Subtarget);
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000687}
688
Akira Hatanakaf2bcad92011-07-01 01:04:43 +0000689void MipsAsmPrinter::PrintDebugValueComment(const MachineInstr *MI,
690 raw_ostream &OS) {
691 // TODO: implement
692}
693
Bob Wilson5a495fe2009-06-23 23:59:40 +0000694// Force static initialization.
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +0000695extern "C" void LLVMInitializeMipsAsmPrinter() {
Daniel Dunbar5680b4f2009-07-25 06:49:55 +0000696 RegisterAsmPrinter<MipsAsmPrinter> X(TheMipsTarget);
697 RegisterAsmPrinter<MipsAsmPrinter> Y(TheMipselTarget);
Akira Hatanaka3d673cc2011-09-21 03:00:58 +0000698 RegisterAsmPrinter<MipsAsmPrinter> A(TheMips64Target);
699 RegisterAsmPrinter<MipsAsmPrinter> B(TheMips64elTarget);
Daniel Dunbare8338102009-07-15 20:24:03 +0000700}