Use better data structure for ConstPoolId2AddrMap.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@58532 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Evan Cheng 2008-10-31 19:55:13 +00:00
parent ba44df60d6
commit 938b9d8ef7
2 changed files with 20 additions and 15 deletions

View File

@ -43,16 +43,17 @@ namespace {
const TargetData *TD; const TargetData *TD;
TargetMachine &TM; TargetMachine &TM;
MachineCodeEmitter &MCE; MachineCodeEmitter &MCE;
const MachineConstantPool *MCP; const std::vector<MachineConstantPoolEntry> *MCPEs;
public: public:
static char ID; static char ID;
explicit ARMCodeEmitter(TargetMachine &tm, MachineCodeEmitter &mce) explicit ARMCodeEmitter(TargetMachine &tm, MachineCodeEmitter &mce)
: MachineFunctionPass(&ID), JTI(0), II(0), TD(0), TM(tm), : MachineFunctionPass(&ID), JTI(0), II(0), TD(0), TM(tm),
MCE(mce), MCP(0) {} MCE(mce), MCPEs(0) {}
ARMCodeEmitter(TargetMachine &tm, MachineCodeEmitter &mce, ARMCodeEmitter(TargetMachine &tm, MachineCodeEmitter &mce,
const ARMInstrInfo &ii, const TargetData &td) const ARMInstrInfo &ii, const TargetData &td)
: MachineFunctionPass(&ID), JTI(0), II(&ii), TD(&td), TM(tm), : MachineFunctionPass(&ID), JTI(0), II(&ii), TD(&td), TM(tm),
MCE(mce), MCP(0) {} MCE(mce), MCPEs(0) {}
bool runOnMachineFunction(MachineFunction &MF); bool runOnMachineFunction(MachineFunction &MF);
@ -153,7 +154,8 @@ bool ARMCodeEmitter::runOnMachineFunction(MachineFunction &MF) {
II = ((ARMTargetMachine&)MF.getTarget()).getInstrInfo(); II = ((ARMTargetMachine&)MF.getTarget()).getInstrInfo();
TD = ((ARMTargetMachine&)MF.getTarget()).getTargetData(); TD = ((ARMTargetMachine&)MF.getTarget()).getTargetData();
JTI = ((ARMTargetMachine&)MF.getTarget()).getJITInfo(); JTI = ((ARMTargetMachine&)MF.getTarget()).getJITInfo();
MCP = MF.getConstantPool(); MCPEs = &MF.getConstantPool()->getConstants();
JTI->ResizeConstPoolMap(MCPEs->size());
do { do {
DOUT << "JITTing function '" << MF.getFunction()->getName() << "'\n"; DOUT << "JITTing function '" << MF.getFunction()->getName() << "'\n";
@ -264,7 +266,7 @@ void ARMCodeEmitter::emitInstruction(const MachineInstr &MI) {
void ARMCodeEmitter::emitConstPoolInstruction(const MachineInstr &MI) { void ARMCodeEmitter::emitConstPoolInstruction(const MachineInstr &MI) {
unsigned CPI = MI.getOperand(0).getImm(); unsigned CPI = MI.getOperand(0).getImm();
unsigned CPIndex = MI.getOperand(1).getIndex(); unsigned CPIndex = MI.getOperand(1).getIndex();
const MachineConstantPoolEntry &MCPE = MCP->getConstants()[CPIndex]; const MachineConstantPoolEntry &MCPE = (*MCPEs)[CPIndex];
// Remember the CONSTPOOL_ENTRY address for later relocation. // Remember the CONSTPOOL_ENTRY address for later relocation.
JTI->addConstantPoolEntryAddr(CPI, MCE.getCurrentPCValue()); JTI->addConstantPoolEntryAddr(CPI, MCE.getCurrentPCValue());

View File

@ -15,7 +15,7 @@
#define ARMJITINFO_H #define ARMJITINFO_H
#include "llvm/Target/TargetJITInfo.h" #include "llvm/Target/TargetJITInfo.h"
#include <map> #include "llvm/ADT/SmallVector.h"
namespace llvm { namespace llvm {
class ARMTargetMachine; class ARMTargetMachine;
@ -25,7 +25,7 @@ namespace llvm {
// ConstPoolId2AddrMap - A map from constant pool ids to the corresponding // ConstPoolId2AddrMap - A map from constant pool ids to the corresponding
// CONSTPOOL_ENTRY addresses. // CONSTPOOL_ENTRY addresses.
std::map<unsigned, intptr_t> ConstPoolId2AddrMap; SmallVector<intptr_t, 32> ConstPoolId2AddrMap;
public: public:
explicit ARMJITInfo(ARMTargetMachine &tm) : TM(tm) { useGOT = false; } explicit ARMJITInfo(ARMTargetMachine &tm) : TM(tm) { useGOT = false; }
@ -56,21 +56,24 @@ namespace llvm {
/// pool address resolution is handled by the target. /// pool address resolution is handled by the target.
virtual bool hasCustomConstantPool() const { return true; } virtual bool hasCustomConstantPool() const { return true; }
void ResizeConstPoolMap(unsigned Size) {
ConstPoolId2AddrMap.resize(Size);
}
/// getConstantPoolEntryAddr - The ARM target puts all constant /// getConstantPoolEntryAddr - The ARM target puts all constant
/// pool entries into constant islands. Resolve the constant pool index /// pool entries into constant islands. Resolve the constant pool index
/// into the address where the constant is stored. /// into the address where the constant is stored.
virtual intptr_t getConstantPoolEntryAddr(unsigned CPID) const { intptr_t getConstantPoolEntryAddr(unsigned CPI) const {
std::map<unsigned, intptr_t>::const_iterator I assert(CPI < ConstPoolId2AddrMap.size());
= ConstPoolId2AddrMap.find(CPID); return ConstPoolId2AddrMap[CPI];
assert(I != ConstPoolId2AddrMap.end() && "Missing constpool_entry?");
return I->second;
} }
/// addConstantPoolEntryAddr - Map a Constant Pool Index (CPID) to the address /// addConstantPoolEntryAddr - Map a Constant Pool Index (CPI) to the address
/// where its associated value is stored. When relocations are processed, /// where its associated value is stored. When relocations are processed,
/// this value will be used to resolve references to the constant. /// this value will be used to resolve references to the constant.
void addConstantPoolEntryAddr(unsigned CPID, intptr_t Addr) { void addConstantPoolEntryAddr(unsigned CPI, intptr_t Addr) {
ConstPoolId2AddrMap[CPID] = Addr; assert(CPI < ConstPoolId2AddrMap.size());
ConstPoolId2AddrMap[CPI] = Addr;
} }
}; };
} }