mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-09-07 16:54:48 +00:00
Support for constant islands in the ARM JIT.
Since the ARM constant pool handling supercedes the standard LLVM constant pool entirely, the JIT emitter does not allocate space for the constants, nor initialize the memory. The constant pool is considered part of the instruction stream. Likewise, when resolving relocations into the constant pool, a hook into the target back end is used to resolve from the constant ID# to the address where the constant is stored. For now, the support in the ARM emitter is limited to 32-bit integer. Future patches will expand this to the full range of constants necessary. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@58338 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
52790e5865
commit
bc6d876adf
@ -107,6 +107,15 @@ namespace llvm {
|
||||
// JIT to manage a GOT for it.
|
||||
bool needsGOT() const { return useGOT; }
|
||||
|
||||
/// hasCustomConstantPool - Allows a target to specify that constant
|
||||
/// pool address resolution is handled by the target.
|
||||
virtual bool hasCustomConstantPool() const { return false; }
|
||||
|
||||
/// getCustomConstantPoolEntryAddress - When using a custom constant
|
||||
/// pool, resolve a constant pool index to the address of where the
|
||||
/// entry is stored.
|
||||
virtual intptr_t getCustomConstantPoolEntryAddress(unsigned CPI) const
|
||||
{return 0;}
|
||||
protected:
|
||||
bool useGOT;
|
||||
};
|
||||
|
@ -1011,6 +1011,11 @@ void* JITEmitter::allocateSpace(intptr_t Size, unsigned Alignment) {
|
||||
}
|
||||
|
||||
void JITEmitter::emitConstantPool(MachineConstantPool *MCP) {
|
||||
if (TheJIT->getJITInfo().hasCustomConstantPool()) {
|
||||
DOUT << "JIT: Target has custom constant pool handling. Omitting standard "
|
||||
"constant pool\n";
|
||||
return;
|
||||
}
|
||||
const std::vector<MachineConstantPoolEntry> &Constants = MCP->getConstants();
|
||||
if (Constants.empty()) return;
|
||||
|
||||
@ -1124,6 +1129,10 @@ void *JITEmitter::finishFunctionStub(const GlobalValue* F) {
|
||||
// method.
|
||||
//
|
||||
intptr_t JITEmitter::getConstantPoolEntryAddress(unsigned ConstantNum) const {
|
||||
if (TheJIT->getJITInfo().hasCustomConstantPool()) {
|
||||
return TheJIT->getJITInfo().getCustomConstantPoolEntryAddress(ConstantNum);
|
||||
}
|
||||
|
||||
assert(ConstantNum < ConstantPool->getConstants().size() &&
|
||||
"Invalid ConstantPoolIndex!");
|
||||
return (intptr_t)ConstantPoolBase +
|
||||
|
@ -19,6 +19,8 @@
|
||||
#include "ARMRelocations.h"
|
||||
#include "ARMSubtarget.h"
|
||||
#include "ARMTargetMachine.h"
|
||||
#include "llvm/Constants.h"
|
||||
#include "llvm/DerivedTypes.h"
|
||||
#include "llvm/Function.h"
|
||||
#include "llvm/PassManager.h"
|
||||
#include "llvm/CodeGen/MachineCodeEmitter.h"
|
||||
@ -358,7 +360,29 @@ unsigned ARMCodeEmitter::getAddrMode1SBit(const MachineInstr &MI,
|
||||
}
|
||||
|
||||
void ARMCodeEmitter::emitConstPoolInstruction(const MachineInstr &MI) {
|
||||
// FIXME
|
||||
unsigned CPID = MI.getOperand(0).getImm();
|
||||
unsigned CPIndex = MI.getOperand(1).getIndex();
|
||||
const MachineConstantPoolEntry &MCPE = MCP->getConstants()[CPIndex];
|
||||
|
||||
//FIXME: Can we get these here?
|
||||
assert (!MCPE.isMachineConstantPoolEntry());
|
||||
|
||||
const Constant *CV = MCPE.Val.ConstVal;
|
||||
// FIXME: We can get other types here. Need to handle them.
|
||||
// According to the constant island pass, everything is multiples,
|
||||
// of 4-bytes in size, though, so that helps.
|
||||
assert (CV->getType()->isInteger());
|
||||
assert (cast<IntegerType>(CV->getType())->getBitWidth() == 32);
|
||||
|
||||
const ConstantInt *CI = dyn_cast<ConstantInt>(CV);
|
||||
uint32_t Val = *(uint32_t*)CI->getValue().getRawData();
|
||||
|
||||
DOUT << "Constant pool #" << CPID << ", value '" << Val << "' @ " <<
|
||||
(void*)MCE.getCurrentPCValue() << "\n";
|
||||
|
||||
if (JTI)
|
||||
JTI->mapCPIDtoAddress(CPID, MCE.getCurrentPCValue());
|
||||
MCE.emitWordLE(Val);
|
||||
}
|
||||
|
||||
void ARMCodeEmitter::emitPseudoInstruction(const MachineInstr &MI) {
|
||||
|
@ -15,14 +15,16 @@
|
||||
#define ARMJITINFO_H
|
||||
|
||||
#include "llvm/Target/TargetJITInfo.h"
|
||||
#include <map>
|
||||
|
||||
namespace llvm {
|
||||
class ARMTargetMachine;
|
||||
|
||||
class ARMJITInfo : public TargetJITInfo {
|
||||
ARMTargetMachine &TM;
|
||||
std::map<unsigned, intptr_t> CPIDtoAddressMap;
|
||||
public:
|
||||
explicit ARMJITInfo(ARMTargetMachine &tm) : TM(tm) {useGOT = 0;}
|
||||
explicit ARMJITInfo(ARMTargetMachine &tm) : TM(tm) { useGOT = false; }
|
||||
|
||||
/// replaceMachineCodeForFunction - Make it so that calling the function
|
||||
/// whose machine code is at OLD turns into a call to NEW, perhaps by
|
||||
@ -45,6 +47,27 @@ namespace llvm {
|
||||
/// referenced global symbols.
|
||||
virtual void relocate(void *Function, MachineRelocation *MR,
|
||||
unsigned NumRelocs, unsigned char* GOTBase);
|
||||
|
||||
/// hasCustomConstantPool - Allows a target to specify that constant
|
||||
/// pool address resolution is handled by the target.
|
||||
virtual bool hasCustomConstantPool() const { return true; }
|
||||
|
||||
/// getCustomConstantPoolEntryAddress - The ARM target puts all constant
|
||||
/// pool entries into constant islands. Resolve the constant pool index
|
||||
/// into the address where the constant is stored.
|
||||
virtual intptr_t getCustomConstantPoolEntryAddress(unsigned CPID) const
|
||||
{
|
||||
std::map<unsigned, intptr_t>::const_iterator elem;
|
||||
elem = CPIDtoAddressMap.find(CPID);
|
||||
assert (elem != CPIDtoAddressMap.end());
|
||||
return elem->second;
|
||||
}
|
||||
|
||||
/// mapCPIDtoAddress - Map a Constant Pool Index (CPID) to the address
|
||||
/// where its associated value is stored. When relocations are processed,
|
||||
/// this value will be used to resolve references to the constant.
|
||||
void mapCPIDtoAddress(unsigned CPID, intptr_t address)
|
||||
{ CPIDtoAddressMap[CPID] = address; }
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user