Provide generic hooks for icache invalidation. Add PPC implementation.
authorAnton Korobeynikov <asl@math.spbu.ru>
Tue, 17 Jun 2008 17:30:05 +0000 (17:30 +0000)
committerAnton Korobeynikov <asl@math.spbu.ru>
Tue, 17 Jun 2008 17:30:05 +0000 (17:30 +0000)
Patch by Gary Benson!

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@52418 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Target/TargetJITInfo.h
lib/ExecutionEngine/JIT/JITEmitter.cpp
lib/Target/PowerPC/PPCCodeEmitter.cpp
lib/Target/PowerPC/PPCJITInfo.cpp
lib/Target/PowerPC/PPCJITInfo.h

index 6e1eb4396c6026baefbc38980a968692ddd32dd8..293e0d38406aadebc077ec50617eca1a232d9cc8 100644 (file)
@@ -94,6 +94,11 @@ namespace llvm {
       assert(NumRelocs == 0 && "This target does not have relocations!");
     }
 
+    /// InvalidateInstructionCache - Before the JIT can run a block of code
+    // that has been emitted it must invalidate the instruction cache on some
+    // platforms.
+    virtual void InvalidateInstructionCache(const void *Addr, unsigned len) {}
+
     /// needsGOT - Allows a target to specify that it would like the
     // JIT to manage a GOT for it.
     bool needsGOT() const { return useGOT; }
index 422022af9cac48b6ac652134e4cdc5947218f6ec..c55bc75560cb9abc70345c97d1fa05474e812d20 100644 (file)
@@ -145,20 +145,6 @@ namespace {
 
 JITResolver *JITResolver::TheJITResolver = 0;
 
-#if (defined(__POWERPC__) || defined (__ppc__) || defined(_POWER)) && \
-    defined(__APPLE__)
-extern "C" void sys_icache_invalidate(const void *Addr, size_t len);
-#endif
-
-/// synchronizeICache - On some targets, the JIT emitted code must be
-/// explicitly refetched to ensure correct execution.
-static void synchronizeICache(const void *Addr, size_t len) {
-#if (defined(__POWERPC__) || defined (__ppc__) || defined(_POWER)) && \
-    defined(__APPLE__)
-  sys_icache_invalidate(Addr, len);
-#endif
-}
-
 /// getFunctionStub - This returns a pointer to a function stub, creating
 /// one on demand as needed.
 void *JITResolver::getFunctionStub(Function *F) {
@@ -756,7 +742,7 @@ bool JITEmitter::finishFunction(MachineFunction &F) {
   }
 
   // Invalidate the icache if necessary.
-  synchronizeICache(FnStart, FnEnd-FnStart);
+  TheJIT->getJITInfo().InvalidateInstructionCache(FnStart, FnEnd-FnStart);
   
   // Add it to the JIT symbol table if the host wants it.
   AddFunctionToSymbolTable(F.getFunction()->getNameStart(),
index c0621a074f342df2973f6e9129e7edb97d1967f8..51672be0491dbe4a8732a4a5467c371473d49e53 100644 (file)
@@ -80,10 +80,6 @@ FunctionPass *llvm::createPPCCodeEmitterPass(PPCTargetMachine &TM,
   return new PPCCodeEmitter(TM, MCE);
 }
 
-#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) &&
index db36881ae5391d8a81012534623da3164ab56e6b..72001ce334b937dc674fa397fdda0f6707b83f79 100644 (file)
@@ -330,12 +330,9 @@ defined(__APPLE__)
 extern "C" void sys_icache_invalidate(const void *Addr, size_t len);
 #endif
 
-/// SyncICache - On PPC, the JIT emitted code must be explicitly refetched to
-/// ensure correct execution.
-static void SyncICache(const void *Addr, size_t len) {
-#if defined(__POWERPC__) || defined (__ppc__) || defined(_POWER)
-  
-#ifdef __APPLE__
+void PPCJITInfo::InvalidateInstructionCache(const void *Addr, unsigned len) {
+#if (defined(__POWERPC__) || defined (__ppc__) || defined(_POWER)) && \
+defined(__APPLE__)  
   sys_icache_invalidate(Addr, len);
 #elif defined(__GNUC__)
   const size_t LineSize = 32;
@@ -352,8 +349,6 @@ static void SyncICache(const void *Addr, size_t len) {
       asm volatile("icbi 0, %0" : : "r"(Line));
   asm volatile("isync");
 #endif
-  
-#endif
 }
 
 void *PPCJITInfo::emitFunctionStub(const Function* F, void *Fn,
@@ -372,7 +367,7 @@ void *PPCJITInfo::emitFunctionStub(const Function* F, void *Fn,
     MCE.emitWordBE(0);
     MCE.emitWordBE(0);
     EmitBranchToAt(Addr, (intptr_t)Fn, false, is64Bit);
-    SyncICache((void*)Addr, 7*4);
+    InvalidateInstructionCache((void*)Addr, 7*4);
     return MCE.finishFunctionStub(F);
   }
 
@@ -400,7 +395,7 @@ void *PPCJITInfo::emitFunctionStub(const Function* F, void *Fn,
   MCE.emitWordBE(0);
   MCE.emitWordBE(0);
   EmitBranchToAt(BranchAddr, (intptr_t)Fn, true, is64Bit);
-  SyncICache((void*)Addr, 10*4);
+  InvalidateInstructionCache((void*)Addr, 10*4);
   return MCE.finishFunctionStub(F);
 }
 
index c93a84aca05f51274b5c22c80811d5815a2eeeb9..b7e6ff56ab1b5683688cbc55a6c8ab4d1a80df24 100644 (file)
@@ -41,6 +41,11 @@ namespace llvm {
     /// code.
     ///
     virtual void replaceMachineCodeForFunction(void *Old, void *New);
+
+    /// InvalidateInstructionCache - Before the JIT can run a block of code
+    // that has been emitted it must invalidate the instruction cache on some
+    // platforms.
+    virtual void InvalidateInstructionCache(const void *Addr, unsigned len);
   };
 }