blob: c662e13d89ade1312250620ef38e5ffbf595f8a9 [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
Akira Hatanaka9c6028f2011-07-07 23:56:50 +000015#include "InstPrinter/MipsInstPrinter.h"
Bruno Cardoso Lopesc85e3ff2011-11-11 22:58:42 +000016#include "MCTargetDesc/MipsBaseInfo.h"
Sasa Stankovic8c5736b2014-02-28 10:00:38 +000017#include "MCTargetDesc/MipsMCNaCl.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"
Eric Christophera5762812015-01-26 17:33:46 +000022#include "MipsTargetMachine.h"
Rafael Espindolaa17151a2013-10-08 13:08:17 +000023#include "MipsTargetStreamer.h"
Bruno Cardoso Lopesd5edb382011-11-08 22:26:47 +000024#include "llvm/ADT/SmallString.h"
25#include "llvm/ADT/StringExtras.h"
26#include "llvm/ADT/Twine.h"
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000027#include "llvm/CodeGen/MachineConstantPool.h"
Bruno Cardoso Lopesbcda5e22007-07-11 23:24:41 +000028#include "llvm/CodeGen/MachineFrameInfo.h"
Jack Carterb2af5122012-07-05 23:58:21 +000029#include "llvm/CodeGen/MachineFunctionPass.h"
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000030#include "llvm/CodeGen/MachineInstr.h"
Sasa Stankovic8c5736b2014-02-28 10:00:38 +000031#include "llvm/CodeGen/MachineJumpTableInfo.h"
Akira Hatanaka2fcc1cf2011-08-12 21:30:06 +000032#include "llvm/CodeGen/MachineMemOperand.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000033#include "llvm/IR/BasicBlock.h"
34#include "llvm/IR/DataLayout.h"
35#include "llvm/IR/InlineAsm.h"
36#include "llvm/IR/Instructions.h"
Rafael Espindola894843c2014-01-07 21:19:40 +000037#include "llvm/IR/Mangler.h"
Chris Lattner7b26fce2009-08-22 20:48:53 +000038#include "llvm/MC/MCAsmInfo.h"
Rafael Espindola2ab7ea72014-01-27 01:33:33 +000039#include "llvm/MC/MCContext.h"
Rafael Espindolaac4ad252013-10-05 16:42:21 +000040#include "llvm/MC/MCELFStreamer.h"
Reed Kotler4cdaa7d2014-02-14 19:16:39 +000041#include "llvm/MC/MCExpr.h"
Akira Hatanaka9c6028f2011-07-07 23:56:50 +000042#include "llvm/MC/MCInst.h"
Reed Kotler4cdaa7d2014-02-14 19:16:39 +000043#include "llvm/MC/MCSection.h"
Rafael Espindola2ab7ea72014-01-27 01:33:33 +000044#include "llvm/MC/MCSectionELF.h"
Chris Lattner4cd44982009-09-13 17:14:04 +000045#include "llvm/MC/MCSymbol.h"
Jack Carterab3cb422013-02-19 22:04:37 +000046#include "llvm/Support/ELF.h"
Jack Carterb2af5122012-07-05 23:58:21 +000047#include "llvm/Support/TargetRegistry.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000048#include "llvm/Support/raw_ostream.h"
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +000049#include "llvm/Target/TargetLoweringObjectFile.h"
Bruno Cardoso Lopesb4391322007-11-12 19:49:57 +000050#include "llvm/Target/TargetOptions.h"
Reed Kotler4cdaa7d2014-02-14 19:16:39 +000051#include <string>
Akira Hatanakaf2bcad92011-07-01 01:04:43 +000052
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000053using namespace llvm;
54
Chandler Carruth84e68b22014-04-22 02:41:26 +000055#define DEBUG_TYPE "mips-asm-printer"
56
Toma Tabacua23f13c2014-12-17 10:56:16 +000057MipsTargetStreamer &MipsAsmPrinter::getTargetStreamer() const {
Rafael Espindola4a1a3602014-01-14 01:21:46 +000058 return static_cast<MipsTargetStreamer &>(*OutStreamer.getTargetStreamer());
Rafael Espindolaa17151a2013-10-08 13:08:17 +000059}
60
Akira Hatanaka34ee3ff2012-03-28 00:22:50 +000061bool MipsAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
Eric Christopher3ee30d02015-02-20 08:39:06 +000062 Subtarget = &MF.getSubtarget<MipsSubtarget>();
Eric Christopher8ef7a6a2014-07-18 00:08:53 +000063
Reed Kotler1595f362013-04-09 19:46:01 +000064 // Initialize TargetLoweringObjectFile.
Eric Christopher4e7d1e72014-07-18 23:41:32 +000065 const_cast<TargetLoweringObjectFile &>(getObjFileLowering())
Reed Kotler1595f362013-04-09 19:46:01 +000066 .Initialize(OutContext, TM);
Eric Christopher4e7d1e72014-07-18 23:41:32 +000067
Akira Hatanaka34ee3ff2012-03-28 00:22:50 +000068 MipsFI = MF.getInfo<MipsFunctionInfo>();
Reed Kotler4cdaa7d2014-02-14 19:16:39 +000069 if (Subtarget->inMips16Mode())
70 for (std::map<
71 const char *,
72 const llvm::Mips16HardFloatInfo::FuncSignature *>::const_iterator
73 it = MipsFI->StubsNeeded.begin();
74 it != MipsFI->StubsNeeded.end(); ++it) {
75 const char *Symbol = it->first;
76 const llvm::Mips16HardFloatInfo::FuncSignature *Signature = it->second;
77 if (StubsNeeded.find(Symbol) == StubsNeeded.end())
78 StubsNeeded[Symbol] = Signature;
79 }
Reed Kotler91ae9822013-10-27 21:57:36 +000080 MCP = MF.getConstantPool();
Sasa Stankovic8c5736b2014-02-28 10:00:38 +000081
82 // In NaCl, all indirect jump targets must be aligned to bundle size.
83 if (Subtarget->isTargetNaCl())
84 NaClAlignIndirectJumpTargets(MF);
85
Akira Hatanaka34ee3ff2012-03-28 00:22:50 +000086 AsmPrinter::runOnMachineFunction(MF);
87 return true;
Bruno Cardoso Lopesd5edb382011-11-08 22:26:47 +000088}
89
Akira Hatanaka42a35242012-09-27 01:59:07 +000090bool MipsAsmPrinter::lowerOperand(const MachineOperand &MO, MCOperand &MCOp) {
91 MCOp = MCInstLowering.LowerOperand(MO);
92 return MCOp.isValid();
93}
94
95#include "MipsGenMCPseudoLowering.inc"
96
Daniel Sandersf5a5fbd2014-07-09 10:21:59 +000097// Lower PseudoReturn/PseudoIndirectBranch/PseudoIndirectBranch64 to JR, JR_MM,
98// JALR, or JALR64 as appropriate for the target
99void MipsAsmPrinter::emitPseudoIndirectBranch(MCStreamer &OutStreamer,
100 const MachineInstr *MI) {
Daniel Sanders338513b2014-07-09 10:16:07 +0000101 bool HasLinkReg = false;
102 MCInst TmpInst0;
103
104 if (Subtarget->hasMips64r6()) {
105 // MIPS64r6 should use (JALR64 ZERO_64, $rs)
106 TmpInst0.setOpcode(Mips::JALR64);
107 HasLinkReg = true;
108 } else if (Subtarget->hasMips32r6()) {
109 // MIPS32r6 should use (JALR ZERO, $rs)
110 TmpInst0.setOpcode(Mips::JALR);
111 HasLinkReg = true;
112 } else if (Subtarget->inMicroMipsMode())
113 // microMIPS should use (JR_MM $rs)
114 TmpInst0.setOpcode(Mips::JR_MM);
115 else {
116 // Everything else should use (JR $rs)
117 TmpInst0.setOpcode(Mips::JR);
118 }
119
120 MCOperand MCOp;
121
122 if (HasLinkReg) {
123 unsigned ZeroReg = Subtarget->isGP64bit() ? Mips::ZERO_64 : Mips::ZERO;
124 TmpInst0.addOperand(MCOperand::CreateReg(ZeroReg));
125 }
126
127 lowerOperand(MI->getOperand(0), MCOp);
128 TmpInst0.addOperand(MCOp);
129
130 EmitToStreamer(OutStreamer, TmpInst0);
131}
132
Akira Hatanakaddd12652011-07-07 20:10:52 +0000133void MipsAsmPrinter::EmitInstruction(const MachineInstr *MI) {
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000134 MipsTargetStreamer &TS = getTargetStreamer();
Daniel Sanderscdb45fa2014-08-14 09:18:14 +0000135 TS.forbidModuleDirective();
Daniel Sandersc7dbc632014-07-08 10:11:38 +0000136
Akira Hatanakaddd12652011-07-07 20:10:52 +0000137 if (MI->isDebugValue()) {
Bruno Cardoso Lopescd1d4472011-12-30 21:09:41 +0000138 SmallString<128> Str;
139 raw_svector_ostream OS(Str);
140
Akira Hatanakaddd12652011-07-07 20:10:52 +0000141 PrintDebugValueComment(MI, OS);
142 return;
143 }
144
Reed Kotler91ae9822013-10-27 21:57:36 +0000145 // If we just ended a constant pool, mark it as such.
146 if (InConstantPool && MI->getOpcode() != Mips::CONSTPOOL_ENTRY) {
147 OutStreamer.EmitDataRegion(MCDR_DataRegionEnd);
148 InConstantPool = false;
149 }
150 if (MI->getOpcode() == Mips::CONSTPOOL_ENTRY) {
151 // CONSTPOOL_ENTRY - This instruction represents a floating
152 //constant pool in the function. The first operand is the ID#
153 // for this instruction, the second is the index into the
154 // MachineConstantPool that this is, the third is the size in
155 // bytes of this constant pool entry.
156 // The required alignment is specified on the basic block holding this MI.
157 //
158 unsigned LabelId = (unsigned)MI->getOperand(0).getImm();
159 unsigned CPIdx = (unsigned)MI->getOperand(1).getIndex();
160
161 // If this is the first entry of the pool, mark it.
162 if (!InConstantPool) {
163 OutStreamer.EmitDataRegion(MCDR_DataRegion);
164 InConstantPool = true;
165 }
166
167 OutStreamer.EmitLabel(GetCPISymbol(LabelId));
168
169 const MachineConstantPoolEntry &MCPE = MCP->getConstants()[CPIdx];
170 if (MCPE.isMachineConstantPoolEntry())
171 EmitMachineConstantPoolValue(MCPE.Val.MachineCPVal);
172 else
173 EmitGlobalConstant(MCPE.Val.ConstVal);
174 return;
175 }
176
Rafael Espindola14d02fe2014-01-25 15:06:56 +0000177
Akira Hatanaka5ac78682012-06-13 23:25:52 +0000178 MachineBasicBlock::const_instr_iterator I = MI;
179 MachineBasicBlock::const_instr_iterator E = MI->getParent()->instr_end();
180
181 do {
Akira Hatanaka556135d2013-02-06 21:50:15 +0000182 // Do any auto-generated pseudo lowerings.
183 if (emitPseudoExpansionLowering(OutStreamer, &*I))
184 continue;
Jack Carterc20a21b2012-08-28 19:07:39 +0000185
Daniel Sanders338513b2014-07-09 10:16:07 +0000186 if (I->getOpcode() == Mips::PseudoReturn ||
Daniel Sandersf5a5fbd2014-07-09 10:21:59 +0000187 I->getOpcode() == Mips::PseudoReturn64 ||
188 I->getOpcode() == Mips::PseudoIndirectBranch ||
189 I->getOpcode() == Mips::PseudoIndirectBranch64) {
190 emitPseudoIndirectBranch(OutStreamer, &*I);
Daniel Sanders338513b2014-07-09 10:16:07 +0000191 continue;
192 }
193
Reed Kotler76c9bcd2013-02-15 21:05:58 +0000194 // The inMips16Mode() test is not permanent.
195 // Some instructions are marked as pseudo right now which
196 // would make the test fail for the wrong reason but
197 // that will be fixed soon. We need this here because we are
198 // removing another test for this situation downstream in the
199 // callchain.
200 //
Sasa Stankovic7b061a42014-04-30 15:06:25 +0000201 if (I->isPseudo() && !Subtarget->inMips16Mode()
202 && !isLongBranchPseudo(I->getOpcode()))
Reed Kotler76c9bcd2013-02-15 21:05:58 +0000203 llvm_unreachable("Pseudo opcode found in EmitInstruction()");
204
Akira Hatanaka556135d2013-02-06 21:50:15 +0000205 MCInst TmpInst0;
206 MCInstLowering.Lower(I, TmpInst0);
David Woodhousee6c13e42014-01-28 23:12:42 +0000207 EmitToStreamer(OutStreamer, TmpInst0);
Akira Hatanaka556135d2013-02-06 21:50:15 +0000208 } while ((++I != E) && I->isInsideBundle()); // Delay slot check
Akira Hatanakaddd12652011-07-07 20:10:52 +0000209}
210
Akira Hatanakae2489122011-04-15 21:51:11 +0000211//===----------------------------------------------------------------------===//
Bruno Cardoso Lopescfd16382007-08-28 05:06:17 +0000212//
213// Mips Asm Directives
214//
215// -- Frame directive "frame Stackpointer, Stacksize, RARegister"
216// Describe the stack frame.
217//
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +0000218// -- Mask directives "(f)mask bitmask, offset"
Bruno Cardoso Lopescfd16382007-08-28 05:06:17 +0000219// Tells the assembler which registers are saved and where.
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +0000220// bitmask - contain a little endian bitset indicating which registers are
221// saved on function prologue (e.g. with a 0x80000000 mask, the
Bruno Cardoso Lopescfd16382007-08-28 05:06:17 +0000222// assembler knows the register 31 (RA) is saved at prologue.
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +0000223// offset - the position before stack pointer subtraction indicating where
Bruno Cardoso Lopescfd16382007-08-28 05:06:17 +0000224// the first saved register on prologue is located. (e.g. with a
225//
226// Consider the following function prologue:
227//
Bill Wendling97925ec2008-02-27 06:33:05 +0000228// .frame $fp,48,$ra
229// .mask 0xc0000000,-8
230// addiu $sp, $sp, -48
231// sw $ra, 40($sp)
232// sw $fp, 36($sp)
Bruno Cardoso Lopescfd16382007-08-28 05:06:17 +0000233//
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +0000234// With a 0xc0000000 mask, the assembler knows the register 31 (RA) and
235// 30 (FP) are saved at prologue. As the save order on prologue is from
236// left to right, RA is saved first. A -8 offset means that after the
Bruno Cardoso Lopescfd16382007-08-28 05:06:17 +0000237// stack pointer subtration, the first register in the mask (RA) will be
238// saved at address 48-8=40.
239//
Akira Hatanakae2489122011-04-15 21:51:11 +0000240//===----------------------------------------------------------------------===//
Bruno Cardoso Lopescfd16382007-08-28 05:06:17 +0000241
Akira Hatanakae2489122011-04-15 21:51:11 +0000242//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes80ab8f92008-07-14 14:42:54 +0000243// Mask directives
Akira Hatanakae2489122011-04-15 21:51:11 +0000244//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes80ab8f92008-07-14 14:42:54 +0000245
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +0000246// Create a bitmask with all callee saved registers for CPU or Floating Point
Bruno Cardoso Lopes4659aad2008-08-06 06:14:43 +0000247// registers. For CPU registers consider RA, GP and FP for saving if necessary.
Rafael Espindola25fa2912014-01-27 04:33:11 +0000248void MipsAsmPrinter::printSavedRegsBitmask() {
Bruno Cardoso Lopes4659aad2008-08-06 06:14:43 +0000249 // CPU and FPU Saved Registers Bitmasks
Akira Hatanaka90d96f42011-05-23 20:34:30 +0000250 unsigned CPUBitmask = 0, FPUBitmask = 0;
251 int CPUTopSavedRegOff, FPUTopSavedRegOff;
Bruno Cardoso Lopescfd16382007-08-28 05:06:17 +0000252
Bruno Cardoso Lopes4659aad2008-08-06 06:14:43 +0000253 // Set the CPU and FPU Bitmasks
Chris Lattnercc9a6f02010-01-28 06:22:43 +0000254 const MachineFrameInfo *MFI = MF->getFrameInfo();
Bruno Cardoso Lopescfd16382007-08-28 05:06:17 +0000255 const std::vector<CalleeSavedInfo> &CSI = MFI->getCalleeSavedInfo();
Akira Hatanaka90d96f42011-05-23 20:34:30 +0000256 // size of stack area to which FP callee-saved regs are saved.
Akira Hatanaka13e6ccf2013-08-06 23:08:38 +0000257 unsigned CPURegSize = Mips::GPR32RegClass.getSize();
Craig Topperc7242e02012-04-20 07:30:17 +0000258 unsigned FGR32RegSize = Mips::FGR32RegClass.getSize();
259 unsigned AFGR64RegSize = Mips::AFGR64RegClass.getSize();
Akira Hatanaka90d96f42011-05-23 20:34:30 +0000260 bool HasAFGR64Reg = false;
261 unsigned CSFPRegsSize = 0;
262 unsigned i, e = CSI.size();
263
264 // Set FPU Bitmask.
265 for (i = 0; i != e; ++i) {
Rafael Espindolaf2dffce2010-06-02 20:02:30 +0000266 unsigned Reg = CSI[i].getReg();
Akira Hatanaka13e6ccf2013-08-06 23:08:38 +0000267 if (Mips::GPR32RegClass.contains(Reg))
Akira Hatanaka90d96f42011-05-23 20:34:30 +0000268 break;
269
Eric Christopherd9134482014-08-04 21:25:23 +0000270 unsigned RegNum =
271 TM.getSubtargetImpl()->getRegisterInfo()->getEncodingValue(Reg);
Craig Topperc7242e02012-04-20 07:30:17 +0000272 if (Mips::AFGR64RegClass.contains(Reg)) {
Akira Hatanaka90d96f42011-05-23 20:34:30 +0000273 FPUBitmask |= (3 << RegNum);
274 CSFPRegsSize += AFGR64RegSize;
275 HasAFGR64Reg = true;
276 continue;
277 }
278
279 FPUBitmask |= (1 << RegNum);
280 CSFPRegsSize += FGR32RegSize;
Bruno Cardoso Lopes4659aad2008-08-06 06:14:43 +0000281 }
Bruno Cardoso Lopescfd16382007-08-28 05:06:17 +0000282
Akira Hatanaka90d96f42011-05-23 20:34:30 +0000283 // Set CPU Bitmask.
284 for (; i != e; ++i) {
285 unsigned Reg = CSI[i].getReg();
Eric Christopherd9134482014-08-04 21:25:23 +0000286 unsigned RegNum =
287 TM.getSubtargetImpl()->getRegisterInfo()->getEncodingValue(Reg);
Akira Hatanaka90d96f42011-05-23 20:34:30 +0000288 CPUBitmask |= (1 << RegNum);
289 }
Anton Korobeynikov0eecf5d2010-11-18 21:19:35 +0000290
Akira Hatanaka90d96f42011-05-23 20:34:30 +0000291 // FP Regs are saved right below where the virtual frame pointer points to.
292 FPUTopSavedRegOff = FPUBitmask ?
293 (HasAFGR64Reg ? -AFGR64RegSize : -FGR32RegSize) : 0;
294
295 // CPU Regs are saved below FP Regs.
296 CPUTopSavedRegOff = CPUBitmask ? -CSFPRegsSize - CPURegSize : 0;
Bruno Cardoso Lopescfd16382007-08-28 05:06:17 +0000297
Rafael Espindola25fa2912014-01-27 04:33:11 +0000298 MipsTargetStreamer &TS = getTargetStreamer();
Bruno Cardoso Lopes4659aad2008-08-06 06:14:43 +0000299 // Print CPUBitmask
Rafael Espindola25fa2912014-01-27 04:33:11 +0000300 TS.emitMask(CPUBitmask, CPUTopSavedRegOff);
Bruno Cardoso Lopes4659aad2008-08-06 06:14:43 +0000301
302 // Print FPUBitmask
Rafael Espindola25fa2912014-01-27 04:33:11 +0000303 TS.emitFMask(FPUBitmask, FPUTopSavedRegOff);
Bruno Cardoso Lopesbcda5e22007-07-11 23:24:41 +0000304}
305
Akira Hatanakae2489122011-04-15 21:51:11 +0000306//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes80ab8f92008-07-14 14:42:54 +0000307// Frame and Set directives
Akira Hatanakae2489122011-04-15 21:51:11 +0000308//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes80ab8f92008-07-14 14:42:54 +0000309
310/// Frame Directive
Chris Lattner5e596182010-04-04 07:05:53 +0000311void MipsAsmPrinter::emitFrameDirective() {
Eric Christopherd9134482014-08-04 21:25:23 +0000312 const TargetRegisterInfo &RI = *TM.getSubtargetImpl()->getRegisterInfo();
Bruno Cardoso Lopes80ab8f92008-07-14 14:42:54 +0000313
Chris Lattnercc9a6f02010-01-28 06:22:43 +0000314 unsigned stackReg = RI.getFrameRegister(*MF);
Bruno Cardoso Lopes80ab8f92008-07-14 14:42:54 +0000315 unsigned returnReg = RI.getRARegister();
Chris Lattnercc9a6f02010-01-28 06:22:43 +0000316 unsigned stackSize = MF->getFrameInfo()->getStackSize();
Bruno Cardoso Lopes80ab8f92008-07-14 14:42:54 +0000317
Rafael Espindola054234f2014-01-27 03:53:56 +0000318 getTargetStreamer().emitFrame(stackReg, stackSize, returnReg);
Bruno Cardoso Lopes80ab8f92008-07-14 14:42:54 +0000319}
320
321/// Emit Set directives.
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +0000322const char *MipsAsmPrinter::getCurrentABIString() const {
Eric Christophera5762812015-01-26 17:33:46 +0000323 switch (static_cast<MipsTargetMachine &>(TM).getABI().GetEnumValue()) {
Daniel Sanderse2e25da2014-10-24 16:15:27 +0000324 case MipsABIInfo::ABI::O32: return "abi32";
325 case MipsABIInfo::ABI::N32: return "abiN32";
326 case MipsABIInfo::ABI::N64: return "abi64";
327 case MipsABIInfo::ABI::EABI: return "eabi32"; // TODO: handle eabi64
Dmitri Gribenkoca1e27b2012-09-10 21:26:47 +0000328 default: llvm_unreachable("Unknown Mips ABI");
Bruno Cardoso Lopes80ab8f92008-07-14 14:42:54 +0000329 }
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +0000330}
Bruno Cardoso Lopes80ab8f92008-07-14 14:42:54 +0000331
Chris Lattner5d9fb4b2010-01-27 23:23:58 +0000332void MipsAsmPrinter::EmitFunctionEntryLabel() {
Rafael Espindola6633d572014-01-14 18:57:12 +0000333 MipsTargetStreamer &TS = getTargetStreamer();
Sasa Stankovic8c5736b2014-02-28 10:00:38 +0000334
335 // NaCl sandboxing requires that indirect call instructions are masked.
336 // This means that function entry points should be bundle-aligned.
337 if (Subtarget->isTargetNaCl())
338 EmitAlignment(std::max(MF->getAlignment(), MIPS_NACL_BUNDLE_ALIGN));
339
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000340 if (Subtarget->inMicroMipsMode())
Rafael Espindola6633d572014-01-14 18:57:12 +0000341 TS.emitDirectiveSetMicroMips();
Matheus Almeidadc7e48e2014-04-16 11:46:59 +0000342 else
343 TS.emitDirectiveSetNoMicroMips();
Rafael Espindola6d5f7ce2014-01-14 04:25:13 +0000344
Rafael Espindola6633d572014-01-14 18:57:12 +0000345 if (Subtarget->inMips16Mode())
346 TS.emitDirectiveSetMips16();
347 else
348 TS.emitDirectiveSetNoMips16();
Jack Carterab3cb422013-02-19 22:04:37 +0000349
Rafael Espindola6633d572014-01-14 18:57:12 +0000350 TS.emitDirectiveEnt(*CurrentFnSym);
Chris Lattner5d9fb4b2010-01-27 23:23:58 +0000351 OutStreamer.EmitLabel(CurrentFnSym);
352}
353
Chris Lattnercc9a6f02010-01-28 06:22:43 +0000354/// EmitFunctionBodyStart - Targets can override this to emit stuff before
355/// the first basic block in the function.
356void MipsAsmPrinter::EmitFunctionBodyStart() {
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000357 MipsTargetStreamer &TS = getTargetStreamer();
358
Rafael Espindola7d78b2a2013-10-29 16:24:21 +0000359 MCInstLowering.Initialize(&MF->getContext());
Akira Hatanaka34ee3ff2012-03-28 00:22:50 +0000360
Duncan P. N. Exon Smith2e753142015-02-14 02:37:48 +0000361 bool IsNakedFunction = MF->getFunction()->hasFnAttribute(Attribute::Naked);
Reed Kotler0f2b10e2013-05-03 23:17:24 +0000362 if (!IsNakedFunction)
363 emitFrameDirective();
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +0000364
Rafael Espindola25fa2912014-01-27 04:33:11 +0000365 if (!IsNakedFunction)
366 printSavedRegsBitmask();
367
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000368 if (!Subtarget->inMips16Mode()) {
369 TS.emitDirectiveSetNoReorder();
370 TS.emitDirectiveSetNoMacro();
371 TS.emitDirectiveSetNoAt();
Akira Hatanaka8f3573032012-05-12 00:48:43 +0000372 }
Chris Lattnercc9a6f02010-01-28 06:22:43 +0000373}
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000374
Chris Lattnercc9a6f02010-01-28 06:22:43 +0000375/// EmitFunctionBodyEnd - Targets can override this to emit stuff after
376/// the last basic block in the function.
377void MipsAsmPrinter::EmitFunctionBodyEnd() {
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000378 MipsTargetStreamer &TS = getTargetStreamer();
379
Chris Lattnerfd97a332010-01-28 01:48:52 +0000380 // There are instruction for this macros, but they must
381 // always be at the function end, and we can't emit and
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +0000382 // break with BB logic.
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000383 if (!Subtarget->inMips16Mode()) {
384 TS.emitDirectiveSetAt();
385 TS.emitDirectiveSetMacro();
386 TS.emitDirectiveSetReorder();
Bruno Cardoso Lopesd5edb382011-11-08 22:26:47 +0000387 }
Rafael Espindolaeb0a8af2014-01-26 05:06:48 +0000388 TS.emitDirectiveEnd(CurrentFnSym->getName());
Reed Kotler91ae9822013-10-27 21:57:36 +0000389 // Make sure to terminate any constant pools that were at the end
390 // of the function.
391 if (!InConstantPool)
392 return;
393 InConstantPool = false;
394 OutStreamer.EmitDataRegion(MCDR_DataRegionEnd);
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000395}
396
Bruno Cardoso Lopes160695f2010-07-20 08:37:04 +0000397/// isBlockOnlyReachableByFallthough - Return true if the basic block has
398/// exactly one predecessor and the control transfer mechanism between
399/// the predecessor and this block is a fall-through.
Akira Hatanakae2489122011-04-15 21:51:11 +0000400bool MipsAsmPrinter::isBlockOnlyReachableByFallthrough(const MachineBasicBlock*
401 MBB) const {
Bruno Cardoso Lopes160695f2010-07-20 08:37:04 +0000402 // The predecessor has to be immediately before this block.
403 const MachineBasicBlock *Pred = *MBB->pred_begin();
404
405 // If the predecessor is a switch statement, assume a jump table
406 // implementation, so it is not a fall through.
407 if (const BasicBlock *bb = Pred->getBasicBlock())
408 if (isa<SwitchInst>(bb->getTerminator()))
409 return false;
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +0000410
Akira Hatanakae625ba42011-04-01 18:57:38 +0000411 // If this is a landing pad, it isn't a fall through. If it has no preds,
412 // then nothing falls through to it.
413 if (MBB->isLandingPad() || MBB->pred_empty())
414 return false;
415
416 // If there isn't exactly one predecessor, it can't be a fall through.
417 MachineBasicBlock::const_pred_iterator PI = MBB->pred_begin(), PI2 = PI;
418 ++PI2;
Jia Liuf54f60f2012-02-28 07:46:26 +0000419
Akira Hatanakae625ba42011-04-01 18:57:38 +0000420 if (PI2 != MBB->pred_end())
Jia Liuf54f60f2012-02-28 07:46:26 +0000421 return false;
Akira Hatanakae625ba42011-04-01 18:57:38 +0000422
423 // The predecessor has to be immediately before this block.
424 if (!Pred->isLayoutSuccessor(MBB))
425 return false;
Jia Liuf54f60f2012-02-28 07:46:26 +0000426
Akira Hatanakae625ba42011-04-01 18:57:38 +0000427 // If the block is completely empty, then it definitely does fall through.
428 if (Pred->empty())
429 return true;
Jia Liuf54f60f2012-02-28 07:46:26 +0000430
Akira Hatanakae625ba42011-04-01 18:57:38 +0000431 // Otherwise, check the last instruction.
432 // Check if the last terminator is an unconditional branch.
433 MachineBasicBlock::const_iterator I = Pred->end();
Evan Cheng7f8e5632011-12-07 07:15:52 +0000434 while (I != Pred->begin() && !(--I)->isTerminator()) ;
Akira Hatanakae625ba42011-04-01 18:57:38 +0000435
Evan Cheng7f8e5632011-12-07 07:15:52 +0000436 return !I->isBarrier();
Bruno Cardoso Lopes160695f2010-07-20 08:37:04 +0000437}
438
Bruno Cardoso Lopes3d4bdcc2008-08-02 19:42:36 +0000439// Print out an operand for an inline asm expression.
Eric Christophered51b9e2012-05-10 21:48:22 +0000440bool MipsAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNum,
Chris Lattner3bb09762010-04-04 05:29:35 +0000441 unsigned AsmVariant,const char *ExtraCode,
442 raw_ostream &O) {
Bruno Cardoso Lopes3d4bdcc2008-08-02 19:42:36 +0000443 // Does this asm operand have a single letter operand modifier?
Eric Christophered51b9e2012-05-10 21:48:22 +0000444 if (ExtraCode && ExtraCode[0]) {
445 if (ExtraCode[1] != 0) return true; // Unknown modifier.
Bruno Cardoso Lopes3d4bdcc2008-08-02 19:42:36 +0000446
Eric Christophered51b9e2012-05-10 21:48:22 +0000447 const MachineOperand &MO = MI->getOperand(OpNum);
448 switch (ExtraCode[0]) {
Eric Christopherbc5d2492012-05-19 00:51:56 +0000449 default:
Jack Carterb2fd5f62012-06-21 17:14:46 +0000450 // See if this is a generic print operand
451 return AsmPrinter::PrintAsmOperand(MI,OpNum,AsmVariant,ExtraCode,O);
Eric Christopherbc5d2492012-05-19 00:51:56 +0000452 case 'X': // hex const int
453 if ((MO.getType()) != MachineOperand::MO_Immediate)
454 return true;
455 O << "0x" << StringRef(utohexstr(MO.getImm())).lower();
456 return false;
457 case 'x': // hex const int (low 16 bits)
458 if ((MO.getType()) != MachineOperand::MO_Immediate)
459 return true;
460 O << "0x" << StringRef(utohexstr(MO.getImm() & 0xffff)).lower();
461 return false;
462 case 'd': // decimal const int
463 if ((MO.getType()) != MachineOperand::MO_Immediate)
464 return true;
465 O << MO.getImm();
466 return false;
Eric Christopherf481ab32012-05-30 19:05:19 +0000467 case 'm': // decimal const int minus 1
468 if ((MO.getType()) != MachineOperand::MO_Immediate)
469 return true;
470 O << MO.getImm() - 1;
471 return false;
Jack Carter27747b52012-06-28 20:46:26 +0000472 case 'z': {
473 // $0 if zero, regular printing otherwise
Toma Tabacu27cab752014-11-06 14:25:42 +0000474 if (MO.getType() == MachineOperand::MO_Immediate && MO.getImm() == 0) {
Jack Carter6c0bc0b2012-06-28 01:33:40 +0000475 O << "$0";
Toma Tabacu27cab752014-11-06 14:25:42 +0000476 return false;
477 }
478 // If not, call printOperand as normal.
479 break;
Jack Carter6c0bc0b2012-06-28 01:33:40 +0000480 }
Jack Cartere8cb2fc2012-07-10 22:41:20 +0000481 case 'D': // Second part of a double word register operand
482 case 'L': // Low order register of a double word register operand
Jack Cartera62ba822012-07-18 06:41:36 +0000483 case 'M': // High order register of a double word register operand
Jack Cartere8cb2fc2012-07-10 22:41:20 +0000484 {
Jack Carterb2af5122012-07-05 23:58:21 +0000485 if (OpNum == 0)
486 return true;
487 const MachineOperand &FlagsOP = MI->getOperand(OpNum - 1);
488 if (!FlagsOP.isImm())
489 return true;
490 unsigned Flags = FlagsOP.getImm();
491 unsigned NumVals = InlineAsm::getNumOperandRegisters(Flags);
Jack Carter2ab73b12012-07-06 02:44:22 +0000492 // Number of registers represented by this operand. We are looking
493 // for 2 for 32 bit mode and 1 for 64 bit mode.
Jack Carterb2af5122012-07-05 23:58:21 +0000494 if (NumVals != 2) {
Jack Carter2ab73b12012-07-06 02:44:22 +0000495 if (Subtarget->isGP64bit() && NumVals == 1 && MO.isReg()) {
Jack Carterb2af5122012-07-05 23:58:21 +0000496 unsigned Reg = MO.getReg();
497 O << '$' << MipsInstPrinter::getRegisterName(Reg);
498 return false;
499 }
500 return true;
501 }
Jack Carter42ebf982012-07-11 21:41:49 +0000502
503 unsigned RegOp = OpNum;
504 if (!Subtarget->isGP64bit()){
Jack Cartere8cb2fc2012-07-10 22:41:20 +0000505 // Endianess reverses which register holds the high or low value
Jack Cartera62ba822012-07-18 06:41:36 +0000506 // between M and L.
Jack Cartere8cb2fc2012-07-10 22:41:20 +0000507 switch(ExtraCode[0]) {
Jack Cartera62ba822012-07-18 06:41:36 +0000508 case 'M':
509 RegOp = (Subtarget->isLittle()) ? OpNum + 1 : OpNum;
Jack Cartere8cb2fc2012-07-10 22:41:20 +0000510 break;
511 case 'L':
Jack Cartera62ba822012-07-18 06:41:36 +0000512 RegOp = (Subtarget->isLittle()) ? OpNum : OpNum + 1;
513 break;
514 case 'D': // Always the second part
515 RegOp = OpNum + 1;
Jack Cartere8cb2fc2012-07-10 22:41:20 +0000516 }
517 if (RegOp >= MI->getNumOperands())
518 return true;
519 const MachineOperand &MO = MI->getOperand(RegOp);
520 if (!MO.isReg())
521 return true;
522 unsigned Reg = MO.getReg();
523 O << '$' << MipsInstPrinter::getRegisterName(Reg);
524 return false;
Jack Carterb2af5122012-07-05 23:58:21 +0000525 }
Eric Christophered51b9e2012-05-10 21:48:22 +0000526 }
Daniel Sanders8b59af12013-11-12 12:56:01 +0000527 case 'w':
528 // Print MSA registers for the 'f' constraint
529 // In LLVM, the 'w' modifier doesn't need to do anything.
530 // We can just call printOperand as normal.
531 break;
Jack Carter2ab73b12012-07-06 02:44:22 +0000532 }
533 }
Eric Christophered51b9e2012-05-10 21:48:22 +0000534
535 printOperand(MI, OpNum, O);
Bruno Cardoso Lopes3d4bdcc2008-08-02 19:42:36 +0000536 return false;
537}
538
Akira Hatanaka4c406e72011-06-21 00:40:49 +0000539bool MipsAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,
540 unsigned OpNum, unsigned AsmVariant,
541 const char *ExtraCode,
542 raw_ostream &O) {
Jack Carterb04e3572013-04-09 23:19:50 +0000543 int Offset = 0;
544 // Currently we are expecting either no ExtraCode or 'D'
545 if (ExtraCode) {
546 if (ExtraCode[0] == 'D')
547 Offset = 4;
548 else
549 return true; // Unknown modifier.
550 }
Jia Liuf54f60f2012-02-28 07:46:26 +0000551
Akira Hatanaka4c406e72011-06-21 00:40:49 +0000552 const MachineOperand &MO = MI->getOperand(OpNum);
553 assert(MO.isReg() && "unexpected inline asm memory operand");
Jack Carterb04e3572013-04-09 23:19:50 +0000554 O << Offset << "($" << MipsInstPrinter::getRegisterName(MO.getReg()) << ")";
Jack Carter6c0bc0b2012-06-28 01:33:40 +0000555
Akira Hatanaka4c406e72011-06-21 00:40:49 +0000556 return false;
557}
558
Chris Lattner76c564b2010-04-04 04:47:45 +0000559void MipsAsmPrinter::printOperand(const MachineInstr *MI, int opNum,
560 raw_ostream &O) {
Eric Christopher8b770652015-01-26 19:03:15 +0000561 const DataLayout *DL = TM.getDataLayout();
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000562 const MachineOperand &MO = MI->getOperand(opNum);
Bruno Cardoso Lopes3e0d0302007-11-05 03:02:32 +0000563 bool closeP = false;
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000564
Bruno Cardoso Lopes0f20a5b2009-09-01 17:27:58 +0000565 if (MO.getTargetFlags())
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000566 closeP = true;
Bruno Cardoso Lopes0f20a5b2009-09-01 17:27:58 +0000567
568 switch(MO.getTargetFlags()) {
569 case MipsII::MO_GPREL: O << "%gp_rel("; break;
570 case MipsII::MO_GOT_CALL: O << "%call16("; break;
Akira Hatanaka56d9ef52011-04-01 21:41:06 +0000571 case MipsII::MO_GOT: O << "%got("; break;
572 case MipsII::MO_ABS_HI: O << "%hi("; break;
573 case MipsII::MO_ABS_LO: O << "%lo("; break;
Bruno Cardoso Lopesbf3c1252011-05-31 02:53:58 +0000574 case MipsII::MO_TLSGD: O << "%tlsgd("; break;
575 case MipsII::MO_GOTTPREL: O << "%gottprel("; break;
576 case MipsII::MO_TPREL_HI: O << "%tprel_hi("; break;
577 case MipsII::MO_TPREL_LO: O << "%tprel_lo("; break;
Akira Hatanaka25ce3642011-09-22 03:09:07 +0000578 case MipsII::MO_GPOFF_HI: O << "%hi(%neg(%gp_rel("; break;
579 case MipsII::MO_GPOFF_LO: O << "%lo(%neg(%gp_rel("; break;
580 case MipsII::MO_GOT_DISP: O << "%got_disp("; break;
581 case MipsII::MO_GOT_PAGE: O << "%got_page("; break;
582 case MipsII::MO_GOT_OFST: O << "%got_ofst("; break;
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000583 }
Bruno Cardoso Lopes0f20a5b2009-09-01 17:27:58 +0000584
Chris Lattnereb2cc682009-09-13 20:31:40 +0000585 switch (MO.getType()) {
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000586 case MachineOperand::MO_Register:
Akira Hatanaka9c6028f2011-07-07 23:56:50 +0000587 O << '$'
Benjamin Kramer20baffb2011-11-06 20:37:06 +0000588 << StringRef(MipsInstPrinter::getRegisterName(MO.getReg())).lower();
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000589 break;
590
591 case MachineOperand::MO_Immediate:
Akira Hatanaka2db176c2011-05-24 21:22:21 +0000592 O << MO.getImm();
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000593 break;
594
595 case MachineOperand::MO_MachineBasicBlock:
Chris Lattner29bdac42010-03-13 21:04:28 +0000596 O << *MO.getMBB()->getSymbol();
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000597 return;
598
599 case MachineOperand::MO_GlobalAddress:
Rafael Espindola79858aa2013-10-29 17:07:16 +0000600 O << *getSymbol(MO.getGlobal());
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000601 break;
602
Bruno Cardoso Lopesf8198e42011-03-04 20:01:52 +0000603 case MachineOperand::MO_BlockAddress: {
Akira Hatanaka5fd22482012-06-14 21:10:56 +0000604 MCSymbol *BA = GetBlockAddressSymbol(MO.getBlockAddress());
Bruno Cardoso Lopesf8198e42011-03-04 20:01:52 +0000605 O << BA->getName();
606 break;
607 }
608
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000609 case MachineOperand::MO_ConstantPoolIndex:
Rafael Espindola58873562014-01-03 19:21:54 +0000610 O << DL->getPrivateGlobalPrefix() << "CPI"
Chris Lattnera5bb3702007-12-30 23:10:15 +0000611 << getFunctionNumber() << "_" << MO.getIndex();
Bruno Cardoso Lopes4713b282009-11-19 06:06:13 +0000612 if (MO.getOffset())
613 O << "+" << MO.getOffset();
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000614 break;
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +0000615
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000616 default:
Torok Edwinfbcc6632009-07-14 16:55:14 +0000617 llvm_unreachable("<unknown operand type>");
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000618 }
619
620 if (closeP) O << ")";
621}
622
Chris Lattner76c564b2010-04-04 04:47:45 +0000623void MipsAsmPrinter::printUnsignedImm(const MachineInstr *MI, int opNum,
624 raw_ostream &O) {
Bruno Cardoso Lopes92c64ae2008-08-13 07:13:40 +0000625 const MachineOperand &MO = MI->getOperand(opNum);
Devang Patel12f68552010-04-27 22:24:37 +0000626 if (MO.isImm())
Bruno Cardoso Lopes92c64ae2008-08-13 07:13:40 +0000627 O << (unsigned short int)MO.getImm();
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +0000628 else
Chris Lattner76c564b2010-04-04 04:47:45 +0000629 printOperand(MI, opNum, O);
Bruno Cardoso Lopes92c64ae2008-08-13 07:13:40 +0000630}
631
Daniel Sanders3f6eb542013-11-12 10:45:18 +0000632void MipsAsmPrinter::printUnsignedImm8(const MachineInstr *MI, int opNum,
633 raw_ostream &O) {
634 const MachineOperand &MO = MI->getOperand(opNum);
635 if (MO.isImm())
636 O << (unsigned short int)(unsigned char)MO.getImm();
637 else
638 printOperand(MI, opNum, O);
639}
640
Bruno Cardoso Lopes92c64ae2008-08-13 07:13:40 +0000641void MipsAsmPrinter::
Akira Hatanaka9f6f6f62011-07-07 20:54:20 +0000642printMemOperand(const MachineInstr *MI, int opNum, raw_ostream &O) {
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +0000643 // Load/Store memory operands -- imm($reg)
644 // If PIC target the target is loaded as the
Bruno Cardoso Lopes3e0d0302007-11-05 03:02:32 +0000645 // pattern lw $25,%call16($28)
Zoran Jovanovica4c4b5f2014-11-19 16:44:02 +0000646
647 // opNum can be invalid if instruction has reglist as operand.
648 // MemOperand is always last operand of instruction (base + offset).
649 switch (MI->getOpcode()) {
650 default:
651 break;
652 case Mips::SWM32_MM:
653 case Mips::LWM32_MM:
654 opNum = MI->getNumOperands() - 2;
655 break;
656 }
657
Chris Lattner76c564b2010-04-04 04:47:45 +0000658 printOperand(MI, opNum+1, O);
Akira Hatanaka2e766ed2011-07-07 18:57:00 +0000659 O << "(";
660 printOperand(MI, opNum, O);
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000661 O << ")";
662}
663
Bruno Cardoso Lopesc9c3f492008-07-05 19:05:21 +0000664void MipsAsmPrinter::
Akira Hatanaka9f6f6f62011-07-07 20:54:20 +0000665printMemOperandEA(const MachineInstr *MI, int opNum, raw_ostream &O) {
666 // when using stack locations for not load/store instructions
667 // print the same way as all normal 3 operand instructions.
668 printOperand(MI, opNum, O);
669 O << ", ";
670 printOperand(MI, opNum+1, O);
671 return;
672}
673
674void MipsAsmPrinter::
Chris Lattner76c564b2010-04-04 04:47:45 +0000675printFCCOperand(const MachineInstr *MI, int opNum, raw_ostream &O,
676 const char *Modifier) {
Akira Hatanaka5fd22482012-06-14 21:10:56 +0000677 const MachineOperand &MO = MI->getOperand(opNum);
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +0000678 O << Mips::MipsFCCToString((Mips::CondCode)MO.getImm());
Bruno Cardoso Lopesc9c3f492008-07-05 19:05:21 +0000679}
680
Zoran Jovanovica4c4b5f2014-11-19 16:44:02 +0000681void MipsAsmPrinter::
682printRegisterList(const MachineInstr *MI, int opNum, raw_ostream &O) {
683 for (int i = opNum, e = MI->getNumOperands(); i != e; ++i) {
684 if (i != opNum) O << ", ";
685 printOperand(MI, i, O);
686 }
687}
688
Bob Wilsonb633d7a2009-09-30 22:06:26 +0000689void MipsAsmPrinter::EmitStartOfAsmFile(Module &M) {
Eric Christopher8af49b32015-02-18 01:01:57 +0000690
691 // Compute MIPS architecture attributes based on the default subtarget
692 // that we'd have constructed. Module level directives aren't LTO
693 // clean anyhow.
694 // FIXME: For ifunc related functions we could iterate over and look
695 // for a feature string that doesn't match the default one.
696 StringRef TT = TM.getTargetTriple();
697 StringRef CPU =
698 MIPS_MC::selectMipsCPU(TM.getTargetTriple(), TM.getTargetCPU());
699 StringRef FS = TM.getTargetFeatureString();
700 const MipsTargetMachine &MTM = static_cast<const MipsTargetMachine &>(TM);
701 const MipsSubtarget STI(TT, CPU, FS, MTM.isLittleEndian(), MTM);
702
703 bool IsABICalls = STI.isABICalls();
704 const MipsABIInfo &ABI = MTM.getABI();
Daniel Sanders16fa1db2014-04-16 13:58:57 +0000705 if (IsABICalls) {
706 getTargetStreamer().emitDirectiveAbiCalls();
Eric Christopher8ef7a6a2014-07-18 00:08:53 +0000707 Reloc::Model RM = TM.getRelocationModel();
Daniel Sanders16fa1db2014-04-16 13:58:57 +0000708 // FIXME: This condition should be a lot more complicated that it is here.
709 // Ideally it should test for properties of the ABI and not the ABI
710 // itself.
711 // For the moment, I'm only correcting enough to make MIPS-IV work.
Eric Christopherd86af632015-01-29 23:27:45 +0000712 if (RM == Reloc::Static && !ABI.IsN64())
Daniel Sanders16fa1db2014-04-16 13:58:57 +0000713 getTargetStreamer().emitDirectiveOptionPic0();
714 }
Jack Carterf9f753c2013-06-18 19:47:15 +0000715
Bruno Cardoso Lopes80ab8f92008-07-14 14:42:54 +0000716 // Tell the assembler which ABI we are using
Rafael Espindola2ab7ea72014-01-27 01:33:33 +0000717 std::string SectionName = std::string(".mdebug.") + getCurrentABIString();
Rafael Espindolaba31e272015-01-29 17:33:21 +0000718 OutStreamer.SwitchSection(
719 OutContext.getELFSection(SectionName, ELF::SHT_PROGBITS, 0));
Bruno Cardoso Lopes80ab8f92008-07-14 14:42:54 +0000720
Matheus Almeida0051f2d2014-04-16 15:48:55 +0000721 // NaN: At the moment we only support:
722 // 1. .nan legacy (default)
723 // 2. .nan 2008
Eric Christopher8af49b32015-02-18 01:01:57 +0000724 STI.isNaN2008() ? getTargetStreamer().emitDirectiveNaN2008()
725 : getTargetStreamer().emitDirectiveNaNLegacy();
Matheus Almeida0051f2d2014-04-16 15:48:55 +0000726
Bruno Cardoso Lopes80ab8f92008-07-14 14:42:54 +0000727 // TODO: handle O64 ABI
Rafael Espindola2ab7ea72014-01-27 01:33:33 +0000728
Eric Christopherd86af632015-01-29 23:27:45 +0000729 if (ABI.IsEABI()) {
Eric Christopher8af49b32015-02-18 01:01:57 +0000730 if (STI.isGP32bit())
Rafael Espindolaba31e272015-01-29 17:33:21 +0000731 OutStreamer.SwitchSection(OutContext.getELFSection(".gcc_compiled_long32",
732 ELF::SHT_PROGBITS, 0));
Rafael Espindola2ab7ea72014-01-27 01:33:33 +0000733 else
Rafael Espindolaba31e272015-01-29 17:33:21 +0000734 OutStreamer.SwitchSection(OutContext.getELFSection(".gcc_compiled_long64",
735 ELF::SHT_PROGBITS, 0));
Benjamin Kramer0151d7b2010-04-05 10:17:15 +0000736 }
Daniel Sanders7e527422014-07-10 13:38:23 +0000737
Eric Christopher8af49b32015-02-18 01:01:57 +0000738 getTargetStreamer().updateABIInfo(STI);
Daniel Sanders7e527422014-07-10 13:38:23 +0000739
Daniel Sanderse22244b2014-07-21 15:25:24 +0000740 // We should always emit a '.module fp=...' but binutils 2.24 does not accept
741 // it. We therefore emit it when it contradicts the ABI defaults (-mfpxx or
742 // -mfp64) and omit it otherwise.
Eric Christopher8af49b32015-02-18 01:01:57 +0000743 if (ABI.IsO32() && (STI.isABI_FPXX() || STI.isFP64bit()))
Daniel Sanderse22244b2014-07-21 15:25:24 +0000744 getTargetStreamer().emitDirectiveModuleFP();
745
746 // We should always emit a '.module [no]oddspreg' but binutils 2.24 does not
747 // accept it. We therefore emit it when it contradicts the default or an
748 // option has changed the default (i.e. FPXX) and omit it otherwise.
Eric Christopher8af49b32015-02-18 01:01:57 +0000749 if (ABI.IsO32() && (!STI.useOddSPReg() || STI.isABI_FPXX()))
750 getTargetStreamer().emitDirectiveModuleOddSPReg(STI.useOddSPReg(),
Eric Christopherd86af632015-01-29 23:27:45 +0000751 ABI.IsO32());
Reed Kotler4cdaa7d2014-02-14 19:16:39 +0000752}
Bruno Cardoso Lopes80ab8f92008-07-14 14:42:54 +0000753
Eric Christopher64d35be2015-02-19 19:52:25 +0000754void MipsAsmPrinter::emitInlineAsmStart() const {
Toma Tabacua23f13c2014-12-17 10:56:16 +0000755 MipsTargetStreamer &TS = getTargetStreamer();
756
Toma Tabacu68e8a9c2015-01-09 15:00:30 +0000757 // GCC's choice of assembler options for inline assembly code ('at', 'macro'
758 // and 'reorder') is different from LLVM's choice for generated code ('noat',
759 // 'nomacro' and 'noreorder').
760 // In order to maintain compatibility with inline assembly code which depends
761 // on GCC's assembler options being used, we have to switch to those options
762 // for the duration of the inline assembly block and then switch back.
Toma Tabacua23f13c2014-12-17 10:56:16 +0000763 TS.emitDirectiveSetPush();
764 TS.emitDirectiveSetAt();
765 TS.emitDirectiveSetMacro();
766 TS.emitDirectiveSetReorder();
767 OutStreamer.AddBlankLine();
768}
769
770void MipsAsmPrinter::emitInlineAsmEnd(const MCSubtargetInfo &StartInfo,
771 const MCSubtargetInfo *EndInfo) const {
772 OutStreamer.AddBlankLine();
773 getTargetStreamer().emitDirectiveSetPop();
774}
775
Eric Christopher327fc972015-02-21 08:48:22 +0000776void MipsAsmPrinter::EmitJal(const MCSubtargetInfo &STI, MCSymbol *Symbol) {
Reed Kotler4cdaa7d2014-02-14 19:16:39 +0000777 MCInst I;
778 I.setOpcode(Mips::JAL);
779 I.addOperand(
780 MCOperand::CreateExpr(MCSymbolRefExpr::Create(Symbol, OutContext)));
Eric Christopher327fc972015-02-21 08:48:22 +0000781 OutStreamer.EmitInstruction(I, STI);
Reed Kotler4cdaa7d2014-02-14 19:16:39 +0000782}
783
Eric Christopher327fc972015-02-21 08:48:22 +0000784void MipsAsmPrinter::EmitInstrReg(const MCSubtargetInfo &STI, unsigned Opcode,
785 unsigned Reg) {
Reed Kotler4cdaa7d2014-02-14 19:16:39 +0000786 MCInst I;
787 I.setOpcode(Opcode);
788 I.addOperand(MCOperand::CreateReg(Reg));
Eric Christopher327fc972015-02-21 08:48:22 +0000789 OutStreamer.EmitInstruction(I, STI);
Reed Kotler4cdaa7d2014-02-14 19:16:39 +0000790}
791
Eric Christopher327fc972015-02-21 08:48:22 +0000792void MipsAsmPrinter::EmitInstrRegReg(const MCSubtargetInfo &STI,
793 unsigned Opcode, unsigned Reg1,
Reed Kotler4cdaa7d2014-02-14 19:16:39 +0000794 unsigned Reg2) {
795 MCInst I;
796 //
797 // Because of the current td files for Mips32, the operands for MTC1
798 // appear backwards from their normal assembly order. It's not a trivial
799 // change to fix this in the td file so we adjust for it here.
800 //
801 if (Opcode == Mips::MTC1) {
802 unsigned Temp = Reg1;
803 Reg1 = Reg2;
804 Reg2 = Temp;
805 }
806 I.setOpcode(Opcode);
807 I.addOperand(MCOperand::CreateReg(Reg1));
808 I.addOperand(MCOperand::CreateReg(Reg2));
Eric Christopher327fc972015-02-21 08:48:22 +0000809 OutStreamer.EmitInstruction(I, STI);
Reed Kotler4cdaa7d2014-02-14 19:16:39 +0000810}
811
Eric Christopher327fc972015-02-21 08:48:22 +0000812void MipsAsmPrinter::EmitInstrRegRegReg(const MCSubtargetInfo &STI,
813 unsigned Opcode, unsigned Reg1,
Reed Kotler4cdaa7d2014-02-14 19:16:39 +0000814 unsigned Reg2, unsigned Reg3) {
815 MCInst I;
816 I.setOpcode(Opcode);
817 I.addOperand(MCOperand::CreateReg(Reg1));
818 I.addOperand(MCOperand::CreateReg(Reg2));
819 I.addOperand(MCOperand::CreateReg(Reg3));
Eric Christopher327fc972015-02-21 08:48:22 +0000820 OutStreamer.EmitInstruction(I, STI);
Reed Kotler4cdaa7d2014-02-14 19:16:39 +0000821}
822
Eric Christopher327fc972015-02-21 08:48:22 +0000823void MipsAsmPrinter::EmitMovFPIntPair(const MCSubtargetInfo &STI,
824 unsigned MovOpc, unsigned Reg1,
Reed Kotler4cdaa7d2014-02-14 19:16:39 +0000825 unsigned Reg2, unsigned FPReg1,
826 unsigned FPReg2, bool LE) {
827 if (!LE) {
828 unsigned temp = Reg1;
829 Reg1 = Reg2;
830 Reg2 = temp;
831 }
Eric Christopher327fc972015-02-21 08:48:22 +0000832 EmitInstrRegReg(STI, MovOpc, Reg1, FPReg1);
833 EmitInstrRegReg(STI, MovOpc, Reg2, FPReg2);
Reed Kotler4cdaa7d2014-02-14 19:16:39 +0000834}
835
Eric Christopher327fc972015-02-21 08:48:22 +0000836void MipsAsmPrinter::EmitSwapFPIntParams(const MCSubtargetInfo &STI,
837 Mips16HardFloatInfo::FPParamVariant PV,
Reed Kotler4cdaa7d2014-02-14 19:16:39 +0000838 bool LE, bool ToFP) {
839 using namespace Mips16HardFloatInfo;
840 unsigned MovOpc = ToFP ? Mips::MTC1 : Mips::MFC1;
841 switch (PV) {
842 case FSig:
Eric Christopher327fc972015-02-21 08:48:22 +0000843 EmitInstrRegReg(STI, MovOpc, Mips::A0, Mips::F12);
Reed Kotler4cdaa7d2014-02-14 19:16:39 +0000844 break;
845 case FFSig:
Eric Christopher327fc972015-02-21 08:48:22 +0000846 EmitMovFPIntPair(STI, MovOpc, Mips::A0, Mips::A1, Mips::F12, Mips::F14, LE);
Reed Kotler4cdaa7d2014-02-14 19:16:39 +0000847 break;
848 case FDSig:
Eric Christopher327fc972015-02-21 08:48:22 +0000849 EmitInstrRegReg(STI, MovOpc, Mips::A0, Mips::F12);
850 EmitMovFPIntPair(STI, MovOpc, Mips::A2, Mips::A3, Mips::F14, Mips::F15, LE);
Reed Kotler4cdaa7d2014-02-14 19:16:39 +0000851 break;
852 case DSig:
Eric Christopher327fc972015-02-21 08:48:22 +0000853 EmitMovFPIntPair(STI, MovOpc, Mips::A0, Mips::A1, Mips::F12, Mips::F13, LE);
Reed Kotler4cdaa7d2014-02-14 19:16:39 +0000854 break;
855 case DDSig:
Eric Christopher327fc972015-02-21 08:48:22 +0000856 EmitMovFPIntPair(STI, MovOpc, Mips::A0, Mips::A1, Mips::F12, Mips::F13, LE);
857 EmitMovFPIntPair(STI, MovOpc, Mips::A2, Mips::A3, Mips::F14, Mips::F15, LE);
Reed Kotler4cdaa7d2014-02-14 19:16:39 +0000858 break;
859 case DFSig:
Eric Christopher327fc972015-02-21 08:48:22 +0000860 EmitMovFPIntPair(STI, MovOpc, Mips::A0, Mips::A1, Mips::F12, Mips::F13, LE);
861 EmitInstrRegReg(STI, MovOpc, Mips::A2, Mips::F14);
Reed Kotler4cdaa7d2014-02-14 19:16:39 +0000862 break;
863 case NoSig:
864 return;
865 }
866}
867
Eric Christopher327fc972015-02-21 08:48:22 +0000868void MipsAsmPrinter::EmitSwapFPIntRetval(
869 const MCSubtargetInfo &STI, Mips16HardFloatInfo::FPReturnVariant RV,
870 bool LE) {
Reed Kotler4cdaa7d2014-02-14 19:16:39 +0000871 using namespace Mips16HardFloatInfo;
872 unsigned MovOpc = Mips::MFC1;
873 switch (RV) {
874 case FRet:
Eric Christopher327fc972015-02-21 08:48:22 +0000875 EmitInstrRegReg(STI, MovOpc, Mips::V0, Mips::F0);
Reed Kotler4cdaa7d2014-02-14 19:16:39 +0000876 break;
877 case DRet:
Eric Christopher327fc972015-02-21 08:48:22 +0000878 EmitMovFPIntPair(STI, MovOpc, Mips::V0, Mips::V1, Mips::F0, Mips::F1, LE);
Reed Kotler4cdaa7d2014-02-14 19:16:39 +0000879 break;
880 case CFRet:
Eric Christopher327fc972015-02-21 08:48:22 +0000881 EmitMovFPIntPair(STI, MovOpc, Mips::V0, Mips::V1, Mips::F0, Mips::F1, LE);
Reed Kotler4cdaa7d2014-02-14 19:16:39 +0000882 break;
883 case CDRet:
Eric Christopher327fc972015-02-21 08:48:22 +0000884 EmitMovFPIntPair(STI, MovOpc, Mips::V0, Mips::V1, Mips::F0, Mips::F1, LE);
885 EmitMovFPIntPair(STI, MovOpc, Mips::A0, Mips::A1, Mips::F2, Mips::F3, LE);
Reed Kotler4cdaa7d2014-02-14 19:16:39 +0000886 break;
887 case NoFPRet:
888 break;
889 }
890}
891
892void MipsAsmPrinter::EmitFPCallStub(
893 const char *Symbol, const Mips16HardFloatInfo::FuncSignature *Signature) {
894 MCSymbol *MSymbol = OutContext.GetOrCreateSymbol(StringRef(Symbol));
895 using namespace Mips16HardFloatInfo;
Eric Christopherbb401642015-02-21 08:32:22 +0000896 bool LE = getDataLayout().isLittleEndian();
Eric Christopher327fc972015-02-21 08:48:22 +0000897 // Construct a local MCSubtargetInfo here.
898 // This is because the MachineFunction won't exist (but have not yet been
899 // freed) and since we're at the global level we can use the default
900 // constructed subtarget.
901 std::unique_ptr<MCSubtargetInfo> STI(TM.getTarget().createMCSubtargetInfo(
902 TM.getTargetTriple(), TM.getTargetCPU(), TM.getTargetFeatureString()));
903
Reed Kotler4cdaa7d2014-02-14 19:16:39 +0000904 //
905 // .global xxxx
906 //
907 OutStreamer.EmitSymbolAttribute(MSymbol, MCSA_Global);
908 const char *RetType;
909 //
910 // make the comment field identifying the return and parameter
911 // types of the floating point stub
912 // # Stub function to call rettype xxxx (params)
913 //
914 switch (Signature->RetSig) {
915 case FRet:
916 RetType = "float";
917 break;
918 case DRet:
919 RetType = "double";
920 break;
921 case CFRet:
922 RetType = "complex";
923 break;
924 case CDRet:
925 RetType = "double complex";
926 break;
927 case NoFPRet:
928 RetType = "";
929 break;
930 }
931 const char *Parms;
932 switch (Signature->ParamSig) {
933 case FSig:
934 Parms = "float";
935 break;
936 case FFSig:
937 Parms = "float, float";
938 break;
939 case FDSig:
940 Parms = "float, double";
941 break;
942 case DSig:
943 Parms = "double";
944 break;
945 case DDSig:
946 Parms = "double, double";
947 break;
948 case DFSig:
949 Parms = "double, float";
950 break;
951 case NoSig:
952 Parms = "";
953 break;
954 }
955 OutStreamer.AddComment("\t# Stub function to call " + Twine(RetType) + " " +
956 Twine(Symbol) + " (" + Twine(Parms) + ")");
957 //
958 // probably not necessary but we save and restore the current section state
959 //
960 OutStreamer.PushSection();
961 //
962 // .section mips16.call.fpxxxx,"ax",@progbits
963 //
964 const MCSectionELF *M = OutContext.getELFSection(
965 ".mips16.call.fp." + std::string(Symbol), ELF::SHT_PROGBITS,
Rafael Espindolaba31e272015-01-29 17:33:21 +0000966 ELF::SHF_ALLOC | ELF::SHF_EXECINSTR);
Craig Topper062a2ba2014-04-25 05:30:21 +0000967 OutStreamer.SwitchSection(M, nullptr);
Reed Kotler4cdaa7d2014-02-14 19:16:39 +0000968 //
969 // .align 2
970 //
971 OutStreamer.EmitValueToAlignment(4);
972 MipsTargetStreamer &TS = getTargetStreamer();
973 //
974 // .set nomips16
975 // .set nomicromips
976 //
977 TS.emitDirectiveSetNoMips16();
978 TS.emitDirectiveSetNoMicroMips();
979 //
980 // .ent __call_stub_fp_xxxx
Vladimir Medicfb8a2a92014-07-08 08:59:22 +0000981 // .type __call_stub_fp_xxxx,@function
Reed Kotler4cdaa7d2014-02-14 19:16:39 +0000982 // __call_stub_fp_xxxx:
983 //
984 std::string x = "__call_stub_fp_" + std::string(Symbol);
985 MCSymbol *Stub = OutContext.GetOrCreateSymbol(StringRef(x));
986 TS.emitDirectiveEnt(*Stub);
987 MCSymbol *MType =
988 OutContext.GetOrCreateSymbol("__call_stub_fp_" + Twine(Symbol));
989 OutStreamer.EmitSymbolAttribute(MType, MCSA_ELF_TypeFunction);
990 OutStreamer.EmitLabel(Stub);
Eric Christopherd5bc07e2015-02-21 08:32:38 +0000991
992 // Only handle non-pic for now.
993 assert(TM.getRelocationModel() != Reloc::PIC_ &&
994 "should not be here if we are compiling pic");
Reed Kotler4cdaa7d2014-02-14 19:16:39 +0000995 TS.emitDirectiveSetReorder();
996 //
997 // We need to add a MipsMCExpr class to MCTargetDesc to fully implement
998 // stubs without raw text but this current patch is for compiler generated
999 // functions and they all return some value.
1000 // The calling sequence for non pic is different in that case and we need
1001 // to implement %lo and %hi in order to handle the case of no return value
1002 // See the corresponding method in Mips16HardFloat for details.
1003 //
1004 // mov the return address to S2.
1005 // we have no stack space to store it and we are about to make another call.
1006 // We need to make sure that the enclosing function knows to save S2
1007 // This should have already been handled.
1008 //
1009 // Mov $18, $31
1010
Eric Christopher327fc972015-02-21 08:48:22 +00001011 EmitInstrRegRegReg(*STI, Mips::ADDu, Mips::S2, Mips::RA, Mips::ZERO);
Reed Kotler4cdaa7d2014-02-14 19:16:39 +00001012
Eric Christopher327fc972015-02-21 08:48:22 +00001013 EmitSwapFPIntParams(*STI, Signature->ParamSig, LE, true);
Reed Kotler4cdaa7d2014-02-14 19:16:39 +00001014
1015 // Jal xxxx
1016 //
Eric Christopher327fc972015-02-21 08:48:22 +00001017 EmitJal(*STI, MSymbol);
Reed Kotler4cdaa7d2014-02-14 19:16:39 +00001018
1019 // fix return values
Eric Christopher327fc972015-02-21 08:48:22 +00001020 EmitSwapFPIntRetval(*STI, Signature->RetSig, LE);
Reed Kotler4cdaa7d2014-02-14 19:16:39 +00001021 //
1022 // do the return
1023 // if (Signature->RetSig == NoFPRet)
1024 // llvm_unreachable("should not be any stubs here with no return value");
1025 // else
Eric Christopher327fc972015-02-21 08:48:22 +00001026 EmitInstrReg(*STI, Mips::JR, Mips::S2);
Reed Kotler4cdaa7d2014-02-14 19:16:39 +00001027
1028 MCSymbol *Tmp = OutContext.CreateTempSymbol();
1029 OutStreamer.EmitLabel(Tmp);
1030 const MCSymbolRefExpr *E = MCSymbolRefExpr::Create(Stub, OutContext);
1031 const MCSymbolRefExpr *T = MCSymbolRefExpr::Create(Tmp, OutContext);
1032 const MCExpr *T_min_E = MCBinaryExpr::CreateSub(T, E, OutContext);
1033 OutStreamer.EmitELFSize(Stub, T_min_E);
1034 TS.emitDirectiveEnd(x);
1035 OutStreamer.PopSection();
1036}
1037
1038void MipsAsmPrinter::EmitEndOfAsmFile(Module &M) {
1039 // Emit needed stubs
1040 //
1041 for (std::map<
1042 const char *,
1043 const llvm::Mips16HardFloatInfo::FuncSignature *>::const_iterator
1044 it = StubsNeeded.begin();
1045 it != StubsNeeded.end(); ++it) {
1046 const char *Symbol = it->first;
1047 const llvm::Mips16HardFloatInfo::FuncSignature *Signature = it->second;
1048 EmitFPCallStub(Symbol, Signature);
1049 }
Rafael Espindola2ab7ea72014-01-27 01:33:33 +00001050 // return to the text section
1051 OutStreamer.SwitchSection(OutContext.getObjectFileInfo()->getTextSection());
Jack Carterc1b17ed2013-01-18 21:20:38 +00001052}
1053
Akira Hatanakaf2bcad92011-07-01 01:04:43 +00001054void MipsAsmPrinter::PrintDebugValueComment(const MachineInstr *MI,
1055 raw_ostream &OS) {
1056 // TODO: implement
1057}
1058
Sasa Stankovic8c5736b2014-02-28 10:00:38 +00001059// Align all targets of indirect branches on bundle size. Used only if target
1060// is NaCl.
1061void MipsAsmPrinter::NaClAlignIndirectJumpTargets(MachineFunction &MF) {
1062 // Align all blocks that are jumped to through jump table.
1063 if (MachineJumpTableInfo *JtInfo = MF.getJumpTableInfo()) {
1064 const std::vector<MachineJumpTableEntry> &JT = JtInfo->getJumpTables();
1065 for (unsigned I = 0; I < JT.size(); ++I) {
1066 const std::vector<MachineBasicBlock*> &MBBs = JT[I].MBBs;
1067
1068 for (unsigned J = 0; J < MBBs.size(); ++J)
1069 MBBs[J]->setAlignment(MIPS_NACL_BUNDLE_ALIGN);
1070 }
1071 }
1072
1073 // If basic block address is taken, block can be target of indirect branch.
1074 for (MachineFunction::iterator MBB = MF.begin(), E = MF.end();
1075 MBB != E; ++MBB) {
1076 if (MBB->hasAddressTaken())
1077 MBB->setAlignment(MIPS_NACL_BUNDLE_ALIGN);
1078 }
1079}
1080
Sasa Stankovic7b061a42014-04-30 15:06:25 +00001081bool MipsAsmPrinter::isLongBranchPseudo(int Opcode) const {
1082 return (Opcode == Mips::LONG_BRANCH_LUi
1083 || Opcode == Mips::LONG_BRANCH_ADDiu
Sasa Stankovic7b061a42014-04-30 15:06:25 +00001084 || Opcode == Mips::LONG_BRANCH_DADDiu);
1085}
1086
Bob Wilson5a495fe2009-06-23 23:59:40 +00001087// Force static initialization.
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +00001088extern "C" void LLVMInitializeMipsAsmPrinter() {
Daniel Dunbar5680b4f2009-07-25 06:49:55 +00001089 RegisterAsmPrinter<MipsAsmPrinter> X(TheMipsTarget);
1090 RegisterAsmPrinter<MipsAsmPrinter> Y(TheMipselTarget);
Akira Hatanaka3d673cc2011-09-21 03:00:58 +00001091 RegisterAsmPrinter<MipsAsmPrinter> A(TheMips64Target);
1092 RegisterAsmPrinter<MipsAsmPrinter> B(TheMips64elTarget);
Daniel Dunbare8338102009-07-15 20:24:03 +00001093}