mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-17 06:33:21 +00:00
* Correctly handle the MovePCtoLR pseudo-instr with a bl to next instr
* Stop the confusion of using rv and Addr for global addresses: just use rv git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@17195 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
40a55e1e29
commit
d4b4a99587
@ -18,6 +18,7 @@
|
|||||||
#include "llvm/Module.h"
|
#include "llvm/Module.h"
|
||||||
#include "llvm/CodeGen/MachineCodeEmitter.h"
|
#include "llvm/CodeGen/MachineCodeEmitter.h"
|
||||||
#include "llvm/CodeGen/MachineFunctionPass.h"
|
#include "llvm/CodeGen/MachineFunctionPass.h"
|
||||||
|
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
||||||
#include "llvm/CodeGen/Passes.h"
|
#include "llvm/CodeGen/Passes.h"
|
||||||
#include "llvm/Support/Debug.h"
|
#include "llvm/Support/Debug.h"
|
||||||
|
|
||||||
@ -204,9 +205,15 @@ void PPC32CodeEmitter::emitBasicBlock(MachineBasicBlock &MBB) {
|
|||||||
for (MachineBasicBlock::iterator I = MBB.begin(), E = MBB.end(); I != E; ++I){
|
for (MachineBasicBlock::iterator I = MBB.begin(), E = MBB.end(); I != E; ++I){
|
||||||
MachineInstr &MI = *I;
|
MachineInstr &MI = *I;
|
||||||
unsigned Opcode = MI.getOpcode();
|
unsigned Opcode = MI.getOpcode();
|
||||||
if (Opcode == PPC::IMPLICIT_DEF) continue;
|
if (Opcode == PPC::IMPLICIT_DEF)
|
||||||
|
continue; // pseudo opcode, no side effects
|
||||||
emitWord(getBinaryCodeForInstr(*I));
|
else if (Opcode == PPC::MovePCtoLR) {
|
||||||
|
// This can be simplified: the resulting 32-bit code is 0x48000005
|
||||||
|
MachineInstr *MI = BuildMI(PPC::BL, 1).addImm(1);
|
||||||
|
emitWord(getBinaryCodeForInstr(*MI));
|
||||||
|
delete MI;
|
||||||
|
} else
|
||||||
|
emitWord(getBinaryCodeForInstr(*I));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -269,16 +276,15 @@ int64_t PPC32CodeEmitter::getMachineOpValue(MachineInstr &MI,
|
|||||||
rv = MO.getImmedValue();
|
rv = MO.getImmedValue();
|
||||||
} else if (MO.isGlobalAddress()) {
|
} else if (MO.isGlobalAddress()) {
|
||||||
GlobalValue *GV = MO.getGlobal();
|
GlobalValue *GV = MO.getGlobal();
|
||||||
intptr_t Addr = (intptr_t)MCE.getGlobalValueAddress(GV);
|
rv = MCE.getGlobalValueAddress(GV);
|
||||||
if (Addr == 0) {
|
if (rv == 0) {
|
||||||
if (Function *F = dyn_cast<Function>(GV)) {
|
if (Function *F = dyn_cast<Function>(GV)) {
|
||||||
if (F->isExternal())
|
if (F->isExternal())
|
||||||
rv = getAddressOfExternalFunction(F);
|
rv = getAddressOfExternalFunction(F);
|
||||||
else {
|
else {
|
||||||
// Function has not yet been code generated!
|
// Function has not yet been code generated! Use lazy resolution.
|
||||||
getResolver(MCE).addFunctionReference(MCE.getCurrentPCValue(), F);
|
getResolver(MCE).addFunctionReference(MCE.getCurrentPCValue(), F);
|
||||||
// Delayed resolution...
|
rv = getResolver(MCE).getLazyResolver(F);
|
||||||
return (intptr_t)getResolver(MCE).getLazyResolver(F);
|
|
||||||
}
|
}
|
||||||
} else if (GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV)) {
|
} else if (GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV)) {
|
||||||
if (GVar->isExternal()) {
|
if (GVar->isExternal()) {
|
||||||
@ -295,7 +301,7 @@ int64_t PPC32CodeEmitter::getMachineOpValue(MachineInstr &MI,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (MO.isPCRelative()) { // Global variable reference
|
if (MO.isPCRelative()) { // Global variable reference
|
||||||
rv = (Addr - MCE.getCurrentPCValue()) >> 2;
|
rv = (rv - MCE.getCurrentPCValue()) >> 2;
|
||||||
}
|
}
|
||||||
} else if (MO.isMachineBasicBlock()) {
|
} else if (MO.isMachineBasicBlock()) {
|
||||||
const BasicBlock *BB = MO.getMachineBasicBlock()->getBasicBlock();
|
const BasicBlock *BB = MO.getMachineBasicBlock()->getBasicBlock();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user