Chris Lattner | 97f0693 | 2009-10-19 20:20:46 +0000 | [diff] [blame] | 1 | //===-- ARMAsmPrinter.cpp - Print machine code to an ARM .s file ----------===// |
| 2 | // |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 4ee451d | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file contains a printer that converts from our internal representation |
| 11 | // of machine-dependent LLVM code to GAS-format ARM assembly language. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
Chris Lattner | 95b2c7d | 2006-12-19 22:59:26 +0000 | [diff] [blame] | 15 | #define DEBUG_TYPE "asm-printer" |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 16 | #include "ARM.h" |
Anton Korobeynikov | 88ce667 | 2009-05-23 19:51:20 +0000 | [diff] [blame] | 17 | #include "ARMBuildAttrs.h" |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 18 | #include "ARMAddressingModes.h" |
| 19 | #include "ARMConstantPoolValue.h" |
Chris Lattner | f447a5f | 2010-07-19 23:44:46 +0000 | [diff] [blame] | 20 | #include "AsmPrinter/ARMInstPrinter.h" |
Chris Lattner | 97f0693 | 2009-10-19 20:20:46 +0000 | [diff] [blame] | 21 | #include "ARMMachineFunctionInfo.h" |
| 22 | #include "ARMMCInstLower.h" |
| 23 | #include "ARMTargetMachine.h" |
Dale Johannesen | 3f282aa | 2010-04-26 20:07:31 +0000 | [diff] [blame] | 24 | #include "llvm/Analysis/DebugInfo.h" |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 25 | #include "llvm/Constants.h" |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 26 | #include "llvm/Module.h" |
Benjamin Kramer | e55b15f | 2009-12-28 12:27:56 +0000 | [diff] [blame] | 27 | #include "llvm/Type.h" |
Dan Gohman | cf20ac4 | 2009-08-13 01:36:44 +0000 | [diff] [blame] | 28 | #include "llvm/Assembly/Writer.h" |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 29 | #include "llvm/CodeGen/AsmPrinter.h" |
Chris Lattner | b0f294c | 2009-10-19 18:38:33 +0000 | [diff] [blame] | 30 | #include "llvm/CodeGen/MachineModuleInfoImpls.h" |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 31 | #include "llvm/CodeGen/MachineFunctionPass.h" |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 32 | #include "llvm/CodeGen/MachineJumpTableInfo.h" |
Anton Korobeynikov | 362dd0b | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 33 | #include "llvm/CodeGen/TargetLoweringObjectFileImpl.h" |
Chris Lattner | b0f294c | 2009-10-19 18:38:33 +0000 | [diff] [blame] | 34 | #include "llvm/MC/MCAsmInfo.h" |
| 35 | #include "llvm/MC/MCContext.h" |
Bill Wendling | becd83e | 2010-03-09 00:40:17 +0000 | [diff] [blame] | 36 | #include "llvm/MC/MCExpr.h" |
Chris Lattner | 97f0693 | 2009-10-19 20:20:46 +0000 | [diff] [blame] | 37 | #include "llvm/MC/MCInst.h" |
Chris Lattner | f9bdedd | 2009-08-10 18:15:01 +0000 | [diff] [blame] | 38 | #include "llvm/MC/MCSectionMachO.h" |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 39 | #include "llvm/MC/MCStreamer.h" |
Chris Lattner | 325d3dc | 2009-09-13 17:14:04 +0000 | [diff] [blame] | 40 | #include "llvm/MC/MCSymbol.h" |
Chris Lattner | d62f1b4 | 2010-03-12 21:19:23 +0000 | [diff] [blame] | 41 | #include "llvm/Target/Mangler.h" |
Rafael Espindola | b01c4bb | 2006-07-27 11:38:51 +0000 | [diff] [blame] | 42 | #include "llvm/Target/TargetData.h" |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 43 | #include "llvm/Target/TargetMachine.h" |
Evan Cheng | 5be54b0 | 2007-01-19 19:25:36 +0000 | [diff] [blame] | 44 | #include "llvm/Target/TargetOptions.h" |
Daniel Dunbar | 51b198a | 2009-07-15 20:24:03 +0000 | [diff] [blame] | 45 | #include "llvm/Target/TargetRegistry.h" |
Evan Cheng | c324ecb | 2009-07-24 18:19:46 +0000 | [diff] [blame] | 46 | #include "llvm/ADT/SmallPtrSet.h" |
Jim Grosbach | c40d9f9 | 2009-09-01 18:49:12 +0000 | [diff] [blame] | 47 | #include "llvm/ADT/SmallString.h" |
Bob Wilson | 54c78ef | 2009-11-06 23:33:28 +0000 | [diff] [blame] | 48 | #include "llvm/ADT/StringExtras.h" |
Chris Lattner | 97f0693 | 2009-10-19 20:20:46 +0000 | [diff] [blame] | 49 | #include "llvm/Support/CommandLine.h" |
Devang Patel | 59135f4 | 2010-08-04 22:39:39 +0000 | [diff] [blame] | 50 | #include "llvm/Support/Debug.h" |
Torok Edwin | 3046470 | 2009-07-08 20:55:50 +0000 | [diff] [blame] | 51 | #include "llvm/Support/ErrorHandling.h" |
Chris Lattner | b23569a | 2010-04-04 08:18:47 +0000 | [diff] [blame] | 52 | #include "llvm/Support/raw_ostream.h" |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 53 | #include <cctype> |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 54 | using namespace llvm; |
| 55 | |
Chris Lattner | 97f0693 | 2009-10-19 20:20:46 +0000 | [diff] [blame] | 56 | static cl::opt<bool> |
| 57 | EnableMCInst("enable-arm-mcinst-printer", cl::Hidden, |
| 58 | cl::desc("enable experimental asmprinter gunk in the arm backend")); |
| 59 | |
Jim Grosbach | 9172900 | 2010-07-21 23:03:52 +0000 | [diff] [blame] | 60 | namespace llvm { |
| 61 | namespace ARM { |
| 62 | enum DW_ISA { |
| 63 | DW_ISA_ARM_thumb = 1, |
| 64 | DW_ISA_ARM_arm = 2 |
| 65 | }; |
| 66 | } |
| 67 | } |
| 68 | |
Chris Lattner | 95b2c7d | 2006-12-19 22:59:26 +0000 | [diff] [blame] | 69 | namespace { |
Chris Lattner | 4a071d6 | 2009-10-19 17:59:19 +0000 | [diff] [blame] | 70 | class ARMAsmPrinter : public AsmPrinter { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 71 | |
| 72 | /// Subtarget - Keep a pointer to the ARMSubtarget around so that we can |
| 73 | /// make the right decision when printing asm code for different targets. |
| 74 | const ARMSubtarget *Subtarget; |
| 75 | |
| 76 | /// AFI - Keep a pointer to ARMFunctionInfo for the current |
Evan Cheng | 6d63a72 | 2008-09-18 07:27:23 +0000 | [diff] [blame] | 77 | /// MachineFunction. |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 78 | ARMFunctionInfo *AFI; |
| 79 | |
Evan Cheng | 6d63a72 | 2008-09-18 07:27:23 +0000 | [diff] [blame] | 80 | /// MCP - Keep a pointer to constantpool entries of the current |
| 81 | /// MachineFunction. |
| 82 | const MachineConstantPool *MCP; |
| 83 | |
Bill Wendling | 57f0db8 | 2009-02-24 08:30:20 +0000 | [diff] [blame] | 84 | public: |
Chris Lattner | b23569a | 2010-04-04 08:18:47 +0000 | [diff] [blame] | 85 | explicit ARMAsmPrinter(TargetMachine &TM, MCStreamer &Streamer) |
| 86 | : AsmPrinter(TM, Streamer), AFI(NULL), MCP(NULL) { |
Bill Wendling | 57f0db8 | 2009-02-24 08:30:20 +0000 | [diff] [blame] | 87 | Subtarget = &TM.getSubtarget<ARMSubtarget>(); |
| 88 | } |
| 89 | |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 90 | virtual const char *getPassName() const { |
| 91 | return "ARM Assembly Printer"; |
| 92 | } |
Jim Grosbach | b0739b7 | 2010-09-02 01:02:06 +0000 | [diff] [blame] | 93 | |
Chris Lattner | 97f0693 | 2009-10-19 20:20:46 +0000 | [diff] [blame] | 94 | void printInstructionThroughMCStreamer(const MachineInstr *MI); |
Jim Grosbach | b0739b7 | 2010-09-02 01:02:06 +0000 | [diff] [blame] | 95 | |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 96 | |
Chris Lattner | 35c33bd | 2010-04-04 04:47:45 +0000 | [diff] [blame] | 97 | void printOperand(const MachineInstr *MI, int OpNum, raw_ostream &O, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 98 | const char *Modifier = 0); |
Chris Lattner | 35c33bd | 2010-04-04 04:47:45 +0000 | [diff] [blame] | 99 | void printSOImmOperand(const MachineInstr *MI, int OpNum, raw_ostream &O); |
| 100 | void printSOImm2PartOperand(const MachineInstr *MI, int OpNum, |
| 101 | raw_ostream &O); |
| 102 | void printSORegOperand(const MachineInstr *MI, int OpNum, |
| 103 | raw_ostream &O); |
| 104 | void printAddrMode2Operand(const MachineInstr *MI, int OpNum, |
| 105 | raw_ostream &O); |
| 106 | void printAddrMode2OffsetOperand(const MachineInstr *MI, int OpNum, |
| 107 | raw_ostream &O); |
| 108 | void printAddrMode3Operand(const MachineInstr *MI, int OpNum, |
| 109 | raw_ostream &O); |
| 110 | void printAddrMode3OffsetOperand(const MachineInstr *MI, int OpNum, |
| 111 | raw_ostream &O); |
| 112 | void printAddrMode4Operand(const MachineInstr *MI, int OpNum,raw_ostream &O, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 113 | const char *Modifier = 0); |
Chris Lattner | 35c33bd | 2010-04-04 04:47:45 +0000 | [diff] [blame] | 114 | void printAddrMode5Operand(const MachineInstr *MI, int OpNum,raw_ostream &O, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 115 | const char *Modifier = 0); |
Chris Lattner | 35c33bd | 2010-04-04 04:47:45 +0000 | [diff] [blame] | 116 | void printAddrMode6Operand(const MachineInstr *MI, int OpNum, |
| 117 | raw_ostream &O); |
| 118 | void printAddrMode6OffsetOperand(const MachineInstr *MI, int OpNum, |
| 119 | raw_ostream &O); |
Evan Cheng | 055b031 | 2009-06-29 07:51:04 +0000 | [diff] [blame] | 120 | void printAddrModePCOperand(const MachineInstr *MI, int OpNum, |
Chris Lattner | 35c33bd | 2010-04-04 04:47:45 +0000 | [diff] [blame] | 121 | raw_ostream &O, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 122 | const char *Modifier = 0); |
Bob Wilson | eaf1c98 | 2010-08-11 23:10:46 +0000 | [diff] [blame] | 123 | void printBitfieldInvMaskImmOperand(const MachineInstr *MI, int OpNum, |
| 124 | raw_ostream &O); |
Johnny Chen | 1adc40c | 2010-08-12 20:46:17 +0000 | [diff] [blame] | 125 | void printMemBOption(const MachineInstr *MI, int OpNum, |
| 126 | raw_ostream &O); |
Bob Wilson | 22f5dc7 | 2010-08-16 18:27:34 +0000 | [diff] [blame] | 127 | void printShiftImmOperand(const MachineInstr *MI, int OpNum, |
Bob Wilson | eaf1c98 | 2010-08-11 23:10:46 +0000 | [diff] [blame] | 128 | raw_ostream &O); |
Evan Cheng | 9cb9e67 | 2009-06-27 02:26:13 +0000 | [diff] [blame] | 129 | |
Chris Lattner | 35c33bd | 2010-04-04 04:47:45 +0000 | [diff] [blame] | 130 | void printThumbS4ImmOperand(const MachineInstr *MI, int OpNum, |
| 131 | raw_ostream &O); |
| 132 | void printThumbITMask(const MachineInstr *MI, int OpNum, raw_ostream &O); |
| 133 | void printThumbAddrModeRROperand(const MachineInstr *MI, int OpNum, |
| 134 | raw_ostream &O); |
Evan Cheng | 055b031 | 2009-06-29 07:51:04 +0000 | [diff] [blame] | 135 | void printThumbAddrModeRI5Operand(const MachineInstr *MI, int OpNum, |
Chris Lattner | 35c33bd | 2010-04-04 04:47:45 +0000 | [diff] [blame] | 136 | raw_ostream &O, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 137 | unsigned Scale); |
Chris Lattner | 35c33bd | 2010-04-04 04:47:45 +0000 | [diff] [blame] | 138 | void printThumbAddrModeS1Operand(const MachineInstr *MI, int OpNum, |
| 139 | raw_ostream &O); |
| 140 | void printThumbAddrModeS2Operand(const MachineInstr *MI, int OpNum, |
| 141 | raw_ostream &O); |
| 142 | void printThumbAddrModeS4Operand(const MachineInstr *MI, int OpNum, |
| 143 | raw_ostream &O); |
| 144 | void printThumbAddrModeSPOperand(const MachineInstr *MI, int OpNum, |
| 145 | raw_ostream &O); |
Evan Cheng | 9cb9e67 | 2009-06-27 02:26:13 +0000 | [diff] [blame] | 146 | |
Chris Lattner | 35c33bd | 2010-04-04 04:47:45 +0000 | [diff] [blame] | 147 | void printT2SOOperand(const MachineInstr *MI, int OpNum, raw_ostream &O); |
| 148 | void printT2AddrModeImm12Operand(const MachineInstr *MI, int OpNum, |
| 149 | raw_ostream &O); |
| 150 | void printT2AddrModeImm8Operand(const MachineInstr *MI, int OpNum, |
| 151 | raw_ostream &O); |
| 152 | void printT2AddrModeImm8s4Operand(const MachineInstr *MI, int OpNum, |
| 153 | raw_ostream &O); |
| 154 | void printT2AddrModeImm8OffsetOperand(const MachineInstr *MI, int OpNum, |
| 155 | raw_ostream &O); |
| 156 | void printT2AddrModeImm8s4OffsetOperand(const MachineInstr *MI, int OpNum, |
| 157 | raw_ostream &O) {} |
| 158 | void printT2AddrModeSoRegOperand(const MachineInstr *MI, int OpNum, |
| 159 | raw_ostream &O); |
Evan Cheng | 9cb9e67 | 2009-06-27 02:26:13 +0000 | [diff] [blame] | 160 | |
Chris Lattner | 35c33bd | 2010-04-04 04:47:45 +0000 | [diff] [blame] | 161 | void printCPSOptionOperand(const MachineInstr *MI, int OpNum, |
| 162 | raw_ostream &O) {} |
| 163 | void printMSRMaskOperand(const MachineInstr *MI, int OpNum, |
| 164 | raw_ostream &O) {} |
| 165 | void printNegZeroOperand(const MachineInstr *MI, int OpNum, |
| 166 | raw_ostream &O) {} |
| 167 | void printPredicateOperand(const MachineInstr *MI, int OpNum, |
| 168 | raw_ostream &O); |
| 169 | void printMandatoryPredicateOperand(const MachineInstr *MI, int OpNum, |
| 170 | raw_ostream &O); |
| 171 | void printSBitModifierOperand(const MachineInstr *MI, int OpNum, |
| 172 | raw_ostream &O); |
| 173 | void printPCLabel(const MachineInstr *MI, int OpNum, |
| 174 | raw_ostream &O); |
| 175 | void printRegisterList(const MachineInstr *MI, int OpNum, |
| 176 | raw_ostream &O); |
Evan Cheng | 055b031 | 2009-06-29 07:51:04 +0000 | [diff] [blame] | 177 | void printCPInstOperand(const MachineInstr *MI, int OpNum, |
Chris Lattner | 35c33bd | 2010-04-04 04:47:45 +0000 | [diff] [blame] | 178 | raw_ostream &O, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 179 | const char *Modifier); |
Chris Lattner | 35c33bd | 2010-04-04 04:47:45 +0000 | [diff] [blame] | 180 | void printJTBlockOperand(const MachineInstr *MI, int OpNum, |
| 181 | raw_ostream &O); |
| 182 | void printJT2BlockOperand(const MachineInstr *MI, int OpNum, |
| 183 | raw_ostream &O); |
| 184 | void printTBAddrMode(const MachineInstr *MI, int OpNum, |
| 185 | raw_ostream &O); |
| 186 | void printNoHashImmediate(const MachineInstr *MI, int OpNum, |
| 187 | raw_ostream &O); |
| 188 | void printVFPf32ImmOperand(const MachineInstr *MI, int OpNum, |
| 189 | raw_ostream &O); |
| 190 | void printVFPf64ImmOperand(const MachineInstr *MI, int OpNum, |
| 191 | raw_ostream &O); |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 192 | void printNEONModImmOperand(const MachineInstr *MI, int OpNum, |
| 193 | raw_ostream &O); |
Bob Wilson | 54c78ef | 2009-11-06 23:33:28 +0000 | [diff] [blame] | 194 | |
Evan Cheng | 055b031 | 2009-06-29 07:51:04 +0000 | [diff] [blame] | 195 | virtual bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNum, |
Chris Lattner | c75c028 | 2010-04-04 05:29:35 +0000 | [diff] [blame] | 196 | unsigned AsmVariant, const char *ExtraCode, |
| 197 | raw_ostream &O); |
Evan Cheng | 055b031 | 2009-06-29 07:51:04 +0000 | [diff] [blame] | 198 | virtual bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNum, |
Bob Wilson | 224c244 | 2009-05-19 05:53:42 +0000 | [diff] [blame] | 199 | unsigned AsmVariant, |
Chris Lattner | c75c028 | 2010-04-04 05:29:35 +0000 | [diff] [blame] | 200 | const char *ExtraCode, raw_ostream &O); |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 201 | |
Chris Lattner | 35c33bd | 2010-04-04 04:47:45 +0000 | [diff] [blame] | 202 | void printInstruction(const MachineInstr *MI, raw_ostream &O); // autogen |
Chris Lattner | d95148f | 2009-09-13 20:19:22 +0000 | [diff] [blame] | 203 | static const char *getRegisterName(unsigned RegNo); |
Chris Lattner | 05af261 | 2009-09-13 20:08:00 +0000 | [diff] [blame] | 204 | |
Chris Lattner | a786cea | 2010-01-28 01:10:34 +0000 | [diff] [blame] | 205 | virtual void EmitInstruction(const MachineInstr *MI); |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 206 | bool runOnMachineFunction(MachineFunction &F); |
Jim Grosbach | b0739b7 | 2010-09-02 01:02:06 +0000 | [diff] [blame] | 207 | |
Chris Lattner | a240619 | 2010-01-28 00:19:24 +0000 | [diff] [blame] | 208 | virtual void EmitConstantPool() {} // we emit constant pools customly! |
Chris Lattner | 953ebb7 | 2010-01-27 23:58:11 +0000 | [diff] [blame] | 209 | virtual void EmitFunctionEntryLabel(); |
Bob Wilson | 812209a | 2009-09-30 22:06:26 +0000 | [diff] [blame] | 210 | void EmitStartOfAsmFile(Module &M); |
Chris Lattner | 4a071d6 | 2009-10-19 17:59:19 +0000 | [diff] [blame] | 211 | void EmitEndOfAsmFile(Module &M); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 212 | |
Devang Patel | 59135f4 | 2010-08-04 22:39:39 +0000 | [diff] [blame] | 213 | MachineLocation getDebugValueLocation(const MachineInstr *MI) const { |
| 214 | MachineLocation Location; |
| 215 | assert (MI->getNumOperands() == 4 && "Invalid no. of machine operands!"); |
| 216 | // Frame address. Currently handles register +- offset only. |
| 217 | if (MI->getOperand(0).isReg() && MI->getOperand(1).isImm()) |
| 218 | Location.set(MI->getOperand(0).getReg(), MI->getOperand(1).getImm()); |
| 219 | else { |
| 220 | DEBUG(dbgs() << "DBG_VALUE instruction ignored! " << *MI << "\n"); |
| 221 | } |
| 222 | return Location; |
| 223 | } |
| 224 | |
Jim Grosbach | 9172900 | 2010-07-21 23:03:52 +0000 | [diff] [blame] | 225 | virtual unsigned getISAEncoding() { |
| 226 | // ARM/Darwin adds ISA to the DWARF info for each function. |
| 227 | if (!Subtarget->isTargetDarwin()) |
| 228 | return 0; |
| 229 | return Subtarget->isThumb() ? |
| 230 | llvm::ARM::DW_ISA_ARM_thumb : llvm::ARM::DW_ISA_ARM_arm; |
| 231 | } |
| 232 | |
Chris Lattner | 0890cf1 | 2010-01-25 19:51:38 +0000 | [diff] [blame] | 233 | MCSymbol *GetARMSetPICJumpTableLabel2(unsigned uid, unsigned uid2, |
| 234 | const MachineBasicBlock *MBB) const; |
| 235 | MCSymbol *GetARMJTIPICJumpTableLabel2(unsigned uid, unsigned uid2) const; |
Chris Lattner | bfcb096 | 2010-01-25 19:39:52 +0000 | [diff] [blame] | 236 | |
Evan Cheng | 711b6dc | 2008-08-08 06:56:16 +0000 | [diff] [blame] | 237 | /// EmitMachineConstantPoolValue - Print a machine constantpool value to |
| 238 | /// the .s file. |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 239 | virtual void EmitMachineConstantPoolValue(MachineConstantPoolValue *MCPV) { |
Chris Lattner | 9d7efd3 | 2010-04-04 07:05:53 +0000 | [diff] [blame] | 240 | SmallString<128> Str; |
| 241 | raw_svector_ostream OS(Str); |
| 242 | EmitMachineConstantPoolValue(MCPV, OS); |
| 243 | OutStreamer.EmitRawText(OS.str()); |
| 244 | } |
Jim Grosbach | b0739b7 | 2010-09-02 01:02:06 +0000 | [diff] [blame] | 245 | |
Chris Lattner | 9d7efd3 | 2010-04-04 07:05:53 +0000 | [diff] [blame] | 246 | void EmitMachineConstantPoolValue(MachineConstantPoolValue *MCPV, |
| 247 | raw_ostream &O) { |
Chris Lattner | ea3cb40 | 2010-01-20 07:33:29 +0000 | [diff] [blame] | 248 | switch (TM.getTargetData()->getTypeAllocSize(MCPV->getType())) { |
| 249 | case 1: O << MAI->getData8bitsDirective(0); break; |
| 250 | case 2: O << MAI->getData16bitsDirective(0); break; |
| 251 | case 4: O << MAI->getData32bitsDirective(0); break; |
| 252 | default: assert(0 && "Unknown CPV size"); |
| 253 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 254 | |
Evan Cheng | 711b6dc | 2008-08-08 06:56:16 +0000 | [diff] [blame] | 255 | ARMConstantPoolValue *ACPV = static_cast<ARMConstantPoolValue*>(MCPV); |
Jim Grosbach | 3fb2b1e | 2009-09-01 01:57:56 +0000 | [diff] [blame] | 256 | |
| 257 | if (ACPV->isLSDA()) { |
Chris Lattner | 9d7efd3 | 2010-04-04 07:05:53 +0000 | [diff] [blame] | 258 | O << MAI->getPrivateGlobalPrefix() << "_LSDA_" << getFunctionNumber(); |
Bob Wilson | 28989a8 | 2009-11-02 16:59:06 +0000 | [diff] [blame] | 259 | } else if (ACPV->isBlockAddress()) { |
Chris Lattner | 0752cda | 2010-04-05 16:32:14 +0000 | [diff] [blame] | 260 | O << *GetBlockAddressSymbol(ACPV->getBlockAddress()); |
Bob Wilson | 28989a8 | 2009-11-02 16:59:06 +0000 | [diff] [blame] | 261 | } else if (ACPV->isGlobalValue()) { |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 262 | const GlobalValue *GV = ACPV->getGV(); |
Evan Cheng | e4e4ed3 | 2009-08-28 23:18:09 +0000 | [diff] [blame] | 263 | bool isIndirect = Subtarget->isTargetDarwin() && |
Evan Cheng | 63476a8 | 2009-09-03 07:04:02 +0000 | [diff] [blame] | 264 | Subtarget->GVIsIndirectSymbol(GV, TM.getRelocationModel()); |
Evan Cheng | e4e4ed3 | 2009-08-28 23:18:09 +0000 | [diff] [blame] | 265 | if (!isIndirect) |
Chris Lattner | d62f1b4 | 2010-03-12 21:19:23 +0000 | [diff] [blame] | 266 | O << *Mang->getSymbol(GV); |
Evan Cheng | e4e4ed3 | 2009-08-28 23:18:09 +0000 | [diff] [blame] | 267 | else { |
| 268 | // FIXME: Remove this when Darwin transition to @GOT like syntax. |
Chris Lattner | 7a2ba94 | 2010-01-16 18:37:32 +0000 | [diff] [blame] | 269 | MCSymbol *Sym = GetSymbolWithGlobalValueBase(GV, "$non_lazy_ptr"); |
Chris Lattner | 10b318b | 2010-01-17 21:43:43 +0000 | [diff] [blame] | 270 | O << *Sym; |
Jim Grosbach | b0739b7 | 2010-09-02 01:02:06 +0000 | [diff] [blame] | 271 | |
Chris Lattner | b8f64a7 | 2009-10-19 18:49:14 +0000 | [diff] [blame] | 272 | MachineModuleInfoMachO &MMIMachO = |
| 273 | MMI->getObjFileInfo<MachineModuleInfoMachO>(); |
Bill Wendling | cebae36 | 2010-03-10 22:34:10 +0000 | [diff] [blame] | 274 | MachineModuleInfoImpl::StubValueTy &StubSym = |
Chris Lattner | b8f64a7 | 2009-10-19 18:49:14 +0000 | [diff] [blame] | 275 | GV->hasHiddenVisibility() ? MMIMachO.getHiddenGVStubEntry(Sym) : |
| 276 | MMIMachO.getGVStubEntry(Sym); |
Bill Wendling | cebae36 | 2010-03-10 22:34:10 +0000 | [diff] [blame] | 277 | if (StubSym.getPointer() == 0) |
| 278 | StubSym = MachineModuleInfoImpl:: |
Chris Lattner | d62f1b4 | 2010-03-12 21:19:23 +0000 | [diff] [blame] | 279 | StubValueTy(Mang->getSymbol(GV), !GV->hasInternalLinkage()); |
Evan Cheng | e4e4ed3 | 2009-08-28 23:18:09 +0000 | [diff] [blame] | 280 | } |
Bob Wilson | 28989a8 | 2009-11-02 16:59:06 +0000 | [diff] [blame] | 281 | } else { |
| 282 | assert(ACPV->isExtSymbol() && "unrecognized constant pool value"); |
Chris Lattner | 10b318b | 2010-01-17 21:43:43 +0000 | [diff] [blame] | 283 | O << *GetExternalSymbolSymbol(ACPV->getSymbol()); |
Bob Wilson | 28989a8 | 2009-11-02 16:59:06 +0000 | [diff] [blame] | 284 | } |
Jim Grosbach | e995221 | 2009-09-04 01:38:51 +0000 | [diff] [blame] | 285 | |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 286 | if (ACPV->hasModifier()) O << "(" << ACPV->getModifier() << ")"; |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 287 | if (ACPV->getPCAdjustment() != 0) { |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 288 | O << "-(" << MAI->getPrivateGlobalPrefix() << "PC" |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 289 | << getFunctionNumber() << "_" << ACPV->getLabelId() |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 290 | << "+" << (unsigned)ACPV->getPCAdjustment(); |
| 291 | if (ACPV->mustAddCurrentAddress()) |
| 292 | O << "-."; |
Chris Lattner | 8b37875 | 2010-01-15 23:26:49 +0000 | [diff] [blame] | 293 | O << ')'; |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 294 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 295 | } |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 296 | }; |
| 297 | } // end of anonymous namespace |
| 298 | |
| 299 | #include "ARMGenAsmWriter.inc" |
| 300 | |
Chris Lattner | 953ebb7 | 2010-01-27 23:58:11 +0000 | [diff] [blame] | 301 | void ARMAsmPrinter::EmitFunctionEntryLabel() { |
| 302 | if (AFI->isThumbFunction()) { |
Chris Lattner | 9d7efd3 | 2010-04-04 07:05:53 +0000 | [diff] [blame] | 303 | OutStreamer.EmitRawText(StringRef("\t.code\t16")); |
Chris Lattner | 0752cda | 2010-04-05 16:32:14 +0000 | [diff] [blame] | 304 | if (!Subtarget->isTargetDarwin()) |
Chris Lattner | 9d7efd3 | 2010-04-04 07:05:53 +0000 | [diff] [blame] | 305 | OutStreamer.EmitRawText(StringRef("\t.thumb_func")); |
Chris Lattner | 0752cda | 2010-04-05 16:32:14 +0000 | [diff] [blame] | 306 | else { |
| 307 | // This needs to emit to a temporary string to get properly quoted |
| 308 | // MCSymbols when they have spaces in them. |
| 309 | SmallString<128> Tmp; |
| 310 | raw_svector_ostream OS(Tmp); |
| 311 | OS << "\t.thumb_func\t" << *CurrentFnSym; |
| 312 | OutStreamer.EmitRawText(OS.str()); |
| 313 | } |
Chris Lattner | 953ebb7 | 2010-01-27 23:58:11 +0000 | [diff] [blame] | 314 | } |
Jim Grosbach | b0739b7 | 2010-09-02 01:02:06 +0000 | [diff] [blame] | 315 | |
Chris Lattner | 953ebb7 | 2010-01-27 23:58:11 +0000 | [diff] [blame] | 316 | OutStreamer.EmitLabel(CurrentFnSym); |
| 317 | } |
| 318 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 319 | /// runOnMachineFunction - This uses the printInstruction() |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 320 | /// method to print assembly for each instruction. |
| 321 | /// |
| 322 | bool ARMAsmPrinter::runOnMachineFunction(MachineFunction &MF) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 323 | AFI = MF.getInfo<ARMFunctionInfo>(); |
Evan Cheng | 6d63a72 | 2008-09-18 07:27:23 +0000 | [diff] [blame] | 324 | MCP = MF.getConstantPool(); |
Rafael Espindola | 4b442b5 | 2006-05-23 02:48:20 +0000 | [diff] [blame] | 325 | |
Chris Lattner | d49fe1b | 2010-01-28 01:28:58 +0000 | [diff] [blame] | 326 | return AsmPrinter::runOnMachineFunction(MF); |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 327 | } |
| 328 | |
Evan Cheng | 055b031 | 2009-06-29 07:51:04 +0000 | [diff] [blame] | 329 | void ARMAsmPrinter::printOperand(const MachineInstr *MI, int OpNum, |
Chris Lattner | 35c33bd | 2010-04-04 04:47:45 +0000 | [diff] [blame] | 330 | raw_ostream &O, const char *Modifier) { |
Evan Cheng | 055b031 | 2009-06-29 07:51:04 +0000 | [diff] [blame] | 331 | const MachineOperand &MO = MI->getOperand(OpNum); |
Anton Korobeynikov | 5cdc3a9 | 2009-11-24 00:44:37 +0000 | [diff] [blame] | 332 | unsigned TF = MO.getTargetFlags(); |
| 333 | |
Rafael Espindola | 2f99b6b | 2006-05-25 12:57:06 +0000 | [diff] [blame] | 334 | switch (MO.getType()) { |
Chris Lattner | 8bc86cb | 2009-10-19 20:59:55 +0000 | [diff] [blame] | 335 | default: |
| 336 | assert(0 && "<unknown operand type>"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 337 | case MachineOperand::MO_Register: { |
| 338 | unsigned Reg = MO.getReg(); |
Chris Lattner | 8bc86cb | 2009-10-19 20:59:55 +0000 | [diff] [blame] | 339 | assert(TargetRegisterInfo::isPhysicalRegister(Reg)); |
Bob Wilson | de0ae8f | 2010-09-16 04:55:00 +0000 | [diff] [blame] | 340 | if (Modifier && strcmp(Modifier, "lane") == 0) { |
Jim Grosbach | a4c3c8f | 2010-09-15 20:26:25 +0000 | [diff] [blame] | 341 | unsigned RegNum = getARMRegisterNumbering(Reg); |
Chris Lattner | 9d1c1ad | 2010-04-04 18:06:11 +0000 | [diff] [blame] | 342 | unsigned DReg = |
Jakob Stoklund Olesen | e00fa64 | 2010-05-25 00:15:15 +0000 | [diff] [blame] | 343 | TM.getRegisterInfo()->getMatchingSuperReg(Reg, |
| 344 | RegNum & 1 ? ARM::ssub_1 : ARM::ssub_0, &ARM::DPR_VFP2RegClass); |
Chris Lattner | 8bc86cb | 2009-10-19 20:59:55 +0000 | [diff] [blame] | 345 | O << getRegisterName(DReg) << '[' << (RegNum & 1) << ']'; |
| 346 | } else { |
Anton Korobeynikov | e8ea011 | 2009-11-07 15:20:32 +0000 | [diff] [blame] | 347 | assert(!MO.getSubReg() && "Subregs should be eliminated!"); |
Chris Lattner | 8bc86cb | 2009-10-19 20:59:55 +0000 | [diff] [blame] | 348 | O << getRegisterName(Reg); |
| 349 | } |
Rafael Espindola | 2f99b6b | 2006-05-25 12:57:06 +0000 | [diff] [blame] | 350 | break; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 351 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 352 | case MachineOperand::MO_Immediate: { |
Evan Cheng | 5adb66a | 2009-09-28 09:14:39 +0000 | [diff] [blame] | 353 | int64_t Imm = MO.getImm(); |
Anton Korobeynikov | 632606c | 2009-10-08 20:43:22 +0000 | [diff] [blame] | 354 | O << '#'; |
Anton Korobeynikov | 5cdc3a9 | 2009-11-24 00:44:37 +0000 | [diff] [blame] | 355 | if ((Modifier && strcmp(Modifier, "lo16") == 0) || |
| 356 | (TF & ARMII::MO_LO16)) |
| 357 | O << ":lower16:"; |
| 358 | else if ((Modifier && strcmp(Modifier, "hi16") == 0) || |
| 359 | (TF & ARMII::MO_HI16)) |
| 360 | O << ":upper16:"; |
Anton Korobeynikov | 632606c | 2009-10-08 20:43:22 +0000 | [diff] [blame] | 361 | O << Imm; |
Rafael Espindola | 2f99b6b | 2006-05-25 12:57:06 +0000 | [diff] [blame] | 362 | break; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 363 | } |
Rafael Espindola | 2f99b6b | 2006-05-25 12:57:06 +0000 | [diff] [blame] | 364 | case MachineOperand::MO_MachineBasicBlock: |
Chris Lattner | 1b2eb0e | 2010-03-13 21:04:28 +0000 | [diff] [blame] | 365 | O << *MO.getMBB()->getSymbol(); |
Rafael Espindola | 2f99b6b | 2006-05-25 12:57:06 +0000 | [diff] [blame] | 366 | return; |
Rafael Espindola | 84b19be | 2006-07-16 01:02:57 +0000 | [diff] [blame] | 367 | case MachineOperand::MO_GlobalAddress: { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 368 | bool isCallOp = Modifier && !strcmp(Modifier, "call"); |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 369 | const GlobalValue *GV = MO.getGlobal(); |
Anton Korobeynikov | 5cdc3a9 | 2009-11-24 00:44:37 +0000 | [diff] [blame] | 370 | |
| 371 | if ((Modifier && strcmp(Modifier, "lo16") == 0) || |
| 372 | (TF & ARMII::MO_LO16)) |
| 373 | O << ":lower16:"; |
| 374 | else if ((Modifier && strcmp(Modifier, "hi16") == 0) || |
| 375 | (TF & ARMII::MO_HI16)) |
| 376 | O << ":upper16:"; |
Chris Lattner | d62f1b4 | 2010-03-12 21:19:23 +0000 | [diff] [blame] | 377 | O << *Mang->getSymbol(GV); |
Anton Korobeynikov | 7751ad9 | 2008-11-22 16:15:34 +0000 | [diff] [blame] | 378 | |
Chris Lattner | 0c08d09 | 2010-04-03 22:28:33 +0000 | [diff] [blame] | 379 | printOffset(MO.getOffset(), O); |
Anton Korobeynikov | 7751ad9 | 2008-11-22 16:15:34 +0000 | [diff] [blame] | 380 | |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 381 | if (isCallOp && Subtarget->isTargetELF() && |
| 382 | TM.getRelocationModel() == Reloc::PIC_) |
| 383 | O << "(PLT)"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 384 | break; |
Rafael Espindola | 84b19be | 2006-07-16 01:02:57 +0000 | [diff] [blame] | 385 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 386 | case MachineOperand::MO_ExternalSymbol: { |
| 387 | bool isCallOp = Modifier && !strcmp(Modifier, "call"); |
Chris Lattner | 10b318b | 2010-01-17 21:43:43 +0000 | [diff] [blame] | 388 | O << *GetExternalSymbolSymbol(MO.getSymbolName()); |
Jim Grosbach | b0739b7 | 2010-09-02 01:02:06 +0000 | [diff] [blame] | 389 | |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 390 | if (isCallOp && Subtarget->isTargetELF() && |
| 391 | TM.getRelocationModel() == Reloc::PIC_) |
| 392 | O << "(PLT)"; |
Rafael Espindola | 2f99b6b | 2006-05-25 12:57:06 +0000 | [diff] [blame] | 393 | break; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 394 | } |
Rafael Espindola | 2f99b6b | 2006-05-25 12:57:06 +0000 | [diff] [blame] | 395 | case MachineOperand::MO_ConstantPoolIndex: |
Chris Lattner | 1b46f43 | 2010-01-23 07:00:21 +0000 | [diff] [blame] | 396 | O << *GetCPISymbol(MO.getIndex()); |
Rafael Espindola | 2f99b6b | 2006-05-25 12:57:06 +0000 | [diff] [blame] | 397 | break; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 398 | case MachineOperand::MO_JumpTableIndex: |
Chris Lattner | 1b46f43 | 2010-01-23 07:00:21 +0000 | [diff] [blame] | 399 | O << *GetJTISymbol(MO.getIndex()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 400 | break; |
Rafael Espindola | 2f99b6b | 2006-05-25 12:57:06 +0000 | [diff] [blame] | 401 | } |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 402 | } |
| 403 | |
Chris Lattner | 35c33bd | 2010-04-04 04:47:45 +0000 | [diff] [blame] | 404 | static void printSOImm(raw_ostream &O, int64_t V, bool VerboseAsm, |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 405 | const MCAsmInfo *MAI) { |
Evan Cheng | e7cbe41 | 2009-07-08 21:03:57 +0000 | [diff] [blame] | 406 | // Break it up into two parts that make up a shifter immediate. |
| 407 | V = ARM_AM::getSOImmVal(V); |
| 408 | assert(V != -1 && "Not a valid so_imm value!"); |
| 409 | |
Evan Cheng | c70d184 | 2007-03-20 08:11:30 +0000 | [diff] [blame] | 410 | unsigned Imm = ARM_AM::getSOImmValImm(V); |
| 411 | unsigned Rot = ARM_AM::getSOImmValRot(V); |
Anton Korobeynikov | 7751ad9 | 2008-11-22 16:15:34 +0000 | [diff] [blame] | 412 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 413 | // Print low-level immediate formation info, per |
| 414 | // A5.1.3: "Data-processing operands - Immediate". |
| 415 | if (Rot) { |
| 416 | O << "#" << Imm << ", " << Rot; |
| 417 | // Pretty printed version. |
Evan Cheng | 3938242 | 2009-10-28 01:44:26 +0000 | [diff] [blame] | 418 | if (VerboseAsm) { |
Chris Lattner | 35c33bd | 2010-04-04 04:47:45 +0000 | [diff] [blame] | 419 | O << "\t" << MAI->getCommentString() << ' '; |
Evan Cheng | 3938242 | 2009-10-28 01:44:26 +0000 | [diff] [blame] | 420 | O << (int)ARM_AM::rotr32(Imm, Rot); |
| 421 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 422 | } else { |
| 423 | O << "#" << Imm; |
| 424 | } |
| 425 | } |
| 426 | |
Evan Cheng | c70d184 | 2007-03-20 08:11:30 +0000 | [diff] [blame] | 427 | /// printSOImmOperand - SOImm is 4-bit rotate amount in bits 8-11 with 8-bit |
| 428 | /// immediate in bits 0-7. |
Chris Lattner | 35c33bd | 2010-04-04 04:47:45 +0000 | [diff] [blame] | 429 | void ARMAsmPrinter::printSOImmOperand(const MachineInstr *MI, int OpNum, |
| 430 | raw_ostream &O) { |
Evan Cheng | c70d184 | 2007-03-20 08:11:30 +0000 | [diff] [blame] | 431 | const MachineOperand &MO = MI->getOperand(OpNum); |
Dan Gohman | d735b80 | 2008-10-03 15:45:36 +0000 | [diff] [blame] | 432 | assert(MO.isImm() && "Not a valid so_imm value!"); |
Chris Lattner | 3f53c83 | 2010-04-04 18:52:31 +0000 | [diff] [blame] | 433 | printSOImm(O, MO.getImm(), isVerbose(), MAI); |
Evan Cheng | c70d184 | 2007-03-20 08:11:30 +0000 | [diff] [blame] | 434 | } |
| 435 | |
Evan Cheng | 9092213 | 2008-11-06 02:25:39 +0000 | [diff] [blame] | 436 | /// printSOImm2PartOperand - SOImm is broken into two pieces using a 'mov' |
| 437 | /// followed by an 'orr' to materialize. |
Chris Lattner | 35c33bd | 2010-04-04 04:47:45 +0000 | [diff] [blame] | 438 | void ARMAsmPrinter::printSOImm2PartOperand(const MachineInstr *MI, int OpNum, |
| 439 | raw_ostream &O) { |
Evan Cheng | c70d184 | 2007-03-20 08:11:30 +0000 | [diff] [blame] | 440 | const MachineOperand &MO = MI->getOperand(OpNum); |
Dan Gohman | d735b80 | 2008-10-03 15:45:36 +0000 | [diff] [blame] | 441 | assert(MO.isImm() && "Not a valid so_imm value!"); |
Chris Lattner | 9a1ceae | 2007-12-30 20:49:49 +0000 | [diff] [blame] | 442 | unsigned V1 = ARM_AM::getSOImmTwoPartFirst(MO.getImm()); |
| 443 | unsigned V2 = ARM_AM::getSOImmTwoPartSecond(MO.getImm()); |
Chris Lattner | 3f53c83 | 2010-04-04 18:52:31 +0000 | [diff] [blame] | 444 | printSOImm(O, V1, isVerbose(), MAI); |
Evan Cheng | 5e148a3 | 2007-06-05 18:55:18 +0000 | [diff] [blame] | 445 | O << "\n\torr"; |
Chris Lattner | 35c33bd | 2010-04-04 04:47:45 +0000 | [diff] [blame] | 446 | printPredicateOperand(MI, 2, O); |
Evan Cheng | 162e309 | 2009-10-26 23:45:59 +0000 | [diff] [blame] | 447 | O << "\t"; |
Chris Lattner | 35c33bd | 2010-04-04 04:47:45 +0000 | [diff] [blame] | 448 | printOperand(MI, 0, O); |
Evan Cheng | c70d184 | 2007-03-20 08:11:30 +0000 | [diff] [blame] | 449 | O << ", "; |
Chris Lattner | 35c33bd | 2010-04-04 04:47:45 +0000 | [diff] [blame] | 450 | printOperand(MI, 0, O); |
Evan Cheng | c70d184 | 2007-03-20 08:11:30 +0000 | [diff] [blame] | 451 | O << ", "; |
Chris Lattner | 3f53c83 | 2010-04-04 18:52:31 +0000 | [diff] [blame] | 452 | printSOImm(O, V2, isVerbose(), MAI); |
Evan Cheng | c70d184 | 2007-03-20 08:11:30 +0000 | [diff] [blame] | 453 | } |
| 454 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 455 | // so_reg is a 4-operand unit corresponding to register forms of the A5.1 |
| 456 | // "Addressing Mode 1 - Data-processing operands" forms. This includes: |
Evan Cheng | 9cb9e67 | 2009-06-27 02:26:13 +0000 | [diff] [blame] | 457 | // REG 0 0 - e.g. R5 |
| 458 | // REG REG 0,SH_OPC - e.g. R5, ROR R3 |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 459 | // REG 0 IMM,SH_OPC - e.g. R5, LSL #3 |
Chris Lattner | 35c33bd | 2010-04-04 04:47:45 +0000 | [diff] [blame] | 460 | void ARMAsmPrinter::printSORegOperand(const MachineInstr *MI, int Op, |
| 461 | raw_ostream &O) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 462 | const MachineOperand &MO1 = MI->getOperand(Op); |
| 463 | const MachineOperand &MO2 = MI->getOperand(Op+1); |
| 464 | const MachineOperand &MO3 = MI->getOperand(Op+2); |
| 465 | |
Chris Lattner | 762ccea | 2009-09-13 20:31:40 +0000 | [diff] [blame] | 466 | O << getRegisterName(MO1.getReg()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 467 | |
| 468 | // Print the shift opc. |
Bob Wilson | 1d9125a | 2010-08-05 00:34:42 +0000 | [diff] [blame] | 469 | ARM_AM::ShiftOpc ShOpc = ARM_AM::getSORegShOp(MO3.getImm()); |
| 470 | O << ", " << ARM_AM::getShiftOpcStr(ShOpc); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 471 | if (MO2.getReg()) { |
Bob Wilson | 1d9125a | 2010-08-05 00:34:42 +0000 | [diff] [blame] | 472 | O << ' ' << getRegisterName(MO2.getReg()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 473 | assert(ARM_AM::getSORegOffset(MO3.getImm()) == 0); |
Bob Wilson | 1d9125a | 2010-08-05 00:34:42 +0000 | [diff] [blame] | 474 | } else if (ShOpc != ARM_AM::rrx) { |
| 475 | O << " #" << ARM_AM::getSORegOffset(MO3.getImm()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 476 | } |
| 477 | } |
| 478 | |
Chris Lattner | 35c33bd | 2010-04-04 04:47:45 +0000 | [diff] [blame] | 479 | void ARMAsmPrinter::printAddrMode2Operand(const MachineInstr *MI, int Op, |
| 480 | raw_ostream &O) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 481 | const MachineOperand &MO1 = MI->getOperand(Op); |
| 482 | const MachineOperand &MO2 = MI->getOperand(Op+1); |
| 483 | const MachineOperand &MO3 = MI->getOperand(Op+2); |
| 484 | |
Dan Gohman | d735b80 | 2008-10-03 15:45:36 +0000 | [diff] [blame] | 485 | if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right. |
Chris Lattner | 35c33bd | 2010-04-04 04:47:45 +0000 | [diff] [blame] | 486 | printOperand(MI, Op, O); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 487 | return; |
| 488 | } |
| 489 | |
Chris Lattner | 762ccea | 2009-09-13 20:31:40 +0000 | [diff] [blame] | 490 | O << "[" << getRegisterName(MO1.getReg()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 491 | |
| 492 | if (!MO2.getReg()) { |
Johnny Chen | 9e08876 | 2010-03-17 17:52:21 +0000 | [diff] [blame] | 493 | if (ARM_AM::getAM2Offset(MO3.getImm())) // Don't print +0. |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 494 | O << ", #" |
Johnny Chen | 9e08876 | 2010-03-17 17:52:21 +0000 | [diff] [blame] | 495 | << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO3.getImm())) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 496 | << ARM_AM::getAM2Offset(MO3.getImm()); |
| 497 | O << "]"; |
| 498 | return; |
| 499 | } |
| 500 | |
| 501 | O << ", " |
Johnny Chen | 9e08876 | 2010-03-17 17:52:21 +0000 | [diff] [blame] | 502 | << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO3.getImm())) |
Chris Lattner | 762ccea | 2009-09-13 20:31:40 +0000 | [diff] [blame] | 503 | << getRegisterName(MO2.getReg()); |
Jim Grosbach | e995221 | 2009-09-04 01:38:51 +0000 | [diff] [blame] | 504 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 505 | if (unsigned ShImm = ARM_AM::getAM2Offset(MO3.getImm())) |
| 506 | O << ", " |
Chris Lattner | 9a1ceae | 2007-12-30 20:49:49 +0000 | [diff] [blame] | 507 | << ARM_AM::getShiftOpcStr(ARM_AM::getAM2ShiftOpc(MO3.getImm())) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 508 | << " #" << ShImm; |
| 509 | O << "]"; |
| 510 | } |
| 511 | |
Chris Lattner | 35c33bd | 2010-04-04 04:47:45 +0000 | [diff] [blame] | 512 | void ARMAsmPrinter::printAddrMode2OffsetOperand(const MachineInstr *MI, int Op, |
| 513 | raw_ostream &O) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 514 | const MachineOperand &MO1 = MI->getOperand(Op); |
| 515 | const MachineOperand &MO2 = MI->getOperand(Op+1); |
| 516 | |
| 517 | if (!MO1.getReg()) { |
Evan Cheng | bdc9869 | 2007-05-03 23:30:36 +0000 | [diff] [blame] | 518 | unsigned ImmOffs = ARM_AM::getAM2Offset(MO2.getImm()); |
Evan Cheng | bdc9869 | 2007-05-03 23:30:36 +0000 | [diff] [blame] | 519 | O << "#" |
Johnny Chen | 9e08876 | 2010-03-17 17:52:21 +0000 | [diff] [blame] | 520 | << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO2.getImm())) |
Evan Cheng | bdc9869 | 2007-05-03 23:30:36 +0000 | [diff] [blame] | 521 | << ImmOffs; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 522 | return; |
| 523 | } |
| 524 | |
Johnny Chen | 9e08876 | 2010-03-17 17:52:21 +0000 | [diff] [blame] | 525 | O << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO2.getImm())) |
Chris Lattner | 762ccea | 2009-09-13 20:31:40 +0000 | [diff] [blame] | 526 | << getRegisterName(MO1.getReg()); |
Jim Grosbach | e995221 | 2009-09-04 01:38:51 +0000 | [diff] [blame] | 527 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 528 | if (unsigned ShImm = ARM_AM::getAM2Offset(MO2.getImm())) |
| 529 | O << ", " |
Chris Lattner | 9a1ceae | 2007-12-30 20:49:49 +0000 | [diff] [blame] | 530 | << ARM_AM::getShiftOpcStr(ARM_AM::getAM2ShiftOpc(MO2.getImm())) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 531 | << " #" << ShImm; |
| 532 | } |
| 533 | |
Chris Lattner | 35c33bd | 2010-04-04 04:47:45 +0000 | [diff] [blame] | 534 | void ARMAsmPrinter::printAddrMode3Operand(const MachineInstr *MI, int Op, |
| 535 | raw_ostream &O) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 536 | const MachineOperand &MO1 = MI->getOperand(Op); |
| 537 | const MachineOperand &MO2 = MI->getOperand(Op+1); |
| 538 | const MachineOperand &MO3 = MI->getOperand(Op+2); |
Jim Grosbach | e995221 | 2009-09-04 01:38:51 +0000 | [diff] [blame] | 539 | |
Dan Gohman | 6f0d024 | 2008-02-10 18:45:23 +0000 | [diff] [blame] | 540 | assert(TargetRegisterInfo::isPhysicalRegister(MO1.getReg())); |
Chris Lattner | 762ccea | 2009-09-13 20:31:40 +0000 | [diff] [blame] | 541 | O << "[" << getRegisterName(MO1.getReg()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 542 | |
| 543 | if (MO2.getReg()) { |
| 544 | O << ", " |
| 545 | << (char)ARM_AM::getAM3Op(MO3.getImm()) |
Chris Lattner | 762ccea | 2009-09-13 20:31:40 +0000 | [diff] [blame] | 546 | << getRegisterName(MO2.getReg()) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 547 | << "]"; |
| 548 | return; |
| 549 | } |
Jim Grosbach | e995221 | 2009-09-04 01:38:51 +0000 | [diff] [blame] | 550 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 551 | if (unsigned ImmOffs = ARM_AM::getAM3Offset(MO3.getImm())) |
| 552 | O << ", #" |
Johnny Chen | 9e08876 | 2010-03-17 17:52:21 +0000 | [diff] [blame] | 553 | << ARM_AM::getAddrOpcStr(ARM_AM::getAM3Op(MO3.getImm())) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 554 | << ImmOffs; |
| 555 | O << "]"; |
| 556 | } |
| 557 | |
Chris Lattner | 35c33bd | 2010-04-04 04:47:45 +0000 | [diff] [blame] | 558 | void ARMAsmPrinter::printAddrMode3OffsetOperand(const MachineInstr *MI, int Op, |
| 559 | raw_ostream &O){ |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 560 | const MachineOperand &MO1 = MI->getOperand(Op); |
| 561 | const MachineOperand &MO2 = MI->getOperand(Op+1); |
| 562 | |
| 563 | if (MO1.getReg()) { |
| 564 | O << (char)ARM_AM::getAM3Op(MO2.getImm()) |
Chris Lattner | 762ccea | 2009-09-13 20:31:40 +0000 | [diff] [blame] | 565 | << getRegisterName(MO1.getReg()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 566 | return; |
| 567 | } |
| 568 | |
| 569 | unsigned ImmOffs = ARM_AM::getAM3Offset(MO2.getImm()); |
| 570 | O << "#" |
Johnny Chen | 9e08876 | 2010-03-17 17:52:21 +0000 | [diff] [blame] | 571 | << ARM_AM::getAddrOpcStr(ARM_AM::getAM3Op(MO2.getImm())) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 572 | << ImmOffs; |
| 573 | } |
Jim Grosbach | e995221 | 2009-09-04 01:38:51 +0000 | [diff] [blame] | 574 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 575 | void ARMAsmPrinter::printAddrMode4Operand(const MachineInstr *MI, int Op, |
Chris Lattner | 35c33bd | 2010-04-04 04:47:45 +0000 | [diff] [blame] | 576 | raw_ostream &O, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 577 | const char *Modifier) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 578 | const MachineOperand &MO2 = MI->getOperand(Op+1); |
| 579 | ARM_AM::AMSubMode Mode = ARM_AM::getAM4SubMode(MO2.getImm()); |
| 580 | if (Modifier && strcmp(Modifier, "submode") == 0) { |
Bob Wilson | ea7f22c | 2010-03-16 16:19:07 +0000 | [diff] [blame] | 581 | O << ARM_AM::getAMSubModeStr(Mode); |
Evan Cheng | d77c7ab | 2009-08-07 21:19:10 +0000 | [diff] [blame] | 582 | } else if (Modifier && strcmp(Modifier, "wide") == 0) { |
| 583 | ARM_AM::AMSubMode Mode = ARM_AM::getAM4SubMode(MO2.getImm()); |
| 584 | if (Mode == ARM_AM::ia) |
| 585 | O << ".w"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 586 | } else { |
Chris Lattner | 35c33bd | 2010-04-04 04:47:45 +0000 | [diff] [blame] | 587 | printOperand(MI, Op, O); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 588 | } |
| 589 | } |
| 590 | |
| 591 | void ARMAsmPrinter::printAddrMode5Operand(const MachineInstr *MI, int Op, |
Chris Lattner | 35c33bd | 2010-04-04 04:47:45 +0000 | [diff] [blame] | 592 | raw_ostream &O, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 593 | const char *Modifier) { |
| 594 | const MachineOperand &MO1 = MI->getOperand(Op); |
| 595 | const MachineOperand &MO2 = MI->getOperand(Op+1); |
| 596 | |
Dan Gohman | d735b80 | 2008-10-03 15:45:36 +0000 | [diff] [blame] | 597 | if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right. |
Chris Lattner | 35c33bd | 2010-04-04 04:47:45 +0000 | [diff] [blame] | 598 | printOperand(MI, Op, O); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 599 | return; |
| 600 | } |
Jim Grosbach | e995221 | 2009-09-04 01:38:51 +0000 | [diff] [blame] | 601 | |
Dan Gohman | 6f0d024 | 2008-02-10 18:45:23 +0000 | [diff] [blame] | 602 | assert(TargetRegisterInfo::isPhysicalRegister(MO1.getReg())); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 603 | |
Chris Lattner | 762ccea | 2009-09-13 20:31:40 +0000 | [diff] [blame] | 604 | O << "[" << getRegisterName(MO1.getReg()); |
Jim Grosbach | e995221 | 2009-09-04 01:38:51 +0000 | [diff] [blame] | 605 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 606 | if (unsigned ImmOffs = ARM_AM::getAM5Offset(MO2.getImm())) { |
| 607 | O << ", #" |
Johnny Chen | 9e08876 | 2010-03-17 17:52:21 +0000 | [diff] [blame] | 608 | << ARM_AM::getAddrOpcStr(ARM_AM::getAM5Op(MO2.getImm())) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 609 | << ImmOffs*4; |
| 610 | } |
| 611 | O << "]"; |
| 612 | } |
| 613 | |
Chris Lattner | 35c33bd | 2010-04-04 04:47:45 +0000 | [diff] [blame] | 614 | void ARMAsmPrinter::printAddrMode6Operand(const MachineInstr *MI, int Op, |
| 615 | raw_ostream &O) { |
Bob Wilson | 8b024a5 | 2009-07-01 23:16:05 +0000 | [diff] [blame] | 616 | const MachineOperand &MO1 = MI->getOperand(Op); |
| 617 | const MachineOperand &MO2 = MI->getOperand(Op+1); |
Bob Wilson | 8b024a5 | 2009-07-01 23:16:05 +0000 | [diff] [blame] | 618 | |
Jim Grosbach | 8a5ec86 | 2009-11-07 21:25:39 +0000 | [diff] [blame] | 619 | O << "[" << getRegisterName(MO1.getReg()); |
Bob Wilson | 226036e | 2010-03-20 22:13:40 +0000 | [diff] [blame] | 620 | if (MO2.getImm()) { |
Anton Korobeynikov | bce3dbd | 2009-11-17 20:04:59 +0000 | [diff] [blame] | 621 | // FIXME: Both darwin as and GNU as violate ARM docs here. |
Bob Wilson | 273ff31 | 2010-07-14 23:54:43 +0000 | [diff] [blame] | 622 | O << ", :" << (MO2.getImm() << 3); |
Jim Grosbach | 8a5ec86 | 2009-11-07 21:25:39 +0000 | [diff] [blame] | 623 | } |
| 624 | O << "]"; |
Bob Wilson | 226036e | 2010-03-20 22:13:40 +0000 | [diff] [blame] | 625 | } |
Bob Wilson | a43e6bf | 2010-03-16 23:01:13 +0000 | [diff] [blame] | 626 | |
Chris Lattner | 35c33bd | 2010-04-04 04:47:45 +0000 | [diff] [blame] | 627 | void ARMAsmPrinter::printAddrMode6OffsetOperand(const MachineInstr *MI, int Op, |
| 628 | raw_ostream &O){ |
Bob Wilson | 226036e | 2010-03-20 22:13:40 +0000 | [diff] [blame] | 629 | const MachineOperand &MO = MI->getOperand(Op); |
| 630 | if (MO.getReg() == 0) |
| 631 | O << "!"; |
| 632 | else |
| 633 | O << ", " << getRegisterName(MO.getReg()); |
Bob Wilson | 8b024a5 | 2009-07-01 23:16:05 +0000 | [diff] [blame] | 634 | } |
| 635 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 636 | void ARMAsmPrinter::printAddrModePCOperand(const MachineInstr *MI, int Op, |
Chris Lattner | 35c33bd | 2010-04-04 04:47:45 +0000 | [diff] [blame] | 637 | raw_ostream &O, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 638 | const char *Modifier) { |
| 639 | if (Modifier && strcmp(Modifier, "label") == 0) { |
Chris Lattner | 35c33bd | 2010-04-04 04:47:45 +0000 | [diff] [blame] | 640 | printPCLabel(MI, Op+1, O); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 641 | return; |
| 642 | } |
| 643 | |
| 644 | const MachineOperand &MO1 = MI->getOperand(Op); |
Dan Gohman | 6f0d024 | 2008-02-10 18:45:23 +0000 | [diff] [blame] | 645 | assert(TargetRegisterInfo::isPhysicalRegister(MO1.getReg())); |
Johnny Chen | 9e08876 | 2010-03-17 17:52:21 +0000 | [diff] [blame] | 646 | O << "[pc, " << getRegisterName(MO1.getReg()) << "]"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 647 | } |
| 648 | |
| 649 | void |
Chris Lattner | 35c33bd | 2010-04-04 04:47:45 +0000 | [diff] [blame] | 650 | ARMAsmPrinter::printBitfieldInvMaskImmOperand(const MachineInstr *MI, int Op, |
| 651 | raw_ostream &O) { |
Evan Cheng | f49810c | 2009-06-23 17:48:47 +0000 | [diff] [blame] | 652 | const MachineOperand &MO = MI->getOperand(Op); |
| 653 | uint32_t v = ~MO.getImm(); |
Evan Cheng | 9e03cbe | 2009-06-25 22:04:44 +0000 | [diff] [blame] | 654 | int32_t lsb = CountTrailingZeros_32(v); |
Nick Lewycky | b825aaa | 2009-06-24 01:08:42 +0000 | [diff] [blame] | 655 | int32_t width = (32 - CountLeadingZeros_32 (v)) - lsb; |
Evan Cheng | f49810c | 2009-06-23 17:48:47 +0000 | [diff] [blame] | 656 | assert(MO.isImm() && "Not a valid bf_inv_mask_imm value!"); |
| 657 | O << "#" << lsb << ", #" << width; |
| 658 | } |
| 659 | |
Johnny Chen | 1adc40c | 2010-08-12 20:46:17 +0000 | [diff] [blame] | 660 | void |
| 661 | ARMAsmPrinter::printMemBOption(const MachineInstr *MI, int OpNum, |
| 662 | raw_ostream &O) { |
| 663 | unsigned val = MI->getOperand(OpNum).getImm(); |
| 664 | O << ARM_MB::MemBOptToString(val); |
| 665 | } |
| 666 | |
Bob Wilson | 22f5dc7 | 2010-08-16 18:27:34 +0000 | [diff] [blame] | 667 | void ARMAsmPrinter::printShiftImmOperand(const MachineInstr *MI, int OpNum, |
Bob Wilson | eaf1c98 | 2010-08-11 23:10:46 +0000 | [diff] [blame] | 668 | raw_ostream &O) { |
| 669 | unsigned ShiftOp = MI->getOperand(OpNum).getImm(); |
| 670 | ARM_AM::ShiftOpc Opc = ARM_AM::getSORegShOp(ShiftOp); |
| 671 | switch (Opc) { |
| 672 | case ARM_AM::no_shift: |
| 673 | return; |
| 674 | case ARM_AM::lsl: |
| 675 | O << ", lsl #"; |
| 676 | break; |
| 677 | case ARM_AM::asr: |
| 678 | O << ", asr #"; |
| 679 | break; |
| 680 | default: |
Bob Wilson | 22f5dc7 | 2010-08-16 18:27:34 +0000 | [diff] [blame] | 681 | assert(0 && "unexpected shift opcode for shift immediate operand"); |
Bob Wilson | eaf1c98 | 2010-08-11 23:10:46 +0000 | [diff] [blame] | 682 | } |
| 683 | O << ARM_AM::getSORegOffset(ShiftOp); |
| 684 | } |
| 685 | |
Evan Cheng | 055b031 | 2009-06-29 07:51:04 +0000 | [diff] [blame] | 686 | //===--------------------------------------------------------------------===// |
| 687 | |
Chris Lattner | 35c33bd | 2010-04-04 04:47:45 +0000 | [diff] [blame] | 688 | void ARMAsmPrinter::printThumbS4ImmOperand(const MachineInstr *MI, int Op, |
| 689 | raw_ostream &O) { |
Evan Cheng | 2ef9c8a | 2009-11-19 06:57:41 +0000 | [diff] [blame] | 690 | O << "#" << MI->getOperand(Op).getImm() * 4; |
| 691 | } |
| 692 | |
Evan Cheng | f49810c | 2009-06-23 17:48:47 +0000 | [diff] [blame] | 693 | void |
Chris Lattner | 35c33bd | 2010-04-04 04:47:45 +0000 | [diff] [blame] | 694 | ARMAsmPrinter::printThumbITMask(const MachineInstr *MI, int Op, |
| 695 | raw_ostream &O) { |
Evan Cheng | e556474 | 2009-07-09 23:43:36 +0000 | [diff] [blame] | 696 | // (3 - the number of trailing zeros) is the number of then / else. |
| 697 | unsigned Mask = MI->getOperand(Op).getImm(); |
Johnny Chen | 9e08876 | 2010-03-17 17:52:21 +0000 | [diff] [blame] | 698 | unsigned CondBit0 = Mask >> 4 & 1; |
Evan Cheng | e556474 | 2009-07-09 23:43:36 +0000 | [diff] [blame] | 699 | unsigned NumTZ = CountTrailingZeros_32(Mask); |
| 700 | assert(NumTZ <= 3 && "Invalid IT mask!"); |
Evan Cheng | 06e1658 | 2009-07-10 01:54:42 +0000 | [diff] [blame] | 701 | for (unsigned Pos = 3, e = NumTZ; Pos > e; --Pos) { |
Johnny Chen | 9e08876 | 2010-03-17 17:52:21 +0000 | [diff] [blame] | 702 | bool T = ((Mask >> Pos) & 1) == CondBit0; |
Evan Cheng | e556474 | 2009-07-09 23:43:36 +0000 | [diff] [blame] | 703 | if (T) |
| 704 | O << 't'; |
| 705 | else |
| 706 | O << 'e'; |
| 707 | } |
| 708 | } |
| 709 | |
| 710 | void |
Chris Lattner | 35c33bd | 2010-04-04 04:47:45 +0000 | [diff] [blame] | 711 | ARMAsmPrinter::printThumbAddrModeRROperand(const MachineInstr *MI, int Op, |
| 712 | raw_ostream &O) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 713 | const MachineOperand &MO1 = MI->getOperand(Op); |
| 714 | const MachineOperand &MO2 = MI->getOperand(Op+1); |
Chris Lattner | 762ccea | 2009-09-13 20:31:40 +0000 | [diff] [blame] | 715 | O << "[" << getRegisterName(MO1.getReg()); |
| 716 | O << ", " << getRegisterName(MO2.getReg()) << "]"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 717 | } |
| 718 | |
| 719 | void |
| 720 | ARMAsmPrinter::printThumbAddrModeRI5Operand(const MachineInstr *MI, int Op, |
Chris Lattner | 35c33bd | 2010-04-04 04:47:45 +0000 | [diff] [blame] | 721 | raw_ostream &O, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 722 | unsigned Scale) { |
| 723 | const MachineOperand &MO1 = MI->getOperand(Op); |
Evan Cheng | cea117d | 2007-01-30 02:35:32 +0000 | [diff] [blame] | 724 | const MachineOperand &MO2 = MI->getOperand(Op+1); |
| 725 | const MachineOperand &MO3 = MI->getOperand(Op+2); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 726 | |
Dan Gohman | d735b80 | 2008-10-03 15:45:36 +0000 | [diff] [blame] | 727 | if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right. |
Chris Lattner | 35c33bd | 2010-04-04 04:47:45 +0000 | [diff] [blame] | 728 | printOperand(MI, Op, O); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 729 | return; |
| 730 | } |
| 731 | |
Chris Lattner | 762ccea | 2009-09-13 20:31:40 +0000 | [diff] [blame] | 732 | O << "[" << getRegisterName(MO1.getReg()); |
Evan Cheng | cea117d | 2007-01-30 02:35:32 +0000 | [diff] [blame] | 733 | if (MO3.getReg()) |
Chris Lattner | 762ccea | 2009-09-13 20:31:40 +0000 | [diff] [blame] | 734 | O << ", " << getRegisterName(MO3.getReg()); |
Evan Cheng | 4b6bbe1 | 2009-11-10 19:48:13 +0000 | [diff] [blame] | 735 | else if (unsigned ImmOffs = MO2.getImm()) |
Johnny Chen | 9e08876 | 2010-03-17 17:52:21 +0000 | [diff] [blame] | 736 | O << ", #" << ImmOffs * Scale; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 737 | O << "]"; |
| 738 | } |
| 739 | |
| 740 | void |
Chris Lattner | 35c33bd | 2010-04-04 04:47:45 +0000 | [diff] [blame] | 741 | ARMAsmPrinter::printThumbAddrModeS1Operand(const MachineInstr *MI, int Op, |
| 742 | raw_ostream &O) { |
| 743 | printThumbAddrModeRI5Operand(MI, Op, O, 1); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 744 | } |
| 745 | void |
Chris Lattner | 35c33bd | 2010-04-04 04:47:45 +0000 | [diff] [blame] | 746 | ARMAsmPrinter::printThumbAddrModeS2Operand(const MachineInstr *MI, int Op, |
| 747 | raw_ostream &O) { |
| 748 | printThumbAddrModeRI5Operand(MI, Op, O, 2); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 749 | } |
| 750 | void |
Chris Lattner | 35c33bd | 2010-04-04 04:47:45 +0000 | [diff] [blame] | 751 | ARMAsmPrinter::printThumbAddrModeS4Operand(const MachineInstr *MI, int Op, |
| 752 | raw_ostream &O) { |
| 753 | printThumbAddrModeRI5Operand(MI, Op, O, 4); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 754 | } |
| 755 | |
Chris Lattner | 35c33bd | 2010-04-04 04:47:45 +0000 | [diff] [blame] | 756 | void ARMAsmPrinter::printThumbAddrModeSPOperand(const MachineInstr *MI,int Op, |
| 757 | raw_ostream &O) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 758 | const MachineOperand &MO1 = MI->getOperand(Op); |
| 759 | const MachineOperand &MO2 = MI->getOperand(Op+1); |
Chris Lattner | 762ccea | 2009-09-13 20:31:40 +0000 | [diff] [blame] | 760 | O << "[" << getRegisterName(MO1.getReg()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 761 | if (unsigned ImmOffs = MO2.getImm()) |
Johnny Chen | 9e08876 | 2010-03-17 17:52:21 +0000 | [diff] [blame] | 762 | O << ", #" << ImmOffs*4; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 763 | O << "]"; |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 764 | } |
| 765 | |
Evan Cheng | 055b031 | 2009-06-29 07:51:04 +0000 | [diff] [blame] | 766 | //===--------------------------------------------------------------------===// |
| 767 | |
Evan Cheng | 9cb9e67 | 2009-06-27 02:26:13 +0000 | [diff] [blame] | 768 | // Constant shifts t2_so_reg is a 2-operand unit corresponding to the Thumb2 |
| 769 | // register with shift forms. |
| 770 | // REG 0 0 - e.g. R5 |
| 771 | // REG IMM, SH_OPC - e.g. R5, LSL #3 |
Chris Lattner | 35c33bd | 2010-04-04 04:47:45 +0000 | [diff] [blame] | 772 | void ARMAsmPrinter::printT2SOOperand(const MachineInstr *MI, int OpNum, |
| 773 | raw_ostream &O) { |
Evan Cheng | 9cb9e67 | 2009-06-27 02:26:13 +0000 | [diff] [blame] | 774 | const MachineOperand &MO1 = MI->getOperand(OpNum); |
| 775 | const MachineOperand &MO2 = MI->getOperand(OpNum+1); |
| 776 | |
| 777 | unsigned Reg = MO1.getReg(); |
| 778 | assert(TargetRegisterInfo::isPhysicalRegister(Reg)); |
Chris Lattner | 762ccea | 2009-09-13 20:31:40 +0000 | [diff] [blame] | 779 | O << getRegisterName(Reg); |
Evan Cheng | 9cb9e67 | 2009-06-27 02:26:13 +0000 | [diff] [blame] | 780 | |
| 781 | // Print the shift opc. |
Evan Cheng | 9cb9e67 | 2009-06-27 02:26:13 +0000 | [diff] [blame] | 782 | assert(MO2.isImm() && "Not a valid t2_so_reg value!"); |
Bob Wilson | 1d9125a | 2010-08-05 00:34:42 +0000 | [diff] [blame] | 783 | ARM_AM::ShiftOpc ShOpc = ARM_AM::getSORegShOp(MO2.getImm()); |
| 784 | O << ", " << ARM_AM::getShiftOpcStr(ShOpc); |
| 785 | if (ShOpc != ARM_AM::rrx) |
| 786 | O << " #" << ARM_AM::getSORegOffset(MO2.getImm()); |
Evan Cheng | 9cb9e67 | 2009-06-27 02:26:13 +0000 | [diff] [blame] | 787 | } |
| 788 | |
Evan Cheng | 055b031 | 2009-06-29 07:51:04 +0000 | [diff] [blame] | 789 | void ARMAsmPrinter::printT2AddrModeImm12Operand(const MachineInstr *MI, |
Chris Lattner | 35c33bd | 2010-04-04 04:47:45 +0000 | [diff] [blame] | 790 | int OpNum, |
| 791 | raw_ostream &O) { |
Evan Cheng | 055b031 | 2009-06-29 07:51:04 +0000 | [diff] [blame] | 792 | const MachineOperand &MO1 = MI->getOperand(OpNum); |
| 793 | const MachineOperand &MO2 = MI->getOperand(OpNum+1); |
Evan Cheng | 9cb9e67 | 2009-06-27 02:26:13 +0000 | [diff] [blame] | 794 | |
Chris Lattner | 762ccea | 2009-09-13 20:31:40 +0000 | [diff] [blame] | 795 | O << "[" << getRegisterName(MO1.getReg()); |
Evan Cheng | 055b031 | 2009-06-29 07:51:04 +0000 | [diff] [blame] | 796 | |
| 797 | unsigned OffImm = MO2.getImm(); |
| 798 | if (OffImm) // Don't print +0. |
Johnny Chen | 9e08876 | 2010-03-17 17:52:21 +0000 | [diff] [blame] | 799 | O << ", #" << OffImm; |
Evan Cheng | 055b031 | 2009-06-29 07:51:04 +0000 | [diff] [blame] | 800 | O << "]"; |
| 801 | } |
| 802 | |
| 803 | void ARMAsmPrinter::printT2AddrModeImm8Operand(const MachineInstr *MI, |
Chris Lattner | 35c33bd | 2010-04-04 04:47:45 +0000 | [diff] [blame] | 804 | int OpNum, |
| 805 | raw_ostream &O) { |
Evan Cheng | 055b031 | 2009-06-29 07:51:04 +0000 | [diff] [blame] | 806 | const MachineOperand &MO1 = MI->getOperand(OpNum); |
| 807 | const MachineOperand &MO2 = MI->getOperand(OpNum+1); |
| 808 | |
Chris Lattner | 762ccea | 2009-09-13 20:31:40 +0000 | [diff] [blame] | 809 | O << "[" << getRegisterName(MO1.getReg()); |
Evan Cheng | 055b031 | 2009-06-29 07:51:04 +0000 | [diff] [blame] | 810 | |
| 811 | int32_t OffImm = (int32_t)MO2.getImm(); |
| 812 | // Don't print +0. |
| 813 | if (OffImm < 0) |
| 814 | O << ", #-" << -OffImm; |
| 815 | else if (OffImm > 0) |
Johnny Chen | 9e08876 | 2010-03-17 17:52:21 +0000 | [diff] [blame] | 816 | O << ", #" << OffImm; |
Evan Cheng | 055b031 | 2009-06-29 07:51:04 +0000 | [diff] [blame] | 817 | O << "]"; |
| 818 | } |
| 819 | |
Evan Cheng | 5c87417 | 2009-07-09 22:21:59 +0000 | [diff] [blame] | 820 | void ARMAsmPrinter::printT2AddrModeImm8s4Operand(const MachineInstr *MI, |
Chris Lattner | 35c33bd | 2010-04-04 04:47:45 +0000 | [diff] [blame] | 821 | int OpNum, |
| 822 | raw_ostream &O) { |
Evan Cheng | 5c87417 | 2009-07-09 22:21:59 +0000 | [diff] [blame] | 823 | const MachineOperand &MO1 = MI->getOperand(OpNum); |
| 824 | const MachineOperand &MO2 = MI->getOperand(OpNum+1); |
| 825 | |
Chris Lattner | 762ccea | 2009-09-13 20:31:40 +0000 | [diff] [blame] | 826 | O << "[" << getRegisterName(MO1.getReg()); |
Evan Cheng | 5c87417 | 2009-07-09 22:21:59 +0000 | [diff] [blame] | 827 | |
| 828 | int32_t OffImm = (int32_t)MO2.getImm() / 4; |
| 829 | // Don't print +0. |
| 830 | if (OffImm < 0) |
Evan Cheng | a64ce45 | 2009-11-19 06:31:26 +0000 | [diff] [blame] | 831 | O << ", #-" << -OffImm * 4; |
Evan Cheng | 5c87417 | 2009-07-09 22:21:59 +0000 | [diff] [blame] | 832 | else if (OffImm > 0) |
Johnny Chen | 9e08876 | 2010-03-17 17:52:21 +0000 | [diff] [blame] | 833 | O << ", #" << OffImm * 4; |
Evan Cheng | 5c87417 | 2009-07-09 22:21:59 +0000 | [diff] [blame] | 834 | O << "]"; |
| 835 | } |
| 836 | |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 837 | void ARMAsmPrinter::printT2AddrModeImm8OffsetOperand(const MachineInstr *MI, |
Chris Lattner | 35c33bd | 2010-04-04 04:47:45 +0000 | [diff] [blame] | 838 | int OpNum, |
| 839 | raw_ostream &O) { |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 840 | const MachineOperand &MO1 = MI->getOperand(OpNum); |
| 841 | int32_t OffImm = (int32_t)MO1.getImm(); |
| 842 | // Don't print +0. |
| 843 | if (OffImm < 0) |
| 844 | O << "#-" << -OffImm; |
| 845 | else if (OffImm > 0) |
Johnny Chen | 9e08876 | 2010-03-17 17:52:21 +0000 | [diff] [blame] | 846 | O << "#" << OffImm; |
| 847 | } |
| 848 | |
Evan Cheng | 055b031 | 2009-06-29 07:51:04 +0000 | [diff] [blame] | 849 | void ARMAsmPrinter::printT2AddrModeSoRegOperand(const MachineInstr *MI, |
Chris Lattner | 35c33bd | 2010-04-04 04:47:45 +0000 | [diff] [blame] | 850 | int OpNum, |
| 851 | raw_ostream &O) { |
Evan Cheng | 055b031 | 2009-06-29 07:51:04 +0000 | [diff] [blame] | 852 | const MachineOperand &MO1 = MI->getOperand(OpNum); |
| 853 | const MachineOperand &MO2 = MI->getOperand(OpNum+1); |
| 854 | const MachineOperand &MO3 = MI->getOperand(OpNum+2); |
| 855 | |
Chris Lattner | 762ccea | 2009-09-13 20:31:40 +0000 | [diff] [blame] | 856 | O << "[" << getRegisterName(MO1.getReg()); |
Evan Cheng | 055b031 | 2009-06-29 07:51:04 +0000 | [diff] [blame] | 857 | |
Evan Cheng | 3a21425 | 2009-08-11 08:52:18 +0000 | [diff] [blame] | 858 | assert(MO2.getReg() && "Invalid so_reg load / store address!"); |
Chris Lattner | 762ccea | 2009-09-13 20:31:40 +0000 | [diff] [blame] | 859 | O << ", " << getRegisterName(MO2.getReg()); |
Evan Cheng | 055b031 | 2009-06-29 07:51:04 +0000 | [diff] [blame] | 860 | |
Evan Cheng | 3a21425 | 2009-08-11 08:52:18 +0000 | [diff] [blame] | 861 | unsigned ShAmt = MO3.getImm(); |
| 862 | if (ShAmt) { |
| 863 | assert(ShAmt <= 3 && "Not a valid Thumb2 addressing mode!"); |
| 864 | O << ", lsl #" << ShAmt; |
Evan Cheng | 055b031 | 2009-06-29 07:51:04 +0000 | [diff] [blame] | 865 | } |
| 866 | O << "]"; |
| 867 | } |
| 868 | |
| 869 | |
| 870 | //===--------------------------------------------------------------------===// |
| 871 | |
Chris Lattner | 35c33bd | 2010-04-04 04:47:45 +0000 | [diff] [blame] | 872 | void ARMAsmPrinter::printPredicateOperand(const MachineInstr *MI, int OpNum, |
| 873 | raw_ostream &O) { |
Evan Cheng | 055b031 | 2009-06-29 07:51:04 +0000 | [diff] [blame] | 874 | ARMCC::CondCodes CC = (ARMCC::CondCodes)MI->getOperand(OpNum).getImm(); |
Evan Cheng | 44bec52 | 2007-05-15 01:29:07 +0000 | [diff] [blame] | 875 | if (CC != ARMCC::AL) |
| 876 | O << ARMCondCodeToString(CC); |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 877 | } |
| 878 | |
Johnny Chen | 9d3acaa | 2010-03-02 17:57:15 +0000 | [diff] [blame] | 879 | void ARMAsmPrinter::printMandatoryPredicateOperand(const MachineInstr *MI, |
Chris Lattner | 35c33bd | 2010-04-04 04:47:45 +0000 | [diff] [blame] | 880 | int OpNum, |
| 881 | raw_ostream &O) { |
Johnny Chen | 9d3acaa | 2010-03-02 17:57:15 +0000 | [diff] [blame] | 882 | ARMCC::CondCodes CC = (ARMCC::CondCodes)MI->getOperand(OpNum).getImm(); |
| 883 | O << ARMCondCodeToString(CC); |
| 884 | } |
| 885 | |
Chris Lattner | 35c33bd | 2010-04-04 04:47:45 +0000 | [diff] [blame] | 886 | void ARMAsmPrinter::printSBitModifierOperand(const MachineInstr *MI, int OpNum, |
| 887 | raw_ostream &O){ |
Evan Cheng | 055b031 | 2009-06-29 07:51:04 +0000 | [diff] [blame] | 888 | unsigned Reg = MI->getOperand(OpNum).getReg(); |
Evan Cheng | dfb2eba | 2007-07-06 01:01:34 +0000 | [diff] [blame] | 889 | if (Reg) { |
| 890 | assert(Reg == ARM::CPSR && "Expect ARM CPSR register!"); |
| 891 | O << 's'; |
| 892 | } |
| 893 | } |
| 894 | |
Chris Lattner | 35c33bd | 2010-04-04 04:47:45 +0000 | [diff] [blame] | 895 | void ARMAsmPrinter::printPCLabel(const MachineInstr *MI, int OpNum, |
| 896 | raw_ostream &O) { |
Evan Cheng | 055b031 | 2009-06-29 07:51:04 +0000 | [diff] [blame] | 897 | int Id = (int)MI->getOperand(OpNum).getImm(); |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 898 | O << MAI->getPrivateGlobalPrefix() |
| 899 | << "PC" << getFunctionNumber() << "_" << Id; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 900 | } |
| 901 | |
Chris Lattner | 35c33bd | 2010-04-04 04:47:45 +0000 | [diff] [blame] | 902 | void ARMAsmPrinter::printRegisterList(const MachineInstr *MI, int OpNum, |
| 903 | raw_ostream &O) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 904 | O << "{"; |
Bob Wilson | 815baeb | 2010-03-13 01:08:20 +0000 | [diff] [blame] | 905 | for (unsigned i = OpNum, e = MI->getNumOperands(); i != e; ++i) { |
Evan Cheng | 4b322e5 | 2009-08-11 21:11:32 +0000 | [diff] [blame] | 906 | if (MI->getOperand(i).isImplicit()) |
| 907 | continue; |
Bob Wilson | 815baeb | 2010-03-13 01:08:20 +0000 | [diff] [blame] | 908 | if ((int)i != OpNum) O << ", "; |
Chris Lattner | 35c33bd | 2010-04-04 04:47:45 +0000 | [diff] [blame] | 909 | printOperand(MI, i, O); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 910 | } |
| 911 | O << "}"; |
| 912 | } |
| 913 | |
Evan Cheng | 055b031 | 2009-06-29 07:51:04 +0000 | [diff] [blame] | 914 | void ARMAsmPrinter::printCPInstOperand(const MachineInstr *MI, int OpNum, |
Chris Lattner | 35c33bd | 2010-04-04 04:47:45 +0000 | [diff] [blame] | 915 | raw_ostream &O, const char *Modifier) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 916 | assert(Modifier && "This operand only works with a modifier!"); |
| 917 | // There are two aspects to a CONSTANTPOOL_ENTRY operand, the label and the |
| 918 | // data itself. |
| 919 | if (!strcmp(Modifier, "label")) { |
Evan Cheng | 055b031 | 2009-06-29 07:51:04 +0000 | [diff] [blame] | 920 | unsigned ID = MI->getOperand(OpNum).getImm(); |
Chris Lattner | 8e089a9 | 2010-02-10 00:36:00 +0000 | [diff] [blame] | 921 | OutStreamer.EmitLabel(GetCPISymbol(ID)); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 922 | } else { |
| 923 | assert(!strcmp(Modifier, "cpentry") && "Unknown modifier for CPE"); |
Evan Cheng | 055b031 | 2009-06-29 07:51:04 +0000 | [diff] [blame] | 924 | unsigned CPI = MI->getOperand(OpNum).getIndex(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 925 | |
Evan Cheng | 6d63a72 | 2008-09-18 07:27:23 +0000 | [diff] [blame] | 926 | const MachineConstantPoolEntry &MCPE = MCP->getConstants()[CPI]; |
Jim Grosbach | e995221 | 2009-09-04 01:38:51 +0000 | [diff] [blame] | 927 | |
Evan Cheng | 711b6dc | 2008-08-08 06:56:16 +0000 | [diff] [blame] | 928 | if (MCPE.isMachineConstantPoolEntry()) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 929 | EmitMachineConstantPoolValue(MCPE.Val.MachineCPVal); |
Evan Cheng | 711b6dc | 2008-08-08 06:56:16 +0000 | [diff] [blame] | 930 | } else { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 931 | EmitGlobalConstant(MCPE.Val.ConstVal); |
Lauro Ramos Venancio | 305b8a5 | 2007-04-25 14:50:40 +0000 | [diff] [blame] | 932 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 933 | } |
| 934 | } |
| 935 | |
Chris Lattner | 0890cf1 | 2010-01-25 19:51:38 +0000 | [diff] [blame] | 936 | MCSymbol *ARMAsmPrinter:: |
| 937 | GetARMSetPICJumpTableLabel2(unsigned uid, unsigned uid2, |
| 938 | const MachineBasicBlock *MBB) const { |
| 939 | SmallString<60> Name; |
| 940 | raw_svector_ostream(Name) << MAI->getPrivateGlobalPrefix() |
Chris Lattner | bfcb096 | 2010-01-25 19:39:52 +0000 | [diff] [blame] | 941 | << getFunctionNumber() << '_' << uid << '_' << uid2 |
Chris Lattner | 0890cf1 | 2010-01-25 19:51:38 +0000 | [diff] [blame] | 942 | << "_set_" << MBB->getNumber(); |
Chris Lattner | 9b97a73 | 2010-03-30 18:10:53 +0000 | [diff] [blame] | 943 | return OutContext.GetOrCreateSymbol(Name.str()); |
Chris Lattner | 0890cf1 | 2010-01-25 19:51:38 +0000 | [diff] [blame] | 944 | } |
| 945 | |
| 946 | MCSymbol *ARMAsmPrinter:: |
| 947 | GetARMJTIPICJumpTableLabel2(unsigned uid, unsigned uid2) const { |
| 948 | SmallString<60> Name; |
| 949 | raw_svector_ostream(Name) << MAI->getPrivateGlobalPrefix() << "JTI" |
Chris Lattner | 281e776 | 2010-01-25 23:28:03 +0000 | [diff] [blame] | 950 | << getFunctionNumber() << '_' << uid << '_' << uid2; |
Chris Lattner | 9b97a73 | 2010-03-30 18:10:53 +0000 | [diff] [blame] | 951 | return OutContext.GetOrCreateSymbol(Name.str()); |
Chris Lattner | bfcb096 | 2010-01-25 19:39:52 +0000 | [diff] [blame] | 952 | } |
| 953 | |
Chris Lattner | 35c33bd | 2010-04-04 04:47:45 +0000 | [diff] [blame] | 954 | void ARMAsmPrinter::printJTBlockOperand(const MachineInstr *MI, int OpNum, |
| 955 | raw_ostream &O) { |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 956 | assert(!Subtarget->isThumb2() && "Thumb2 should use double-jump jumptables!"); |
| 957 | |
Evan Cheng | 055b031 | 2009-06-29 07:51:04 +0000 | [diff] [blame] | 958 | const MachineOperand &MO1 = MI->getOperand(OpNum); |
| 959 | const MachineOperand &MO2 = MI->getOperand(OpNum+1); // Unique Id |
Jim Grosbach | b0739b7 | 2010-09-02 01:02:06 +0000 | [diff] [blame] | 960 | |
Chris Lattner | 8aa797a | 2007-12-30 23:10:15 +0000 | [diff] [blame] | 961 | unsigned JTI = MO1.getIndex(); |
Chris Lattner | 0890cf1 | 2010-01-25 19:51:38 +0000 | [diff] [blame] | 962 | MCSymbol *JTISymbol = GetARMJTIPICJumpTableLabel2(JTI, MO2.getImm()); |
Chris Lattner | 0333535 | 2010-04-05 17:52:31 +0000 | [diff] [blame] | 963 | // Can't use EmitLabel until instprinter happens, label comes out in the wrong |
| 964 | // order. |
Bob Wilson | d4d188e | 2010-07-31 06:28:10 +0000 | [diff] [blame] | 965 | O << "\n" << *JTISymbol << ":\n"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 966 | |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 967 | const char *JTEntryDirective = MAI->getData32bitsDirective(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 968 | |
Dan Gohman | 4542611 | 2008-07-07 20:06:06 +0000 | [diff] [blame] | 969 | const MachineJumpTableInfo *MJTI = MF->getJumpTableInfo(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 970 | const std::vector<MachineJumpTableEntry> &JT = MJTI->getJumpTables(); |
| 971 | const std::vector<MachineBasicBlock*> &JTBBs = JT[JTI].MBBs; |
Chris Lattner | cee6332 | 2010-01-26 20:40:54 +0000 | [diff] [blame] | 972 | bool UseSet= MAI->hasSetDirective() && TM.getRelocationModel() == Reloc::PIC_; |
Evan Cheng | c324ecb | 2009-07-24 18:19:46 +0000 | [diff] [blame] | 973 | SmallPtrSet<MachineBasicBlock*, 8> JTSets; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 974 | for (unsigned i = 0, e = JTBBs.size(); i != e; ++i) { |
| 975 | MachineBasicBlock *MBB = JTBBs[i]; |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 976 | bool isNew = JTSets.insert(MBB); |
| 977 | |
Chris Lattner | 0890cf1 | 2010-01-25 19:51:38 +0000 | [diff] [blame] | 978 | if (UseSet && isNew) { |
Chris Lattner | cee6332 | 2010-01-26 20:40:54 +0000 | [diff] [blame] | 979 | O << "\t.set\t" |
Jim Grosbach | 1f9b48a | 2010-01-25 23:50:13 +0000 | [diff] [blame] | 980 | << *GetARMSetPICJumpTableLabel2(JTI, MO2.getImm(), MBB) << ',' |
Chris Lattner | 1b2eb0e | 2010-03-13 21:04:28 +0000 | [diff] [blame] | 981 | << *MBB->getSymbol() << '-' << *JTISymbol << '\n'; |
Chris Lattner | 0890cf1 | 2010-01-25 19:51:38 +0000 | [diff] [blame] | 982 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 983 | |
| 984 | O << JTEntryDirective << ' '; |
| 985 | if (UseSet) |
Chris Lattner | 0890cf1 | 2010-01-25 19:51:38 +0000 | [diff] [blame] | 986 | O << *GetARMSetPICJumpTableLabel2(JTI, MO2.getImm(), MBB); |
| 987 | else if (TM.getRelocationModel() == Reloc::PIC_) |
Chris Lattner | 1b2eb0e | 2010-03-13 21:04:28 +0000 | [diff] [blame] | 988 | O << *MBB->getSymbol() << '-' << *JTISymbol; |
Chris Lattner | 0890cf1 | 2010-01-25 19:51:38 +0000 | [diff] [blame] | 989 | else |
Chris Lattner | 1b2eb0e | 2010-03-13 21:04:28 +0000 | [diff] [blame] | 990 | O << *MBB->getSymbol(); |
Chris Lattner | 0890cf1 | 2010-01-25 19:51:38 +0000 | [diff] [blame] | 991 | |
Evan Cheng | d85ac4d | 2007-01-27 02:29:45 +0000 | [diff] [blame] | 992 | if (i != e-1) |
| 993 | O << '\n'; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 994 | } |
| 995 | } |
| 996 | |
Chris Lattner | 35c33bd | 2010-04-04 04:47:45 +0000 | [diff] [blame] | 997 | void ARMAsmPrinter::printJT2BlockOperand(const MachineInstr *MI, int OpNum, |
| 998 | raw_ostream &O) { |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 999 | const MachineOperand &MO1 = MI->getOperand(OpNum); |
| 1000 | const MachineOperand &MO2 = MI->getOperand(OpNum+1); // Unique Id |
| 1001 | unsigned JTI = MO1.getIndex(); |
Jim Grosbach | b0739b7 | 2010-09-02 01:02:06 +0000 | [diff] [blame] | 1002 | |
Chris Lattner | 0890cf1 | 2010-01-25 19:51:38 +0000 | [diff] [blame] | 1003 | MCSymbol *JTISymbol = GetARMJTIPICJumpTableLabel2(JTI, MO2.getImm()); |
Jim Grosbach | b0739b7 | 2010-09-02 01:02:06 +0000 | [diff] [blame] | 1004 | |
Chris Lattner | 0333535 | 2010-04-05 17:52:31 +0000 | [diff] [blame] | 1005 | // Can't use EmitLabel until instprinter happens, label comes out in the wrong |
| 1006 | // order. |
Bob Wilson | d4d188e | 2010-07-31 06:28:10 +0000 | [diff] [blame] | 1007 | O << "\n" << *JTISymbol << ":\n"; |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 1008 | |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 1009 | const MachineJumpTableInfo *MJTI = MF->getJumpTableInfo(); |
| 1010 | const std::vector<MachineJumpTableEntry> &JT = MJTI->getJumpTables(); |
| 1011 | const std::vector<MachineBasicBlock*> &JTBBs = JT[JTI].MBBs; |
Evan Cheng | 5657c01 | 2009-07-29 02:18:14 +0000 | [diff] [blame] | 1012 | bool ByteOffset = false, HalfWordOffset = false; |
| 1013 | if (MI->getOpcode() == ARM::t2TBB) |
| 1014 | ByteOffset = true; |
| 1015 | else if (MI->getOpcode() == ARM::t2TBH) |
| 1016 | HalfWordOffset = true; |
| 1017 | |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 1018 | for (unsigned i = 0, e = JTBBs.size(); i != e; ++i) { |
| 1019 | MachineBasicBlock *MBB = JTBBs[i]; |
Evan Cheng | 5657c01 | 2009-07-29 02:18:14 +0000 | [diff] [blame] | 1020 | if (ByteOffset) |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1021 | O << MAI->getData8bitsDirective(); |
Evan Cheng | 5657c01 | 2009-07-29 02:18:14 +0000 | [diff] [blame] | 1022 | else if (HalfWordOffset) |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1023 | O << MAI->getData16bitsDirective(); |
Jim Grosbach | b0739b7 | 2010-09-02 01:02:06 +0000 | [diff] [blame] | 1024 | |
Chris Lattner | 0890cf1 | 2010-01-25 19:51:38 +0000 | [diff] [blame] | 1025 | if (ByteOffset || HalfWordOffset) |
Chris Lattner | 1b2eb0e | 2010-03-13 21:04:28 +0000 | [diff] [blame] | 1026 | O << '(' << *MBB->getSymbol() << "-" << *JTISymbol << ")/2"; |
Chris Lattner | 0890cf1 | 2010-01-25 19:51:38 +0000 | [diff] [blame] | 1027 | else |
Chris Lattner | 1b2eb0e | 2010-03-13 21:04:28 +0000 | [diff] [blame] | 1028 | O << "\tb.w " << *MBB->getSymbol(); |
Chris Lattner | 0890cf1 | 2010-01-25 19:51:38 +0000 | [diff] [blame] | 1029 | |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 1030 | if (i != e-1) |
| 1031 | O << '\n'; |
| 1032 | } |
| 1033 | } |
| 1034 | |
Chris Lattner | 35c33bd | 2010-04-04 04:47:45 +0000 | [diff] [blame] | 1035 | void ARMAsmPrinter::printTBAddrMode(const MachineInstr *MI, int OpNum, |
| 1036 | raw_ostream &O) { |
Chris Lattner | 762ccea | 2009-09-13 20:31:40 +0000 | [diff] [blame] | 1037 | O << "[pc, " << getRegisterName(MI->getOperand(OpNum).getReg()); |
Evan Cheng | 5657c01 | 2009-07-29 02:18:14 +0000 | [diff] [blame] | 1038 | if (MI->getOpcode() == ARM::t2TBH) |
| 1039 | O << ", lsl #1"; |
| 1040 | O << ']'; |
| 1041 | } |
| 1042 | |
Chris Lattner | 35c33bd | 2010-04-04 04:47:45 +0000 | [diff] [blame] | 1043 | void ARMAsmPrinter::printNoHashImmediate(const MachineInstr *MI, int OpNum, |
| 1044 | raw_ostream &O) { |
Anton Korobeynikov | 8e9ece7 | 2009-08-08 23:10:41 +0000 | [diff] [blame] | 1045 | O << MI->getOperand(OpNum).getImm(); |
| 1046 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1047 | |
Chris Lattner | 35c33bd | 2010-04-04 04:47:45 +0000 | [diff] [blame] | 1048 | void ARMAsmPrinter::printVFPf32ImmOperand(const MachineInstr *MI, int OpNum, |
| 1049 | raw_ostream &O) { |
Evan Cheng | 3938242 | 2009-10-28 01:44:26 +0000 | [diff] [blame] | 1050 | const ConstantFP *FP = MI->getOperand(OpNum).getFPImm(); |
Jim Grosbach | 77b02be | 2009-11-23 21:08:25 +0000 | [diff] [blame] | 1051 | O << '#' << FP->getValueAPF().convertToFloat(); |
Chris Lattner | 3f53c83 | 2010-04-04 18:52:31 +0000 | [diff] [blame] | 1052 | if (isVerbose()) { |
Chris Lattner | 35c33bd | 2010-04-04 04:47:45 +0000 | [diff] [blame] | 1053 | O << "\t\t" << MAI->getCommentString() << ' '; |
Evan Cheng | 3938242 | 2009-10-28 01:44:26 +0000 | [diff] [blame] | 1054 | WriteAsOperand(O, FP, /*PrintType=*/false); |
| 1055 | } |
| 1056 | } |
| 1057 | |
Chris Lattner | 35c33bd | 2010-04-04 04:47:45 +0000 | [diff] [blame] | 1058 | void ARMAsmPrinter::printVFPf64ImmOperand(const MachineInstr *MI, int OpNum, |
| 1059 | raw_ostream &O) { |
Evan Cheng | 3938242 | 2009-10-28 01:44:26 +0000 | [diff] [blame] | 1060 | const ConstantFP *FP = MI->getOperand(OpNum).getFPImm(); |
Jim Grosbach | 77b02be | 2009-11-23 21:08:25 +0000 | [diff] [blame] | 1061 | O << '#' << FP->getValueAPF().convertToDouble(); |
Chris Lattner | 3f53c83 | 2010-04-04 18:52:31 +0000 | [diff] [blame] | 1062 | if (isVerbose()) { |
Chris Lattner | 35c33bd | 2010-04-04 04:47:45 +0000 | [diff] [blame] | 1063 | O << "\t\t" << MAI->getCommentString() << ' '; |
Evan Cheng | 3938242 | 2009-10-28 01:44:26 +0000 | [diff] [blame] | 1064 | WriteAsOperand(O, FP, /*PrintType=*/false); |
| 1065 | } |
| 1066 | } |
| 1067 | |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 1068 | void ARMAsmPrinter::printNEONModImmOperand(const MachineInstr *MI, int OpNum, |
| 1069 | raw_ostream &O) { |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 1070 | unsigned EncodedImm = MI->getOperand(OpNum).getImm(); |
| 1071 | unsigned EltBits; |
| 1072 | uint64_t Val = ARM_AM::decodeNEONModImm(EncodedImm, EltBits); |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 1073 | O << "#0x" << utohexstr(Val); |
| 1074 | } |
| 1075 | |
Evan Cheng | 055b031 | 2009-06-29 07:51:04 +0000 | [diff] [blame] | 1076 | bool ARMAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNum, |
Chris Lattner | c75c028 | 2010-04-04 05:29:35 +0000 | [diff] [blame] | 1077 | unsigned AsmVariant, const char *ExtraCode, |
| 1078 | raw_ostream &O) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1079 | // Does this asm operand have a single letter operand modifier? |
| 1080 | if (ExtraCode && ExtraCode[0]) { |
| 1081 | if (ExtraCode[1] != 0) return true; // Unknown modifier. |
Anton Korobeynikov | 8e9ece7 | 2009-08-08 23:10:41 +0000 | [diff] [blame] | 1082 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1083 | switch (ExtraCode[0]) { |
| 1084 | default: return true; // Unknown modifier. |
Bob Wilson | 9b4b00a | 2009-07-09 23:54:51 +0000 | [diff] [blame] | 1085 | case 'a': // Print as a memory address. |
| 1086 | if (MI->getOperand(OpNum).isReg()) { |
Chris Lattner | 762ccea | 2009-09-13 20:31:40 +0000 | [diff] [blame] | 1087 | O << "[" << getRegisterName(MI->getOperand(OpNum).getReg()) << "]"; |
Bob Wilson | 9b4b00a | 2009-07-09 23:54:51 +0000 | [diff] [blame] | 1088 | return false; |
| 1089 | } |
| 1090 | // Fallthrough |
| 1091 | case 'c': // Don't print "#" before an immediate operand. |
Bob Wilson | 4f38b38 | 2009-08-21 21:58:55 +0000 | [diff] [blame] | 1092 | if (!MI->getOperand(OpNum).isImm()) |
| 1093 | return true; |
Chris Lattner | 35c33bd | 2010-04-04 04:47:45 +0000 | [diff] [blame] | 1094 | printNoHashImmediate(MI, OpNum, O); |
Bob Wilson | 8f34346 | 2009-04-06 21:46:51 +0000 | [diff] [blame] | 1095 | return false; |
Evan Cheng | e21e396 | 2007-04-04 00:13:29 +0000 | [diff] [blame] | 1096 | case 'P': // Print a VFP double precision register. |
Evan Cheng | d831cda | 2009-12-08 23:06:22 +0000 | [diff] [blame] | 1097 | case 'q': // Print a NEON quad precision register. |
Chris Lattner | 35c33bd | 2010-04-04 04:47:45 +0000 | [diff] [blame] | 1098 | printOperand(MI, OpNum, O); |
Evan Cheng | 23a9570 | 2007-03-08 22:42:46 +0000 | [diff] [blame] | 1099 | return false; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1100 | case 'Q': |
Bob Wilson | d984eb6 | 2010-05-27 20:23:42 +0000 | [diff] [blame] | 1101 | case 'R': |
Bob Wilson | d984eb6 | 2010-05-27 20:23:42 +0000 | [diff] [blame] | 1102 | case 'H': |
Evan Cheng | 1261672 | 2010-05-27 23:45:31 +0000 | [diff] [blame] | 1103 | report_fatal_error("llvm does not support 'Q', 'R', and 'H' modifiers!"); |
Bob Wilson | d984eb6 | 2010-05-27 20:23:42 +0000 | [diff] [blame] | 1104 | return true; |
Evan Cheng | 84f60b7 | 2010-05-27 22:08:38 +0000 | [diff] [blame] | 1105 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1106 | } |
Jim Grosbach | e995221 | 2009-09-04 01:38:51 +0000 | [diff] [blame] | 1107 | |
Chris Lattner | 35c33bd | 2010-04-04 04:47:45 +0000 | [diff] [blame] | 1108 | printOperand(MI, OpNum, O); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1109 | return false; |
| 1110 | } |
| 1111 | |
Bob Wilson | 224c244 | 2009-05-19 05:53:42 +0000 | [diff] [blame] | 1112 | bool ARMAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI, |
Evan Cheng | 055b031 | 2009-06-29 07:51:04 +0000 | [diff] [blame] | 1113 | unsigned OpNum, unsigned AsmVariant, |
Chris Lattner | c75c028 | 2010-04-04 05:29:35 +0000 | [diff] [blame] | 1114 | const char *ExtraCode, |
| 1115 | raw_ostream &O) { |
Bob Wilson | 224c244 | 2009-05-19 05:53:42 +0000 | [diff] [blame] | 1116 | if (ExtraCode && ExtraCode[0]) |
| 1117 | return true; // Unknown modifier. |
Bob Wilson | 765cc0b | 2009-10-13 20:50:28 +0000 | [diff] [blame] | 1118 | |
| 1119 | const MachineOperand &MO = MI->getOperand(OpNum); |
| 1120 | assert(MO.isReg() && "unexpected inline asm memory operand"); |
| 1121 | O << "[" << getRegisterName(MO.getReg()) << "]"; |
Bob Wilson | 224c244 | 2009-05-19 05:53:42 +0000 | [diff] [blame] | 1122 | return false; |
| 1123 | } |
| 1124 | |
Chris Lattner | a786cea | 2010-01-28 01:10:34 +0000 | [diff] [blame] | 1125 | void ARMAsmPrinter::EmitInstruction(const MachineInstr *MI) { |
Chris Lattner | 97f0693 | 2009-10-19 20:20:46 +0000 | [diff] [blame] | 1126 | if (EnableMCInst) { |
| 1127 | printInstructionThroughMCStreamer(MI); |
Chris Lattner | 7ad07c4 | 2010-04-04 06:12:20 +0000 | [diff] [blame] | 1128 | return; |
Chris Lattner | 97f0693 | 2009-10-19 20:20:46 +0000 | [diff] [blame] | 1129 | } |
Jim Grosbach | b0739b7 | 2010-09-02 01:02:06 +0000 | [diff] [blame] | 1130 | |
Chris Lattner | 7ad07c4 | 2010-04-04 06:12:20 +0000 | [diff] [blame] | 1131 | if (MI->getOpcode() == ARM::CONSTPOOL_ENTRY) |
| 1132 | EmitAlignment(2); |
Jim Grosbach | b0739b7 | 2010-09-02 01:02:06 +0000 | [diff] [blame] | 1133 | |
Chris Lattner | 7ad07c4 | 2010-04-04 06:12:20 +0000 | [diff] [blame] | 1134 | SmallString<128> Str; |
| 1135 | raw_svector_ostream OS(Str); |
Dale Johannesen | 3f282aa | 2010-04-26 20:07:31 +0000 | [diff] [blame] | 1136 | if (MI->getOpcode() == ARM::DBG_VALUE) { |
| 1137 | unsigned NOps = MI->getNumOperands(); |
| 1138 | assert(NOps==4); |
| 1139 | OS << '\t' << MAI->getCommentString() << "DEBUG_VALUE: "; |
| 1140 | // cast away const; DIetc do not take const operands for some reason. |
| 1141 | DIVariable V(const_cast<MDNode *>(MI->getOperand(NOps-1).getMetadata())); |
| 1142 | OS << V.getName(); |
| 1143 | OS << " <- "; |
| 1144 | // Frame address. Currently handles register +- offset only. |
| 1145 | assert(MI->getOperand(0).isReg() && MI->getOperand(1).isImm()); |
| 1146 | OS << '['; printOperand(MI, 0, OS); OS << '+'; printOperand(MI, 1, OS); |
| 1147 | OS << ']'; |
| 1148 | OS << "+"; |
| 1149 | printOperand(MI, NOps-2, OS); |
Jim Grosbach | e6be85e | 2010-09-17 22:36:38 +0000 | [diff] [blame] | 1150 | } else if (MI->getOpcode() == ARM::MOVs) { |
| 1151 | // FIXME: Thumb variants? |
| 1152 | const MachineOperand &Dst = MI->getOperand(0); |
| 1153 | const MachineOperand &MO1 = MI->getOperand(1); |
| 1154 | const MachineOperand &MO2 = MI->getOperand(2); |
| 1155 | const MachineOperand &MO3 = MI->getOperand(3); |
Dale Johannesen | 3f282aa | 2010-04-26 20:07:31 +0000 | [diff] [blame] | 1156 | |
Jim Grosbach | e6be85e | 2010-09-17 22:36:38 +0000 | [diff] [blame] | 1157 | OS << '\t' << ARM_AM::getShiftOpcStr(ARM_AM::getSORegShOp(MO3.getImm())); |
| 1158 | printSBitModifierOperand(MI, 6, OS); |
| 1159 | printPredicateOperand(MI, 4, OS); |
| 1160 | |
| 1161 | OS << '\t' << getRegisterName(Dst.getReg()) |
| 1162 | << ", " << getRegisterName(MO1.getReg()); |
| 1163 | |
| 1164 | if (ARM_AM::getSORegShOp(MO3.getImm()) != ARM_AM::rrx) { |
| 1165 | OS << ", "; |
| 1166 | |
| 1167 | if (MO2.getReg()) { |
| 1168 | OS << getRegisterName(MO2.getReg()); |
| 1169 | assert(ARM_AM::getSORegOffset(MO3.getImm()) == 0); |
| 1170 | } else { |
| 1171 | OS << "#" << ARM_AM::getSORegOffset(MO3.getImm()); |
| 1172 | } |
| 1173 | } |
| 1174 | } else |
| 1175 | // A8.6.123 PUSH |
| 1176 | if ((MI->getOpcode() == ARM::STM_UPD || MI->getOpcode() == ARM::t2STM_UPD) && |
| 1177 | MI->getOperand(0).getReg() == ARM::SP) { |
| 1178 | const MachineOperand &MO1 = MI->getOperand(2); |
| 1179 | if (ARM_AM::getAM4SubMode(MO1.getImm()) == ARM_AM::db) { |
| 1180 | OS << '\t' << "push"; |
| 1181 | printPredicateOperand(MI, 3, OS); |
| 1182 | OS << '\t'; |
| 1183 | printRegisterList(MI, 5, OS); |
| 1184 | } |
| 1185 | } else |
| 1186 | // A8.6.122 POP |
| 1187 | if ((MI->getOpcode() == ARM::LDM_UPD || MI->getOpcode() == ARM::t2LDM_UPD) && |
| 1188 | MI->getOperand(0).getReg() == ARM::SP) { |
| 1189 | const MachineOperand &MO1 = MI->getOperand(2); |
| 1190 | if (ARM_AM::getAM4SubMode(MO1.getImm()) == ARM_AM::ia) { |
| 1191 | OS << '\t' << "pop"; |
| 1192 | printPredicateOperand(MI, 3, OS); |
| 1193 | OS << '\t'; |
| 1194 | printRegisterList(MI, 5, OS); |
| 1195 | } |
| 1196 | } else |
| 1197 | // A8.6.355 VPUSH |
| 1198 | if ((MI->getOpcode() == ARM::VSTMS_UPD || MI->getOpcode() ==ARM::VSTMD_UPD) && |
| 1199 | MI->getOperand(0).getReg() == ARM::SP) { |
| 1200 | const MachineOperand &MO1 = MI->getOperand(2); |
| 1201 | if (ARM_AM::getAM4SubMode(MO1.getImm()) == ARM_AM::db) { |
| 1202 | OS << '\t' << "vpush"; |
| 1203 | printPredicateOperand(MI, 3, OS); |
| 1204 | OS << '\t'; |
| 1205 | printRegisterList(MI, 5, OS); |
| 1206 | } |
| 1207 | } else |
| 1208 | // A8.6.354 VPOP |
| 1209 | if ((MI->getOpcode() == ARM::VLDMS_UPD || MI->getOpcode() ==ARM::VLDMD_UPD) && |
| 1210 | MI->getOperand(0).getReg() == ARM::SP) { |
| 1211 | const MachineOperand &MO1 = MI->getOperand(2); |
| 1212 | if (ARM_AM::getAM4SubMode(MO1.getImm()) == ARM_AM::ia) { |
| 1213 | OS << '\t' << "vpop"; |
| 1214 | printPredicateOperand(MI, 3, OS); |
| 1215 | OS << '\t'; |
| 1216 | printRegisterList(MI, 5, OS); |
| 1217 | } |
| 1218 | } else |
| 1219 | printInstruction(MI, OS); |
| 1220 | |
| 1221 | // Output the instruction to the stream |
Chris Lattner | 7ad07c4 | 2010-04-04 06:12:20 +0000 | [diff] [blame] | 1222 | OutStreamer.EmitRawText(OS.str()); |
Jim Grosbach | b0739b7 | 2010-09-02 01:02:06 +0000 | [diff] [blame] | 1223 | |
Chris Lattner | 7ad07c4 | 2010-04-04 06:12:20 +0000 | [diff] [blame] | 1224 | // Make sure the instruction that follows TBB is 2-byte aligned. |
| 1225 | // FIXME: Constant island pass should insert an "ALIGN" instruction instead. |
| 1226 | if (MI->getOpcode() == ARM::t2TBB) |
| 1227 | EmitAlignment(1); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1228 | } |
| 1229 | |
Bob Wilson | 812209a | 2009-09-30 22:06:26 +0000 | [diff] [blame] | 1230 | void ARMAsmPrinter::EmitStartOfAsmFile(Module &M) { |
Bob Wilson | 0fb3468 | 2009-09-30 00:23:42 +0000 | [diff] [blame] | 1231 | if (Subtarget->isTargetDarwin()) { |
| 1232 | Reloc::Model RelocM = TM.getRelocationModel(); |
| 1233 | if (RelocM == Reloc::PIC_ || RelocM == Reloc::DynamicNoPIC) { |
| 1234 | // Declare all the text sections up front (before the DWARF sections |
| 1235 | // emitted by AsmPrinter::doInitialization) so the assembler will keep |
| 1236 | // them together at the beginning of the object file. This helps |
| 1237 | // avoid out-of-range branches that are due a fundamental limitation of |
| 1238 | // the way symbol offsets are encoded with the current Darwin ARM |
| 1239 | // relocations. |
Jim Grosbach | b0739b7 | 2010-09-02 01:02:06 +0000 | [diff] [blame] | 1240 | const TargetLoweringObjectFileMachO &TLOFMacho = |
Dan Gohman | 0d805c3 | 2010-04-17 16:44:48 +0000 | [diff] [blame] | 1241 | static_cast<const TargetLoweringObjectFileMachO &>( |
| 1242 | getObjFileLowering()); |
Bob Wilson | 29e0669 | 2009-09-30 22:25:37 +0000 | [diff] [blame] | 1243 | OutStreamer.SwitchSection(TLOFMacho.getTextSection()); |
| 1244 | OutStreamer.SwitchSection(TLOFMacho.getTextCoalSection()); |
| 1245 | OutStreamer.SwitchSection(TLOFMacho.getConstTextCoalSection()); |
| 1246 | if (RelocM == Reloc::DynamicNoPIC) { |
| 1247 | const MCSection *sect = |
Chris Lattner | 2277221 | 2010-04-08 20:40:11 +0000 | [diff] [blame] | 1248 | OutContext.getMachOSection("__TEXT", "__symbol_stub4", |
| 1249 | MCSectionMachO::S_SYMBOL_STUBS, |
| 1250 | 12, SectionKind::getText()); |
Bob Wilson | 29e0669 | 2009-09-30 22:25:37 +0000 | [diff] [blame] | 1251 | OutStreamer.SwitchSection(sect); |
| 1252 | } else { |
| 1253 | const MCSection *sect = |
Chris Lattner | 2277221 | 2010-04-08 20:40:11 +0000 | [diff] [blame] | 1254 | OutContext.getMachOSection("__TEXT", "__picsymbolstub4", |
| 1255 | MCSectionMachO::S_SYMBOL_STUBS, |
| 1256 | 16, SectionKind::getText()); |
Bob Wilson | 29e0669 | 2009-09-30 22:25:37 +0000 | [diff] [blame] | 1257 | OutStreamer.SwitchSection(sect); |
| 1258 | } |
Bob Wilson | 63db594 | 2010-07-30 19:55:47 +0000 | [diff] [blame] | 1259 | const MCSection *StaticInitSect = |
| 1260 | OutContext.getMachOSection("__TEXT", "__StaticInit", |
| 1261 | MCSectionMachO::S_REGULAR | |
| 1262 | MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS, |
| 1263 | SectionKind::getText()); |
| 1264 | OutStreamer.SwitchSection(StaticInitSect); |
Bob Wilson | 0fb3468 | 2009-09-30 00:23:42 +0000 | [diff] [blame] | 1265 | } |
| 1266 | } |
| 1267 | |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1268 | // Use unified assembler syntax. |
Chris Lattner | 9d7efd3 | 2010-04-04 07:05:53 +0000 | [diff] [blame] | 1269 | OutStreamer.EmitRawText(StringRef("\t.syntax unified")); |
Anton Korobeynikov | d61eca5 | 2009-06-17 23:43:18 +0000 | [diff] [blame] | 1270 | |
Anton Korobeynikov | 88ce667 | 2009-05-23 19:51:20 +0000 | [diff] [blame] | 1271 | // Emit ARM Build Attributes |
| 1272 | if (Subtarget->isTargetELF()) { |
| 1273 | // CPU Type |
Anton Korobeynikov | d260c24 | 2009-06-01 19:03:17 +0000 | [diff] [blame] | 1274 | std::string CPUString = Subtarget->getCPUString(); |
| 1275 | if (CPUString != "generic") |
Chris Lattner | 9d7efd3 | 2010-04-04 07:05:53 +0000 | [diff] [blame] | 1276 | OutStreamer.EmitRawText("\t.cpu " + Twine(CPUString)); |
Anton Korobeynikov | 88ce667 | 2009-05-23 19:51:20 +0000 | [diff] [blame] | 1277 | |
| 1278 | // FIXME: Emit FPU type |
| 1279 | if (Subtarget->hasVFP2()) |
Chris Lattner | 9d7efd3 | 2010-04-04 07:05:53 +0000 | [diff] [blame] | 1280 | OutStreamer.EmitRawText("\t.eabi_attribute " + |
| 1281 | Twine(ARMBuildAttrs::VFP_arch) + ", 2"); |
Anton Korobeynikov | 88ce667 | 2009-05-23 19:51:20 +0000 | [diff] [blame] | 1282 | |
| 1283 | // Signal various FP modes. |
Chris Lattner | 9d7efd3 | 2010-04-04 07:05:53 +0000 | [diff] [blame] | 1284 | if (!UnsafeFPMath) { |
| 1285 | OutStreamer.EmitRawText("\t.eabi_attribute " + |
| 1286 | Twine(ARMBuildAttrs::ABI_FP_denormal) + ", 1"); |
| 1287 | OutStreamer.EmitRawText("\t.eabi_attribute " + |
| 1288 | Twine(ARMBuildAttrs::ABI_FP_exceptions) + ", 1"); |
| 1289 | } |
Jim Grosbach | b0739b7 | 2010-09-02 01:02:06 +0000 | [diff] [blame] | 1290 | |
Evan Cheng | 60108e9 | 2010-07-15 22:07:12 +0000 | [diff] [blame] | 1291 | if (NoInfsFPMath && NoNaNsFPMath) |
Chris Lattner | 9d7efd3 | 2010-04-04 07:05:53 +0000 | [diff] [blame] | 1292 | OutStreamer.EmitRawText("\t.eabi_attribute " + |
| 1293 | Twine(ARMBuildAttrs::ABI_FP_number_model)+ ", 1"); |
Anton Korobeynikov | 88ce667 | 2009-05-23 19:51:20 +0000 | [diff] [blame] | 1294 | else |
Chris Lattner | 9d7efd3 | 2010-04-04 07:05:53 +0000 | [diff] [blame] | 1295 | OutStreamer.EmitRawText("\t.eabi_attribute " + |
| 1296 | Twine(ARMBuildAttrs::ABI_FP_number_model)+ ", 3"); |
Anton Korobeynikov | 88ce667 | 2009-05-23 19:51:20 +0000 | [diff] [blame] | 1297 | |
| 1298 | // 8-bytes alignment stuff. |
Chris Lattner | 9d7efd3 | 2010-04-04 07:05:53 +0000 | [diff] [blame] | 1299 | OutStreamer.EmitRawText("\t.eabi_attribute " + |
| 1300 | Twine(ARMBuildAttrs::ABI_align8_needed) + ", 1"); |
| 1301 | OutStreamer.EmitRawText("\t.eabi_attribute " + |
| 1302 | Twine(ARMBuildAttrs::ABI_align8_preserved) + ", 1"); |
Anton Korobeynikov | 88ce667 | 2009-05-23 19:51:20 +0000 | [diff] [blame] | 1303 | |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1304 | // Hard float. Use both S and D registers and conform to AAPCS-VFP. |
Chris Lattner | 9d7efd3 | 2010-04-04 07:05:53 +0000 | [diff] [blame] | 1305 | if (Subtarget->isAAPCS_ABI() && FloatABIType == FloatABI::Hard) { |
| 1306 | OutStreamer.EmitRawText("\t.eabi_attribute " + |
| 1307 | Twine(ARMBuildAttrs::ABI_HardFP_use) + ", 3"); |
| 1308 | OutStreamer.EmitRawText("\t.eabi_attribute " + |
| 1309 | Twine(ARMBuildAttrs::ABI_VFP_args) + ", 1"); |
| 1310 | } |
Anton Korobeynikov | 88ce667 | 2009-05-23 19:51:20 +0000 | [diff] [blame] | 1311 | // FIXME: Should we signal R9 usage? |
| 1312 | } |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 1313 | } |
| 1314 | |
Anton Korobeynikov | 0f3cc65 | 2008-08-07 09:54:23 +0000 | [diff] [blame] | 1315 | |
Chris Lattner | 4a071d6 | 2009-10-19 17:59:19 +0000 | [diff] [blame] | 1316 | void ARMAsmPrinter::EmitEndOfAsmFile(Module &M) { |
Evan Cheng | 5be54b0 | 2007-01-19 19:25:36 +0000 | [diff] [blame] | 1317 | if (Subtarget->isTargetDarwin()) { |
Chris Lattner | f61159b | 2009-08-03 22:18:15 +0000 | [diff] [blame] | 1318 | // All darwin targets use mach-o. |
Dan Gohman | 0d805c3 | 2010-04-17 16:44:48 +0000 | [diff] [blame] | 1319 | const TargetLoweringObjectFileMachO &TLOFMacho = |
| 1320 | static_cast<const TargetLoweringObjectFileMachO &>(getObjFileLowering()); |
Chris Lattner | b0f294c | 2009-10-19 18:38:33 +0000 | [diff] [blame] | 1321 | MachineModuleInfoMachO &MMIMacho = |
| 1322 | MMI->getObjFileInfo<MachineModuleInfoMachO>(); |
Jim Grosbach | e995221 | 2009-09-04 01:38:51 +0000 | [diff] [blame] | 1323 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1324 | // Output non-lazy-pointers for external and common global variables. |
Chris Lattner | b0f294c | 2009-10-19 18:38:33 +0000 | [diff] [blame] | 1325 | MachineModuleInfoMachO::SymbolListTy Stubs = MMIMacho.GetGVStubList(); |
Bill Wendling | cebae36 | 2010-03-10 22:34:10 +0000 | [diff] [blame] | 1326 | |
Chris Lattner | b0f294c | 2009-10-19 18:38:33 +0000 | [diff] [blame] | 1327 | if (!Stubs.empty()) { |
Chris Lattner | ff4bc46 | 2009-08-10 01:39:42 +0000 | [diff] [blame] | 1328 | // Switch with ".non_lazy_symbol_pointer" directive. |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 1329 | OutStreamer.SwitchSection(TLOFMacho.getNonLazySymbolPointerSection()); |
Chris Lattner | c076a97 | 2009-08-10 18:01:34 +0000 | [diff] [blame] | 1330 | EmitAlignment(2); |
Chris Lattner | b0f294c | 2009-10-19 18:38:33 +0000 | [diff] [blame] | 1331 | for (unsigned i = 0, e = Stubs.size(); i != e; ++i) { |
Bill Wendling | becd83e | 2010-03-09 00:40:17 +0000 | [diff] [blame] | 1332 | // L_foo$stub: |
| 1333 | OutStreamer.EmitLabel(Stubs[i].first); |
| 1334 | // .indirect_symbol _foo |
Bill Wendling | 52a50e5 | 2010-03-11 01:18:13 +0000 | [diff] [blame] | 1335 | MachineModuleInfoImpl::StubValueTy &MCSym = Stubs[i].second; |
| 1336 | OutStreamer.EmitSymbolAttribute(MCSym.getPointer(),MCSA_IndirectSymbol); |
Bill Wendling | cf6f28d | 2010-03-09 00:43:34 +0000 | [diff] [blame] | 1337 | |
Bill Wendling | 52a50e5 | 2010-03-11 01:18:13 +0000 | [diff] [blame] | 1338 | if (MCSym.getInt()) |
Bill Wendling | cf6f28d | 2010-03-09 00:43:34 +0000 | [diff] [blame] | 1339 | // External to current translation unit. |
| 1340 | OutStreamer.EmitIntValue(0, 4/*size*/, 0/*addrspace*/); |
| 1341 | else |
| 1342 | // Internal to current translation unit. |
Bill Wendling | 5e1b55d | 2010-03-31 18:47:10 +0000 | [diff] [blame] | 1343 | // |
| 1344 | // When we place the LSDA into the TEXT section, the type info pointers |
| 1345 | // need to be indirect and pc-rel. We accomplish this by using NLPs. |
| 1346 | // However, sometimes the types are local to the file. So we need to |
| 1347 | // fill in the value for the NLP in those cases. |
Bill Wendling | 52a50e5 | 2010-03-11 01:18:13 +0000 | [diff] [blame] | 1348 | OutStreamer.EmitValue(MCSymbolRefExpr::Create(MCSym.getPointer(), |
| 1349 | OutContext), |
Bill Wendling | cf6f28d | 2010-03-09 00:43:34 +0000 | [diff] [blame] | 1350 | 4/*size*/, 0/*addrspace*/); |
Evan Cheng | ae94e59 | 2008-12-05 01:06:39 +0000 | [diff] [blame] | 1351 | } |
Bill Wendling | becd83e | 2010-03-09 00:40:17 +0000 | [diff] [blame] | 1352 | |
| 1353 | Stubs.clear(); |
| 1354 | OutStreamer.AddBlankLine(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1355 | } |
| 1356 | |
Chris Lattner | e4d9ea8 | 2009-10-19 18:44:38 +0000 | [diff] [blame] | 1357 | Stubs = MMIMacho.GetHiddenGVStubList(); |
| 1358 | if (!Stubs.empty()) { |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 1359 | OutStreamer.SwitchSection(getObjFileLowering().getDataSection()); |
Chris Lattner | f3231de | 2009-08-10 18:02:16 +0000 | [diff] [blame] | 1360 | EmitAlignment(2); |
Bill Wendling | becd83e | 2010-03-09 00:40:17 +0000 | [diff] [blame] | 1361 | for (unsigned i = 0, e = Stubs.size(); i != e; ++i) { |
| 1362 | // L_foo$stub: |
| 1363 | OutStreamer.EmitLabel(Stubs[i].first); |
| 1364 | // .long _foo |
Bill Wendling | cebae36 | 2010-03-10 22:34:10 +0000 | [diff] [blame] | 1365 | OutStreamer.EmitValue(MCSymbolRefExpr:: |
| 1366 | Create(Stubs[i].second.getPointer(), |
| 1367 | OutContext), |
Bill Wendling | becd83e | 2010-03-09 00:40:17 +0000 | [diff] [blame] | 1368 | 4/*size*/, 0/*addrspace*/); |
| 1369 | } |
Bill Wendling | cf6f28d | 2010-03-09 00:43:34 +0000 | [diff] [blame] | 1370 | |
| 1371 | Stubs.clear(); |
| 1372 | OutStreamer.AddBlankLine(); |
Evan Cheng | ae94e59 | 2008-12-05 01:06:39 +0000 | [diff] [blame] | 1373 | } |
| 1374 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1375 | // Funny Darwin hack: This flag tells the linker that no global symbols |
| 1376 | // contain code that falls through to other global symbols (e.g. the obvious |
| 1377 | // implementation of multiple entry points). If this doesn't occur, the |
| 1378 | // linker can safely perform dead code stripping. Since LLVM never |
| 1379 | // generates code that does this, it is always safe to set. |
Chris Lattner | a5ad93a | 2010-01-23 06:39:22 +0000 | [diff] [blame] | 1380 | OutStreamer.EmitAssemblerFlag(MCAF_SubsectionsViaSymbols); |
Rafael Espindola | b01c4bb | 2006-07-27 11:38:51 +0000 | [diff] [blame] | 1381 | } |
Rafael Espindola | 7bc59bc | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 1382 | } |
Anton Korobeynikov | 0bd8971 | 2008-08-17 13:55:10 +0000 | [diff] [blame] | 1383 | |
Chris Lattner | 97f0693 | 2009-10-19 20:20:46 +0000 | [diff] [blame] | 1384 | //===----------------------------------------------------------------------===// |
| 1385 | |
| 1386 | void ARMAsmPrinter::printInstructionThroughMCStreamer(const MachineInstr *MI) { |
Chris Lattner | 96bc217 | 2009-10-20 00:52:47 +0000 | [diff] [blame] | 1387 | ARMMCInstLower MCInstLowering(OutContext, *Mang, *this); |
Chris Lattner | 97f0693 | 2009-10-19 20:20:46 +0000 | [diff] [blame] | 1388 | switch (MI->getOpcode()) { |
Chris Lattner | c6b8a99 | 2009-10-20 05:58:02 +0000 | [diff] [blame] | 1389 | case ARM::t2MOVi32imm: |
| 1390 | assert(0 && "Should be lowered by thumb2it pass"); |
Chris Lattner | 4d15222 | 2009-10-19 22:23:04 +0000 | [diff] [blame] | 1391 | default: break; |
Jim Grosbach | fbd1873 | 2010-09-17 23:41:53 +0000 | [diff] [blame^] | 1392 | case ARM::tPICADD: { |
| 1393 | // This is a pseudo op for a label + instruction sequence, which looks like: |
| 1394 | // LPC0: |
| 1395 | // add r0, pc |
| 1396 | // This adds the address of LPC0 to r0. |
| 1397 | |
| 1398 | // Emit the label. |
| 1399 | // FIXME: MOVE TO SHARED PLACE. |
| 1400 | unsigned Id = (unsigned)MI->getOperand(2).getImm(); |
| 1401 | const char *Prefix = MAI->getPrivateGlobalPrefix(); |
| 1402 | MCSymbol *Label =OutContext.GetOrCreateSymbol(Twine(Prefix) |
| 1403 | + "PC" + Twine(getFunctionNumber()) + "_" + Twine(Id)); |
| 1404 | OutStreamer.EmitLabel(Label); |
| 1405 | |
| 1406 | // Form and emit the add. |
| 1407 | MCInst AddInst; |
| 1408 | AddInst.setOpcode(ARM::tADDhirr); |
| 1409 | AddInst.addOperand(MCOperand::CreateReg(MI->getOperand(0).getReg())); |
| 1410 | AddInst.addOperand(MCOperand::CreateReg(MI->getOperand(0).getReg())); |
| 1411 | AddInst.addOperand(MCOperand::CreateReg(ARM::PC)); |
| 1412 | // Add predicate operands. |
| 1413 | AddInst.addOperand(MCOperand::CreateImm(ARMCC::AL)); |
| 1414 | AddInst.addOperand(MCOperand::CreateReg(0)); |
| 1415 | OutStreamer.EmitInstruction(AddInst); |
| 1416 | return; |
| 1417 | } |
Chris Lattner | 4d15222 | 2009-10-19 22:23:04 +0000 | [diff] [blame] | 1418 | case ARM::PICADD: { // FIXME: Remove asm string from td file. |
| 1419 | // This is a pseudo op for a label + instruction sequence, which looks like: |
| 1420 | // LPC0: |
| 1421 | // add r0, pc, r0 |
| 1422 | // This adds the address of LPC0 to r0. |
Jim Grosbach | b0739b7 | 2010-09-02 01:02:06 +0000 | [diff] [blame] | 1423 | |
Chris Lattner | 4d15222 | 2009-10-19 22:23:04 +0000 | [diff] [blame] | 1424 | // Emit the label. |
| 1425 | // FIXME: MOVE TO SHARED PLACE. |
Chris Lattner | a70e644 | 2009-10-19 22:33:05 +0000 | [diff] [blame] | 1426 | unsigned Id = (unsigned)MI->getOperand(2).getImm(); |
Chris Lattner | 7c5b021 | 2009-10-19 22:49:00 +0000 | [diff] [blame] | 1427 | const char *Prefix = MAI->getPrivateGlobalPrefix(); |
Chris Lattner | 9b97a73 | 2010-03-30 18:10:53 +0000 | [diff] [blame] | 1428 | MCSymbol *Label =OutContext.GetOrCreateSymbol(Twine(Prefix) |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1429 | + "PC" + Twine(getFunctionNumber()) + "_" + Twine(Id)); |
Chris Lattner | 7c5b021 | 2009-10-19 22:49:00 +0000 | [diff] [blame] | 1430 | OutStreamer.EmitLabel(Label); |
Jim Grosbach | b0739b7 | 2010-09-02 01:02:06 +0000 | [diff] [blame] | 1431 | |
| 1432 | |
Jim Grosbach | f3f0952 | 2010-09-14 21:05:34 +0000 | [diff] [blame] | 1433 | // Form and emit the add. |
Chris Lattner | 4d15222 | 2009-10-19 22:23:04 +0000 | [diff] [blame] | 1434 | MCInst AddInst; |
| 1435 | AddInst.setOpcode(ARM::ADDrr); |
| 1436 | AddInst.addOperand(MCOperand::CreateReg(MI->getOperand(0).getReg())); |
| 1437 | AddInst.addOperand(MCOperand::CreateReg(ARM::PC)); |
| 1438 | AddInst.addOperand(MCOperand::CreateReg(MI->getOperand(1).getReg())); |
Jim Grosbach | 5b46d62 | 2010-09-14 21:28:17 +0000 | [diff] [blame] | 1439 | // Add predicate operands. |
| 1440 | AddInst.addOperand(MCOperand::CreateImm(MI->getOperand(3).getImm())); |
| 1441 | AddInst.addOperand(MCOperand::CreateReg(MI->getOperand(4).getReg())); |
| 1442 | // Add 's' bit operand (always reg0 for this) |
| 1443 | AddInst.addOperand(MCOperand::CreateReg(0)); |
Chris Lattner | 850d2e2 | 2010-02-03 01:16:28 +0000 | [diff] [blame] | 1444 | OutStreamer.EmitInstruction(AddInst); |
Chris Lattner | 4d15222 | 2009-10-19 22:23:04 +0000 | [diff] [blame] | 1445 | return; |
| 1446 | } |
Jim Grosbach | a28abbe | 2010-09-17 16:25:52 +0000 | [diff] [blame] | 1447 | case ARM::PICSTR: |
| 1448 | case ARM::PICSTRB: |
| 1449 | case ARM::PICSTRH: |
| 1450 | case ARM::PICLDR: |
| 1451 | case ARM::PICLDRB: |
| 1452 | case ARM::PICLDRH: |
| 1453 | case ARM::PICLDRSB: |
| 1454 | case ARM::PICLDRSH: { |
Jim Grosbach | b74ca9d | 2010-09-16 17:43:25 +0000 | [diff] [blame] | 1455 | // This is a pseudo op for a label + instruction sequence, which looks like: |
| 1456 | // LPC0: |
Jim Grosbach | a28abbe | 2010-09-17 16:25:52 +0000 | [diff] [blame] | 1457 | // OP r0, [pc, r0] |
Jim Grosbach | b74ca9d | 2010-09-16 17:43:25 +0000 | [diff] [blame] | 1458 | // The LCP0 label is referenced by a constant pool entry in order to get |
| 1459 | // a PC-relative address at the ldr instruction. |
| 1460 | |
| 1461 | // Emit the label. |
| 1462 | // FIXME: MOVE TO SHARED PLACE. |
| 1463 | unsigned Id = (unsigned)MI->getOperand(2).getImm(); |
| 1464 | const char *Prefix = MAI->getPrivateGlobalPrefix(); |
| 1465 | MCSymbol *Label =OutContext.GetOrCreateSymbol(Twine(Prefix) |
| 1466 | + "PC" + Twine(getFunctionNumber()) + "_" + Twine(Id)); |
| 1467 | OutStreamer.EmitLabel(Label); |
| 1468 | |
| 1469 | // Form and emit the load |
Jim Grosbach | a28abbe | 2010-09-17 16:25:52 +0000 | [diff] [blame] | 1470 | unsigned Opcode; |
| 1471 | switch (MI->getOpcode()) { |
| 1472 | default: |
| 1473 | llvm_unreachable("Unexpected opcode!"); |
| 1474 | case ARM::PICSTR: Opcode = ARM::STR; break; |
| 1475 | case ARM::PICSTRB: Opcode = ARM::STRB; break; |
| 1476 | case ARM::PICSTRH: Opcode = ARM::STRH; break; |
| 1477 | case ARM::PICLDR: Opcode = ARM::LDR; break; |
| 1478 | case ARM::PICLDRB: Opcode = ARM::LDRB; break; |
| 1479 | case ARM::PICLDRH: Opcode = ARM::LDRH; break; |
| 1480 | case ARM::PICLDRSB: Opcode = ARM::LDRSB; break; |
| 1481 | case ARM::PICLDRSH: Opcode = ARM::LDRSH; break; |
| 1482 | } |
| 1483 | MCInst LdStInst; |
| 1484 | LdStInst.setOpcode(Opcode); |
| 1485 | LdStInst.addOperand(MCOperand::CreateReg(MI->getOperand(0).getReg())); |
| 1486 | LdStInst.addOperand(MCOperand::CreateReg(ARM::PC)); |
| 1487 | LdStInst.addOperand(MCOperand::CreateReg(MI->getOperand(1).getReg())); |
| 1488 | LdStInst.addOperand(MCOperand::CreateImm(0)); |
Jim Grosbach | b74ca9d | 2010-09-16 17:43:25 +0000 | [diff] [blame] | 1489 | // Add predicate operands. |
Jim Grosbach | a28abbe | 2010-09-17 16:25:52 +0000 | [diff] [blame] | 1490 | LdStInst.addOperand(MCOperand::CreateImm(MI->getOperand(3).getImm())); |
| 1491 | LdStInst.addOperand(MCOperand::CreateReg(MI->getOperand(4).getReg())); |
| 1492 | OutStreamer.EmitInstruction(LdStInst); |
Jim Grosbach | b74ca9d | 2010-09-16 17:43:25 +0000 | [diff] [blame] | 1493 | |
| 1494 | return; |
| 1495 | } |
Chris Lattner | a70e644 | 2009-10-19 22:33:05 +0000 | [diff] [blame] | 1496 | case ARM::CONSTPOOL_ENTRY: { // FIXME: Remove asm string from td file. |
| 1497 | /// CONSTPOOL_ENTRY - This instruction represents a floating constant pool |
| 1498 | /// in the function. The first operand is the ID# for this instruction, the |
| 1499 | /// second is the index into the MachineConstantPool that this is, the third |
| 1500 | /// is the size in bytes of this constant pool entry. |
| 1501 | unsigned LabelId = (unsigned)MI->getOperand(0).getImm(); |
| 1502 | unsigned CPIdx = (unsigned)MI->getOperand(1).getIndex(); |
| 1503 | |
| 1504 | EmitAlignment(2); |
Chris Lattner | 1b46f43 | 2010-01-23 07:00:21 +0000 | [diff] [blame] | 1505 | OutStreamer.EmitLabel(GetCPISymbol(LabelId)); |
Chris Lattner | a70e644 | 2009-10-19 22:33:05 +0000 | [diff] [blame] | 1506 | |
| 1507 | const MachineConstantPoolEntry &MCPE = MCP->getConstants()[CPIdx]; |
| 1508 | if (MCPE.isMachineConstantPoolEntry()) |
| 1509 | EmitMachineConstantPoolValue(MCPE.Val.MachineCPVal); |
| 1510 | else |
| 1511 | EmitGlobalConstant(MCPE.Val.ConstVal); |
Jim Grosbach | b0739b7 | 2010-09-02 01:02:06 +0000 | [diff] [blame] | 1512 | |
Chris Lattner | a70e644 | 2009-10-19 22:33:05 +0000 | [diff] [blame] | 1513 | return; |
| 1514 | } |
Chris Lattner | 017d947 | 2009-10-20 00:40:56 +0000 | [diff] [blame] | 1515 | case ARM::MOVi2pieces: { // FIXME: Remove asmstring from td file. |
| 1516 | // This is a hack that lowers as a two instruction sequence. |
| 1517 | unsigned DstReg = MI->getOperand(0).getReg(); |
| 1518 | unsigned ImmVal = (unsigned)MI->getOperand(1).getImm(); |
| 1519 | |
| 1520 | unsigned SOImmValV1 = ARM_AM::getSOImmTwoPartFirst(ImmVal); |
| 1521 | unsigned SOImmValV2 = ARM_AM::getSOImmTwoPartSecond(ImmVal); |
Jim Grosbach | b0739b7 | 2010-09-02 01:02:06 +0000 | [diff] [blame] | 1522 | |
Chris Lattner | 017d947 | 2009-10-20 00:40:56 +0000 | [diff] [blame] | 1523 | { |
| 1524 | MCInst TmpInst; |
| 1525 | TmpInst.setOpcode(ARM::MOVi); |
| 1526 | TmpInst.addOperand(MCOperand::CreateReg(DstReg)); |
| 1527 | TmpInst.addOperand(MCOperand::CreateImm(SOImmValV1)); |
Jim Grosbach | b0739b7 | 2010-09-02 01:02:06 +0000 | [diff] [blame] | 1528 | |
Chris Lattner | 017d947 | 2009-10-20 00:40:56 +0000 | [diff] [blame] | 1529 | // Predicate. |
| 1530 | TmpInst.addOperand(MCOperand::CreateImm(MI->getOperand(2).getImm())); |
| 1531 | TmpInst.addOperand(MCOperand::CreateReg(MI->getOperand(3).getReg())); |
Chris Lattner | 233917c | 2009-10-20 00:46:11 +0000 | [diff] [blame] | 1532 | |
| 1533 | TmpInst.addOperand(MCOperand::CreateReg(0)); // cc_out |
Chris Lattner | 850d2e2 | 2010-02-03 01:16:28 +0000 | [diff] [blame] | 1534 | OutStreamer.EmitInstruction(TmpInst); |
Chris Lattner | 017d947 | 2009-10-20 00:40:56 +0000 | [diff] [blame] | 1535 | } |
| 1536 | |
| 1537 | { |
| 1538 | MCInst TmpInst; |
| 1539 | TmpInst.setOpcode(ARM::ORRri); |
| 1540 | TmpInst.addOperand(MCOperand::CreateReg(DstReg)); // dstreg |
| 1541 | TmpInst.addOperand(MCOperand::CreateReg(DstReg)); // inreg |
| 1542 | TmpInst.addOperand(MCOperand::CreateImm(SOImmValV2)); // so_imm |
| 1543 | // Predicate. |
| 1544 | TmpInst.addOperand(MCOperand::CreateImm(MI->getOperand(2).getImm())); |
| 1545 | TmpInst.addOperand(MCOperand::CreateReg(MI->getOperand(3).getReg())); |
Jim Grosbach | b0739b7 | 2010-09-02 01:02:06 +0000 | [diff] [blame] | 1546 | |
Chris Lattner | 017d947 | 2009-10-20 00:40:56 +0000 | [diff] [blame] | 1547 | TmpInst.addOperand(MCOperand::CreateReg(0)); // cc_out |
Chris Lattner | 850d2e2 | 2010-02-03 01:16:28 +0000 | [diff] [blame] | 1548 | OutStreamer.EmitInstruction(TmpInst); |
Chris Lattner | 017d947 | 2009-10-20 00:40:56 +0000 | [diff] [blame] | 1549 | } |
Jim Grosbach | b0739b7 | 2010-09-02 01:02:06 +0000 | [diff] [blame] | 1550 | return; |
Chris Lattner | 017d947 | 2009-10-20 00:40:56 +0000 | [diff] [blame] | 1551 | } |
Chris Lattner | 161dcbf | 2009-10-20 01:11:37 +0000 | [diff] [blame] | 1552 | case ARM::MOVi32imm: { // FIXME: Remove asmstring from td file. |
| 1553 | // This is a hack that lowers as a two instruction sequence. |
| 1554 | unsigned DstReg = MI->getOperand(0).getReg(); |
Rafael Espindola | 18c1021 | 2010-05-12 05:16:34 +0000 | [diff] [blame] | 1555 | const MachineOperand &MO = MI->getOperand(1); |
| 1556 | MCOperand V1, V2; |
| 1557 | if (MO.isImm()) { |
| 1558 | unsigned ImmVal = (unsigned)MI->getOperand(1).getImm(); |
| 1559 | V1 = MCOperand::CreateImm(ImmVal & 65535); |
| 1560 | V2 = MCOperand::CreateImm(ImmVal >> 16); |
| 1561 | } else if (MO.isGlobal()) { |
Jim Grosbach | c686e33 | 2010-09-17 18:25:25 +0000 | [diff] [blame] | 1562 | MCSymbol *Symbol = MCInstLowering.GetGlobalAddressSymbol(MO.getGlobal()); |
Rafael Espindola | 18c1021 | 2010-05-12 05:16:34 +0000 | [diff] [blame] | 1563 | const MCSymbolRefExpr *SymRef1 = |
Duncan Sands | 3472766 | 2010-07-12 08:16:59 +0000 | [diff] [blame] | 1564 | MCSymbolRefExpr::Create(Symbol, |
| 1565 | MCSymbolRefExpr::VK_ARM_LO16, OutContext); |
Rafael Espindola | 18c1021 | 2010-05-12 05:16:34 +0000 | [diff] [blame] | 1566 | const MCSymbolRefExpr *SymRef2 = |
Duncan Sands | 3472766 | 2010-07-12 08:16:59 +0000 | [diff] [blame] | 1567 | MCSymbolRefExpr::Create(Symbol, |
| 1568 | MCSymbolRefExpr::VK_ARM_HI16, OutContext); |
Rafael Espindola | 18c1021 | 2010-05-12 05:16:34 +0000 | [diff] [blame] | 1569 | V1 = MCOperand::CreateExpr(SymRef1); |
| 1570 | V2 = MCOperand::CreateExpr(SymRef2); |
| 1571 | } else { |
| 1572 | MI->dump(); |
| 1573 | llvm_unreachable("cannot handle this operand"); |
| 1574 | } |
| 1575 | |
Chris Lattner | 161dcbf | 2009-10-20 01:11:37 +0000 | [diff] [blame] | 1576 | { |
| 1577 | MCInst TmpInst; |
| 1578 | TmpInst.setOpcode(ARM::MOVi16); |
| 1579 | TmpInst.addOperand(MCOperand::CreateReg(DstReg)); // dstreg |
Rafael Espindola | 18c1021 | 2010-05-12 05:16:34 +0000 | [diff] [blame] | 1580 | TmpInst.addOperand(V1); // lower16(imm) |
Jim Grosbach | b0739b7 | 2010-09-02 01:02:06 +0000 | [diff] [blame] | 1581 | |
Chris Lattner | 161dcbf | 2009-10-20 01:11:37 +0000 | [diff] [blame] | 1582 | // Predicate. |
| 1583 | TmpInst.addOperand(MCOperand::CreateImm(MI->getOperand(2).getImm())); |
| 1584 | TmpInst.addOperand(MCOperand::CreateReg(MI->getOperand(3).getReg())); |
Jim Grosbach | b0739b7 | 2010-09-02 01:02:06 +0000 | [diff] [blame] | 1585 | |
Chris Lattner | 850d2e2 | 2010-02-03 01:16:28 +0000 | [diff] [blame] | 1586 | OutStreamer.EmitInstruction(TmpInst); |
Chris Lattner | 161dcbf | 2009-10-20 01:11:37 +0000 | [diff] [blame] | 1587 | } |
Jim Grosbach | b0739b7 | 2010-09-02 01:02:06 +0000 | [diff] [blame] | 1588 | |
Chris Lattner | 161dcbf | 2009-10-20 01:11:37 +0000 | [diff] [blame] | 1589 | { |
| 1590 | MCInst TmpInst; |
| 1591 | TmpInst.setOpcode(ARM::MOVTi16); |
| 1592 | TmpInst.addOperand(MCOperand::CreateReg(DstReg)); // dstreg |
| 1593 | TmpInst.addOperand(MCOperand::CreateReg(DstReg)); // srcreg |
Rafael Espindola | 18c1021 | 2010-05-12 05:16:34 +0000 | [diff] [blame] | 1594 | TmpInst.addOperand(V2); // upper16(imm) |
Jim Grosbach | b0739b7 | 2010-09-02 01:02:06 +0000 | [diff] [blame] | 1595 | |
Chris Lattner | 161dcbf | 2009-10-20 01:11:37 +0000 | [diff] [blame] | 1596 | // Predicate. |
| 1597 | TmpInst.addOperand(MCOperand::CreateImm(MI->getOperand(2).getImm())); |
| 1598 | TmpInst.addOperand(MCOperand::CreateReg(MI->getOperand(3).getReg())); |
Jim Grosbach | b0739b7 | 2010-09-02 01:02:06 +0000 | [diff] [blame] | 1599 | |
Chris Lattner | 850d2e2 | 2010-02-03 01:16:28 +0000 | [diff] [blame] | 1600 | OutStreamer.EmitInstruction(TmpInst); |
Chris Lattner | 161dcbf | 2009-10-20 01:11:37 +0000 | [diff] [blame] | 1601 | } |
Jim Grosbach | b0739b7 | 2010-09-02 01:02:06 +0000 | [diff] [blame] | 1602 | |
Chris Lattner | 161dcbf | 2009-10-20 01:11:37 +0000 | [diff] [blame] | 1603 | return; |
| 1604 | } |
Chris Lattner | 97f0693 | 2009-10-19 20:20:46 +0000 | [diff] [blame] | 1605 | } |
Jim Grosbach | b0739b7 | 2010-09-02 01:02:06 +0000 | [diff] [blame] | 1606 | |
Chris Lattner | 97f0693 | 2009-10-19 20:20:46 +0000 | [diff] [blame] | 1607 | MCInst TmpInst; |
| 1608 | MCInstLowering.Lower(MI, TmpInst); |
Chris Lattner | 850d2e2 | 2010-02-03 01:16:28 +0000 | [diff] [blame] | 1609 | OutStreamer.EmitInstruction(TmpInst); |
Chris Lattner | 97f0693 | 2009-10-19 20:20:46 +0000 | [diff] [blame] | 1610 | } |
Daniel Dunbar | 2685a29 | 2009-10-20 05:15:36 +0000 | [diff] [blame] | 1611 | |
| 1612 | //===----------------------------------------------------------------------===// |
| 1613 | // Target Registry Stuff |
| 1614 | //===----------------------------------------------------------------------===// |
| 1615 | |
| 1616 | static MCInstPrinter *createARMMCInstPrinter(const Target &T, |
| 1617 | unsigned SyntaxVariant, |
Chris Lattner | d374087 | 2010-04-04 05:04:31 +0000 | [diff] [blame] | 1618 | const MCAsmInfo &MAI) { |
Daniel Dunbar | 2685a29 | 2009-10-20 05:15:36 +0000 | [diff] [blame] | 1619 | if (SyntaxVariant == 0) |
Jim Grosbach | 74d7e6c | 2010-09-17 21:33:25 +0000 | [diff] [blame] | 1620 | return new ARMInstPrinter(MAI); |
Daniel Dunbar | 2685a29 | 2009-10-20 05:15:36 +0000 | [diff] [blame] | 1621 | return 0; |
| 1622 | } |
| 1623 | |
| 1624 | // Force static initialization. |
| 1625 | extern "C" void LLVMInitializeARMAsmPrinter() { |
| 1626 | RegisterAsmPrinter<ARMAsmPrinter> X(TheARMTarget); |
| 1627 | RegisterAsmPrinter<ARMAsmPrinter> Y(TheThumbTarget); |
| 1628 | |
| 1629 | TargetRegistry::RegisterMCInstPrinter(TheARMTarget, createARMMCInstPrinter); |
| 1630 | TargetRegistry::RegisterMCInstPrinter(TheThumbTarget, createARMMCInstPrinter); |
| 1631 | } |
| 1632 | |