diff options
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Support/APFloat.cpp | 74 | ||||
-rw-r--r-- | llvm/lib/Support/CrashRecoveryContext.cpp | 55 | ||||
-rw-r--r-- | llvm/lib/Support/Errno.cpp | 14 | ||||
-rw-r--r-- | llvm/lib/Support/Host.cpp | 24 | ||||
-rw-r--r-- | llvm/lib/Support/MathExtras.cpp | 6 | ||||
-rw-r--r-- | llvm/lib/Support/Mutex.cpp | 10 | ||||
-rw-r--r-- | llvm/lib/Support/RWMutex.cpp | 11 | ||||
-rw-r--r-- | llvm/lib/Support/SHA1.cpp | 15 | ||||
-rw-r--r-- | llvm/lib/Support/SearchForAddressOfSpecialSymbol.cpp | 12 | ||||
-rw-r--r-- | llvm/lib/Support/Unix/Path.inc | 41 | ||||
-rw-r--r-- | llvm/lib/Support/Unix/Process.inc | 36 | ||||
-rw-r--r-- | llvm/lib/Support/Unix/Program.inc | 29 | ||||
-rw-r--r-- | llvm/lib/Support/Unix/Signals.inc | 53 | ||||
-rw-r--r-- | llvm/lib/Support/Unix/ThreadLocal.inc | 12 | ||||
-rw-r--r-- | llvm/lib/Support/Unix/Unix.h | 8 | ||||
-rw-r--r-- | llvm/lib/Target/X86/X86ISelDAGToDAG.cpp | 71 |
16 files changed, 287 insertions, 184 deletions
diff --git a/llvm/lib/Support/APFloat.cpp b/llvm/lib/Support/APFloat.cpp index a8e14d6c08b..e2debfc5466 100644 --- a/llvm/lib/Support/APFloat.cpp +++ b/llvm/lib/Support/APFloat.cpp @@ -14,14 +14,19 @@ #include "llvm/ADT/APFloat.h" #include "llvm/ADT/APSInt.h" +#include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/FoldingSet.h" #include "llvm/ADT/Hashing.h" +#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/MathExtras.h" +#include <algorithm> +#include <cassert> +#include <cstdint> #include <cstring> -#include <limits.h> +#include <limits> using namespace llvm; @@ -93,18 +98,21 @@ namespace llvm { const unsigned int maxPowerOfFiveExponent = maxExponent + maxPrecision - 1; const unsigned int maxPowerOfFiveParts = 2 + ((maxPowerOfFiveExponent * 815) / (351 * integerPartWidth)); -} + +} // end namespace llvm + +namespace { /* A bunch of private, handy routines. */ -static inline unsigned int +inline unsigned int partCountForBits(unsigned int bits) { return ((bits) + integerPartWidth - 1) / integerPartWidth; } /* Returns 0U-9U. Return values >= 10U are not digits. */ -static inline unsigned int +inline unsigned int decDigitValue(unsigned int c) { return c - '0'; @@ -115,7 +123,7 @@ decDigitValue(unsigned int c) If the exponent overflows, returns a large exponent with the appropriate sign. */ -static int +int readExponent(StringRef::iterator begin, StringRef::iterator end) { bool isNegative; @@ -159,7 +167,7 @@ readExponent(StringRef::iterator begin, StringRef::iterator end) /* This is ugly and needs cleaning up, but I don't immediately see how whilst remaining safe. */ -static int +int totalExponent(StringRef::iterator p, StringRef::iterator end, int exponentAdjustment) { @@ -208,7 +216,7 @@ totalExponent(StringRef::iterator p, StringRef::iterator end, return exponent; } -static StringRef::iterator +StringRef::iterator skipLeadingZeroesAndAnyDot(StringRef::iterator begin, StringRef::iterator end, StringRef::iterator *dot) { @@ -249,7 +257,7 @@ struct decimalInfo { int normalizedExponent; }; -static void +void interpretDecimal(StringRef::iterator begin, StringRef::iterator end, decimalInfo *D) { @@ -308,7 +316,7 @@ interpretDecimal(StringRef::iterator begin, StringRef::iterator end, /* Return the trailing fraction of a hexadecimal number. DIGITVALUE is the first hex digit of the fraction, P points to the next digit. */ -static lostFraction +lostFraction trailingHexadecimalFraction(StringRef::iterator p, StringRef::iterator end, unsigned int digitValue) { @@ -339,7 +347,7 @@ trailingHexadecimalFraction(StringRef::iterator p, StringRef::iterator end, /* Return the fraction lost were a bignum truncated losing the least significant BITS bits. */ -static lostFraction +lostFraction lostFractionThroughTruncation(const integerPart *parts, unsigned int partCount, unsigned int bits) @@ -361,7 +369,7 @@ lostFractionThroughTruncation(const integerPart *parts, } /* Shift DST right BITS bits noting lost fraction. */ -static lostFraction +lostFraction shiftRight(integerPart *dst, unsigned int parts, unsigned int bits) { lostFraction lost_fraction; @@ -374,7 +382,7 @@ shiftRight(integerPart *dst, unsigned int parts, unsigned int bits) } /* Combine the effect of two lost fractions. */ -static lostFraction +lostFraction combineLostFractions(lostFraction moreSignificant, lostFraction lessSignificant) { @@ -395,7 +403,7 @@ combineLostFractions(lostFraction moreSignificant, See "How to Read Floating Point Numbers Accurately" by William D Clinger. */ -static unsigned int +unsigned int HUerrBound(bool inexactMultiply, unsigned int HUerr1, unsigned int HUerr2) { assert(HUerr1 < 2 || HUerr2 < 2 || (HUerr1 + HUerr2 < 8)); @@ -409,7 +417,7 @@ HUerrBound(bool inexactMultiply, unsigned int HUerr1, unsigned int HUerr2) /* The number of ulps from the boundary (zero, or half if ISNEAREST) when the least significant BITS are truncated. BITS cannot be zero. */ -static integerPart +integerPart ulpsFromBoundary(const integerPart *parts, unsigned int bits, bool isNearest) { unsigned int count, partBits; @@ -454,7 +462,7 @@ ulpsFromBoundary(const integerPart *parts, unsigned int bits, bool isNearest) /* Place pow(5, power) in DST, and return the number of parts used. DST must be at least one part larger than size of the answer. */ -static unsigned int +unsigned int powerOf5(integerPart *dst, unsigned int power) { static const integerPart firstEightPowers[] = { 1, 5, 25, 125, 625, 3125, @@ -517,17 +525,17 @@ powerOf5(integerPart *dst, unsigned int power) /* Zero at the end to avoid modular arithmetic when adding one; used when rounding up during hexadecimal output. */ -static const char hexDigitsLower[] = "0123456789abcdef0"; -static const char hexDigitsUpper[] = "0123456789ABCDEF0"; -static const char infinityL[] = "infinity"; -static const char infinityU[] = "INFINITY"; -static const char NaNL[] = "nan"; -static const char NaNU[] = "NAN"; +const char hexDigitsLower[] = "0123456789abcdef0"; +const char hexDigitsUpper[] = "0123456789ABCDEF0"; +const char infinityL[] = "infinity"; +const char infinityU[] = "INFINITY"; +const char NaNL[] = "nan"; +const char NaNU[] = "NAN"; /* Write out an integerPart in hexadecimal, starting with the most significant nibble. Write out exactly COUNT hexdigits, return COUNT. */ -static unsigned int +unsigned int partAsHex (char *dst, integerPart part, unsigned int count, const char *hexDigitChars) { @@ -545,7 +553,7 @@ partAsHex (char *dst, integerPart part, unsigned int count, } /* Write out an unsigned decimal integer. */ -static char * +char * writeUnsignedDecimal (char *dst, unsigned int n) { char buff[40], *p; @@ -563,7 +571,7 @@ writeUnsignedDecimal (char *dst, unsigned int n) } /* Write out a signed decimal integer. */ -static char * +char * writeSignedDecimal (char *dst, int value) { if (value < 0) { @@ -575,6 +583,8 @@ writeSignedDecimal (char *dst, int value) return dst; } +} // end anonymous namespace + /* Constructors. */ void APFloat::initialize(const fltSemantics *ourSemantics) @@ -852,11 +862,13 @@ APFloat::semanticsPrecision(const fltSemantics &semantics) { return semantics.precision; } + APFloat::ExponentType APFloat::semanticsMaxExponent(const fltSemantics &semantics) { return semantics.maxExponent; } + APFloat::ExponentType APFloat::semanticsMinExponent(const fltSemantics &semantics) { @@ -1907,7 +1919,6 @@ APFloat::opStatus APFloat::roundToIntegral(roundingMode rounding_mode) { return fs; } - /* Comparison requires normalized numbers. */ APFloat::cmpResult APFloat::compare(const APFloat &rhs) const @@ -2558,14 +2569,16 @@ APFloat::convertFromDecimalString(StringRef str, roundingMode rounding_mode) /* Check whether the normalized exponent is high enough to overflow max during the log-rebasing in the max-exponent check below. */ - } else if (D.normalizedExponent - 1 > INT_MAX / 42039) { + } else if (D.normalizedExponent - 1 > + std::numeric_limits<int>::max() / 42039) { fs = handleOverflow(rounding_mode); /* If it wasn't, then it also wasn't high enough to overflow max during the log-rebasing in the min-exponent check. Check that it won't overflow min in either check, then perform the min-exponent check. */ - } else if (D.normalizedExponent - 1 < INT_MIN / 42039 || + } else if ((D.normalizedExponent - 1 < + std::numeric_limits<int>::min() / 42039) || (D.normalizedExponent + 1) * 28738 <= 8651 * (semantics->minExponent - (int) semantics->precision)) { /* Underflow to zero and round. */ @@ -3219,7 +3232,7 @@ APFloat::initFromQuadrupleAPInt(const APInt &api) uint64_t mysignificand2 = i2 & 0xffffffffffffLL; initialize(&APFloat::IEEEquad); - assert(partCount()==2); + assert(partCount() == 2); sign = static_cast<unsigned int>(i2>>63); if (myexponent==0 && @@ -3485,6 +3498,7 @@ APFloat::APFloat(double d) { } namespace { + void append(SmallVectorImpl<char> &Buffer, StringRef Str) { Buffer.append(Str.begin(), Str.end()); } @@ -3521,7 +3535,6 @@ namespace { significand = significand.trunc(significand.getActiveBits()); } - void AdjustToPrecision(SmallVectorImpl<char> &buffer, int &exp, unsigned FormatPrecision) { unsigned N = buffer.size(); @@ -3566,7 +3579,8 @@ namespace { exp += FirstSignificant; buffer.erase(&buffer[0], &buffer[FirstSignificant]); } -} + +} // end anonymous namespace void APFloat::toString(SmallVectorImpl<char> &Str, unsigned FormatPrecision, diff --git a/llvm/lib/Support/CrashRecoveryContext.cpp b/llvm/lib/Support/CrashRecoveryContext.cpp index 98865f5e065..1c5e8d93934 100644 --- a/llvm/lib/Support/CrashRecoveryContext.cpp +++ b/llvm/lib/Support/CrashRecoveryContext.cpp @@ -8,19 +8,23 @@ //===----------------------------------------------------------------------===// #include "llvm/Support/CrashRecoveryContext.h" +#include "llvm/ADT/STLExtras.h" #include "llvm/Config/config.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/ManagedStatic.h" #include "llvm/Support/Mutex.h" #include "llvm/Support/ThreadLocal.h" -#include <setjmp.h> +#include "llvm/Support/Threading.h" +#include <cassert> +#include <csetjmp> + using namespace llvm; namespace { struct CrashRecoveryContextImpl; -static ManagedStatic< +ManagedStatic< sys::ThreadLocal<const CrashRecoveryContextImpl> > CurrentContext; struct CrashRecoveryContextImpl { @@ -42,6 +46,7 @@ public: Next = CurrentContext->get(); CurrentContext->set(this); } + ~CrashRecoveryContextImpl() { if (!SwitchedThread) CurrentContext->set(Next); @@ -70,14 +75,14 @@ public: } }; -} +ManagedStatic<sys::Mutex> gCrashRecoveryContextMutex; +bool gCrashRecoveryEnabled = false; -static ManagedStatic<sys::Mutex> gCrashRecoveryContextMutex; -static bool gCrashRecoveryEnabled = false; - -static ManagedStatic<sys::ThreadLocal<const CrashRecoveryContext>> +ManagedStatic<sys::ThreadLocal<const CrashRecoveryContext>> tlIsRecoveringFromCrash; +} // end anonymous namespace + CrashRecoveryContextCleanup::~CrashRecoveryContextCleanup() {} CrashRecoveryContext::~CrashRecoveryContext() { @@ -162,7 +167,9 @@ CrashRecoveryContext::unregisterCleanup(CrashRecoveryContextCleanup *cleanup) { // SetUnhandledExceptionFilter API, but there's a risk of that // being entirely overwritten (it's not a chain). -static LONG CALLBACK ExceptionHandler(PEXCEPTION_POINTERS ExceptionInfo) +namespace { + +LONG CALLBACK ExceptionHandler(PEXCEPTION_POINTERS ExceptionInfo) { // Lookup the current thread local recovery object. const CrashRecoveryContextImpl *CRCI = CurrentContext->get(); @@ -190,7 +197,9 @@ static LONG CALLBACK ExceptionHandler(PEXCEPTION_POINTERS ExceptionInfo) // CrashRecoveryContext at all. So we make use of a thread-local // exception table. The handles contained in here will either be // non-NULL, valid VEH handles, or NULL. -static sys::ThreadLocal<const void> sCurrentExceptionHandle; +sys::ThreadLocal<const void> sCurrentExceptionHandle; + +} // end anonymous namespace void CrashRecoveryContext::Enable() { sys::ScopedLock L(*gCrashRecoveryContextMutex); @@ -239,14 +248,15 @@ void CrashRecoveryContext::Disable() { // reliable fashion -- if we get a signal outside of a crash recovery context we // simply disable crash recovery and raise the signal again. -#include <signal.h> +#include <csignal> -static const int Signals[] = - { SIGABRT, SIGBUS, SIGFPE, SIGILL, SIGSEGV, SIGTRAP }; -static const unsigned NumSignals = array_lengthof(Signals); -static struct sigaction PrevActions[NumSignals]; +namespace { -static void CrashRecoverySignalHandler(int Signal) { +const int Signals[] = { SIGABRT, SIGBUS, SIGFPE, SIGILL, SIGSEGV, SIGTRAP }; +const unsigned NumSignals = array_lengthof(Signals); +struct sigaction PrevActions[NumSignals]; + +void CrashRecoverySignalHandler(int Signal) { // Lookup the current thread local recovery object. const CrashRecoveryContextImpl *CRCI = CurrentContext->get(); @@ -278,6 +288,8 @@ static void CrashRecoverySignalHandler(int Signal) { const_cast<CrashRecoveryContextImpl*>(CRCI)->HandleCrash(); } +} // end anonymous namespace + void CrashRecoveryContext::Enable() { sys::ScopedLock L(*gCrashRecoveryContextMutex); @@ -334,14 +346,16 @@ void CrashRecoveryContext::HandleCrash() { CRCI->HandleCrash(); } +namespace { + // FIXME: Portability. -static void setThreadBackgroundPriority() { +void setThreadBackgroundPriority() { #ifdef __APPLE__ setpriority(PRIO_DARWIN_THREAD, 0, PRIO_DARWIN_BG); #endif } -static bool hasThreadBackgroundPriority() { +bool hasThreadBackgroundPriority() { #ifdef __APPLE__ return getpriority(PRIO_DARWIN_THREAD, 0) == 1; #else @@ -349,16 +363,14 @@ static bool hasThreadBackgroundPriority() { #endif } -namespace { struct RunSafelyOnThreadInfo { function_ref<void()> Fn; CrashRecoveryContext *CRC; bool UseBackgroundPriority; bool Result; }; -} -static void RunSafelyOnThread_Dispatch(void *UserData) { +void RunSafelyOnThread_Dispatch(void *UserData) { RunSafelyOnThreadInfo *Info = reinterpret_cast<RunSafelyOnThreadInfo*>(UserData); @@ -367,6 +379,9 @@ static void RunSafelyOnThread_Dispatch(void *UserData) { Info->Result = Info->CRC->RunSafely(Info->Fn); } + +} // end anonymous namespace + bool CrashRecoveryContext::RunSafelyOnThread(function_ref<void()> Fn, unsigned RequestedStackSize) { bool UseBackgroundPriority = hasThreadBackgroundPriority(); diff --git a/llvm/lib/Support/Errno.cpp b/llvm/lib/Support/Errno.cpp index 3ba2a1277d0..888887cb938 100644 --- a/llvm/lib/Support/Errno.cpp +++ b/llvm/lib/Support/Errno.cpp @@ -14,11 +14,9 @@ #include "llvm/Support/Errno.h" #include "llvm/Config/config.h" // Get autoconf configuration settings #include "llvm/Support/raw_ostream.h" -#include <string.h> - -#if HAVE_ERRNO_H -#include <errno.h> -#endif +#include <cerrno> +#include <cstring> +#include <string> //===----------------------------------------------------------------------===// //=== WARNING: Implementation here must contain only TRULY operating system @@ -32,7 +30,7 @@ namespace sys { std::string StrError() { return StrError(errno); } -#endif // HAVE_ERRNO_H +#endif // HAVE_ERRNO_H std::string StrError(int errnum) { std::string str; @@ -72,5 +70,5 @@ std::string StrError(int errnum) { return str; } -} // namespace sys -} // namespace llvm +} // namespace sys +} // namespace llvm diff --git a/llvm/lib/Support/Host.cpp b/llvm/lib/Support/Host.cpp index 1ca8eac7184..5962e5ee1df 100644 --- a/llvm/lib/Support/Host.cpp +++ b/llvm/lib/Support/Host.cpp @@ -19,8 +19,8 @@ #include "llvm/Config/config.h" #include "llvm/Support/Debug.h" #include "llvm/Support/FileSystem.h" -#include "llvm/Support/raw_ostream.h" -#include <string.h> +#include <cstring> +#include <string> // Include the platform-specific parts of this class. #ifdef LLVM_ON_UNIX @@ -49,8 +49,10 @@ using namespace llvm; +namespace { + #if defined(__linux__) -static ssize_t LLVM_ATTRIBUTE_UNUSED readCpuInfo(void *Buf, size_t Size) { +ssize_t LLVM_ATTRIBUTE_UNUSED readCpuInfo(void *Buf, size_t Size) { // Note: We cannot mmap /proc/cpuinfo here and then process the resulting // memory buffer because the 'file' has 0 size (it can be read from only // as a stream). @@ -74,8 +76,8 @@ static ssize_t LLVM_ATTRIBUTE_UNUSED readCpuInfo(void *Buf, size_t Size) { /// GetX86CpuIDAndInfo - Execute the specified cpuid and return the 4 values in the /// specified arguments. If we can't run cpuid on the host, return true. -static bool GetX86CpuIDAndInfo(unsigned value, unsigned *rEAX, unsigned *rEBX, - unsigned *rECX, unsigned *rEDX) { +bool GetX86CpuIDAndInfo(unsigned value, unsigned *rEAX, unsigned *rEBX, + unsigned *rECX, unsigned *rEDX) { #if defined(__GNUC__) || defined(__clang__) #if defined(__x86_64__) || defined(_M_AMD64) || defined (_M_X64) // gcc doesn't know cpuid would clobber ebx/rbx. Preseve it manually. @@ -120,9 +122,8 @@ static bool GetX86CpuIDAndInfo(unsigned value, unsigned *rEAX, unsigned *rEBX, /// GetX86CpuIDAndInfoEx - Execute the specified cpuid with subleaf and return the /// 4 values in the specified arguments. If we can't run cpuid on the host, /// return true. -static bool GetX86CpuIDAndInfoEx(unsigned value, unsigned subleaf, - unsigned *rEAX, unsigned *rEBX, unsigned *rECX, - unsigned *rEDX) { +bool GetX86CpuIDAndInfoEx(unsigned value, unsigned subleaf, unsigned *rEAX, + unsigned *rEBX, unsigned *rECX, unsigned *rEDX) { #if defined(__x86_64__) || defined(_M_AMD64) || defined (_M_X64) #if defined(__GNUC__) // gcc doesn't know cpuid would clobber ebx/rbx. Preseve it manually. @@ -182,7 +183,7 @@ static bool GetX86CpuIDAndInfoEx(unsigned value, unsigned subleaf, #endif } -static bool GetX86XCR0(unsigned *rEAX, unsigned *rEDX) { +bool GetX86XCR0(unsigned *rEAX, unsigned *rEDX) { #if defined(__GNUC__) // Check xgetbv; this uses a .byte sequence instead of the instruction // directly because older assemblers do not include support for xgetbv and @@ -199,8 +200,7 @@ static bool GetX86XCR0(unsigned *rEAX, unsigned *rEDX) { #endif } -static void DetectX86FamilyModel(unsigned EAX, unsigned &Family, - unsigned &Model) { +void DetectX86FamilyModel(unsigned EAX, unsigned &Family, unsigned &Model) { Family = (EAX >> 8) & 0xf; // Bits 8 - 11 Model = (EAX >> 4) & 0xf; // Bits 4 - 7 if (Family == 6 || Family == 0xf) { @@ -212,6 +212,8 @@ static void DetectX86FamilyModel(unsigned EAX, unsigned &Family, } } +} // end anonymous namespace + StringRef sys::getHostCPUName() { unsigned EAX = 0, EBX = 0, ECX = 0, EDX = 0; if (GetX86CpuIDAndInfo(0x1, &EAX, &EBX, &ECX, &EDX)) diff --git a/llvm/lib/Support/MathExtras.cpp b/llvm/lib/Support/MathExtras.cpp index ba0924540ce..6b9d048f636 100644 --- a/llvm/lib/Support/MathExtras.cpp +++ b/llvm/lib/Support/MathExtras.cpp @@ -1,4 +1,4 @@ -//===-- MathExtras.cpp - Implement the MathExtras header --------------===// +//===-- MathExtras.cpp - Implement the MathExtras header ------------------===// // // The LLVM Compiler Infrastructure // @@ -16,7 +16,7 @@ #ifdef _MSC_VER #include <limits> #else -#include <math.h> +#include <cmath> #endif namespace llvm { @@ -29,4 +29,4 @@ namespace llvm { const float huge_valf = HUGE_VALF; #endif -} +} // end namespace llvm diff --git a/llvm/lib/Support/Mutex.cpp b/llvm/lib/Support/Mutex.cpp index c8d3844d0c9..db30c73de51 100644 --- a/llvm/lib/Support/Mutex.cpp +++ b/llvm/lib/Support/Mutex.cpp @@ -22,22 +22,26 @@ #if !defined(LLVM_ENABLE_THREADS) || LLVM_ENABLE_THREADS == 0 // Define all methods as no-ops if threading is explicitly disabled namespace llvm { + using namespace sys; + MutexImpl::MutexImpl( bool recursive) { } MutexImpl::~MutexImpl() { } bool MutexImpl::acquire() { return true; } bool MutexImpl::release() { return true; } bool MutexImpl::tryacquire() { return true; } -} + +} // end namespace llvm #else #if defined(HAVE_PTHREAD_H) && defined(HAVE_PTHREAD_MUTEX_LOCK) #include <cassert> +#include <cstdlib> #include <pthread.h> -#include <stdlib.h> namespace llvm { + using namespace sys; // Construct a Mutex using pthread calls @@ -110,7 +114,7 @@ MutexImpl::tryacquire() return errorcode == 0; } -} +} // end namespace llvm #elif defined(LLVM_ON_UNIX) #include "Unix/Mutex.inc" diff --git a/llvm/lib/Support/RWMutex.cpp b/llvm/lib/Support/RWMutex.cpp index 3b6309cef21..2a3239a22b2 100644 --- a/llvm/lib/Support/RWMutex.cpp +++ b/llvm/lib/Support/RWMutex.cpp @@ -13,7 +13,6 @@ #include "llvm/Config/config.h" #include "llvm/Support/RWMutex.h" -#include <cstring> //===----------------------------------------------------------------------===// //=== WARNING: Implementation here must contain only TRULY operating system @@ -23,23 +22,27 @@ #if !defined(LLVM_ENABLE_THREADS) || LLVM_ENABLE_THREADS == 0 // Define all methods as no-ops if threading is explicitly disabled namespace llvm { + using namespace sys; + RWMutexImpl::RWMutexImpl() { } RWMutexImpl::~RWMutexImpl() { } bool RWMutexImpl::reader_acquire() { return true; } bool RWMutexImpl::reader_release() { return true; } bool RWMutexImpl::writer_acquire() { return true; } bool RWMutexImpl::writer_release() { return true; } -} + +} // end namespace llvm #else #if defined(HAVE_PTHREAD_H) && defined(HAVE_PTHREAD_RWLOCK_INIT) #include <cassert> +#include <cstdlib> #include <pthread.h> -#include <stdlib.h> namespace llvm { + using namespace sys; // Construct a RWMutex using pthread calls @@ -113,7 +116,7 @@ RWMutexImpl::writer_release() return errorcode == 0; } -} +} // end namespace llvm #elif defined(LLVM_ON_UNIX) #include "Unix/RWMutex.inc" diff --git a/llvm/lib/Support/SHA1.cpp b/llvm/lib/Support/SHA1.cpp index 980c3bbffac..5ff2eed34c4 100644 --- a/llvm/lib/Support/SHA1.cpp +++ b/llvm/lib/Support/SHA1.cpp @@ -1,4 +1,4 @@ -//======- SHA1.h - Private copy of the SHA1 implementation ---*- C++ -* ======// +//===--- SHA1.h - Private copy of the SHA1 implementation -------*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -13,12 +13,13 @@ // //===----------------------------------------------------------------------===// +#include "llvm/ADT/StringRef.h" #include "llvm/Support/Host.h" #include "llvm/Support/SHA1.h" -using namespace llvm; -#include <stdint.h> -#include <string.h> +#include <cstring> + +using namespace llvm; #if defined(BYTE_ORDER) && defined(BIG_ENDIAN) && BYTE_ORDER == BIG_ENDIAN #define SHA_BIG_ENDIAN @@ -46,10 +47,14 @@ void SHA1::init() { InternalState.BufferOffset = 0; } -static uint32_t rol32(uint32_t number, uint8_t bits) { +namespace { + +uint32_t rol32(uint32_t number, uint8_t bits) { return ((number << bits) | (number >> (32 - bits))); } +} // end anonymous namespace + void SHA1::hashBlock() { uint8_t i; uint32_t a, b, c, d, e, t; diff --git a/llvm/lib/Support/SearchForAddressOfSpecialSymbol.cpp b/llvm/lib/Support/SearchForAddressOfSpecialSymbol.cpp index 55f3320f640..711760b2479 100644 --- a/llvm/lib/Support/SearchForAddressOfSpecialSymbol.cpp +++ b/llvm/lib/Support/SearchForAddressOfSpecialSymbol.cpp @@ -14,10 +14,12 @@ // //===----------------------------------------------------------------------===// -#include <string.h> +#include <cstring> + +namespace { // Must declare the symbols in the global namespace. -static void *DoSearch(const char* symbolName) { +void *DoSearch(const char* symbolName) { #define EXPLICIT_SYMBOL(SYM) \ extern void *SYM; if (!strcmp(symbolName, #SYM)) return &SYM @@ -51,8 +53,12 @@ static void *DoSearch(const char* symbolName) { return nullptr; } +} // end anonymous namespace + namespace llvm { + void *SearchForAddressOfSpecialSymbol(const char* symbolName) { return DoSearch(symbolName); } -} // namespace llvm + +} // end namespace llvm diff --git a/llvm/lib/Support/Unix/Path.inc b/llvm/lib/Support/Unix/Path.inc index 3cedf64d4b0..8d1dfc76aea 100644 --- a/llvm/lib/Support/Unix/Path.inc +++ b/llvm/lib/Support/Unix/Path.inc @@ -17,8 +17,9 @@ //===----------------------------------------------------------------------===// #include "Unix.h" -#include <limits.h> -#include <stdio.h> +#include <cassert> +#include <climits> +#include <cstdio> #if HAVE_SYS_STAT_H #include <sys/stat.h> #endif @@ -86,7 +87,10 @@ namespace fs { #if defined(__FreeBSD__) || defined (__NetBSD__) || defined(__Bitrig__) || \ defined(__OpenBSD__) || defined(__minix) || defined(__FreeBSD_kernel__) || \ defined(__linux__) || defined(__CYGWIN__) || defined(__DragonFly__) -static int + +namespace { + +int test_dir(char ret[PATH_MAX], const char *dir, const char *bin) { struct stat sb; @@ -101,7 +105,7 @@ test_dir(char ret[PATH_MAX], const char *dir, const char *bin) return 0; } -static char * +char * getprogpath(char ret[PATH_MAX], const char *bin) { char *pv, *s, *t; @@ -138,6 +142,9 @@ getprogpath(char ret[PATH_MAX], const char *bin) free(pv); return nullptr; } + +} // end anonymous namespace + #endif // __FreeBSD__ || __NetBSD__ || __FreeBSD_kernel__ /// GetMainExecutable - Return the path to the main executable, given the @@ -330,7 +337,9 @@ std::error_code resize_file(int FD, uint64_t Size) { return std::error_code(); } -static int convertAccessMode(AccessMode Mode) { +namespace { + +int convertAccessMode(AccessMode Mode) { switch (Mode) { case AccessMode::Exist: return F_OK; @@ -342,6 +351,8 @@ static int convertAccessMode(AccessMode Mode) { llvm_unreachable("invalid enum"); } +} // end anonymous namespace + std::error_code access(const Twine &Path, AccessMode Mode) { SmallString<128> PathStorage; StringRef P = Path.toNullTerminatedStringRef(PathStorage); @@ -381,8 +392,10 @@ std::error_code equivalent(const Twine &A, const Twine &B, bool &result) { return std::error_code(); } -static std::error_code fillStatus(int StatRet, const struct stat &Status, - file_status &Result) { +namespace { + +std::error_code fillStatus(int StatRet, const struct stat &Status, + file_status &Result) { if (StatRet != 0) { std::error_code ec(errno, std::generic_category()); if (ec == errc::no_such_file_or_directory) @@ -416,6 +429,8 @@ static std::error_code fillStatus(int StatRet, const struct stat &Status, return std::error_code(); } +} // end anonymous namespace + std::error_code status(const Twine &Path, file_status &Result) { SmallString<128> PathStorage; StringRef P = Path.toNullTerminatedStringRef(PathStorage); @@ -597,7 +612,9 @@ bool home_directory(SmallVectorImpl<char> &result) { return false; } -static bool getDarwinConfDir(bool TempDir, SmallVectorImpl<char> &Result) { +namespace { + +bool getDarwinConfDir(bool TempDir, SmallVectorImpl<char> &Result) { #if defined(_CS_DARWIN_USER_TEMP_DIR) && defined(_CS_DARWIN_USER_CACHE_DIR) // On Darwin, use DARWIN_USER_TEMP_DIR or DARWIN_USER_CACHE_DIR. // macros defined in <unistd.h> on darwin >= 9 @@ -622,7 +639,7 @@ static bool getDarwinConfDir(bool TempDir, SmallVectorImpl<char> &Result) { return false; } -static bool getUserCacheDir(SmallVectorImpl<char> &Result) { +bool getUserCacheDir(SmallVectorImpl<char> &Result) { // First try using XDG_CACHE_HOME env variable, // as specified in XDG Base Directory Specification at // http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html @@ -645,7 +662,7 @@ static bool getUserCacheDir(SmallVectorImpl<char> &Result) { return false; } -static const char *getEnvTempDir() { +const char *getEnvTempDir() { // Check whether the temporary directory is specified by an environment // variable. const char *EnvironmentVariables[] = {"TMPDIR", "TMP", "TEMP", "TEMPDIR"}; @@ -657,7 +674,7 @@ static const char *getEnvTempDir() { return nullptr; } -static const char *getDefaultTempDir(bool ErasedOnReboot) { +const char *getDefaultTempDir(bool ErasedOnReboot) { #ifdef P_tmpdir if ((bool)P_tmpdir) return P_tmpdir; @@ -668,6 +685,8 @@ static const char *getDefaultTempDir(bool ErasedOnReboot) { return "/var/tmp"; } +} // end anonymous namespace + void system_temp_directory(bool ErasedOnReboot, SmallVectorImpl<char> &Result) { Result.clear(); diff --git a/llvm/lib/Support/Unix/Process.inc b/llvm/lib/Support/Unix/Process.inc index cad81f8074f..350b145c28c 100644 --- a/llvm/lib/Support/Unix/Process.inc +++ b/llvm/lib/Support/Unix/Process.inc @@ -30,9 +30,7 @@ #ifdef HAVE_SYS_STAT_H #include <sys/stat.h> #endif -#if HAVE_SIGNAL_H -#include <signal.h> -#endif +#include <csignal> // DragonFlyBSD, OpenBSD, and Bitrig have deprecated <malloc.h> for // <stdlib.h> instead. Unix.h includes this for us already. #if defined(HAVE_MALLOC_H) && !defined(__DragonFly__) && \ @@ -60,7 +58,9 @@ using namespace llvm; using namespace sys; -static std::pair<TimeValue, TimeValue> getRUsageTimes() { +namespace { + +std::pair<TimeValue, TimeValue> getRUsageTimes() { #if defined(HAVE_GETRUSAGE) struct rusage RU; ::getrusage(RUSAGE_SELF, &RU); @@ -79,6 +79,8 @@ static std::pair<TimeValue, TimeValue> getRUsageTimes() { #endif } +} // end anonymous namespace + // On Cygwin, getpagesize() returns 64k(AllocationGranularity) and // offset in mmap(3) should be aligned to the AllocationGranularity. unsigned Process::getPageSize() { @@ -189,6 +191,7 @@ Process::GetArgumentVector(SmallVectorImpl<const char *> &ArgsOut, } namespace { + class FDCloser { public: FDCloser(int &FD) : FD(FD), KeepOpen(false) {} @@ -205,7 +208,8 @@ private: int &FD; bool KeepOpen; }; -} + +} // end anonymous namespace std::error_code Process::FixupStandardFileDescriptors() { int NullFD = -1; @@ -300,7 +304,9 @@ bool Process::FileDescriptorIsDisplayed(int fd) { #endif } -static unsigned getColumns(int FileID) { +namespace { + +unsigned getColumns(int FileID) { // If COLUMNS is defined in the environment, wrap to that many columns. if (const char *ColumnsStr = std::getenv("COLUMNS")) { int Columns = std::atoi(ColumnsStr); @@ -320,6 +326,8 @@ static unsigned getColumns(int FileID) { return Columns; } +} // end anonymous namespace + unsigned Process::StandardOutColumns() { if (!StandardOutIsDisplayed()) return 0; @@ -344,11 +352,13 @@ extern "C" int del_curterm(struct term *termp); extern "C" int tigetnum(char *capname); #endif +namespace { + #ifdef HAVE_TERMINFO -static ManagedStatic<sys::Mutex> TermColorMutex; +ManagedStatic<sys::Mutex> TermColorMutex; #endif -static bool terminalHasColors(int fd) { +bool terminalHasColors(int fd) { #ifdef HAVE_TERMINFO // First, acquire a global lock because these C routines are thread hostile. MutexGuard G(*TermColorMutex); @@ -388,6 +398,8 @@ static bool terminalHasColors(int fd) { return false; } +} // end anonymous namespace + bool Process::FileDescriptorHasColors(int fd) { // A file descriptor has colors if it is displayed and the terminal has // colors. @@ -428,7 +440,10 @@ const char *Process::ResetColor() { } #if !defined(HAVE_DECL_ARC4RANDOM) || !HAVE_DECL_ARC4RANDOM -static unsigned GetRandomNumberSeed() { + +namespace { + +unsigned GetRandomNumberSeed() { // Attempt to get the initial seed from /dev/urandom, if possible. int urandomFD = open("/dev/urandom", O_RDONLY); @@ -450,6 +465,9 @@ static unsigned GetRandomNumberSeed() { TimeValue Now = TimeValue::now(); return hash_combine(Now.seconds(), Now.nanoseconds(), ::getpid()); } + +} // end anonymous namespace + #endif unsigned llvm::sys::Process::GetRandomNumber() { diff --git a/llvm/lib/Support/Unix/Program.inc b/llvm/lib/Support/Unix/Program.inc index 7d3537e2072..ee7df0a86b8 100644 --- a/llvm/lib/Support/Unix/Program.inc +++ b/llvm/lib/Support/Unix/Program.inc @@ -1,4 +1,4 @@ -//===- llvm/Support/Unix/Program.cpp -----------------------------*- C++ -*-===// +//===- llvm/Support/Unix/Program.cpp ----------------------------*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -30,9 +30,7 @@ #if HAVE_SYS_RESOURCE_H #include <sys/resource.h> #endif -#if HAVE_SIGNAL_H -#include <signal.h> -#endif +#include <csignal> #if HAVE_FCNTL_H #include <fcntl.h> #endif @@ -96,7 +94,9 @@ ErrorOr<std::string> sys::findProgramByName(StringRef Name, return errc::no_such_file_or_directory; } -static bool RedirectIO(const StringRef *Path, int FD, std::string* ErrMsg) { +namespace { + +bool RedirectIO(const StringRef *Path, int FD, std::string* ErrMsg) { if (!Path) // Noop return false; std::string File; @@ -125,8 +125,8 @@ static bool RedirectIO(const StringRef *Path, int FD, std::string* ErrMsg) { } #ifdef HAVE_POSIX_SPAWN -static bool RedirectIO_PS(const std::string *Path, int FD, std::string *ErrMsg, - posix_spawn_file_actions_t *FileActions) { +bool RedirectIO_PS(const std::string *Path, int FD, std::string *ErrMsg, + posix_spawn_file_actions_t *FileActions) { if (!Path) // Noop return false; const char *File; @@ -144,10 +144,10 @@ static bool RedirectIO_PS(const std::string *Path, int FD, std::string *ErrMsg, } #endif -static void TimeOutHandler(int Sig) { +void TimeOutHandler(int Sig) { } -static void SetMemoryLimits (unsigned size) +void SetMemoryLimits (unsigned size) { #if HAVE_SYS_RESOURCE_H && HAVE_GETRLIMIT && HAVE_SETRLIMIT struct rlimit r; @@ -176,7 +176,9 @@ static void SetMemoryLimits (unsigned size) #endif } -} +} // end anonymous namespace + +} // end namespace llvm static bool Execute(ProcessInfo &PI, StringRef Program, const char **args, const char **envp, const StringRef **redirects, @@ -419,12 +421,12 @@ ProcessInfo sys::Wait(const ProcessInfo &PI, unsigned SecondsToWait, return WaitResult; } - std::error_code sys::ChangeStdinToBinary(){ +std::error_code sys::ChangeStdinToBinary() { // Do nothing, as Unix doesn't differentiate between text and binary. return std::error_code(); } - std::error_code sys::ChangeStdoutToBinary(){ +std::error_code sys::ChangeStdoutToBinary() { // Do nothing, as Unix doesn't differentiate between text and binary. return std::error_code(); } @@ -466,4 +468,5 @@ bool llvm::sys::commandLineFitsWithinSystemLimits(StringRef Program, ArrayRef<co } return true; } -} + +} // end namespace llvm diff --git a/llvm/lib/Support/Unix/Signals.inc b/llvm/lib/Support/Unix/Signals.inc index 061cdb3da21..8be91cd5fb8 100644 --- a/llvm/lib/Support/Unix/Signals.inc +++ b/llvm/lib/Support/Unix/Signals.inc @@ -1,4 +1,4 @@ -//===- Signals.cpp - Generic Unix Signals Implementation -----*- C++ -*-===// +//===- Signals.cpp - Generic Unix Signals Implementation --------*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -27,9 +27,7 @@ #if HAVE_EXECINFO_H # include <execinfo.h> // For backtrace(). #endif -#if HAVE_SIGNAL_H -#include <signal.h> -#endif +#include <csignal> #if HAVE_SYS_STAT_H #include <sys/stat.h> #endif @@ -48,25 +46,27 @@ using namespace llvm; -static RETSIGTYPE SignalHandler(int Sig); // defined below. +namespace { + +RETSIGTYPE SignalHandler(int Sig); // defined below. -static ManagedStatic<SmartMutex<true> > SignalsMutex; +ManagedStatic<SmartMutex<true> > SignalsMutex; /// InterruptFunction - The function to call if ctrl-c is pressed. -static void (*InterruptFunction)() = nullptr; +void (*InterruptFunction)() = nullptr; -static ManagedStatic<std::vector<std::string>> FilesToRemove; +ManagedStatic<std::vector<std::string>> FilesToRemove; // IntSigs - Signals that represent requested termination. There's no bug // or failure, or if there is, it's not our direct responsibility. For whatever // reason, our continued execution is no longer desirable. -static const int IntSigs[] = { +const int IntSigs[] = { SIGHUP, SIGINT, SIGPIPE, SIGTERM, SIGUSR1, SIGUSR2 }; // KillSigs - Signals that represent that we have a bug, and our prompt // termination has been ordered. -static const int KillSigs[] = { +const int KillSigs[] = { SIGILL, SIGTRAP, SIGABRT, SIGFPE, SIGBUS, SIGSEGV, SIGQUIT #ifdef SIGSYS , SIGSYS @@ -82,14 +82,13 @@ static const int KillSigs[] = { #endif }; -static unsigned NumRegisteredSignals = 0; -static struct { +unsigned NumRegisteredSignals = 0; +struct { struct sigaction SA; int SigNo; } RegisteredSignalInfo[array_lengthof(IntSigs) + array_lengthof(KillSigs)]; - -static void RegisterHandler(int Signal) { +void RegisterHandler(int Signal) { assert(NumRegisteredSignals < array_lengthof(RegisteredSignalInfo) && "Out of space for signal handlers!"); @@ -106,7 +105,7 @@ static void RegisterHandler(int Signal) { ++NumRegisteredSignals; } -static void RegisterHandlers() { +void RegisterHandlers() { // We need to dereference the signals mutex during handler registration so // that we force its construction. This is to prevent the first use being // during handling an actual signal because you can't safely call new in a @@ -120,7 +119,7 @@ static void RegisterHandlers() { for (auto S : KillSigs) RegisterHandler(S); } -static void UnregisterHandlers() { +void UnregisterHandlers() { // Restore all of the signal handlers to how they were before we showed up. for (unsigned i = 0, e = NumRegisteredSignals; i != e; ++i) sigaction(RegisteredSignalInfo[i].SigNo, @@ -128,12 +127,11 @@ static void UnregisterHandlers() { NumRegisteredSignals = 0; } - /// RemoveFilesToRemove - Process the FilesToRemove list. This function /// should be called with the SignalsMutex lock held. /// NB: This must be an async signal safe function. It cannot allocate or free /// memory, even in debug builds. -static void RemoveFilesToRemove() { +void RemoveFilesToRemove() { // Avoid constructing ManagedStatic in the signal handler. // If FilesToRemove is not constructed, there are no files to remove. if (!FilesToRemove.isConstructed()) @@ -164,7 +162,7 @@ static void RemoveFilesToRemove() { } // SignalHandler - The signal handler that runs. -static RETSIGTYPE SignalHandler(int Sig) { +RETSIGTYPE SignalHandler(int Sig) { // Restore the signal behavior to default, so that the program actually // crashes when we return and the signal reissues. This also ensures that if // we crash in our signal handler that the program will terminate immediately @@ -209,6 +207,8 @@ static RETSIGTYPE SignalHandler(int Sig) { #endif } +} // end anonymous namespace + void llvm::sys::RunInterruptHandlers() { sys::SmartScopedLock<true> Guard(*SignalsMutex); RemoveFilesToRemove(); @@ -264,7 +264,9 @@ struct DlIteratePhdrData { const char *main_exec_name; }; -static int dl_iterate_phdr_cb(dl_phdr_info *info, size_t size, void *arg) { +namespace { + +int dl_iterate_phdr_cb(dl_phdr_info *info, size_t size, void *arg) { DlIteratePhdrData *data = (DlIteratePhdrData*)arg; const char *name = data->first ? data->main_exec_name : info->dlpi_name; data->first = false; @@ -287,6 +289,8 @@ static int dl_iterate_phdr_cb(dl_phdr_info *info, size_t size, void *arg) { return 0; } +} // end anonymous namespace + /// If this is an ELF platform, we can find all loaded modules and their virtual /// addresses with dl_iterate_phdr. static bool findModulesAndOffsets(void **StackTrace, int Depth, @@ -375,10 +379,14 @@ void llvm::sys::PrintStackTrace(raw_ostream &OS) { #endif } -static void PrintStackTraceSignalHandler(void *) { +namespace { + +void PrintStackTraceSignalHandler(void *) { PrintStackTrace(llvm::errs()); } +} // end anonymous namespace + void llvm::sys::DisableSystemDialogsOnCrash() {} /// PrintStackTraceOnErrorSignal - When an error signal (such as SIGABRT or @@ -403,9 +411,6 @@ void llvm::sys::PrintStackTraceOnErrorSignal(bool DisableCrashReporting) { #endif } - -/***/ - // On Darwin, raise sends a signal to the main thread instead of the current // thread. This has the unfortunate effect that assert() and abort() will end up // bypassing our crash recovery attempts. We work around this for anything in diff --git a/llvm/lib/Support/Unix/ThreadLocal.inc b/llvm/lib/Support/Unix/ThreadLocal.inc index 31c3f3835b2..78c694c908d 100644 --- a/llvm/lib/Support/Unix/ThreadLocal.inc +++ b/llvm/lib/Support/Unix/ThreadLocal.inc @@ -19,10 +19,11 @@ #if defined(HAVE_PTHREAD_H) && defined(HAVE_PTHREAD_GETSPECIFIC) #include <cassert> +#include <cstdlib> #include <pthread.h> -#include <stdlib.h> namespace llvm { + using namespace sys; ThreadLocalImpl::ThreadLocalImpl() : data() { @@ -56,14 +57,19 @@ void ThreadLocalImpl::removeInstance() { setInstance(nullptr); } -} +} // end namespace llvm #else + namespace llvm { + using namespace sys; + ThreadLocalImpl::ThreadLocalImpl() : data() { } ThreadLocalImpl::~ThreadLocalImpl() { } void ThreadLocalImpl::setInstance(const void* d) { data = const_cast<void*>(d);} void *ThreadLocalImpl::getInstance() { return data; } void ThreadLocalImpl::removeInstance() { setInstance(0); } -} + +} // end namespace llvm + #endif diff --git a/llvm/lib/Support/Unix/Unix.h b/llvm/lib/Support/Unix/Unix.h index 871e612f6c1..832d65bcc3a 100644 --- a/llvm/lib/Support/Unix/Unix.h +++ b/llvm/lib/Support/Unix/Unix.h @@ -1,4 +1,4 @@ -//===- llvm/Support/Unix/Unix.h - Common Unix Include File -------*- C++ -*-===// +//===- llvm/Support/Unix/Unix.h - Common Unix Include File ------*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -22,7 +22,7 @@ #include "llvm/Config/config.h" // Get autoconf configuration settings #include "llvm/Support/Errno.h" #include <algorithm> -#include <assert.h> +#include <cassert> #include <cerrno> #include <cstdio> #include <cstdlib> @@ -42,7 +42,7 @@ #ifdef HAVE_SYS_TIME_H # include <sys/time.h> #endif -#include <time.h> +#include <ctime> #ifdef HAVE_DLFCN_H # include <dlfcn.h> @@ -65,4 +65,4 @@ static inline bool MakeErrMsg( return true; } -#endif +#endif // LLVM_LIB_SUPPORT_UNIX_UNIX_H diff --git a/llvm/lib/Target/X86/X86ISelDAGToDAG.cpp b/llvm/lib/Target/X86/X86ISelDAGToDAG.cpp index 4105191147a..16f6367f41a 100644 --- a/llvm/lib/Target/X86/X86ISelDAGToDAG.cpp +++ b/llvm/lib/Target/X86/X86ISelDAGToDAG.cpp @@ -34,7 +34,8 @@ #include "llvm/Support/raw_ostream.h" #include "llvm/Target/TargetMachine.h" #include "llvm/Target/TargetOptions.h" -#include <stdint.h> +#include <cstdint> + using namespace llvm; #define DEBUG_TYPE "x86-isel" @@ -141,7 +142,7 @@ namespace { } #endif }; -} +} // end anonymous namespace namespace { //===--------------------------------------------------------------------===// @@ -301,7 +302,6 @@ namespace { // Walk all the users of the immediate. for (SDNode::use_iterator UI = N->use_begin(), UE = N->use_end(); (UI != UE) && (UseCount < 2); ++UI) { - SDNode *User = *UI; // This user is already selected. Count it as a legitimate use and @@ -393,8 +393,7 @@ namespace { return true; } }; -} - +} // end anonymous namespace bool X86DAGToDAGISel::IsProfitableToFold(SDValue N, SDNode *U, SDNode *Root) const { @@ -459,10 +458,12 @@ X86DAGToDAGISel::IsProfitableToFold(SDValue N, SDNode *U, SDNode *Root) const { return true; } +namespace { + /// Replace the original chain operand of the call with /// load's chain operand and move load below the call's chain operand. -static void moveBelowOrigChain(SelectionDAG *CurDAG, SDValue Load, - SDValue Call, SDValue OrigChain) { +void moveBelowOrigChain(SelectionDAG *CurDAG, SDValue Load, SDValue Call, + SDValue OrigChain) { SmallVector<SDValue, 8> Ops; SDValue Chain = OrigChain.getOperand(0); if (Chain.getNode() == Load.getNode()) @@ -496,7 +497,7 @@ static void moveBelowOrigChain(SelectionDAG *CurDAG, SDValue Load, /// Return the CALLSEQ_START by reference as a second output. /// In the case of a tail call, there isn't a callseq node between the call /// chain and the load. -static bool isCalleeLoad(SDValue Callee, SDValue &Chain, bool HasCallSeq) { +bool isCalleeLoad(SDValue Callee, SDValue &Chain, bool HasCallSeq) { // The transformation is somewhat dangerous if the call's chain was glued to // the call. After MoveBelowOrigChain the load is moved between the call and // the chain, this can create a cycle if the load is not folded. So it is @@ -533,6 +534,8 @@ static bool isCalleeLoad(SDValue Callee, SDValue &Chain, bool HasCallSeq) { return false; } +} // end anonymous namespace + void X86DAGToDAGISel::PreprocessISelDAG() { // OptFor[Min]Size are used in pattern predicates that isel is matching. OptForSize = MF->getFunction()->optForSize(); @@ -651,7 +654,6 @@ void X86DAGToDAGISel::PreprocessISelDAG() { } } - /// Emit any code that needs to be executed only in the main function. void X86DAGToDAGISel::emitSpecialCodeForMain() { if (Subtarget->isTargetCygMing()) { @@ -676,7 +678,9 @@ void X86DAGToDAGISel::EmitFunctionEntryCode() { emitSpecialCodeForMain(); } -static bool isDispSafeForFrameIndex(int64_t Val) { +namespace { + +bool isDispSafeForFrameIndex(int64_t Val) { // On 64-bit platforms, we can run into an issue where a frame index // includes a displacement that, when added to the explicit displacement, // will overflow the displacement field. Assuming that the frame index @@ -686,6 +690,8 @@ static bool isDispSafeForFrameIndex(int64_t Val) { return isInt<31>(Val); } +} // end anonymous namespace + bool X86DAGToDAGISel::foldOffsetIntoAddress(uint64_t Offset, X86ISelAddressMode &AM) { // Cannot combine ExternalSymbol displacements with integer offsets. @@ -705,7 +711,6 @@ bool X86DAGToDAGISel::foldOffsetIntoAddress(uint64_t Offset, } AM.Disp = Val; return false; - } bool X86DAGToDAGISel::matchLoadInAddress(LoadSDNode *N, X86ISelAddressMode &AM){ @@ -896,12 +901,14 @@ bool X86DAGToDAGISel::matchAdd(SDValue N, X86ISelAddressMode &AM, return true; } +namespace { + // Insert a node into the DAG at least before the Pos node's position. This // will reposition the node as needed, and will assign it a node ID that is <= // the Pos node's ID. Note that this does *not* preserve the uniqueness of node // IDs! The selection DAG must no longer depend on their uniqueness when this // is used. -static void insertDAGNode(SelectionDAG &DAG, SDValue Pos, SDValue N) { +void insertDAGNode(SelectionDAG &DAG, SDValue Pos, SDValue N) { if (N.getNode()->getNodeId() == -1 || N.getNode()->getNodeId() > Pos.getNode()->getNodeId()) { DAG.RepositionNode(Pos.getNode()->getIterator(), N.getNode()); @@ -913,10 +920,9 @@ static void insertDAGNode(SelectionDAG &DAG, SDValue Pos, SDValue N) { // safe. This allows us to convert the shift and and into an h-register // extract and a scaled index. Returns false if the simplification is // performed. -static bool foldMaskAndShiftToExtract(SelectionDAG &DAG, SDValue N, - uint64_t Mask, - SDValue Shift, SDValue X, - X86ISelAddressMode &AM) { +bool foldMaskAndShiftToExtract(SelectionDAG &DAG, SDValue N, uint64_t Mask, + SDValue Shift, SDValue X, + X86ISelAddressMode &AM) { if (Shift.getOpcode() != ISD::SRL || !isa<ConstantSDNode>(Shift.getOperand(1)) || !Shift.hasOneUse()) @@ -956,10 +962,9 @@ static bool foldMaskAndShiftToExtract(SelectionDAG &DAG, SDValue N, // Transforms "(X << C1) & C2" to "(X & (C2>>C1)) << C1" if safe and if this // allows us to fold the shift into this addressing mode. Returns false if the // transform succeeded. -static bool foldMaskedShiftToScaledMask(SelectionDAG &DAG, SDValue N, - uint64_t Mask, - SDValue Shift, SDValue X, - X86ISelAddressMode &AM) { +bool foldMaskedShiftToScaledMask(SelectionDAG &DAG, SDValue N, uint64_t Mask, + SDValue Shift, SDValue X, + X86ISelAddressMode &AM) { if (Shift.getOpcode() != ISD::SHL || !isa<ConstantSDNode>(Shift.getOperand(1))) return true; @@ -1023,10 +1028,8 @@ static bool foldMaskedShiftToScaledMask(SelectionDAG &DAG, SDValue N, // Note that this function assumes the mask is provided as a mask *after* the // value is shifted. The input chain may or may not match that, but computing // such a mask is trivial. -static bool foldMaskAndShiftToScale(SelectionDAG &DAG, SDValue N, - uint64_t Mask, - SDValue Shift, SDValue X, - X86ISelAddressMode &AM) { +bool foldMaskAndShiftToScale(SelectionDAG &DAG, SDValue N, uint64_t Mask, + SDValue Shift, SDValue X, X86ISelAddressMode &AM) { if (Shift.getOpcode() != ISD::SRL || !Shift.hasOneUse() || !isa<ConstantSDNode>(Shift.getOperand(1))) return true; @@ -1104,6 +1107,8 @@ static bool foldMaskAndShiftToScale(SelectionDAG &DAG, SDValue N, return false; } +} // end anonymous namespace + bool X86DAGToDAGISel::matchAddressRecursively(SDValue N, X86ISelAddressMode &AM, unsigned Depth) { SDLoc dl(N); @@ -1418,7 +1423,6 @@ bool X86DAGToDAGISel::matchAddressBase(SDValue N, X86ISelAddressMode &AM) { bool X86DAGToDAGISel::selectVectorAddr(SDNode *Parent, SDValue N, SDValue &Base, SDValue &Scale, SDValue &Index, SDValue &Disp, SDValue &Segment) { - MaskedGatherScatterSDNode *Mgs = dyn_cast<MaskedGatherScatterSDNode>(Parent); if (!Mgs) return false; @@ -1541,7 +1545,6 @@ bool X86DAGToDAGISel::selectScalarSSELoad(SDNode *Root, return false; } - bool X86DAGToDAGISel::selectMOV64Imm32(SDValue N, SDValue &Imm) { if (const ConstantSDNode *CN = dyn_cast<ConstantSDNode>(N)) { uint64_t ImmVal = CN->getZExtValue(); @@ -1695,7 +1698,6 @@ bool X86DAGToDAGISel::selectTLSADDRAddr(SDValue N, SDValue &Base, return true; } - bool X86DAGToDAGISel::tryFoldLoad(SDNode *P, SDValue N, SDValue &Base, SDValue &Scale, SDValue &Index, SDValue &Disp, @@ -1718,9 +1720,11 @@ SDNode *X86DAGToDAGISel::getGlobalBaseReg() { return CurDAG->getRegister(GlobalBaseReg, TLI->getPointerTy(DL)).getNode(); } +namespace { + /// Test whether the given X86ISD::CMP node has any uses which require the SF /// or OF bits to be accurate. -static bool hasNoSignedComparisonUses(SDNode *N) { +bool hasNoSignedComparisonUses(SDNode *N) { // Examine each user of the node. for (SDNode::use_iterator UI = N->use_begin(), UE = N->use_end(); UI != UE; ++UI) { @@ -1782,10 +1786,9 @@ static bool hasNoSignedComparisonUses(SDNode *N) { /// Check whether or not the chain ending in StoreNode is suitable for doing /// the {load; increment or decrement; store} to modify transformation. -static bool isLoadIncOrDecStore(StoreSDNode *StoreNode, unsigned Opc, - SDValue StoredVal, SelectionDAG *CurDAG, - LoadSDNode* &LoadNode, SDValue &InputChain) { - +bool isLoadIncOrDecStore(StoreSDNode *StoreNode, unsigned Opc, + SDValue StoredVal, SelectionDAG *CurDAG, + LoadSDNode* &LoadNode, SDValue &InputChain) { // is the value stored the result of a DEC or INC? if (!(Opc == X86ISD::DEC || Opc == X86ISD::INC)) return false; @@ -1867,7 +1870,7 @@ static bool isLoadIncOrDecStore(StoreSDNode *StoreNode, unsigned Opc, /// Get the appropriate X86 opcode for an in-memory increment or decrement. /// Opc should be X86ISD::DEC or X86ISD::INC. -static unsigned getFusedLdStOpcode(EVT &LdVT, unsigned Opc) { +unsigned getFusedLdStOpcode(EVT &LdVT, unsigned Opc) { if (Opc == X86ISD::DEC) { if (LdVT == MVT::i64) return X86::DEC64m; if (LdVT == MVT::i32) return X86::DEC32m; @@ -1883,6 +1886,8 @@ static unsigned getFusedLdStOpcode(EVT &LdVT, unsigned Opc) { llvm_unreachable("unrecognized size for LdVT"); } +} // end anonymous namespace + /// Customized ISel for GATHER operations. SDNode *X86DAGToDAGISel::selectGather(SDNode *Node, unsigned Opc) { // Operands of Gather: VSrc, Base, VIdx, VMask, Scale |