summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Target/PowerPC
diff options
context:
space:
mode:
authorEvan Cheng <evan.cheng@apple.com>2006-07-25 20:40:54 +0000
committerEvan Cheng <evan.cheng@apple.com>2006-07-25 20:40:54 +0000
commitf6acb34d239ed2828fce6bc2c1a69d92354df73a (patch)
treef7fbac3669a48447ce3ea63724624d22e155411d /llvm/lib/Target/PowerPC
parent66ed41cac17713d7fd90445412d207ab0673f712 (diff)
downloadbcm5719-llvm-f6acb34d239ed2828fce6bc2c1a69d92354df73a.tar.gz
bcm5719-llvm-f6acb34d239ed2828fce6bc2c1a69d92354df73a.zip
- Refactor the code that resolve basic block references to a TargetJITInfo
method. - Added synchronizeICache() to TargetJITInfo. It is called after each block of code is emitted to flush the icache. This ensures correct execution on targets that have separate dcache and icache. - Added PPC / Mac OS X specific code to do icache flushing. llvm-svn: 29276
Diffstat (limited to 'llvm/lib/Target/PowerPC')
-rw-r--r--llvm/lib/Target/PowerPC/PPCCodeEmitter.cpp32
-rw-r--r--llvm/lib/Target/PowerPC/PPCJITInfo.cpp35
-rw-r--r--llvm/lib/Target/PowerPC/PPCJITInfo.h3
3 files changed, 43 insertions, 27 deletions
diff --git a/llvm/lib/Target/PowerPC/PPCCodeEmitter.cpp b/llvm/lib/Target/PowerPC/PPCCodeEmitter.cpp
index 76dc349b50c..73b0436fd18 100644
--- a/llvm/lib/Target/PowerPC/PPCCodeEmitter.cpp
+++ b/llvm/lib/Target/PowerPC/PPCCodeEmitter.cpp
@@ -32,9 +32,6 @@ namespace {
TargetMachine &TM;
MachineCodeEmitter &MCE;
- // Tracks which instruction references which BasicBlock
- std::vector<std::pair<MachineBasicBlock*, unsigned*> > BBRefs;
-
/// getMachineOpValue - evaluates the MachineOperand of a given MachineInstr
///
int getMachineOpValue(MachineInstr &MI, MachineOperand &MO);
@@ -80,39 +77,20 @@ bool PPCTargetMachine::addPassesToEmitMachineCode(FunctionPassManager &PM,
return false;
}
+#ifdef __APPLE__
+extern "C" void sys_icache_invalidate(const void *Addr, size_t len);
+#endif
+
bool PPCCodeEmitter::runOnMachineFunction(MachineFunction &MF) {
assert((MF.getTarget().getRelocationModel() != Reloc::Default ||
MF.getTarget().getRelocationModel() != Reloc::Static) &&
"JIT relocation model must be set to static or default!");
do {
- BBRefs.clear();
-
MCE.startFunction(MF);
for (MachineFunction::iterator BB = MF.begin(), E = MF.end(); BB != E; ++BB)
emitBasicBlock(*BB);
} while (MCE.finishFunction(MF));
- // Resolve branches to BasicBlocks for the entire function
- for (unsigned i = 0, e = BBRefs.size(); i != e; ++i) {
- intptr_t Location = MCE.getMachineBasicBlockAddress(BBRefs[i].first);
- unsigned *Ref = BBRefs[i].second;
- DEBUG(std::cerr << "Fixup @ " << (void*)Ref << " to " << (void*)Location
- << "\n");
- unsigned Instr = *Ref;
- intptr_t BranchTargetDisp = (Location - (intptr_t)Ref) >> 2;
-
- switch (Instr >> 26) {
- default: assert(0 && "Unknown branch user!");
- case 18: // This is B or BL
- *Ref |= (BranchTargetDisp & ((1 << 24)-1)) << 2;
- break;
- case 16: // This is BLT,BLE,BEQ,BGE,BGT,BNE, or other bcx instruction
- *Ref |= (BranchTargetDisp & ((1 << 14)-1)) << 2;
- break;
- }
- }
- BBRefs.clear();
-
return false;
}
@@ -203,7 +181,7 @@ int PPCCodeEmitter::getMachineOpValue(MachineInstr &MI, MachineOperand &MO) {
Reloc, MO.getSymbolName(), 0));
} else if (MO.isMachineBasicBlock()) {
unsigned* CurrPC = (unsigned*)(intptr_t)MCE.getCurrentPCValue();
- BBRefs.push_back(std::make_pair(MO.getMachineBasicBlock(), CurrPC));
+ TM.getJITInfo()->addBBRef(MO.getMachineBasicBlock(), (intptr_t)CurrPC);
} else if (MO.isConstantPoolIndex() || MO.isJumpTableIndex()) {
if (MO.isConstantPoolIndex())
rv = MCE.getConstantPoolEntryAddress(MO.getConstantPoolIndex());
diff --git a/llvm/lib/Target/PowerPC/PPCJITInfo.cpp b/llvm/lib/Target/PowerPC/PPCJITInfo.cpp
index 1d4760affaf..0c6044c928a 100644
--- a/llvm/lib/Target/PowerPC/PPCJITInfo.cpp
+++ b/llvm/lib/Target/PowerPC/PPCJITInfo.cpp
@@ -16,7 +16,9 @@
#include "PPCRelocations.h"
#include "llvm/CodeGen/MachineCodeEmitter.h"
#include "llvm/Config/alloca.h"
+#include "llvm/Support/Debug.h"
#include <set>
+#include <iostream>
using namespace llvm;
static TargetJITInfo::JITCompilerFn JITCompilerFunction;
@@ -243,3 +245,36 @@ void PPCJITInfo::relocate(void *Function, MachineRelocation *MR,
void PPCJITInfo::replaceMachineCodeForFunction(void *Old, void *New) {
EmitBranchToAt(Old, New, false);
}
+
+void PPCJITInfo::resolveBBRefs(MachineCodeEmitter &MCE) {
+ // Resolve branches to BasicBlocks for the entire function
+ for (unsigned i = 0, e = BBRefs.size(); i != e; ++i) {
+ intptr_t Location = MCE.getMachineBasicBlockAddress(BBRefs[i].first);
+ unsigned *Ref = (unsigned *)BBRefs[i].second;
+ DEBUG(std::cerr << "Fixup @ " << (void*)Ref << " to " << (void*)Location
+ << "\n");
+ unsigned Instr = *Ref;
+ intptr_t BranchTargetDisp = (Location - (intptr_t)Ref) >> 2;
+
+ switch (Instr >> 26) {
+ default: assert(0 && "Unknown branch user!");
+ case 18: // This is B or BL
+ *Ref |= (BranchTargetDisp & ((1 << 24)-1)) << 2;
+ break;
+ case 16: // This is BLT,BLE,BEQ,BGE,BGT,BNE, or other bcx instruction
+ *Ref |= (BranchTargetDisp & ((1 << 14)-1)) << 2;
+ break;
+ }
+ }
+ BBRefs.clear();
+}
+
+#ifdef __APPLE__
+extern "C" void sys_icache_invalidate(const void *Addr, size_t len);
+#endif
+
+void PPCJITInfo::synchronizeICache(const void *Addr, size_t Len) {
+#ifdef __APPLE__
+ sys_icache_invalidate(Addr, Len);
+#endif
+}
diff --git a/llvm/lib/Target/PowerPC/PPCJITInfo.h b/llvm/lib/Target/PowerPC/PPCJITInfo.h
index 245cf9ad902..292539f3ec9 100644
--- a/llvm/lib/Target/PowerPC/PPCJITInfo.h
+++ b/llvm/lib/Target/PowerPC/PPCJITInfo.h
@@ -42,6 +42,9 @@ namespace llvm {
/// code.
///
virtual void replaceMachineCodeForFunction(void *Old, void *New);
+
+ virtual void resolveBBRefs(MachineCodeEmitter &MCE);
+ virtual void synchronizeICache(const void *Addr, size_t Len);
};
}
OpenPOWER on IntegriCloud