From d27a258d2d7691db3731135a448b7654d260cc07 Mon Sep 17 00:00:00 2001 From: Anton Korobeynikov Date: Sun, 10 Dec 2006 23:12:42 +0000 Subject: [PATCH] Cleaned setjmp/longjmp lowering interfaces. Now we're producing right code (both asm & cbe) for Mingw32 target. Removed autoconf checks for underscored versions of setjmp/longjmp. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@32415 91177308-0d34-0410-b5e6-96231b3b80d8 --- autoconf/configure.ac | 2 +- include/llvm/Config/config.h.in | 6 --- include/llvm/Target/TargetLowering.h | 45 +++++++++++++------ lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp | 4 +- lib/CodeGen/SelectionDAG/TargetLowering.cpp | 3 +- lib/Target/CBackend/CBackend.cpp | 8 +--- lib/Target/CBackend/Writer.cpp | 8 +--- lib/Target/PowerPC/PPCISelLowering.cpp | 3 +- lib/Target/X86/X86ISelLowering.cpp | 15 +++++-- 9 files changed, 54 insertions(+), 40 deletions(-) diff --git a/autoconf/configure.ac b/autoconf/configure.ac index 040ef628f1e..3ca2e54a047 100644 --- a/autoconf/configure.ac +++ b/autoconf/configure.ac @@ -670,7 +670,7 @@ AC_CHECK_FUNCS([backtrace ceilf floorf roundf rintf nearbyintf getcwd ]) AC_CHECK_FUNCS([getpagesize getrusage gettimeofday isatty mkdtemp mkstemp ]) AC_CHECK_FUNCS([mktemp realpath sbrk setrlimit strdup strerror strerror_r ]) AC_CHECK_FUNCS([strtoll strtoq sysconf malloc_zone_statistics ]) -AC_CHECK_FUNCS([_setjmp _longjmp setjmp longjmp sigsetjmp siglongjmp]) +AC_CHECK_FUNCS([setjmp longjmp sigsetjmp siglongjmp]) AC_C_PRINTF_A AC_FUNC_ALLOCA AC_FUNC_RAND48 diff --git a/include/llvm/Config/config.h.in b/include/llvm/Config/config.h.in index 0068c5169c2..38aa75f1de5 100644 --- a/include/llvm/Config/config.h.in +++ b/include/llvm/Config/config.h.in @@ -416,12 +416,6 @@ /* Define to 1 if you have the header file. */ #undef HAVE_WINDOWS_H -/* Define to 1 if you have the `_longjmp' function. */ -#undef HAVE__LONGJMP - -/* Define to 1 if you have the `_setjmp' function. */ -#undef HAVE__SETJMP - /* Installation directory for binary executables */ #undef LLVM_BINDIR diff --git a/include/llvm/Target/TargetLowering.h b/include/llvm/Target/TargetLowering.h index 5ebed7a0062..cea70d11539 100644 --- a/include/llvm/Target/TargetLowering.h +++ b/include/llvm/Target/TargetLowering.h @@ -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 --git a/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp index cb408e18a3b..d4947a01fed 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp @@ -1974,10 +1974,10 @@ SelectionDAGLowering::visitIntrinsicCall(CallInst &I, unsigned Intrinsic) { 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 --git a/lib/CodeGen/SelectionDAG/TargetLowering.cpp b/lib/CodeGen/SelectionDAG/TargetLowering.cpp index 314941a3561..79e8013e4f5 100644 --- a/lib/CodeGen/SelectionDAG/TargetLowering.cpp +++ b/lib/CodeGen/SelectionDAG/TargetLowering.cpp @@ -47,7 +47,8 @@ TargetLowering::TargetLowering(TargetMachine &tm) sizeof(TargetDAGCombineArray)/sizeof(TargetDAGCombineArray[0])); maxStoresPerMemset = maxStoresPerMemcpy = maxStoresPerMemmove = 8; allowUnalignedMemoryAccesses = false; - UseUnderscoreSetJmpLongJmp = false; + UseUnderscoreSetJmp = false; + UseUnderscoreLongJmp = false; IntDivIsCheap = false; Pow2DivIsCheap = false; StackPointerRegisterToSaveRestore = 0; diff --git a/lib/Target/CBackend/CBackend.cpp b/lib/Target/CBackend/CBackend.cpp index 3cfd6d0386a..250ffc1fb50 100644 --- a/lib/Target/CBackend/CBackend.cpp +++ b/lib/Target/CBackend/CBackend.cpp @@ -1136,6 +1136,8 @@ static void generateCompilerSpecificCode(std::ostream& Out) { << "#elif defined(__APPLE__)\n" << "extern void *__builtin_alloca(unsigned long);\n" << "#define alloca(x) __builtin_alloca(x)\n" + << "#define longjmp _longjmp\n" + << "#define setjmp _setjmp\n" << "#elif defined(__sun__)\n" << "#if defined(__sparcv9)\n" << "extern void *__builtin_alloca(unsigned long);\n" @@ -2141,17 +2143,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 --git a/lib/Target/CBackend/Writer.cpp b/lib/Target/CBackend/Writer.cpp index 3cfd6d0386a..250ffc1fb50 100644 --- a/lib/Target/CBackend/Writer.cpp +++ b/lib/Target/CBackend/Writer.cpp @@ -1136,6 +1136,8 @@ static void generateCompilerSpecificCode(std::ostream& Out) { << "#elif defined(__APPLE__)\n" << "extern void *__builtin_alloca(unsigned long);\n" << "#define alloca(x) __builtin_alloca(x)\n" + << "#define longjmp _longjmp\n" + << "#define setjmp _setjmp\n" << "#elif defined(__sun__)\n" << "#if defined(__sparcv9)\n" << "extern void *__builtin_alloca(unsigned long);\n" @@ -2141,17 +2143,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 --git a/lib/Target/PowerPC/PPCISelLowering.cpp b/lib/Target/PowerPC/PPCISelLowering.cpp index bcdb1e1584f..438251735a4 100644 --- a/lib/Target/PowerPC/PPCISelLowering.cpp +++ b/lib/Target/PowerPC/PPCISelLowering.cpp @@ -41,7 +41,8 @@ PPCTargetLowering::PPCTargetLowering(PPCTargetMachine &TM) 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 --git a/lib/Target/X86/X86ISelLowering.cpp b/lib/Target/X86/X86ISelLowering.cpp index c139dd27e9b..5eaac0faeaf 100644 --- a/lib/Target/X86/X86ISelLowering.cpp +++ b/lib/Target/X86/X86ISelLowering.cpp @@ -54,10 +54,19 @@ X86TargetLowering::X86TargetLowering(TargetMachine &TM) 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); -- 2.34.1