blob: e68b78ad86ac507b9d5faf224c49d9753c184257 [file] [log] [blame]
Chris Lattner556d89d2003-08-01 22:19:03 +00001//===-- SparcV9CodeEmitter.cpp --------------------------------------------===//
Misha Brukmana9f7f6e2003-05-30 20:17:33 +00002//
Chris Lattner556d89d2003-08-01 22:19:03 +00003// FIXME: document
Misha Brukmana9f7f6e2003-05-30 20:17:33 +00004//
5//===----------------------------------------------------------------------===//
6
Misha Brukmanf86aaa82003-06-02 04:12:39 +00007#include "llvm/Constants.h"
8#include "llvm/Function.h"
9#include "llvm/GlobalVariable.h"
Misha Brukman3de36f52003-05-27 20:07:58 +000010#include "llvm/PassManager.h"
11#include "llvm/CodeGen/MachineCodeEmitter.h"
Misha Brukmana2196c12003-06-04 20:01:13 +000012#include "llvm/CodeGen/MachineConstantPool.h"
Misha Brukmanf86aaa82003-06-02 04:12:39 +000013#include "llvm/CodeGen/MachineFunctionInfo.h"
Misha Brukman3de36f52003-05-27 20:07:58 +000014#include "llvm/CodeGen/MachineFunctionPass.h"
15#include "llvm/CodeGen/MachineInstr.h"
Misha Brukmana9f7f6e2003-05-30 20:17:33 +000016#include "llvm/Target/TargetMachine.h"
Misha Brukmanf86aaa82003-06-02 04:12:39 +000017#include "llvm/Target/TargetData.h"
Chris Lattner556d89d2003-08-01 22:19:03 +000018#include "Support/Debug.h"
Misha Brukmanf86aaa82003-06-02 04:12:39 +000019#include "Support/hash_set"
Misha Brukman3de36f52003-05-27 20:07:58 +000020#include "SparcInternals.h"
Misha Brukman0cc640e2003-05-27 21:45:05 +000021#include "SparcV9CodeEmitter.h"
Misha Brukman3de36f52003-05-27 20:07:58 +000022
23bool UltraSparc::addPassesToEmitMachineCode(PassManager &PM,
24 MachineCodeEmitter &MCE) {
Misha Brukman8f122222003-06-06 00:26:11 +000025 MachineCodeEmitter *M = &MCE;
Misha Brukmande07be32003-06-06 04:41:22 +000026 DEBUG(M = MachineCodeEmitter::createFilePrinterEmitter(MCE));
Misha Brukmana2196c12003-06-04 20:01:13 +000027 PM.add(new SparcV9CodeEmitter(*this, *M));
Misha Brukmandcbe7122003-05-31 06:26:06 +000028 PM.add(createMachineCodeDestructionPass()); // Free stuff no longer needed
Misha Brukman3de36f52003-05-27 20:07:58 +000029 return false;
30}
31
Misha Brukmanf86aaa82003-06-02 04:12:39 +000032namespace {
33 class JITResolver {
Misha Brukmana2196c12003-06-04 20:01:13 +000034 SparcV9CodeEmitter &SparcV9;
Misha Brukmanf86aaa82003-06-02 04:12:39 +000035 MachineCodeEmitter &MCE;
36
Misha Brukman0897c602003-08-06 16:20:22 +000037 /// LazyCodeGenMap - Keep track of call sites for functions that are to be
38 /// lazily resolved.
39 ///
Misha Brukmana2196c12003-06-04 20:01:13 +000040 std::map<uint64_t, Function*> LazyCodeGenMap;
Misha Brukmanf86aaa82003-06-02 04:12:39 +000041
Misha Brukman0897c602003-08-06 16:20:22 +000042 /// LazyResolverMap - Keep track of the lazy resolver created for a
43 /// particular function so that we can reuse them if necessary.
44 ///
Misha Brukmana2196c12003-06-04 20:01:13 +000045 std::map<Function*, uint64_t> LazyResolverMap;
Misha Brukman0897c602003-08-06 16:20:22 +000046
47 public:
48 enum CallType { ShortCall, FarCall };
49
50 private:
51 /// We need to keep track of whether we used a simple call or a far call
52 /// (many instructions) in sequence. This means we need to keep track of
53 /// what type of stub we generate.
54 static std::map<uint64_t, CallType> LazyCallFlavor;
55
Misha Brukmanf86aaa82003-06-02 04:12:39 +000056 public:
Misha Brukmana2196c12003-06-04 20:01:13 +000057 JITResolver(SparcV9CodeEmitter &V9,
58 MachineCodeEmitter &mce) : SparcV9(V9), MCE(mce) {}
59 uint64_t getLazyResolver(Function *F);
60 uint64_t addFunctionReference(uint64_t Address, Function *F);
Misha Brukman0897c602003-08-06 16:20:22 +000061 void deleteFunctionReference(uint64_t Address);
62 void addCallFlavor(uint64_t Address, CallType Flavor) {
63 LazyCallFlavor[Address] = Flavor;
64 }
Misha Brukmana2196c12003-06-04 20:01:13 +000065
66 // Utility functions for accessing data from static callback
67 uint64_t getCurrentPCValue() {
68 return MCE.getCurrentPCValue();
69 }
70 unsigned getBinaryCodeForInstr(MachineInstr &MI) {
71 return SparcV9.getBinaryCodeForInstr(MI);
72 }
73
Misha Brukmanf47d9c22003-06-05 20:52:06 +000074 inline uint64_t insertFarJumpAtAddr(int64_t Value, uint64_t Addr);
75
Misha Brukmanf86aaa82003-06-02 04:12:39 +000076 private:
Misha Brukmana2196c12003-06-04 20:01:13 +000077 uint64_t emitStubForFunction(Function *F);
Misha Brukmanf86aaa82003-06-02 04:12:39 +000078 static void CompilationCallback();
Misha Brukmana2196c12003-06-04 20:01:13 +000079 uint64_t resolveFunctionReference(uint64_t RetAddr);
Misha Brukmanf47d9c22003-06-05 20:52:06 +000080
Misha Brukmanf86aaa82003-06-02 04:12:39 +000081 };
82
83 JITResolver *TheJITResolver;
Misha Brukman0897c602003-08-06 16:20:22 +000084 std::map<uint64_t, JITResolver::CallType> JITResolver::LazyCallFlavor;
Misha Brukmanf86aaa82003-06-02 04:12:39 +000085}
86
87/// addFunctionReference - This method is called when we need to emit the
88/// address of a function that has not yet been emitted, so we don't know the
89/// address. Instead, we emit a call to the CompilationCallback method, and
90/// keep track of where we are.
91///
Misha Brukmana2196c12003-06-04 20:01:13 +000092uint64_t JITResolver::addFunctionReference(uint64_t Address, Function *F) {
Misha Brukman0897c602003-08-06 16:20:22 +000093 LazyCodeGenMap[Address] = F;
Misha Brukmanf86aaa82003-06-02 04:12:39 +000094 return (intptr_t)&JITResolver::CompilationCallback;
95}
96
Misha Brukman0897c602003-08-06 16:20:22 +000097/// deleteFunctionReference - If we are emitting a far call, we already added a
98/// reference to the function, but it is now incorrect, since the address to the
99/// JIT resolver is too far away to be a simple call instruction. This is used
100/// to remove the address from the map.
101///
102void JITResolver::deleteFunctionReference(uint64_t Address) {
103 std::map<uint64_t, Function*>::iterator I = LazyCodeGenMap.find(Address);
104 assert(I != LazyCodeGenMap.end() && "Not in map!");
105 LazyCodeGenMap.erase(I);
106}
107
Misha Brukmana2196c12003-06-04 20:01:13 +0000108uint64_t JITResolver::resolveFunctionReference(uint64_t RetAddr) {
109 std::map<uint64_t, Function*>::iterator I = LazyCodeGenMap.find(RetAddr);
Misha Brukmanf86aaa82003-06-02 04:12:39 +0000110 assert(I != LazyCodeGenMap.end() && "Not in map!");
111 Function *F = I->second;
112 LazyCodeGenMap.erase(I);
113 return MCE.forceCompilationOf(F);
114}
115
Misha Brukmana2196c12003-06-04 20:01:13 +0000116uint64_t JITResolver::getLazyResolver(Function *F) {
117 std::map<Function*, uint64_t>::iterator I = LazyResolverMap.lower_bound(F);
Misha Brukmanf86aaa82003-06-02 04:12:39 +0000118 if (I != LazyResolverMap.end() && I->first == F) return I->second;
119
120//std::cerr << "Getting lazy resolver for : " << ((Value*)F)->getName() << "\n";
121
Misha Brukmana2196c12003-06-04 20:01:13 +0000122 uint64_t Stub = emitStubForFunction(F);
Misha Brukmanf86aaa82003-06-02 04:12:39 +0000123 LazyResolverMap.insert(I, std::make_pair(F, Stub));
124 return Stub;
125}
126
Misha Brukmanf47d9c22003-06-05 20:52:06 +0000127uint64_t JITResolver::insertFarJumpAtAddr(int64_t Target, uint64_t Addr) {
128
129 static const unsigned i1 = SparcIntRegClass::i1, i2 = SparcIntRegClass::i2,
130 i7 = SparcIntRegClass::i7,
Misha Brukman0870e972003-08-06 22:19:18 +0000131 o6 = SparcIntRegClass::o6, g0 = SparcIntRegClass::g0,
132 g1 = SparcIntRegClass::g1, g5 = SparcIntRegClass::g5;
Misha Brukmanf47d9c22003-06-05 20:52:06 +0000133
Misha Brukman0897c602003-08-06 16:20:22 +0000134 MachineInstr* BinaryCode[] = {
135 //
Misha Brukman0870e972003-08-06 22:19:18 +0000136 // Get address to branch into %g1, using %g5 as a temporary
Misha Brukman0897c602003-08-06 16:20:22 +0000137 //
Misha Brukman0870e972003-08-06 22:19:18 +0000138 // sethi %uhi(Target), %g5 ;; get upper 22 bits of Target into %g5
139 BuildMI(V9::SETHI, 2).addSImm(Target >> 42).addReg(g5),
140 // or %g5, %ulo(Target), %g5 ;; get 10 lower bits of upper word into %g5
141 BuildMI(V9::ORi, 3).addReg(g5).addSImm((Target >> 32) & 0x03ff).addReg(g5),
142 // sllx %g5, 32, %g5 ;; shift those 10 bits to the upper word
143 BuildMI(V9::SLLXi6, 3).addReg(g5).addSImm(32).addReg(g5),
144 // sethi %hi(Target), %g1 ;; extract bits 10-31 into the dest reg
145 BuildMI(V9::SETHI, 2).addSImm((Target >> 10) & 0x03fffff).addReg(g1),
146 // or %g5, %g1, %g1 ;; get upper word (in %i1) into %g1
147 BuildMI(V9::ORr, 3).addReg(g5).addReg(g1).addReg(g1),
148 // or %g1, %lo(Target), %g1 ;; get lowest 10 bits of Target into %g1
149 BuildMI(V9::ORi, 3).addReg(g1).addSImm(Target & 0x03ff).addReg(g1),
150 // jmpl %g1, %g0, %g0 ;; indirect branch on %g1
151 BuildMI(V9::JMPLRETr, 3).addReg(g1).addReg(g0).addReg(g0),
152 // nop ;; delay slot
153 BuildMI(V9::NOP, 0)
Misha Brukman0897c602003-08-06 16:20:22 +0000154 };
Misha Brukmanf47d9c22003-06-05 20:52:06 +0000155
Misha Brukman0897c602003-08-06 16:20:22 +0000156 for (unsigned i=0, e=sizeof(BinaryCode)/sizeof(BinaryCode[0]); i!=e; ++i) {
157 *((unsigned*)(intptr_t)Addr) = getBinaryCodeForInstr(*BinaryCode[i]);
158 delete BinaryCode[i];
159 Addr += 4;
160 }
Misha Brukmanf47d9c22003-06-05 20:52:06 +0000161
162 return Addr;
163}
164
Misha Brukmanf86aaa82003-06-02 04:12:39 +0000165void JITResolver::CompilationCallback() {
Misha Brukmanf47d9c22003-06-05 20:52:06 +0000166 uint64_t CameFrom = (uint64_t)(intptr_t)__builtin_return_address(0);
167 int64_t Target = (int64_t)TheJITResolver->resolveFunctionReference(CameFrom);
Misha Brukman8f122222003-06-06 00:26:11 +0000168 DEBUG(std::cerr << "In callback! Addr=0x" << std::hex << CameFrom << "\n");
Misha Brukman0897c602003-08-06 16:20:22 +0000169#if defined(sparc) || defined(__sparc__) || defined(__sparcv9)
170 register int64_t returnAddr;
171 __asm__ __volatile__ ("add %%i7, %%g0, %0" : "=r" (returnAddr) : );
172 DEBUG(std::cerr << "Read i7 (return addr) = "
173 << std::hex << returnAddr << ", value: "
174 << std::hex << *(unsigned*)returnAddr << "\n");
Misha Brukmanf47d9c22003-06-05 20:52:06 +0000175#endif
176
Misha Brukman0897c602003-08-06 16:20:22 +0000177 // Rewrite the call target so that we don't fault every time we execute it.
Misha Brukmanf47d9c22003-06-05 20:52:06 +0000178 //
Misha Brukmanf47d9c22003-06-05 20:52:06 +0000179
Misha Brukman0897c602003-08-06 16:20:22 +0000180 static const unsigned o6 = SparcIntRegClass::o6;
Misha Brukmanf47d9c22003-06-05 20:52:06 +0000181
Misha Brukman0897c602003-08-06 16:20:22 +0000182 // Subtract enough to overwrite up to the 'save' instruction
Misha Brukman0870e972003-08-06 22:19:18 +0000183 // This depends on whether we made a short call (1 instruction) or the
184 // farCall (long form: 10 instructions, short form: 7 instructions)
185 uint64_t Offset = (LazyCallFlavor[CameFrom] == ShortCall) ? 4 : 28;
Misha Brukman0897c602003-08-06 16:20:22 +0000186 uint64_t CodeBegin = CameFrom - Offset;
187
188 // Make sure that what we're about to overwrite is indeed "save"
189 MachineInstr *SV = BuildMI(V9::SAVEi, 3).addReg(o6).addSImm(-192).addReg(o6);
190 unsigned SaveInst = TheJITResolver->getBinaryCodeForInstr(*SV);
191 delete SV;
192 unsigned CodeInMem = *(unsigned*)(intptr_t)CodeBegin;
193 assert(CodeInMem == SaveInst && "About to overwrite smthg not a save instr!");
194 DEBUG(std::cerr << "Emitting a far jump to 0x" << std::hex << Target << "\n");
195 TheJITResolver->insertFarJumpAtAddr(Target, CodeBegin);
Misha Brukmanf47d9c22003-06-05 20:52:06 +0000196
197 // FIXME: if the target function is close enough to fit into the 19bit disp of
198 // BA, we should use this version, as its much cheaper to generate.
Misha Brukman0897c602003-08-06 16:20:22 +0000199#if 0
200 uint64_t InstAddr = CodeBegin;
201 // ba <target>
202 MachineInstr *MI = BuildMI(V9::BA, 1).addSImm(Target);
203 *((unsigned*)(intptr_t)InstAddr)=TheJITResolver->getBinaryCodeForInstr(*MI);
204 InstAddr += 4;
Misha Brukmana2196c12003-06-04 20:01:13 +0000205 delete MI;
Misha Brukmanf47d9c22003-06-05 20:52:06 +0000206
Misha Brukman0897c602003-08-06 16:20:22 +0000207 // nop
208 MI = BuildMI(V9::NOP, 0);
209 *((unsigned*)(intptr_t))=TheJITResolver->getBinaryCodeForInstr(*Nop);
210 delete MI;
211#endif
Misha Brukmanf47d9c22003-06-05 20:52:06 +0000212
Misha Brukman0897c602003-08-06 16:20:22 +0000213 // Change the return address to reexecute the restore, then the jump
Misha Brukmanf47d9c22003-06-05 20:52:06 +0000214 // The return address is really %o7, but will disappear after this function
215 // returns, and the register windows are rotated away.
216#if defined(sparc) || defined(__sparc__) || defined(__sparcv9)
Misha Brukman0897c602003-08-06 16:20:22 +0000217 __asm__ __volatile__ ("sub %%i7, %0, %%i7" : : "r" (Offset+12));
218 DEBUG(std::cerr << "Callback setting return addr to "
219 << std::hex << (CameFrom-Offset-12) << "\n");
Misha Brukmanf47d9c22003-06-05 20:52:06 +0000220#endif
Misha Brukmanf86aaa82003-06-02 04:12:39 +0000221}
222
223/// emitStubForFunction - This method is used by the JIT when it needs to emit
224/// the address of a function for a function whose code has not yet been
225/// generated. In order to do this, it generates a stub which jumps to the lazy
226/// function compiler, which will eventually get fixed to call the function
227/// directly.
228///
Misha Brukmana2196c12003-06-04 20:01:13 +0000229uint64_t JITResolver::emitStubForFunction(Function *F) {
Misha Brukman0897c602003-08-06 16:20:22 +0000230 MCE.startFunctionStub(*F, 20);
Misha Brukmanf86aaa82003-06-02 04:12:39 +0000231
Misha Brukman8f122222003-06-06 00:26:11 +0000232 DEBUG(std::cerr << "Emitting stub at addr: 0x"
233 << std::hex << MCE.getCurrentPCValue() << "\n");
Misha Brukmanf86aaa82003-06-02 04:12:39 +0000234
Misha Brukman0897c602003-08-06 16:20:22 +0000235 unsigned o6 = SparcIntRegClass::o6, g0 = SparcIntRegClass::g0;
236
237 // restore %g0, 0, %g0
238 MachineInstr *R = BuildMI(V9::RESTOREi, 3).addMReg(g0).addSImm(0)
239 .addMReg(g0, MOTy::Def);
240 SparcV9.emitWord(SparcV9.getBinaryCodeForInstr(*R));
241 delete R;
242
Misha Brukmanf47d9c22003-06-05 20:52:06 +0000243 // save %sp, -192, %sp
244 MachineInstr *SV = BuildMI(V9::SAVEi, 3).addReg(o6).addSImm(-192).addReg(o6);
245 SparcV9.emitWord(SparcV9.getBinaryCodeForInstr(*SV));
246 delete SV;
Misha Brukmana2196c12003-06-04 20:01:13 +0000247
248 int64_t CurrPC = MCE.getCurrentPCValue();
249 int64_t Addr = (int64_t)addFunctionReference(CurrPC, F);
250 int64_t CallTarget = (Addr-CurrPC) >> 2;
Misha Brukman0897c602003-08-06 16:20:22 +0000251 //if (CallTarget >= (1 << 29) || CallTarget <= -(1 << 29)) {
Misha Brukman0870e972003-08-06 22:19:18 +0000252 // Since this is a far call, the actual address of the call is shifted
253 // by the number of instructions it takes to calculate the exact address
Misha Brukman0897c602003-08-06 16:20:22 +0000254 deleteFunctionReference(CurrPC);
255 SparcV9.emitFarCall(Addr, F);
256#if 0
Misha Brukman0870e972003-08-06 22:19:18 +0000257 else {
Misha Brukmana1f1fea2003-07-29 19:00:58 +0000258 // call CallTarget ;; invoke the callback
259 MachineInstr *Call = BuildMI(V9::CALL, 1).addSImm(CallTarget);
260 SparcV9.emitWord(SparcV9.getBinaryCodeForInstr(*Call));
261 delete Call;
Misha Brukmana2196c12003-06-04 20:01:13 +0000262
Misha Brukmana1f1fea2003-07-29 19:00:58 +0000263 // nop ;; call delay slot
264 MachineInstr *Nop = BuildMI(V9::NOP, 0);
265 SparcV9.emitWord(SparcV9.getBinaryCodeForInstr(*Nop));
266 delete Nop;
Misha Brukman0897c602003-08-06 16:20:22 +0000267
268 addCallFlavor(CurrPC, ShortCall);
Misha Brukmana1f1fea2003-07-29 19:00:58 +0000269 }
Misha Brukman0897c602003-08-06 16:20:22 +0000270#endif
Misha Brukmana2196c12003-06-04 20:01:13 +0000271
272 SparcV9.emitWord(0xDEADBEEF); // marker so that we know it's really a stub
Misha Brukman0897c602003-08-06 16:20:22 +0000273 return (intptr_t)MCE.finishFunctionStub(*F)+4; /* 1 instr past the restore */
Misha Brukmanf86aaa82003-06-02 04:12:39 +0000274}
275
276
Misha Brukmana2196c12003-06-04 20:01:13 +0000277SparcV9CodeEmitter::SparcV9CodeEmitter(TargetMachine &tm,
278 MachineCodeEmitter &M): TM(tm), MCE(M)
279{
280 TheJITResolver = new JITResolver(*this, M);
281}
282
283SparcV9CodeEmitter::~SparcV9CodeEmitter() {
284 delete TheJITResolver;
285}
286
287void SparcV9CodeEmitter::emitWord(unsigned Val) {
Misha Brukman3de36f52003-05-27 20:07:58 +0000288 // Output the constant in big endian byte order...
289 unsigned byteVal;
Misha Brukmana2196c12003-06-04 20:01:13 +0000290 for (int i = 3; i >= 0; --i) {
Misha Brukman3de36f52003-05-27 20:07:58 +0000291 byteVal = Val >> 8*i;
Misha Brukmana2196c12003-06-04 20:01:13 +0000292 MCE.emitByte(byteVal & 255);
Misha Brukmana9f7f6e2003-05-30 20:17:33 +0000293 }
Misha Brukmana9f7f6e2003-05-30 20:17:33 +0000294}
295
Misha Brukmanf47d9c22003-06-05 20:52:06 +0000296unsigned
Misha Brukman173e2502003-07-14 23:26:03 +0000297SparcV9CodeEmitter::getRealRegNum(unsigned fakeReg,
Misha Brukman9cedd432003-07-03 18:36:47 +0000298 MachineInstr &MI) {
Misha Brukman173e2502003-07-14 23:26:03 +0000299 const TargetRegInfo &RI = TM.getRegInfo();
300 unsigned regClass, regType = RI.getRegType(fakeReg);
301 // At least map fakeReg into its class
302 fakeReg = RI.getClassRegNum(fakeReg, regClass);
303
Misha Brukman9cedd432003-07-03 18:36:47 +0000304 switch (regClass) {
305 case UltraSparcRegInfo::IntRegClassID: {
306 // Sparc manual, p31
307 static const unsigned IntRegMap[] = {
308 // "o0", "o1", "o2", "o3", "o4", "o5", "o7",
309 8, 9, 10, 11, 12, 13, 15,
310 // "l0", "l1", "l2", "l3", "l4", "l5", "l6", "l7",
311 16, 17, 18, 19, 20, 21, 22, 23,
312 // "i0", "i1", "i2", "i3", "i4", "i5", "i6", "i7",
313 24, 25, 26, 27, 28, 29, 30, 31,
314 // "g0", "g1", "g2", "g3", "g4", "g5", "g6", "g7",
315 0, 1, 2, 3, 4, 5, 6, 7,
316 // "o6"
317 14
318 };
319
320 return IntRegMap[fakeReg];
321 break;
322 }
323 case UltraSparcRegInfo::FloatRegClassID: {
324 DEBUG(std::cerr << "FP reg: " << fakeReg << "\n");
Misha Brukman173e2502003-07-14 23:26:03 +0000325 if (regType == UltraSparcRegInfo::FPSingleRegType) {
326 // only numbered 0-31, hence can already fit into 5 bits (and 6)
327 DEBUG(std::cerr << "FP single reg, returning: " << fakeReg << "\n");
328 } else if (regType == UltraSparcRegInfo::FPDoubleRegType) {
329 // FIXME: This assumes that we only have 5-bit register fiels!
330 // From Sparc Manual, page 40.
331 // The bit layout becomes: b[4], b[3], b[2], b[1], b[5]
332 fakeReg |= (fakeReg >> 5) & 1;
333 fakeReg &= 0x1f;
334 DEBUG(std::cerr << "FP double reg, returning: " << fakeReg << "\n");
335 }
Misha Brukman9cedd432003-07-03 18:36:47 +0000336 return fakeReg;
337 }
338 case UltraSparcRegInfo::IntCCRegClassID: {
Misha Brukmandfbfc572003-07-16 20:30:40 +0000339 /* xcc, icc, ccr */
340 static const unsigned IntCCReg[] = { 6, 4, 2 };
Misha Brukman9cedd432003-07-03 18:36:47 +0000341
Misha Brukmandfbfc572003-07-16 20:30:40 +0000342 assert(fakeReg < sizeof(IntCCReg)/sizeof(IntCCReg[0])
343 && "CC register out of bounds for IntCCReg map");
344 DEBUG(std::cerr << "IntCC reg: " << IntCCReg[fakeReg] << "\n");
345 return IntCCReg[fakeReg];
Misha Brukman9cedd432003-07-03 18:36:47 +0000346 }
347 case UltraSparcRegInfo::FloatCCRegClassID: {
348 /* These are laid out %fcc0 - %fcc3 => 0 - 3, so are correct */
349 DEBUG(std::cerr << "FP CC reg: " << fakeReg << "\n");
350 return fakeReg;
351 }
352 default:
353 assert(0 && "Invalid unified register number in getRegType");
354 return fakeReg;
355 }
356}
357
358
Misha Brukman07d45162003-07-15 19:09:43 +0000359// WARNING: if the call used the delay slot to do meaningful work, that's not
360// being accounted for, and the behavior will be incorrect!!
Misha Brukman0897c602003-08-06 16:20:22 +0000361inline void SparcV9CodeEmitter::emitFarCall(uint64_t Target, Function *F) {
Misha Brukman07d45162003-07-15 19:09:43 +0000362 static const unsigned i1 = SparcIntRegClass::i1, i2 = SparcIntRegClass::i2,
Misha Brukman0870e972003-08-06 22:19:18 +0000363 i7 = SparcIntRegClass::i7, o6 = SparcIntRegClass::o6,
364 o7 = SparcIntRegClass::o7, g0 = SparcIntRegClass::g0,
365 g1 = SparcIntRegClass::g1, g5 = SparcIntRegClass::g5;
Misha Brukman07d45162003-07-15 19:09:43 +0000366
Misha Brukman0897c602003-08-06 16:20:22 +0000367 MachineInstr* BinaryCode[] = {
Misha Brukman0897c602003-08-06 16:20:22 +0000368 //
Misha Brukman0870e972003-08-06 22:19:18 +0000369 // Get address to branch into %g1, using %g5 as a temporary
Misha Brukman0897c602003-08-06 16:20:22 +0000370 //
Misha Brukman0870e972003-08-06 22:19:18 +0000371 // sethi %uhi(Target), %g5 ;; get upper 22 bits of Target into %g5
372 BuildMI(V9::SETHI, 2).addSImm(Target >> 42).addReg(g5),
373 // or %g5, %ulo(Target), %g5 ;; get 10 lower bits of upper word into %1
374 BuildMI(V9::ORi, 3).addReg(g5).addSImm((Target >> 32) & 0x03ff).addReg(g5),
375 // sllx %g5, 32, %g5 ;; shift those 10 bits to the upper word
376 BuildMI(V9::SLLXi6, 3).addReg(g5).addSImm(32).addReg(g5),
377 // sethi %hi(Target), %g1 ;; extract bits 10-31 into the dest reg
378 BuildMI(V9::SETHI, 2).addSImm((Target >> 10) & 0x03fffff).addReg(g1),
379 // or %g5, %g1, %g1 ;; get upper word (in %g5) into %g1
380 BuildMI(V9::ORr, 3).addReg(g5).addReg(g1).addReg(g1),
381 // or %g1, %lo(Target), %g1 ;; get lowest 10 bits of Target into %g1
382 BuildMI(V9::ORi, 3).addReg(g1).addSImm(Target & 0x03ff).addReg(g1),
383 // jmpl %g1, %g0, %o7 ;; indirect call on %g1
384 BuildMI(V9::JMPLRETr, 3).addReg(g1).addReg(g0).addReg(o7),
385 // nop ;; delay slot
386 BuildMI(V9::NOP, 0)
Misha Brukman0897c602003-08-06 16:20:22 +0000387 };
Misha Brukman07d45162003-07-15 19:09:43 +0000388
Misha Brukman0897c602003-08-06 16:20:22 +0000389 for (unsigned i=0, e=sizeof(BinaryCode)/sizeof(BinaryCode[0]); i!=e; ++i) {
390 // This is where we save the return address in the LazyResolverMap!!
Misha Brukman0870e972003-08-06 22:19:18 +0000391 if (i == 6 && F != 0) { // Do this right before the JMPL
Misha Brukman0897c602003-08-06 16:20:22 +0000392 uint64_t CurrPC = MCE.getCurrentPCValue();
393 TheJITResolver->addFunctionReference(CurrPC, F);
394 // Remember that this is a far call, to subtract appropriate offset later
395 TheJITResolver->addCallFlavor(CurrPC, JITResolver::FarCall);
396 }
Misha Brukman07d45162003-07-15 19:09:43 +0000397
Misha Brukman0897c602003-08-06 16:20:22 +0000398 emitWord(getBinaryCodeForInstr(*BinaryCode[i]));
399 delete BinaryCode[i];
400 }
Misha Brukman07d45162003-07-15 19:09:43 +0000401}
402
403
Misha Brukmana9f7f6e2003-05-30 20:17:33 +0000404int64_t SparcV9CodeEmitter::getMachineOpValue(MachineInstr &MI,
405 MachineOperand &MO) {
Brian Gaekec3eaa892003-06-02 02:13:26 +0000406 int64_t rv = 0; // Return value; defaults to 0 for unhandled cases
407 // or things that get fixed up later by the JIT.
408
Misha Brukmaneaaf8ad2003-06-02 05:24:46 +0000409 if (MO.isVirtualRegister()) {
Misha Brukman33394592003-06-06 03:35:37 +0000410 std::cerr << "ERROR: virtual register found in machine code.\n";
Misha Brukmaneaaf8ad2003-06-02 05:24:46 +0000411 abort();
412 } else if (MO.isPCRelativeDisp()) {
Misha Brukman8f122222003-06-06 00:26:11 +0000413 DEBUG(std::cerr << "PCRelativeDisp: ");
Misha Brukmaneaaf8ad2003-06-02 05:24:46 +0000414 Value *V = MO.getVRegValue();
415 if (BasicBlock *BB = dyn_cast<BasicBlock>(V)) {
Misha Brukman8f122222003-06-06 00:26:11 +0000416 DEBUG(std::cerr << "Saving reference to BB (VReg)\n");
Misha Brukmana2196c12003-06-04 20:01:13 +0000417 unsigned* CurrPC = (unsigned*)(intptr_t)MCE.getCurrentPCValue();
Misha Brukmaneaaf8ad2003-06-02 05:24:46 +0000418 BBRefs.push_back(std::make_pair(BB, std::make_pair(CurrPC, &MI)));
Misha Brukmana2196c12003-06-04 20:01:13 +0000419 } else if (const Constant *C = dyn_cast<Constant>(V)) {
420 if (ConstantMap.find(C) != ConstantMap.end()) {
421 rv = (int64_t)MCE.getConstantPoolEntryAddress(ConstantMap[C]);
Misha Brukman8f122222003-06-06 00:26:11 +0000422 DEBUG(std::cerr << "const: 0x" << std::hex << rv << "\n");
Misha Brukmana2196c12003-06-04 20:01:13 +0000423 } else {
Misha Brukman33394592003-06-06 03:35:37 +0000424 std::cerr << "ERROR: constant not in map:" << MO << "\n";
Misha Brukmaneaaf8ad2003-06-02 05:24:46 +0000425 abort();
426 }
Misha Brukmana2196c12003-06-04 20:01:13 +0000427 } else if (GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
428 // same as MO.isGlobalAddress()
Misha Brukman8f122222003-06-06 00:26:11 +0000429 DEBUG(std::cerr << "GlobalValue: ");
Misha Brukmana2196c12003-06-04 20:01:13 +0000430 // external function calls, etc.?
431 if (Function *F = dyn_cast<Function>(GV)) {
Misha Brukman8f122222003-06-06 00:26:11 +0000432 DEBUG(std::cerr << "Function: ");
Misha Brukmana2196c12003-06-04 20:01:13 +0000433 if (F->isExternal()) {
434 // Sparc backend broken: this MO should be `ExternalSymbol'
435 rv = (int64_t)MCE.getGlobalValueAddress(F->getName());
436 } else {
437 rv = (int64_t)MCE.getGlobalValueAddress(F);
438 }
439 if (rv == 0) {
Misha Brukman8f122222003-06-06 00:26:11 +0000440 DEBUG(std::cerr << "not yet generated\n");
Misha Brukmana2196c12003-06-04 20:01:13 +0000441 // Function has not yet been code generated!
442 TheJITResolver->addFunctionReference(MCE.getCurrentPCValue(), F);
443 // Delayed resolution...
444 rv = TheJITResolver->getLazyResolver(F);
445 } else {
Misha Brukman8f122222003-06-06 00:26:11 +0000446 DEBUG(std::cerr << "already generated: 0x" << std::hex << rv << "\n");
Misha Brukmana2196c12003-06-04 20:01:13 +0000447 }
448 } else {
Misha Brukman33394592003-06-06 03:35:37 +0000449 rv = (int64_t)MCE.getGlobalValueAddress(GV);
Misha Brukmande07be32003-06-06 04:41:22 +0000450 if (rv == 0) {
451 if (Constant *C = ConstantPointerRef::get(GV)) {
452 if (ConstantMap.find(C) != ConstantMap.end()) {
453 rv = MCE.getConstantPoolEntryAddress(ConstantMap[C]);
454 } else {
Misha Brukman8631ac42003-06-06 09:53:28 +0000455 std::cerr << "Constant: 0x" << std::hex << (intptr_t)C
Misha Brukmande07be32003-06-06 04:41:22 +0000456 << ", " << *V << " not found in ConstantMap!\n";
457 abort();
458 }
459 }
460 }
Misha Brukman0870e972003-08-06 22:19:18 +0000461 DEBUG(std::cerr << "Global addr: 0x" << std::hex << rv << "\n");
Misha Brukmana2196c12003-06-04 20:01:13 +0000462 }
463 // The real target of the call is Addr = PC + (rv * 4)
464 // So undo that: give the instruction (Addr - PC) / 4
465 if (MI.getOpcode() == V9::CALL) {
466 int64_t CurrPC = MCE.getCurrentPCValue();
Misha Brukman8f122222003-06-06 00:26:11 +0000467 DEBUG(std::cerr << "rv addr: 0x" << std::hex << rv << "\n"
Misha Brukman0870e972003-08-06 22:19:18 +0000468 << "curr PC: 0x" << std::hex << CurrPC << "\n");
Misha Brukman07d45162003-07-15 19:09:43 +0000469 int64_t CallInstTarget = (rv - CurrPC) >> 2;
470 if (CallInstTarget >= (1<<29) || CallInstTarget <= -(1<<29)) {
471 DEBUG(std::cerr << "Making far call!\n");
472 // addresss is out of bounds for the 30-bit call,
473 // make an indirect jump-and-link
474 emitFarCall(rv);
475 // this invalidates the instruction so that the call with an incorrect
476 // address will not be emitted
477 rv = 0;
478 } else {
479 // The call fits into 30 bits, so just return the corrected address
480 rv = CallInstTarget;
Misha Brukmana2196c12003-06-04 20:01:13 +0000481 }
Misha Brukman8f122222003-06-06 00:26:11 +0000482 DEBUG(std::cerr << "returning addr: 0x" << rv << "\n");
Misha Brukmana2196c12003-06-04 20:01:13 +0000483 }
Misha Brukmaneaaf8ad2003-06-02 05:24:46 +0000484 } else {
485 std::cerr << "ERROR: PC relative disp unhandled:" << MO << "\n";
486 abort();
487 }
Misha Brukmanf47d9c22003-06-05 20:52:06 +0000488 } else if (MO.isPhysicalRegister() ||
489 MO.getType() == MachineOperand::MO_CCRegister)
490 {
Misha Brukman9cedd432003-07-03 18:36:47 +0000491 // This is necessary because the Sparc backend doesn't actually lay out
492 // registers in the real fashion -- it skips those that it chooses not to
493 // allocate, i.e. those that are the FP, SP, etc.
Misha Brukman173e2502003-07-14 23:26:03 +0000494 unsigned fakeReg = MO.getAllocatedRegNum();
495 unsigned realRegByClass = getRealRegNum(fakeReg, MI);
496 DEBUG(std::cerr << MO << ": Reg[" << std::dec << fakeReg << "] => "
Misha Brukmandfbfc572003-07-16 20:30:40 +0000497 << realRegByClass << " (LLC: "
498 << TM.getRegInfo().getUnifiedRegName(fakeReg) << ")\n");
Misha Brukman9cedd432003-07-03 18:36:47 +0000499 rv = realRegByClass;
Misha Brukman3de36f52003-05-27 20:07:58 +0000500 } else if (MO.isImmediate()) {
Brian Gaekec3eaa892003-06-02 02:13:26 +0000501 rv = MO.getImmedValue();
Misha Brukman8f122222003-06-06 00:26:11 +0000502 DEBUG(std::cerr << "immed: " << rv << "\n");
Misha Brukmaneaaf8ad2003-06-02 05:24:46 +0000503 } else if (MO.isGlobalAddress()) {
Misha Brukman8f122222003-06-06 00:26:11 +0000504 DEBUG(std::cerr << "GlobalAddress: not PC-relative\n");
Misha Brukmanf86aaa82003-06-02 04:12:39 +0000505 rv = (int64_t)
506 (intptr_t)getGlobalAddress(cast<GlobalValue>(MO.getVRegValue()),
Misha Brukmaneaaf8ad2003-06-02 05:24:46 +0000507 MI, MO.isPCRelative());
Misha Brukmana9f7f6e2003-05-30 20:17:33 +0000508 } else if (MO.isMachineBasicBlock()) {
Misha Brukmaneaaf8ad2003-06-02 05:24:46 +0000509 // Duplicate code of the above case for VirtualRegister, BasicBlock...
510 // It should really hit this case, but Sparc backend uses VRegs instead
Misha Brukman8f122222003-06-06 00:26:11 +0000511 DEBUG(std::cerr << "Saving reference to MBB\n");
Chris Lattner6856d112003-07-26 23:04:00 +0000512 const BasicBlock *BB = MO.getMachineBasicBlock()->getBasicBlock();
Misha Brukmana2196c12003-06-04 20:01:13 +0000513 unsigned* CurrPC = (unsigned*)(intptr_t)MCE.getCurrentPCValue();
Misha Brukmaneaaf8ad2003-06-02 05:24:46 +0000514 BBRefs.push_back(std::make_pair(BB, std::make_pair(CurrPC, &MI)));
Misha Brukmana9f7f6e2003-05-30 20:17:33 +0000515 } else if (MO.isExternalSymbol()) {
Misha Brukmaneaaf8ad2003-06-02 05:24:46 +0000516 // Sparc backend doesn't generate this (yet...)
517 std::cerr << "ERROR: External symbol unhandled: " << MO << "\n";
518 abort();
519 } else if (MO.isFrameIndex()) {
520 // Sparc backend doesn't generate this (yet...)
521 int FrameIndex = MO.getFrameIndex();
522 std::cerr << "ERROR: Frame index unhandled.\n";
523 abort();
524 } else if (MO.isConstantPoolIndex()) {
525 // Sparc backend doesn't generate this (yet...)
526 std::cerr << "ERROR: Constant Pool index unhandled.\n";
527 abort();
Misha Brukman3de36f52003-05-27 20:07:58 +0000528 } else {
Misha Brukmana9f7f6e2003-05-30 20:17:33 +0000529 std::cerr << "ERROR: Unknown type of MachineOperand: " << MO << "\n";
Misha Brukmaneaaf8ad2003-06-02 05:24:46 +0000530 abort();
Brian Gaekec3eaa892003-06-02 02:13:26 +0000531 }
532
533 // Finally, deal with the various bitfield-extracting functions that
534 // are used in SPARC assembly. (Some of these make no sense in combination
535 // with some of the above; we'll trust that the instruction selector
536 // will not produce nonsense, and not check for valid combinations here.)
Misha Brukmanf47d9c22003-06-05 20:52:06 +0000537 if (MO.opLoBits32()) { // %lo(val) == %lo() in Sparc ABI doc
Brian Gaekec3eaa892003-06-02 02:13:26 +0000538 return rv & 0x03ff;
Misha Brukmanf47d9c22003-06-05 20:52:06 +0000539 } else if (MO.opHiBits32()) { // %lm(val) == %hi() in Sparc ABI doc
Brian Gaekec3eaa892003-06-02 02:13:26 +0000540 return (rv >> 10) & 0x03fffff;
Misha Brukmanf47d9c22003-06-05 20:52:06 +0000541 } else if (MO.opLoBits64()) { // %hm(val) == %ulo() in Sparc ABI doc
Brian Gaekec3eaa892003-06-02 02:13:26 +0000542 return (rv >> 32) & 0x03ff;
Misha Brukmanf47d9c22003-06-05 20:52:06 +0000543 } else if (MO.opHiBits64()) { // %hh(val) == %uhi() in Sparc ABI doc
Brian Gaekec3eaa892003-06-02 02:13:26 +0000544 return rv >> 42;
545 } else { // (unadorned) val
546 return rv;
Misha Brukman3de36f52003-05-27 20:07:58 +0000547 }
548}
549
550unsigned SparcV9CodeEmitter::getValueBit(int64_t Val, unsigned bit) {
551 Val >>= bit;
552 return (Val & 1);
553}
554
Misha Brukman3de36f52003-05-27 20:07:58 +0000555bool SparcV9CodeEmitter::runOnMachineFunction(MachineFunction &MF) {
Misha Brukmana2196c12003-06-04 20:01:13 +0000556 MCE.startFunction(MF);
Misha Brukman8f122222003-06-06 00:26:11 +0000557 DEBUG(std::cerr << "Starting function " << MF.getFunction()->getName()
Misha Brukmanf86aaa82003-06-02 04:12:39 +0000558 << ", address: " << "0x" << std::hex
Misha Brukman8f122222003-06-06 00:26:11 +0000559 << (long)MCE.getCurrentPCValue() << "\n");
Misha Brukmanf86aaa82003-06-02 04:12:39 +0000560
Misha Brukmana2196c12003-06-04 20:01:13 +0000561 // The Sparc backend does not use MachineConstantPool;
562 // instead, it has its own constant pool implementation.
563 // We create a new MachineConstantPool here to be compatible with the emitter.
564 MachineConstantPool MCP;
Misha Brukmanf86aaa82003-06-02 04:12:39 +0000565 const hash_set<const Constant*> &pool = MF.getInfo()->getConstantPoolValues();
566 for (hash_set<const Constant*>::const_iterator I = pool.begin(),
567 E = pool.end(); I != E; ++I)
568 {
Misha Brukmana2196c12003-06-04 20:01:13 +0000569 Constant *C = (Constant*)*I;
570 unsigned idx = MCP.getConstantPoolIndex(C);
Misha Brukman9cedd432003-07-03 18:36:47 +0000571 DEBUG(std::cerr << "Constant[" << idx << "] = 0x" << (intptr_t)C << "\n");
Misha Brukmana2196c12003-06-04 20:01:13 +0000572 ConstantMap[C] = idx;
Misha Brukmanf86aaa82003-06-02 04:12:39 +0000573 }
Misha Brukmana2196c12003-06-04 20:01:13 +0000574 MCE.emitConstantPool(&MCP);
Misha Brukmanf86aaa82003-06-02 04:12:39 +0000575
Misha Brukman3de36f52003-05-27 20:07:58 +0000576 for (MachineFunction::iterator I = MF.begin(), E = MF.end(); I != E; ++I)
577 emitBasicBlock(*I);
Misha Brukmana2196c12003-06-04 20:01:13 +0000578 MCE.finishFunction(MF);
Misha Brukmanf86aaa82003-06-02 04:12:39 +0000579
Misha Brukman9cedd432003-07-03 18:36:47 +0000580 DEBUG(std::cerr << "Finishing fn " << MF.getFunction()->getName() << "\n");
Misha Brukmanf86aaa82003-06-02 04:12:39 +0000581 ConstantMap.clear();
Misha Brukmanf86aaa82003-06-02 04:12:39 +0000582
583 // Resolve branches to BasicBlocks for the entire function
584 for (unsigned i = 0, e = BBRefs.size(); i != e; ++i) {
585 long Location = BBLocations[BBRefs[i].first];
586 unsigned *Ref = BBRefs[i].second.first;
587 MachineInstr *MI = BBRefs[i].second.second;
Misha Brukman9cedd432003-07-03 18:36:47 +0000588 DEBUG(std::cerr << "Fixup @ " << std::hex << Ref << " to 0x" << Location
589 << " in instr: " << std::dec << *MI);
Misha Brukmanf86aaa82003-06-02 04:12:39 +0000590 for (unsigned ii = 0, ee = MI->getNumOperands(); ii != ee; ++ii) {
591 MachineOperand &op = MI->getOperand(ii);
592 if (op.isPCRelativeDisp()) {
593 // the instruction's branch target is made such that it branches to
Misha Brukman9cedd432003-07-03 18:36:47 +0000594 // PC + (branchTarget * 4), so undo that arithmetic here:
Misha Brukmanf86aaa82003-06-02 04:12:39 +0000595 // Location is the target of the branch
596 // Ref is the location of the instruction, and hence the PC
Misha Brukman9cedd432003-07-03 18:36:47 +0000597 int64_t branchTarget = (Location - (long)Ref) >> 2;
Misha Brukmanf86aaa82003-06-02 04:12:39 +0000598 // Save the flags.
599 bool loBits32=false, hiBits32=false, loBits64=false, hiBits64=false;
600 if (op.opLoBits32()) { loBits32=true; }
601 if (op.opHiBits32()) { hiBits32=true; }
602 if (op.opLoBits64()) { loBits64=true; }
603 if (op.opHiBits64()) { hiBits64=true; }
604 MI->SetMachineOperandConst(ii, MachineOperand::MO_SignExtendedImmed,
605 branchTarget);
606 if (loBits32) { MI->setOperandLo32(ii); }
607 else if (hiBits32) { MI->setOperandHi32(ii); }
608 else if (loBits64) { MI->setOperandLo64(ii); }
609 else if (hiBits64) { MI->setOperandHi64(ii); }
Misha Brukman8f122222003-06-06 00:26:11 +0000610 DEBUG(std::cerr << "Rewrote BB ref: ");
Misha Brukmanf86aaa82003-06-02 04:12:39 +0000611 unsigned fixedInstr = SparcV9CodeEmitter::getBinaryCodeForInstr(*MI);
612 *Ref = fixedInstr;
613 break;
614 }
615 }
616 }
617 BBRefs.clear();
618 BBLocations.clear();
619
Misha Brukman3de36f52003-05-27 20:07:58 +0000620 return false;
621}
622
623void SparcV9CodeEmitter::emitBasicBlock(MachineBasicBlock &MBB) {
Misha Brukman0d603452003-05-27 22:41:44 +0000624 currBB = MBB.getBasicBlock();
Misha Brukmana2196c12003-06-04 20:01:13 +0000625 BBLocations[currBB] = MCE.getCurrentPCValue();
Misha Brukman07d45162003-07-15 19:09:43 +0000626 for (MachineBasicBlock::iterator I = MBB.begin(), E = MBB.end(); I != E; ++I){
627 unsigned binCode = getBinaryCodeForInstr(**I);
628 if (binCode == (1 << 30)) {
629 // this is an invalid call: the addr is out of bounds. that means a code
630 // sequence has already been emitted, and this is a no-op
631 DEBUG(std::cerr << "Call supressed: already emitted far call.\n");
632 } else {
633 emitWord(binCode);
634 }
635 }
Misha Brukman3de36f52003-05-27 20:07:58 +0000636}
637
Misha Brukmanf86aaa82003-06-02 04:12:39 +0000638void* SparcV9CodeEmitter::getGlobalAddress(GlobalValue *V, MachineInstr &MI,
639 bool isPCRelative)
640{
641 if (isPCRelative) { // must be a call, this is a major hack!
642 // Try looking up the function to see if it is already compiled!
Misha Brukmana2196c12003-06-04 20:01:13 +0000643 if (void *Addr = (void*)(intptr_t)MCE.getGlobalValueAddress(V)) {
644 intptr_t CurByte = MCE.getCurrentPCValue();
Misha Brukmanf86aaa82003-06-02 04:12:39 +0000645 // The real target of the call is Addr = PC + (target * 4)
646 // CurByte is the PC, Addr we just received
647 return (void*) (((long)Addr - (long)CurByte) >> 2);
648 } else {
649 if (Function *F = dyn_cast<Function>(V)) {
650 // Function has not yet been code generated!
Misha Brukmana2196c12003-06-04 20:01:13 +0000651 TheJITResolver->addFunctionReference(MCE.getCurrentPCValue(),
Misha Brukmanf86aaa82003-06-02 04:12:39 +0000652 cast<Function>(V));
653 // Delayed resolution...
Misha Brukmaneaaf8ad2003-06-02 05:24:46 +0000654 return
655 (void*)(intptr_t)TheJITResolver->getLazyResolver(cast<Function>(V));
Misha Brukmanf86aaa82003-06-02 04:12:39 +0000656
657 } else if (Constant *C = ConstantPointerRef::get(V)) {
658 if (ConstantMap.find(C) != ConstantMap.end()) {
Misha Brukmana2196c12003-06-04 20:01:13 +0000659 return (void*)
660 (intptr_t)MCE.getConstantPoolEntryAddress(ConstantMap[C]);
Misha Brukmanf86aaa82003-06-02 04:12:39 +0000661 } else {
662 std::cerr << "Constant: 0x" << std::hex << &*C << std::dec
663 << ", " << *V << " not found in ConstantMap!\n";
664 abort();
665 }
Misha Brukmanf86aaa82003-06-02 04:12:39 +0000666 } else {
667 std::cerr << "Unhandled global: " << *V << "\n";
668 abort();
669 }
670 }
671 } else {
Misha Brukmana2196c12003-06-04 20:01:13 +0000672 return (void*)(intptr_t)MCE.getGlobalValueAddress(V);
Misha Brukmanf86aaa82003-06-02 04:12:39 +0000673 }
674}
675
676
Misha Brukman3de36f52003-05-27 20:07:58 +0000677#include "SparcV9CodeEmitter.inc"