//
// The LLVM Compiler Infrastructure
//
-// This file was developed by the LLVM research group and is distributed under
-// the University of Illinois Open Source License. See LICENSE.TXT for details.
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
#define DEBUG_TYPE "jit"
#include "AlphaJITInfo.h"
#include "AlphaRelocations.h"
+#include "llvm/Function.h"
#include "llvm/CodeGen/MachineCodeEmitter.h"
#include "llvm/Config/alloca.h"
#include "llvm/Support/Debug.h"
#include <cstdlib>
-#include <iostream>
#include <map>
-using namespace std;
using namespace llvm;
#define BUILD_OFormatI(Op, RA, LIT, FUN, RC) \
AtI[0] = BUILD_OR(0, 27, 27);
- DEBUG(std::cerr << "Stub targeting " << To << "\n");
+ DOUT << "Stub targeting " << To << "\n";
for (int x = 1; x <= 8; ++x) {
AtI[2*x - 1] = BUILD_SLLi(27,27,8);
unsigned d = (Fn >> (64 - 8 * x)) & 0x00FF;
- DEBUG(std::cerr << "outputing " << hex << d << dec << "\n");
+ //DOUT << "outputing " << hex << d << dec << "\n";
AtI[2*x] = BUILD_ORi(27, 27, d);
}
AtI[17] = BUILD_JMP(31,27,0); //jump, preserving ra, and setting pv
//rewrite the stub to an unconditional branch
if (((unsigned*)CameFromStub)[18] == 0x00FFFFFF) {
- DEBUG(std::cerr << "Came from a stub, rewriting\n");
+ DOUT << "Came from a stub, rewriting\n";
EmitBranchToAt(CameFromStub, Target);
} else {
- DEBUG(std::cerr << "confused, didn't come from stub at " << CameFromStub
- << " old jump vector " << oldpv
- << " new jump vector " << Target << "\n");
+ DOUT << "confused, didn't come from stub at " << CameFromStub
+ << " old jump vector " << oldpv
+ << " new jump vector " << Target << "\n";
}
//Change pv to new Target
);
#else
void AlphaCompilationCallback() {
- std::cerr << "Cannot call AlphaCompilationCallback() on a non-Alpha arch!\n";
+ cerr << "Cannot call AlphaCompilationCallback() on a non-Alpha arch!\n";
abort();
}
#endif
}
-void *AlphaJITInfo::emitFunctionStub(void *Fn, MachineCodeEmitter &MCE) {
+void *AlphaJITInfo::emitFunctionStub(const Function* F, void *Fn,
+ MachineCodeEmitter &MCE) {
//assert(Fn == AlphaCompilationCallback && "Where are you going?\n");
//Do things in a stupid slow way!
- MCE.startFunctionStub(19*4);
+ MCE.startGVStub(F, 19*4);
void* Addr = (void*)(intptr_t)MCE.getCurrentPCValue();
for (int x = 0; x < 19; ++ x)
- MCE.emitWord(0);
+ MCE.emitWordLE(0);
EmitBranchToAt(Addr, Fn);
- DEBUG(std::cerr << "Emitting Stub to " << Fn << " at [" << Addr << "]\n");
- return MCE.finishFunctionStub(0);
+ DOUT << "Emitting Stub to " << Fn << " at [" << Addr << "]\n";
+ return MCE.finishGVStub(F);
}
TargetJITInfo::LazyResolverFn
//because gpdist are paired and relative to the pc of the first inst,
//we need to have some state
- static map<pair<void*, int>, void*> gpdistmap;
+ static std::map<std::pair<void*, int>, void*> gpdistmap;
for (unsigned i = 0; i != NumRelocs; ++i, ++MR) {
unsigned *RelocPos = (unsigned*)Function + MR->getMachineCodeOffset()/4;
case Alpha::reloc_literal:
//This is a LDQl
idx = MR->getGOTIndex();
- DEBUG(std::cerr << "Literal relocation to slot " << idx);
+ DOUT << "Literal relocation to slot " << idx;
idx = (idx - GOToffset) * 8;
- DEBUG(std::cerr << " offset " << idx << "\n");
+ DOUT << " offset " << idx << "\n";
break;
case Alpha::reloc_gprellow:
idx = (unsigned char*)MR->getResultPointer() - &GOTBase[GOToffset * 8];
idx = getLower16(idx);
- DEBUG(std::cerr << "gprellow relocation offset " << idx << "\n");
- DEBUG(std::cerr << " Pointer is " << (void*)MR->getResultPointer()
- << " GOT is " << (void*)&GOTBase[GOToffset * 8] << "\n");
+ DOUT << "gprellow relocation offset " << idx << "\n";
+ DOUT << " Pointer is " << (void*)MR->getResultPointer()
+ << " GOT is " << (void*)&GOTBase[GOToffset * 8] << "\n";
break;
case Alpha::reloc_gprelhigh:
idx = (unsigned char*)MR->getResultPointer() - &GOTBase[GOToffset * 8];
idx = getUpper16(idx);
- DEBUG(std::cerr << "gprelhigh relocation offset " << idx << "\n");
- DEBUG(std::cerr << " Pointer is " << (void*)MR->getResultPointer()
- << " GOT is " << (void*)&GOTBase[GOToffset * 8] << "\n");
+ DOUT << "gprelhigh relocation offset " << idx << "\n";
+ DOUT << " Pointer is " << (void*)MR->getResultPointer()
+ << " GOT is " << (void*)&GOTBase[GOToffset * 8] << "\n";
break;
case Alpha::reloc_gpdist:
switch (*RelocPos >> 26) {
case 0x09: //LDAH
idx = &GOTBase[GOToffset * 8] - (unsigned char*)RelocPos;
idx = getUpper16(idx);
- DEBUG(std::cerr << "LDAH: " << idx << "\n");
+ DOUT << "LDAH: " << idx << "\n";
//add the relocation to the map
- gpdistmap[make_pair(Function, MR->getConstantVal())] = RelocPos;
+ gpdistmap[std::make_pair(Function, MR->getConstantVal())] = RelocPos;
break;
case 0x08: //LDA
- assert(gpdistmap[make_pair(Function, MR->getConstantVal())] &&
+ assert(gpdistmap[std::make_pair(Function, MR->getConstantVal())] &&
"LDAg without seeing LDAHg");
idx = &GOTBase[GOToffset * 8] -
- (unsigned char*)gpdistmap[make_pair(Function, MR->getConstantVal())];
+ (unsigned char*)gpdistmap[std::make_pair(Function, MR->getConstantVal())];
idx = getLower16(idx);
- DEBUG(std::cerr << "LDA: " << idx << "\n");
+ DOUT << "LDA: " << idx << "\n";
break;
default:
assert(0 && "Cannot handle gpdist yet");
}
break;
case Alpha::reloc_bsr: {
- idx = (((unsigned char*)MR->getResultPointer() -
+ idx = (((unsigned char*)MR->getResultPointer() -
(unsigned char*)RelocPos) >> 2) + 1; //skip first 2 inst of fun
*RelocPos |= (idx & ((1 << 21)-1));
doCommon = false;