blob: 06131616342b9e12e65cbabcc1d07c85dd345f07 [file] [log] [blame]
Chris Lattner556d89d2003-08-01 22:19:03 +00001//===-- SparcV9CodeEmitter.cpp --------------------------------------------===//
Misha Brukmanb5f662f2005-04-21 23:30:14 +00002//
John Criswellb576c942003-10-20 19:43:21 +00003// The LLVM Compiler Infrastructure
4//
5// This file was developed by the LLVM research group and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
Misha Brukmanb5f662f2005-04-21 23:30:14 +00007//
John Criswellb576c942003-10-20 19:43:21 +00008//===----------------------------------------------------------------------===//
Misha Brukmana9f7f6e2003-05-30 20:17:33 +00009//
Brian Gaeke42960882003-10-13 19:51:20 +000010// SPARC-specific backend for emitting machine code to memory.
11//
Chris Lattner42c7a162004-12-16 16:47:56 +000012// This module also contains the code for lazily resolving the targets of call
13// instructions, including the callback used to redirect calls to functions for
14// which the code has not yet been generated into the JIT compiler.
Brian Gaeke42960882003-10-13 19:51:20 +000015//
Chris Lattner42c7a162004-12-16 16:47:56 +000016// This file #includes SparcV9GenCodeEmitter.inc, which contains the code for
17// getBinaryCodeForInstr(), a method that converts a MachineInstr into the
18// corresponding binary machine code word.
Misha Brukmana9f7f6e2003-05-30 20:17:33 +000019//
20//===----------------------------------------------------------------------===//
21
Misha Brukmanf86aaa82003-06-02 04:12:39 +000022#include "llvm/Constants.h"
23#include "llvm/Function.h"
24#include "llvm/GlobalVariable.h"
Misha Brukman3de36f52003-05-27 20:07:58 +000025#include "llvm/PassManager.h"
26#include "llvm/CodeGen/MachineCodeEmitter.h"
Misha Brukmana2196c12003-06-04 20:01:13 +000027#include "llvm/CodeGen/MachineConstantPool.h"
Misha Brukman3de36f52003-05-27 20:07:58 +000028#include "llvm/CodeGen/MachineFunctionPass.h"
29#include "llvm/CodeGen/MachineInstr.h"
Misha Brukmana9f7f6e2003-05-30 20:17:33 +000030#include "llvm/Target/TargetMachine.h"
Misha Brukmanf86aaa82003-06-02 04:12:39 +000031#include "llvm/Target/TargetData.h"
Reid Spencer551ccae2004-09-01 22:55:40 +000032#include "llvm/Support/Debug.h"
Brian Gaekee3d68072004-02-25 18:44:15 +000033#include "SparcV9Internals.h"
34#include "SparcV9TargetMachine.h"
35#include "SparcV9RegInfo.h"
Misha Brukman0cc640e2003-05-27 21:45:05 +000036#include "SparcV9CodeEmitter.h"
Chris Lattner54a4d6a32004-11-22 20:25:10 +000037#include "SparcV9Relocations.h"
Chris Lattner85015a02004-08-16 21:55:02 +000038#include "MachineFunctionInfo.h"
Chris Lattner54a4d6a32004-11-22 20:25:10 +000039using namespace llvm;
Misha Brukman103f0c32003-09-05 22:59:31 +000040
Brian Gaekee3d68072004-02-25 18:44:15 +000041bool SparcV9TargetMachine::addPassesToEmitMachineCode(FunctionPassManager &PM,
Misha Brukman7a750e12004-08-04 21:48:00 +000042 MachineCodeEmitter &MCE) {
Brian Gaekeeb6c29b2004-07-27 19:37:37 +000043 PM.add(new SparcV9CodeEmitter(*this, MCE));
Misha Brukman7a750e12004-08-04 21:48:00 +000044 PM.add(createSparcV9MachineCodeDestructionPass());
Misha Brukman3de36f52003-05-27 20:07:58 +000045 return false;
46}
47
Misha Brukmana2196c12003-06-04 20:01:13 +000048SparcV9CodeEmitter::SparcV9CodeEmitter(TargetMachine &tm,
Chris Lattner54a4d6a32004-11-22 20:25:10 +000049 MachineCodeEmitter &M): TM(tm), MCE(M) {}
Misha Brukmana2196c12003-06-04 20:01:13 +000050
51void SparcV9CodeEmitter::emitWord(unsigned Val) {
Brian Gaeke62c6f872004-04-23 17:11:15 +000052 MCE.emitWord(Val);
Misha Brukmana9f7f6e2003-05-30 20:17:33 +000053}
54
Misha Brukmanb5f662f2005-04-21 23:30:14 +000055unsigned
Misha Brukman173e2502003-07-14 23:26:03 +000056SparcV9CodeEmitter::getRealRegNum(unsigned fakeReg,
Misha Brukmanfad49292003-08-15 00:26:50 +000057 MachineInstr &MI) {
Brian Gaeke498231b2004-06-03 02:45:09 +000058 const SparcV9RegInfo &RI = *TM.getRegInfo();
Misha Brukman173e2502003-07-14 23:26:03 +000059 unsigned regClass, regType = RI.getRegType(fakeReg);
60 // At least map fakeReg into its class
61 fakeReg = RI.getClassRegNum(fakeReg, regClass);
62
Misha Brukman9cedd432003-07-03 18:36:47 +000063 switch (regClass) {
Brian Gaekee3d68072004-02-25 18:44:15 +000064 case SparcV9RegInfo::IntRegClassID: {
65 // SparcV9 manual, p31
Misha Brukman9cedd432003-07-03 18:36:47 +000066 static const unsigned IntRegMap[] = {
67 // "o0", "o1", "o2", "o3", "o4", "o5", "o7",
68 8, 9, 10, 11, 12, 13, 15,
69 // "l0", "l1", "l2", "l3", "l4", "l5", "l6", "l7",
70 16, 17, 18, 19, 20, 21, 22, 23,
71 // "i0", "i1", "i2", "i3", "i4", "i5", "i6", "i7",
72 24, 25, 26, 27, 28, 29, 30, 31,
Misha Brukmanb5f662f2005-04-21 23:30:14 +000073 // "g0", "g1", "g2", "g3", "g4", "g5", "g6", "g7",
Misha Brukman9cedd432003-07-03 18:36:47 +000074 0, 1, 2, 3, 4, 5, 6, 7,
75 // "o6"
76 14
Misha Brukmanb5f662f2005-04-21 23:30:14 +000077 };
78
Misha Brukman9cedd432003-07-03 18:36:47 +000079 return IntRegMap[fakeReg];
80 break;
81 }
Brian Gaekee3d68072004-02-25 18:44:15 +000082 case SparcV9RegInfo::FloatRegClassID: {
Misha Brukman9cedd432003-07-03 18:36:47 +000083 DEBUG(std::cerr << "FP reg: " << fakeReg << "\n");
Brian Gaekee3d68072004-02-25 18:44:15 +000084 if (regType == SparcV9RegInfo::FPSingleRegType) {
Misha Brukman173e2502003-07-14 23:26:03 +000085 // only numbered 0-31, hence can already fit into 5 bits (and 6)
86 DEBUG(std::cerr << "FP single reg, returning: " << fakeReg << "\n");
Brian Gaekee3d68072004-02-25 18:44:15 +000087 } else if (regType == SparcV9RegInfo::FPDoubleRegType) {
Misha Brukmancf00c4a2003-10-10 17:57:28 +000088 // FIXME: This assumes that we only have 5-bit register fields!
Brian Gaekee3d68072004-02-25 18:44:15 +000089 // From SparcV9 Manual, page 40.
Misha Brukman173e2502003-07-14 23:26:03 +000090 // The bit layout becomes: b[4], b[3], b[2], b[1], b[5]
91 fakeReg |= (fakeReg >> 5) & 1;
92 fakeReg &= 0x1f;
Misha Brukmanb5f662f2005-04-21 23:30:14 +000093 DEBUG(std::cerr << "FP double reg, returning: " << fakeReg << "\n");
Misha Brukman173e2502003-07-14 23:26:03 +000094 }
Misha Brukman9cedd432003-07-03 18:36:47 +000095 return fakeReg;
96 }
Brian Gaekee3d68072004-02-25 18:44:15 +000097 case SparcV9RegInfo::IntCCRegClassID: {
Misha Brukmandfbfc572003-07-16 20:30:40 +000098 /* xcc, icc, ccr */
99 static const unsigned IntCCReg[] = { 6, 4, 2 };
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000100
Misha Brukmandfbfc572003-07-16 20:30:40 +0000101 assert(fakeReg < sizeof(IntCCReg)/sizeof(IntCCReg[0])
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000102 && "CC register out of bounds for IntCCReg map");
Misha Brukmandfbfc572003-07-16 20:30:40 +0000103 DEBUG(std::cerr << "IntCC reg: " << IntCCReg[fakeReg] << "\n");
104 return IntCCReg[fakeReg];
Misha Brukman9cedd432003-07-03 18:36:47 +0000105 }
Brian Gaekee3d68072004-02-25 18:44:15 +0000106 case SparcV9RegInfo::FloatCCRegClassID: {
Misha Brukman9cedd432003-07-03 18:36:47 +0000107 /* These are laid out %fcc0 - %fcc3 => 0 - 3, so are correct */
108 DEBUG(std::cerr << "FP CC reg: " << fakeReg << "\n");
109 return fakeReg;
110 }
Brian Gaeke7fa84b72004-06-09 21:54:59 +0000111 case SparcV9RegInfo::SpecialRegClassID: {
112 // Currently only "special" reg is %fsr, which is encoded as 1 in
113 // instructions and 0 in SparcV9SpecialRegClass.
114 static const unsigned SpecialReg[] = { 1 };
115 assert(fakeReg < sizeof(SpecialReg)/sizeof(SpecialReg[0])
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000116 && "Special register out of bounds for SpecialReg map");
Brian Gaeke7fa84b72004-06-09 21:54:59 +0000117 DEBUG(std::cerr << "Special reg: " << SpecialReg[fakeReg] << "\n");
118 return SpecialReg[fakeReg];
119 }
Misha Brukman9cedd432003-07-03 18:36:47 +0000120 default:
Brian Gaekee8a6bee2004-06-09 20:44:42 +0000121 assert(0 && "Invalid unified register number in getRealRegNum");
Misha Brukman9cedd432003-07-03 18:36:47 +0000122 return fakeReg;
123 }
124}
125
126
Misha Brukman07d45162003-07-15 19:09:43 +0000127
Misha Brukmana9f7f6e2003-05-30 20:17:33 +0000128int64_t SparcV9CodeEmitter::getMachineOpValue(MachineInstr &MI,
129 MachineOperand &MO) {
Brian Gaekec3eaa892003-06-02 02:13:26 +0000130 int64_t rv = 0; // Return value; defaults to 0 for unhandled cases
131 // or things that get fixed up later by the JIT.
Chris Lattner54a4d6a32004-11-22 20:25:10 +0000132 if (MO.isPCRelativeDisp() || MO.isGlobalAddress()) {
Misha Brukman8f122222003-06-06 00:26:11 +0000133 DEBUG(std::cerr << "PCRelativeDisp: ");
Misha Brukmaneaaf8ad2003-06-02 05:24:46 +0000134 Value *V = MO.getVRegValue();
135 if (BasicBlock *BB = dyn_cast<BasicBlock>(V)) {
Misha Brukman8f122222003-06-06 00:26:11 +0000136 DEBUG(std::cerr << "Saving reference to BB (VReg)\n");
Misha Brukmana2196c12003-06-04 20:01:13 +0000137 unsigned* CurrPC = (unsigned*)(intptr_t)MCE.getCurrentPCValue();
Misha Brukmaneaaf8ad2003-06-02 05:24:46 +0000138 BBRefs.push_back(std::make_pair(BB, std::make_pair(CurrPC, &MI)));
Brian Gaekea9004522004-05-19 21:30:01 +0000139 } else if (const ConstantInt *CI = dyn_cast<ConstantInt>(V)) {
Brian Gaekeceabd972004-05-20 07:43:40 +0000140 // The real target of the branch is CI = PC + (rv * 4)
141 // So undo that: give the instruction (CI - PC) / 4
142 rv = (CI->getRawValue() - MCE.getCurrentPCValue()) / 4;
Misha Brukmana2196c12003-06-04 20:01:13 +0000143 } else if (GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
Chris Lattneradbcc102004-11-23 15:57:01 +0000144 unsigned Reloc = 0;
Misha Brukmana2196c12003-06-04 20:01:13 +0000145 if (MI.getOpcode() == V9::CALL) {
Chris Lattner54a4d6a32004-11-22 20:25:10 +0000146 Reloc = V9::reloc_pcrel_call;
Chris Lattner54a4d6a32004-11-22 20:25:10 +0000147 } else if (MI.getOpcode() == V9::SETHI) {
148 if (MO.isHiBits64())
149 Reloc = V9::reloc_sethi_hh;
150 else if (MO.isHiBits32())
151 Reloc = V9::reloc_sethi_lm;
152 else
153 assert(0 && "Unknown relocation!");
154 } else if (MI.getOpcode() == V9::ORi) {
155 if (MO.isLoBits32())
156 Reloc = V9::reloc_or_lo;
157 else if (MO.isLoBits64())
158 Reloc = V9::reloc_or_hm;
159 else
160 assert(0 && "Unknown relocation!");
161 } else {
162 assert(0 && "Unknown relocation!");
Misha Brukmana2196c12003-06-04 20:01:13 +0000163 }
Chris Lattner54a4d6a32004-11-22 20:25:10 +0000164
Chris Lattner2eeda6e2004-11-22 21:42:40 +0000165 MCE.addRelocation(MachineRelocation(MCE.getCurrentPCOffset(), Reloc, GV));
Chris Lattner54a4d6a32004-11-22 20:25:10 +0000166 rv = 0;
Misha Brukmaneaaf8ad2003-06-02 05:24:46 +0000167 } else {
168 std::cerr << "ERROR: PC relative disp unhandled:" << MO << "\n";
169 abort();
170 }
Alkis Evlogimenosaf862112004-02-11 05:55:00 +0000171 } else if (MO.isRegister() || MO.getType() == MachineOperand::MO_CCRegister)
Misha Brukmanf47d9c22003-06-05 20:52:06 +0000172 {
Brian Gaekee3d68072004-02-25 18:44:15 +0000173 // This is necessary because the SparcV9 backend doesn't actually lay out
Misha Brukman9cedd432003-07-03 18:36:47 +0000174 // registers in the real fashion -- it skips those that it chooses not to
175 // allocate, i.e. those that are the FP, SP, etc.
Alkis Evlogimenosbe766c72004-02-13 21:01:20 +0000176 unsigned fakeReg = MO.getReg();
Misha Brukman173e2502003-07-14 23:26:03 +0000177 unsigned realRegByClass = getRealRegNum(fakeReg, MI);
178 DEBUG(std::cerr << MO << ": Reg[" << std::dec << fakeReg << "] => "
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000179 << realRegByClass << " (LLC: "
Chris Lattnerd029cd22004-06-02 05:55:25 +0000180 << TM.getRegInfo()->getUnifiedRegName(fakeReg) << ")\n");
Misha Brukman9cedd432003-07-03 18:36:47 +0000181 rv = realRegByClass;
Misha Brukman3de36f52003-05-27 20:07:58 +0000182 } else if (MO.isImmediate()) {
Brian Gaekec3eaa892003-06-02 02:13:26 +0000183 rv = MO.getImmedValue();
Misha Brukman8f122222003-06-06 00:26:11 +0000184 DEBUG(std::cerr << "immed: " << rv << "\n");
Misha Brukmana9f7f6e2003-05-30 20:17:33 +0000185 } else if (MO.isMachineBasicBlock()) {
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000186 // Duplicate code of the above case for VirtualRegister, BasicBlock...
Brian Gaekee3d68072004-02-25 18:44:15 +0000187 // It should really hit this case, but SparcV9 backend uses VRegs instead
Misha Brukman8f122222003-06-06 00:26:11 +0000188 DEBUG(std::cerr << "Saving reference to MBB\n");
Chris Lattner6856d112003-07-26 23:04:00 +0000189 const BasicBlock *BB = MO.getMachineBasicBlock()->getBasicBlock();
Misha Brukmana2196c12003-06-04 20:01:13 +0000190 unsigned* CurrPC = (unsigned*)(intptr_t)MCE.getCurrentPCValue();
Misha Brukmaneaaf8ad2003-06-02 05:24:46 +0000191 BBRefs.push_back(std::make_pair(BB, std::make_pair(CurrPC, &MI)));
Misha Brukmana9f7f6e2003-05-30 20:17:33 +0000192 } else if (MO.isExternalSymbol()) {
Brian Gaekee3d68072004-02-25 18:44:15 +0000193 // SparcV9 backend doesn't generate this (yet...)
Misha Brukmaneaaf8ad2003-06-02 05:24:46 +0000194 std::cerr << "ERROR: External symbol unhandled: " << MO << "\n";
195 abort();
196 } else if (MO.isFrameIndex()) {
Brian Gaekee3d68072004-02-25 18:44:15 +0000197 // SparcV9 backend doesn't generate this (yet...)
Misha Brukmaneaaf8ad2003-06-02 05:24:46 +0000198 int FrameIndex = MO.getFrameIndex();
199 std::cerr << "ERROR: Frame index unhandled.\n";
200 abort();
201 } else if (MO.isConstantPoolIndex()) {
Misha Brukmane5ad8152003-11-07 18:06:26 +0000202 unsigned Index = MO.getConstantPoolIndex();
203 rv = MCE.getConstantPoolEntryAddress(Index);
Misha Brukman3de36f52003-05-27 20:07:58 +0000204 } else {
Misha Brukmana9f7f6e2003-05-30 20:17:33 +0000205 std::cerr << "ERROR: Unknown type of MachineOperand: " << MO << "\n";
Misha Brukmaneaaf8ad2003-06-02 05:24:46 +0000206 abort();
Brian Gaekec3eaa892003-06-02 02:13:26 +0000207 }
208
209 // Finally, deal with the various bitfield-extracting functions that
210 // are used in SPARC assembly. (Some of these make no sense in combination
211 // with some of the above; we'll trust that the instruction selector
212 // will not produce nonsense, and not check for valid combinations here.)
Brian Gaekee3d68072004-02-25 18:44:15 +0000213 if (MO.isLoBits32()) { // %lo(val) == %lo() in SparcV9 ABI doc
Brian Gaekec3eaa892003-06-02 02:13:26 +0000214 return rv & 0x03ff;
Brian Gaekee3d68072004-02-25 18:44:15 +0000215 } else if (MO.isHiBits32()) { // %lm(val) == %hi() in SparcV9 ABI doc
Brian Gaekec3eaa892003-06-02 02:13:26 +0000216 return (rv >> 10) & 0x03fffff;
Brian Gaekee3d68072004-02-25 18:44:15 +0000217 } else if (MO.isLoBits64()) { // %hm(val) == %ulo() in SparcV9 ABI doc
Brian Gaekec3eaa892003-06-02 02:13:26 +0000218 return (rv >> 32) & 0x03ff;
Brian Gaekee3d68072004-02-25 18:44:15 +0000219 } else if (MO.isHiBits64()) { // %hh(val) == %uhi() in SparcV9 ABI doc
Brian Gaekec3eaa892003-06-02 02:13:26 +0000220 return rv >> 42;
221 } else { // (unadorned) val
222 return rv;
Misha Brukman3de36f52003-05-27 20:07:58 +0000223 }
224}
225
226unsigned SparcV9CodeEmitter::getValueBit(int64_t Val, unsigned bit) {
227 Val >>= bit;
228 return (Val & 1);
229}
230
Misha Brukman3de36f52003-05-27 20:07:58 +0000231bool SparcV9CodeEmitter::runOnMachineFunction(MachineFunction &MF) {
Misha Brukmana2196c12003-06-04 20:01:13 +0000232 MCE.startFunction(MF);
Misha Brukman8f122222003-06-06 00:26:11 +0000233 DEBUG(std::cerr << "Starting function " << MF.getFunction()->getName()
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000234 << ", address: " << "0x" << std::hex
Misha Brukman8f122222003-06-06 00:26:11 +0000235 << (long)MCE.getCurrentPCValue() << "\n");
Misha Brukmanf86aaa82003-06-02 04:12:39 +0000236
Misha Brukmane5ad8152003-11-07 18:06:26 +0000237 MCE.emitConstantPool(MF.getConstantPool());
Misha Brukman3de36f52003-05-27 20:07:58 +0000238 for (MachineFunction::iterator I = MF.begin(), E = MF.end(); I != E; ++I)
239 emitBasicBlock(*I);
Misha Brukmana2196c12003-06-04 20:01:13 +0000240 MCE.finishFunction(MF);
Misha Brukmanf86aaa82003-06-02 04:12:39 +0000241
Misha Brukman9cedd432003-07-03 18:36:47 +0000242 DEBUG(std::cerr << "Finishing fn " << MF.getFunction()->getName() << "\n");
Misha Brukmanf86aaa82003-06-02 04:12:39 +0000243
244 // Resolve branches to BasicBlocks for the entire function
245 for (unsigned i = 0, e = BBRefs.size(); i != e; ++i) {
246 long Location = BBLocations[BBRefs[i].first];
247 unsigned *Ref = BBRefs[i].second.first;
248 MachineInstr *MI = BBRefs[i].second.second;
Misha Brukman9cedd432003-07-03 18:36:47 +0000249 DEBUG(std::cerr << "Fixup @ " << std::hex << Ref << " to 0x" << Location
250 << " in instr: " << std::dec << *MI);
Misha Brukmanf86aaa82003-06-02 04:12:39 +0000251 for (unsigned ii = 0, ee = MI->getNumOperands(); ii != ee; ++ii) {
252 MachineOperand &op = MI->getOperand(ii);
253 if (op.isPCRelativeDisp()) {
254 // the instruction's branch target is made such that it branches to
Misha Brukman9cedd432003-07-03 18:36:47 +0000255 // PC + (branchTarget * 4), so undo that arithmetic here:
Misha Brukmanf86aaa82003-06-02 04:12:39 +0000256 // Location is the target of the branch
257 // Ref is the location of the instruction, and hence the PC
Misha Brukman9cedd432003-07-03 18:36:47 +0000258 int64_t branchTarget = (Location - (long)Ref) >> 2;
Misha Brukmanf86aaa82003-06-02 04:12:39 +0000259 // Save the flags.
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000260 bool loBits32=false, hiBits32=false, loBits64=false, hiBits64=false;
Alkis Evlogimenos4d7af652003-12-14 13:24:17 +0000261 if (op.isLoBits32()) { loBits32=true; }
262 if (op.isHiBits32()) { hiBits32=true; }
263 if (op.isLoBits64()) { loBits64=true; }
264 if (op.isHiBits64()) { hiBits64=true; }
Misha Brukmanf86aaa82003-06-02 04:12:39 +0000265 MI->SetMachineOperandConst(ii, MachineOperand::MO_SignExtendedImmed,
266 branchTarget);
Chris Lattnerf4fc36e2004-07-19 07:52:35 +0000267 if (loBits32) { MI->getOperand(ii).markLo32(); }
268 else if (hiBits32) { MI->getOperand(ii).markHi32(); }
269 else if (loBits64) { MI->getOperand(ii).markLo64(); }
270 else if (hiBits64) { MI->getOperand(ii).markHi64(); }
Misha Brukman8f122222003-06-06 00:26:11 +0000271 DEBUG(std::cerr << "Rewrote BB ref: ");
Misha Brukmanf86aaa82003-06-02 04:12:39 +0000272 unsigned fixedInstr = SparcV9CodeEmitter::getBinaryCodeForInstr(*MI);
Brian Gaeke62c6f872004-04-23 17:11:15 +0000273 MCE.emitWordAt (fixedInstr, Ref);
Misha Brukmanf86aaa82003-06-02 04:12:39 +0000274 break;
275 }
276 }
277 }
278 BBRefs.clear();
279 BBLocations.clear();
280
Misha Brukman3de36f52003-05-27 20:07:58 +0000281 return false;
282}
283
284void SparcV9CodeEmitter::emitBasicBlock(MachineBasicBlock &MBB) {
Misha Brukman0d603452003-05-27 22:41:44 +0000285 currBB = MBB.getBasicBlock();
Misha Brukmana2196c12003-06-04 20:01:13 +0000286 BBLocations[currBB] = MCE.getCurrentPCValue();
Chris Lattner54a4d6a32004-11-22 20:25:10 +0000287 for (MachineBasicBlock::iterator I = MBB.begin(), E = MBB.end(); I != E; ++I)
Chris Lattnerbefc3742004-11-22 21:25:10 +0000288 if (I->getOpcode() != V9::RDCCR) {
289 emitWord(getBinaryCodeForInstr(*I));
290 } else {
291 // FIXME: The tblgen produced code emitter cannot deal with the fact that
292 // machine operand #0 of the RDCCR instruction should be ignored. This is
293 // really a bug in the representation of the RDCCR instruction (which has
294 // no need to explicitly represent the CCR dest), but we hack around it
295 // here.
296 unsigned RegNo = getMachineOpValue(*I, I->getOperand(1));
297 RegNo &= (1<<5)-1;
298 emitWord((RegNo << 25) | 2168487936U);
299 }
Misha Brukman3de36f52003-05-27 20:07:58 +0000300}
301
Chris Lattner42c7a162004-12-16 16:47:56 +0000302#include "SparcV9GenCodeEmitter.inc"
Brian Gaeked0fde302003-11-11 22:41:34 +0000303