Hello, Everyone.

Prev. patch should be considered as obsolete: MS runtime is weird: it
uses underscore version of setjump() but non-underscore for
longjump() :)

Updated patch attached. Please note, that it will update .h file, so,
it's recommended to rebuild the whole LLVM tree (well, at least Codegen,
Target & backends).

-- 
With best regards, Anton Korobeynikov.

Faculty of Mathematics & Mechanics, Saint Petersburg State University.

diff -r f7b4f57b400c include/llvm/Target/TargetLowering.h
--- a/include/llvm/Target/TargetLowering.h	Wed Dec 06 13:35:10 2006 +0000
+++ b/include/llvm/Target/TargetLowering.h	Sat Dec 09 23:46:52 2006 +0300
@@ -379,12 +379,18 @@ public:
     return allowUnalignedMemoryAccesses;
   }
   
-  /// usesUnderscoreSetJmpLongJmp - Determine if we should use _setjmp or setjmp
+  /// usesUnderscoreSetJmp - Determine if we should use _setjmp or setjmp
   /// to implement llvm.setjmp.
-  bool usesUnderscoreSetJmpLongJmp() const {
-    return UseUnderscoreSetJmpLongJmp;
-  }
-  
+  bool usesUnderscoreSetJmp() const {
+    return UseUnderscoreSetJmp;
+  }
+
+  /// usesUnderscoreLongJmp - Determine if we should use _longjmp or longjmp
+  /// to implement llvm.longjmp.
+  bool usesUnderscoreLongJmp() const {
+    return UseUnderscoreLongJmp;
+  }
+
   /// getStackPointerRegisterToSaveRestore - If a physical register, this
   /// specifies the register that llvm.savestack/llvm.restorestack should save
   /// and restore.
@@ -564,13 +570,20 @@ protected:
     ShiftAmtHandling = OORSA;
   }
 
-  /// setUseUnderscoreSetJmpLongJmp - Indicate whether this target prefers to
-  /// use _setjmp and _longjmp to or implement llvm.setjmp/llvm.longjmp or
-  /// the non _ versions.  Defaults to false.
-  void setUseUnderscoreSetJmpLongJmp(bool Val) {
-    UseUnderscoreSetJmpLongJmp = Val;
-  }
-  
+  /// setUseUnderscoreSetJmp - Indicate whether this target prefers to
+  /// use _setjmp to implement llvm.setjmp or the non _ version.
+  /// Defaults to false.
+  void setUseUnderscoreSetJmp(bool Val) {
+    UseUnderscoreSetJmp = Val;
+  }
+
+  /// setUseUnderscoreLongJmp - Indicate whether this target prefers to
+  /// use _longjmp to implement llvm.longjmp or the non _ version.
+  /// Defaults to false.
+  void setUseUnderscoreLongJmp(bool Val) {
+    UseUnderscoreLongJmp = Val;
+  }
+
   /// setStackPointerRegisterToSaveRestore - If set to a physical register, this
   /// specifies the register that llvm.savestack/llvm.restorestack should save
   /// and restore.
@@ -883,10 +896,14 @@ private:
   /// total cycles or lowest register usage.
   SchedPreference SchedPreferenceInfo;
   
-  /// UseUnderscoreSetJmpLongJmp - This target prefers to use _setjmp and
-  /// _longjmp to implement llvm.setjmp/llvm.longjmp.  Defaults to false.
-  bool UseUnderscoreSetJmpLongJmp;
-  
+  /// UseUnderscoreSetJmp - This target prefers to use _setjmp to implement
+  /// llvm.setjmp.  Defaults to false.
+  bool UseUnderscoreSetJmp;
+
+  /// UseUnderscoreLongJmp - This target prefers to use _longjmp to implement
+  /// llvm.longjmp.  Defaults to false.
+  bool UseUnderscoreLongJmp;
+
   /// JumpBufSize - The size, in bytes, of the target's jmp_buf buffers
   unsigned JumpBufSize;
   
diff -r f7b4f57b400c lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
--- a/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp	Wed Dec 06 13:35:10 2006 +0000
+++ b/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp	Sat Dec 09 23:53:05 2006 +0300
@@ -1975,10 +1975,10 @@ SelectionDAGLowering::visitIntrinsicCall
   case Intrinsic::returnaddress: visitFrameReturnAddress(I, false); return 0;
   case Intrinsic::frameaddress:  visitFrameReturnAddress(I, true); return 0;
   case Intrinsic::setjmp:
-    return "_setjmp"+!TLI.usesUnderscoreSetJmpLongJmp();
+    return "_setjmp"+!TLI.usesUnderscoreSetJmp();
     break;
   case Intrinsic::longjmp:
-    return "_longjmp"+!TLI.usesUnderscoreSetJmpLongJmp();
+    return "_longjmp"+!TLI.usesUnderscoreLongJmp();
     break;
   case Intrinsic::memcpy_i32:
   case Intrinsic::memcpy_i64:
diff -r f7b4f57b400c lib/CodeGen/SelectionDAG/TargetLowering.cpp
--- a/lib/CodeGen/SelectionDAG/TargetLowering.cpp	Wed Dec 06 13:35:10 2006 +0000
+++ b/lib/CodeGen/SelectionDAG/TargetLowering.cpp	Sun Dec 10 00:40:31 2006 +0300
@@ -47,7 +47,8 @@ TargetLowering::TargetLowering(TargetMac
          sizeof(TargetDAGCombineArray)/sizeof(TargetDAGCombineArray[0]));
   maxStoresPerMemset = maxStoresPerMemcpy = maxStoresPerMemmove = 8;
   allowUnalignedMemoryAccesses = false;
-  UseUnderscoreSetJmpLongJmp = false;
+  UseUnderscoreSetJmp = false;
+  UseUnderscoreLongJmp = false;
   IntDivIsCheap = false;
   Pow2DivIsCheap = false;
   StackPointerRegisterToSaveRestore = 0;
diff -r f7b4f57b400c lib/Target/CBackend/Writer.cpp
--- a/lib/Target/CBackend/Writer.cpp	Wed Dec 06 13:35:10 2006 +0000
+++ b/lib/Target/CBackend/Writer.cpp	Sat Dec 09 12:13:58 2006 +0300
@@ -1138,6 +1138,8 @@ static void generateCompilerSpecificCode
       << "#elif defined(__APPLE__)\n"
       << "extern void *__builtin_alloca(unsigned long);\n"
       << "#define alloca(x) __builtin_alloca(x)\n"
+      << "#define longjmp(x) _longjmp(x)\n"
+      << "#define setjmp(x) _setjmp(x)\n"
       << "#elif defined(__sun__)\n"
       << "#if defined(__sparcv9)\n"
       << "extern void *__builtin_alloca(unsigned long);\n"
@@ -2143,17 +2145,11 @@ void CWriter::visitCallInst(CallInst &I)
         Out << ')';
         return;
       case Intrinsic::setjmp:
-#if defined(HAVE__SETJMP) && defined(HAVE__LONGJMP)
-        Out << "_";  // Use _setjmp on systems that support it!
-#endif
         Out << "setjmp(*(jmp_buf*)";
         writeOperand(I.getOperand(1));
         Out << ')';
         return;
       case Intrinsic::longjmp:
-#if defined(HAVE__SETJMP) && defined(HAVE__LONGJMP)
-        Out << "_";  // Use _longjmp on systems that support it!
-#endif
         Out << "longjmp(*(jmp_buf*)";
         writeOperand(I.getOperand(1));
         Out << ", ";
diff -r f7b4f57b400c lib/Target/PowerPC/PPCISelLowering.cpp
--- a/lib/Target/PowerPC/PPCISelLowering.cpp	Wed Dec 06 13:35:10 2006 +0000
+++ b/lib/Target/PowerPC/PPCISelLowering.cpp	Sat Dec 09 23:47:32 2006 +0300
@@ -41,7 +41,8 @@ PPCTargetLowering::PPCTargetLowering(PPC
   setPow2DivIsCheap();
   
   // Use _setjmp/_longjmp instead of setjmp/longjmp.
-  setUseUnderscoreSetJmpLongJmp(true);
+  setUseUnderscoreSetJmp(true);
+  setUseUnderscoreLongJmp(true);
     
   // Set up the register classes.
   addRegisterClass(MVT::i32, PPC::GPRCRegisterClass);
diff -r f7b4f57b400c lib/Target/X86/X86ISelLowering.cpp
--- a/lib/Target/X86/X86ISelLowering.cpp	Wed Dec 06 13:35:10 2006 +0000
+++ b/lib/Target/X86/X86ISelLowering.cpp	Sat Dec 09 23:50:44 2006 +0300
@@ -54,10 +54,19 @@ X86TargetLowering::X86TargetLowering(Tar
   setShiftAmountFlavor(Mask);   // shl X, 32 == shl X, 0
   setStackPointerRegisterToSaveRestore(X86StackPtr);
 
-  if (!Subtarget->isTargetDarwin())
+  if (Subtarget->isTargetDarwin()) {
     // Darwin should use _setjmp/_longjmp instead of setjmp/longjmp.
-    setUseUnderscoreSetJmpLongJmp(true);
-
+    setUseUnderscoreSetJmp(false);
+    setUseUnderscoreLongJmp(false);
+  } else if (Subtarget->isTargetCygwin()) {
+    // MS runtime is weird: it exports _setjmp, but longjmp!
+    setUseUnderscoreSetJmp(true);
+    setUseUnderscoreLongJmp(false);
+  } else {
+    setUseUnderscoreSetJmp(true);
+    setUseUnderscoreLongJmp(true);
+  }
+  
   // Add legal addressing mode scale values.
   addLegalAddressScale(8);
   addLegalAddressScale(4);
_______________________________________________
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits

Reply via email to