From d04d2ef54dab9f49453e1c2c44b559ad27840671 Mon Sep 17 00:00:00 2001 From: Misha Brukman Date: Fri, 7 Nov 2003 18:06:26 +0000 Subject: [PATCH] Switch to emitting MachineConstantPool the way it was meant to be done. llvm-svn: 9777 --- lib/Target/Sparc/SparcV9CodeEmitter.cpp | 53 ++++--------------------- lib/Target/Sparc/SparcV9CodeEmitter.h | 4 -- 2 files changed, 8 insertions(+), 49 deletions(-) diff --git a/lib/Target/Sparc/SparcV9CodeEmitter.cpp b/lib/Target/Sparc/SparcV9CodeEmitter.cpp index 15bb1bc2d30..a674d8a00cc 100644 --- a/lib/Target/Sparc/SparcV9CodeEmitter.cpp +++ b/lib/Target/Sparc/SparcV9CodeEmitter.cpp @@ -593,13 +593,8 @@ int64_t SparcV9CodeEmitter::getMachineOpValue(MachineInstr &MI, unsigned* CurrPC = (unsigned*)(intptr_t)MCE.getCurrentPCValue(); BBRefs.push_back(std::make_pair(BB, std::make_pair(CurrPC, &MI))); } else if (const Constant *C = dyn_cast(V)) { - if (ConstantMap.find(C) != ConstantMap.end()) { - rv = (int64_t)MCE.getConstantPoolEntryAddress(ConstantMap[C]); - DEBUG(std::cerr << "const: 0x" << std::hex << rv << "\n"); - } else { - std::cerr << "ERROR: constant not in map:" << MO << "\n"; - abort(); - } + std::cerr << "ERROR: constants should not appear in PcRel:" << MO << "\n"; + abort(); } else if (GlobalValue *GV = dyn_cast(V)) { // same as MO.isGlobalAddress() DEBUG(std::cerr << "GlobalValue: "); @@ -623,17 +618,6 @@ int64_t SparcV9CodeEmitter::getMachineOpValue(MachineInstr &MI, } } else { rv = (int64_t)MCE.getGlobalValueAddress(GV); - if (rv == 0) { - if (Constant *C = ConstantPointerRef::get(GV)) { - if (ConstantMap.find(C) != ConstantMap.end()) { - rv = MCE.getConstantPoolEntryAddress(ConstantMap[C]); - } else { - std::cerr << "Constant: 0x" << std::hex << (intptr_t)C - << ", " << *V << " not found in ConstantMap!\n"; - abort(); - } - } - } DEBUG(std::cerr << "Global addr: 0x" << std::hex << rv << "\n"); } // The real target of the call is Addr = PC + (rv * 4) @@ -698,9 +682,8 @@ int64_t SparcV9CodeEmitter::getMachineOpValue(MachineInstr &MI, std::cerr << "ERROR: Frame index unhandled.\n"; abort(); } else if (MO.isConstantPoolIndex()) { - // Sparc backend doesn't generate this (yet...) - std::cerr << "ERROR: Constant Pool index unhandled.\n"; - abort(); + unsigned Index = MO.getConstantPoolIndex(); + rv = MCE.getConstantPoolEntryAddress(Index); } else { std::cerr << "ERROR: Unknown type of MachineOperand: " << MO << "\n"; abort(); @@ -734,27 +717,12 @@ bool SparcV9CodeEmitter::runOnMachineFunction(MachineFunction &MF) { << ", address: " << "0x" << std::hex << (long)MCE.getCurrentPCValue() << "\n"); - // The Sparc backend does not use MachineConstantPool; - // instead, it has its own constant pool implementation. - // We create a new MachineConstantPool here to be compatible with the emitter. - MachineConstantPool MCP; - const hash_set &pool = MF.getInfo()->getConstantPoolValues(); - for (hash_set::const_iterator I = pool.begin(), - E = pool.end(); I != E; ++I) - { - Constant *C = (Constant*)*I; - unsigned idx = MCP.getConstantPoolIndex(C); - DEBUG(std::cerr << "Constant[" << idx << "] = 0x" << (intptr_t)C << "\n"); - ConstantMap[C] = idx; - } - MCE.emitConstantPool(&MCP); - + MCE.emitConstantPool(MF.getConstantPool()); for (MachineFunction::iterator I = MF.begin(), E = MF.end(); I != E; ++I) emitBasicBlock(*I); MCE.finishFunction(MF); DEBUG(std::cerr << "Finishing fn " << MF.getFunction()->getName() << "\n"); - ConstantMap.clear(); // Resolve branches to BasicBlocks for the entire function for (unsigned i = 0, e = BBRefs.size(); i != e; ++i) { @@ -831,14 +799,9 @@ void* SparcV9CodeEmitter::getGlobalAddress(GlobalValue *V, MachineInstr &MI, (void*)(intptr_t)TheJITResolver->getLazyResolver(cast(V)); } else if (Constant *C = ConstantPointerRef::get(V)) { - if (ConstantMap.find(C) != ConstantMap.end()) { - return (void*) - (intptr_t)MCE.getConstantPoolEntryAddress(ConstantMap[C]); - } else { - std::cerr << "Constant: 0x" << std::hex << &*C << std::dec - << ", " << *V << " not found in ConstantMap!\n"; - abort(); - } + // no longer applicable + std::cerr << "Unhandled Constant: " << *C << "\n"; + abort(); } else { std::cerr << "Unhandled global: " << *V << "\n"; abort(); diff --git a/lib/Target/Sparc/SparcV9CodeEmitter.h b/lib/Target/Sparc/SparcV9CodeEmitter.h index 48bb6734dd5..7e19c44ce03 100644 --- a/lib/Target/Sparc/SparcV9CodeEmitter.h +++ b/lib/Target/Sparc/SparcV9CodeEmitter.h @@ -34,10 +34,6 @@ class SparcV9CodeEmitter : public MachineFunctionPass { // Tracks where each BasicBlock starts std::map BBLocations; - // Tracks locations of Constants which are laid out in memory (e.g. FP) - // But we also need to map Constants to ConstantPool indices - std::map ConstantMap; - public: SparcV9CodeEmitter(TargetMachine &T, MachineCodeEmitter &M); ~SparcV9CodeEmitter();