Use use_empty() instead of getNumUses(), avoiding a use list traversal.
[oota-llvm.git] / lib / ExecutionEngine / JIT / JITEmitter.cpp
index 06daec69da08e04b9e67367923907093fc210933..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) {
@@ -308,7 +294,7 @@ void *JITResolver::JITCompilerFn(void *Stub) {
 // have useful answers.  However, we don't go crazy with atomic operations, we
 // just do a "reasonable effort".
 #ifdef __APPLE__ 
-#define ENABLE_JIT_SYMBOL_TABLE 1
+#define ENABLE_JIT_SYMBOL_TABLE 0
 #endif
 
 /// JitSymbolEntry - Each function that is JIT compiled results in one of these
@@ -421,7 +407,7 @@ static void RemoveFunctionFromSymbolTable(void *FnStart) {
   --SymTabPtr->NumSymbols;
 
   // Finally, if we deleted the final symbol, deallocate the table itself.
-  if (SymTabPtr->NumSymbols == 0) 
+  if (SymTabPtr->NumSymbols != 0) 
     return;
   
   *SymTabPtrPtr = 0;
@@ -623,35 +609,38 @@ static unsigned GetJumpTableSizeInBytes(MachineJumpTableInfo *MJTI) {
   return NumEntries * EntrySize;
 }
 
-static void AddAlignment(uintptr_t& Size, unsigned Alignment) {
+static uintptr_t RoundUpToAlign(uintptr_t Size, unsigned Alignment) {
   if (Alignment == 0) Alignment = 1;
-  Size = (Size + Alignment - 1) & (Alignment - 1);
+  // Since we do not know where the buffer will be allocated, be pessimistic. 
+  return Size + Alignment;
 }
 
 void JITEmitter::startFunction(MachineFunction &F) {
   uintptr_t ActualSize = 0;
-  if (MemMgr->RequiresSize()) {
+  if (MemMgr->NeedsExactSize()) {
     const TargetInstrInfo* TII = F.getTarget().getInstrInfo();
     MachineJumpTableInfo *MJTI = F.getJumpTableInfo();
     MachineConstantPool *MCP = F.getConstantPool();
     
     // Ensure the constant pool/jump table info is at least 4-byte aligned.
-    AddAlignment(ActualSize, 16);
+    ActualSize = RoundUpToAlign(ActualSize, 16);
     
     // Add the alignment of the constant pool
-    AddAlignment(ActualSize, 1 << MCP->getConstantPoolAlignment());
+    ActualSize = RoundUpToAlign(ActualSize, 
+                                1 << MCP->getConstantPoolAlignment());
 
     // Add the constant pool size
     ActualSize += GetConstantPoolSizeInBytes(MCP);
 
     // Add the aligment of the jump table info
-    AddAlignment(ActualSize, MJTI->getAlignment());
+    ActualSize = RoundUpToAlign(ActualSize, MJTI->getAlignment());
 
     // Add the jump table size
     ActualSize += GetJumpTableSizeInBytes(MJTI);
     
     // Add the alignment for the function
-    AddAlignment(ActualSize, std::max(F.getFunction()->getAlignment(), 8U));
+    ActualSize = RoundUpToAlign(ActualSize,
+                                std::max(F.getFunction()->getAlignment(), 8U));
 
     // Add the function size
     ActualSize += TII->GetFunctionSizeInBytes(F);
@@ -753,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(),
@@ -776,8 +765,8 @@ bool JITEmitter::finishFunction(MachineFunction &F) {
     SavedBufferEnd = BufferEnd;
     SavedCurBufferPtr = CurBufferPtr;
     
-    if (MemMgr->RequiresSize()) {
-      ActualSize = DE->GetDwarfTableSize(F, *this, FnStart, FnEnd);
+    if (MemMgr->NeedsExactSize()) {
+      ActualSize = DE->GetDwarfTableSizeInBytes(F, *this, FnStart, FnEnd);
     }
 
     BufferBegin = CurBufferPtr = MemMgr->startExceptionTable(F.getFunction(),