[llvm-commits] [llvm] r59516 - in /llvm/trunk: include/llvm/CodeGen/MachineCodeEmitter.h lib/ExecutionEngine/JIT/JITDwarfEmitter.cpp

Nicolas Geoffray nicolas.geoffray at lip6.fr
Tue Nov 18 02:44:46 PST 2008


Author: geoffray
Date: Tue Nov 18 04:44:46 2008
New Revision: 59516

URL: http://llvm.org/viewvc/llvm-project?rev=59516&view=rev
Log:
Implement support for JIT exceptions on X86_64. Relative offsets are
encoded on 32 bytes, and the personality function is not encoded as
relative.


Modified:
    llvm/trunk/include/llvm/CodeGen/MachineCodeEmitter.h
    llvm/trunk/lib/ExecutionEngine/JIT/JITDwarfEmitter.cpp

Modified: llvm/trunk/include/llvm/CodeGen/MachineCodeEmitter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/MachineCodeEmitter.h?rev=59516&r1=59515&r2=59516&view=diff

==============================================================================
--- llvm/trunk/include/llvm/CodeGen/MachineCodeEmitter.h (original)
+++ llvm/trunk/include/llvm/CodeGen/MachineCodeEmitter.h Tue Nov 18 04:44:46 2008
@@ -228,12 +228,19 @@
     }
   }
   
-  /// emitAt - Emit Value in Addr
-  void emitAt(uintptr_t *Addr, uintptr_t Value) {
+  /// emitInt32At - Emit the Int32 Value in Addr.
+  void emitInt32At(uintptr_t *Addr, uintptr_t Value) {
     if (Addr >= (uintptr_t*)BufferBegin && Addr < (uintptr_t*)BufferEnd)
-      (*Addr) = Value;
+      (*(uint32_t*)Addr) = (uint32_t)Value;
   }
   
+  /// emitInt64At - Emit the Int64 Value in Addr.
+  void emitInt64At(uintptr_t *Addr, uintptr_t Value) {
+    if (Addr >= (uintptr_t*)BufferBegin && Addr < (uintptr_t*)BufferEnd)
+      (*(uint64_t*)Addr) = (uint64_t)Value;
+  }
+  
+  
   /// emitLabel - Emits a label
   virtual void emitLabel(uint64_t LabelID) = 0;
 

Modified: llvm/trunk/lib/ExecutionEngine/JIT/JITDwarfEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/JIT/JITDwarfEmitter.cpp?rev=59516&r1=59515&r2=59516&view=diff

==============================================================================
--- llvm/trunk/lib/ExecutionEngine/JIT/JITDwarfEmitter.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/JIT/JITDwarfEmitter.cpp Tue Nov 18 04:44:46 2008
@@ -89,11 +89,7 @@
     // Advance row if new location.
     if (BaseLabelPtr && LabelID && (BaseLabelID != LabelID || !IsLocal)) {
       MCE->emitByte(dwarf::DW_CFA_advance_loc4);
-      if (PointerSize == 8) {
-        MCE->emitInt64(LabelPtr - BaseLabelPtr);
-      } else {
-        MCE->emitInt32(LabelPtr - BaseLabelPtr);
-      }
+      MCE->emitInt32(LabelPtr - BaseLabelPtr);
       
       BaseLabelID = LabelID; 
       BaseLabelPtr = LabelPtr;
@@ -435,46 +431,28 @@
 
     if (!S.BeginLabel) {
       BeginLabelPtr = (intptr_t)StartFunction;
-      if (TD->getPointerSize() == sizeof(int32_t))
-        MCE->emitInt32(0);
-      else
-        MCE->emitInt64(0);
+      MCE->emitInt32(0);
     } else {
       BeginLabelPtr = MCE->getLabelAddress(S.BeginLabel);
-      if (TD->getPointerSize() == sizeof(int32_t))
-        MCE->emitInt32(BeginLabelPtr - (intptr_t)StartFunction);
-      else
-        MCE->emitInt64(BeginLabelPtr - (intptr_t)StartFunction);
+      MCE->emitInt32(BeginLabelPtr - (intptr_t)StartFunction);
     }
 
     // Asm->EOL("Region start");
 
     if (!S.EndLabel) {
       EndLabelPtr = (intptr_t)EndFunction;
-      if (TD->getPointerSize() == sizeof(int32_t))
-        MCE->emitInt32((intptr_t)EndFunction - BeginLabelPtr);
-      else
-        MCE->emitInt64((intptr_t)EndFunction - BeginLabelPtr);
+      MCE->emitInt32((intptr_t)EndFunction - BeginLabelPtr);
     } else {
       EndLabelPtr = MCE->getLabelAddress(S.EndLabel);
-      if (TD->getPointerSize() == sizeof(int32_t))
-        MCE->emitInt32(EndLabelPtr - BeginLabelPtr);
-      else
-        MCE->emitInt64(EndLabelPtr - BeginLabelPtr);
+      MCE->emitInt32(EndLabelPtr - BeginLabelPtr);
     }
     //Asm->EOL("Region length");
 
     if (!S.PadLabel) {
-      if (TD->getPointerSize() == sizeof(int32_t))
-        MCE->emitInt32(0);
-      else
-        MCE->emitInt64(0);
+      MCE->emitInt32(0);
     } else {
       unsigned PadLabelPtr = MCE->getLabelAddress(S.PadLabel);
-      if (TD->getPointerSize() == sizeof(int32_t))
-        MCE->emitInt32(PadLabelPtr - (intptr_t)StartFunction);
-      else
-        MCE->emitInt64(PadLabelPtr - (intptr_t)StartFunction);
+      MCE->emitInt32(PadLabelPtr - (intptr_t)StartFunction);
     }
     // Asm->EOL("Landing pad");
 
@@ -531,7 +509,7 @@
   
   unsigned char* StartCommonPtr = (unsigned char*)MCE->getCurrentPCValue();
   // EH Common Frame header
-  MCE->allocateSpace(PointerSize, 0);
+  MCE->allocateSpace(4, 0);
   unsigned char* FrameCommonBeginPtr = (unsigned char*)MCE->getCurrentPCValue();
   MCE->emitInt32((int)0);
   MCE->emitByte(dwarf::DW_CIE_VERSION);
@@ -543,15 +521,12 @@
   if (Personality) {
     MCE->emitULEB128Bytes(7);
     
-    // Direct encoding, because we use the function pointer.
-    MCE->emitByte(dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4);
-    
-    if (PointerSize == 8)
-      MCE->emitInt64((intptr_t)Jit.getPointerToGlobal(Personality) - 
-                MCE->getCurrentPCValue());
-    else
-      MCE->emitInt32((intptr_t)Jit.getPointerToGlobal(Personality) - 
-                MCE->getCurrentPCValue());
+    // Direct encoding, because we use the function pointer. Not relative,
+    // because the current PC value may be bigger than the personality
+    // function pointer.
+    MCE->emitByte(dwarf::DW_EH_PE_sdata4);
+     
+    MCE->emitInt32(((intptr_t)Jit.getPointerToGlobal(Personality)));
     
     MCE->emitULEB128Bytes(dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4);
     MCE->emitULEB128Bytes(dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4);
@@ -564,9 +539,9 @@
   std::vector<MachineMove> Moves;
   RI->getInitialFrameState(Moves);
   EmitFrameMoves(0, Moves);
-  MCE->emitAlignment(4);
+  MCE->emitAlignment(PointerSize);
   
-  MCE->emitAt((uintptr_t*)StartCommonPtr, 
+  MCE->emitInt32At((uintptr_t*)StartCommonPtr, 
               (uintptr_t)((unsigned char*)MCE->getCurrentPCValue() - 
                           FrameCommonBeginPtr));
 
@@ -584,18 +559,12 @@
   
   // EH frame header.
   unsigned char* StartEHPtr = (unsigned char*)MCE->getCurrentPCValue();
-  MCE->allocateSpace(PointerSize, 0);
+  MCE->allocateSpace(4, 0);
   unsigned char* FrameBeginPtr = (unsigned char*)MCE->getCurrentPCValue();
   // FDE CIE Offset
-  if (PointerSize == 8) {
-    MCE->emitInt64(FrameBeginPtr - StartCommonPtr);
-    MCE->emitInt64(StartFunction - (unsigned char*)MCE->getCurrentPCValue());
-    MCE->emitInt64(EndFunction - StartFunction);
-  } else {
-    MCE->emitInt32(FrameBeginPtr - StartCommonPtr);
-    MCE->emitInt32(StartFunction - (unsigned char*)MCE->getCurrentPCValue());
-    MCE->emitInt32(EndFunction - StartFunction);
-  }
+  MCE->emitInt32(FrameBeginPtr - StartCommonPtr);
+  MCE->emitInt32(StartFunction - (unsigned char*)MCE->getCurrentPCValue());
+  MCE->emitInt32(EndFunction - StartFunction);
 
   // If there is a personality and landing pads then point to the language
   // specific data area in the exception table.
@@ -603,12 +572,7 @@
     MCE->emitULEB128Bytes(4);
         
     if (!MMI->getLandingPads().empty()) {
-      if (PointerSize == 8)
-        MCE->emitInt64(ExceptionTable - (unsigned char*)MCE->getCurrentPCValue());
-      else
-        MCE->emitInt32(ExceptionTable - (unsigned char*)MCE->getCurrentPCValue());
-    } else if (PointerSize == 8) {
-      MCE->emitInt64((int)0);
+      MCE->emitInt32(ExceptionTable - (unsigned char*)MCE->getCurrentPCValue());
     } else {
       MCE->emitInt32((int)0);
     }
@@ -620,10 +584,10 @@
   // frame.
   EmitFrameMoves((intptr_t)StartFunction, MMI->getFrameMoves());
       
-  MCE->emitAlignment(4);
+  MCE->emitAlignment(PointerSize);
   
   // Indicate the size of the table
-  MCE->emitAt((uintptr_t*)StartEHPtr, 
+  MCE->emitInt32At((uintptr_t*)StartEHPtr, 
               (uintptr_t)((unsigned char*)MCE->getCurrentPCValue() - 
                           StartEHPtr));
   
@@ -655,9 +619,11 @@
   FinalSize += GetExceptionTableSizeInBytes(&F);
       
   const std::vector<Function *> Personalities = MMI->getPersonalities();
-  FinalSize += GetCommonEHFrameSizeInBytes(Personalities[MMI->getPersonalityIndex()]);
+  FinalSize += 
+    GetCommonEHFrameSizeInBytes(Personalities[MMI->getPersonalityIndex()]);
 
-  FinalSize += GetEHFrameSizeInBytes(Personalities[MMI->getPersonalityIndex()], StartFunction);
+  FinalSize += GetEHFrameSizeInBytes(Personalities[MMI->getPersonalityIndex()],
+                                     StartFunction);
   
   return FinalSize;
 }





More information about the llvm-commits mailing list