Imported Upstream version 5.18.0.167

Former-commit-id: 289509151e0fee68a1b591a20c9f109c3c789d3a
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2018-10-20 08:25:10 +00:00
parent e19d552987
commit b084638f15
28489 changed files with 184 additions and 3866856 deletions

View File

@ -1,237 +0,0 @@
//===--- AMDGPUMetadata.cpp -------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
/// \file
/// \brief AMDGPU metadata definitions and in-memory representations.
///
//
//===----------------------------------------------------------------------===//
#include "llvm/ADT/Twine.h"
#include "llvm/Support/AMDGPUMetadata.h"
#include "llvm/Support/YAMLTraits.h"
using namespace llvm::AMDGPU;
using namespace llvm::AMDGPU::HSAMD;
LLVM_YAML_IS_SEQUENCE_VECTOR(Kernel::Arg::Metadata)
LLVM_YAML_IS_SEQUENCE_VECTOR(Kernel::Metadata)
namespace llvm {
namespace yaml {
template <>
struct ScalarEnumerationTraits<AccessQualifier> {
static void enumeration(IO &YIO, AccessQualifier &EN) {
YIO.enumCase(EN, "Default", AccessQualifier::Default);
YIO.enumCase(EN, "ReadOnly", AccessQualifier::ReadOnly);
YIO.enumCase(EN, "WriteOnly", AccessQualifier::WriteOnly);
YIO.enumCase(EN, "ReadWrite", AccessQualifier::ReadWrite);
}
};
template <>
struct ScalarEnumerationTraits<AddressSpaceQualifier> {
static void enumeration(IO &YIO, AddressSpaceQualifier &EN) {
YIO.enumCase(EN, "Private", AddressSpaceQualifier::Private);
YIO.enumCase(EN, "Global", AddressSpaceQualifier::Global);
YIO.enumCase(EN, "Constant", AddressSpaceQualifier::Constant);
YIO.enumCase(EN, "Local", AddressSpaceQualifier::Local);
YIO.enumCase(EN, "Generic", AddressSpaceQualifier::Generic);
YIO.enumCase(EN, "Region", AddressSpaceQualifier::Region);
}
};
template <>
struct ScalarEnumerationTraits<ValueKind> {
static void enumeration(IO &YIO, ValueKind &EN) {
YIO.enumCase(EN, "ByValue", ValueKind::ByValue);
YIO.enumCase(EN, "GlobalBuffer", ValueKind::GlobalBuffer);
YIO.enumCase(EN, "DynamicSharedPointer", ValueKind::DynamicSharedPointer);
YIO.enumCase(EN, "Sampler", ValueKind::Sampler);
YIO.enumCase(EN, "Image", ValueKind::Image);
YIO.enumCase(EN, "Pipe", ValueKind::Pipe);
YIO.enumCase(EN, "Queue", ValueKind::Queue);
YIO.enumCase(EN, "HiddenGlobalOffsetX", ValueKind::HiddenGlobalOffsetX);
YIO.enumCase(EN, "HiddenGlobalOffsetY", ValueKind::HiddenGlobalOffsetY);
YIO.enumCase(EN, "HiddenGlobalOffsetZ", ValueKind::HiddenGlobalOffsetZ);
YIO.enumCase(EN, "HiddenNone", ValueKind::HiddenNone);
YIO.enumCase(EN, "HiddenPrintfBuffer", ValueKind::HiddenPrintfBuffer);
YIO.enumCase(EN, "HiddenDefaultQueue", ValueKind::HiddenDefaultQueue);
YIO.enumCase(EN, "HiddenCompletionAction",
ValueKind::HiddenCompletionAction);
}
};
template <>
struct ScalarEnumerationTraits<ValueType> {
static void enumeration(IO &YIO, ValueType &EN) {
YIO.enumCase(EN, "Struct", ValueType::Struct);
YIO.enumCase(EN, "I8", ValueType::I8);
YIO.enumCase(EN, "U8", ValueType::U8);
YIO.enumCase(EN, "I16", ValueType::I16);
YIO.enumCase(EN, "U16", ValueType::U16);
YIO.enumCase(EN, "F16", ValueType::F16);
YIO.enumCase(EN, "I32", ValueType::I32);
YIO.enumCase(EN, "U32", ValueType::U32);
YIO.enumCase(EN, "F32", ValueType::F32);
YIO.enumCase(EN, "I64", ValueType::I64);
YIO.enumCase(EN, "U64", ValueType::U64);
YIO.enumCase(EN, "F64", ValueType::F64);
}
};
template <>
struct MappingTraits<Kernel::Attrs::Metadata> {
static void mapping(IO &YIO, Kernel::Attrs::Metadata &MD) {
YIO.mapOptional(Kernel::Attrs::Key::ReqdWorkGroupSize,
MD.mReqdWorkGroupSize, std::vector<uint32_t>());
YIO.mapOptional(Kernel::Attrs::Key::WorkGroupSizeHint,
MD.mWorkGroupSizeHint, std::vector<uint32_t>());
YIO.mapOptional(Kernel::Attrs::Key::VecTypeHint,
MD.mVecTypeHint, std::string());
YIO.mapOptional(Kernel::Attrs::Key::RuntimeHandle, MD.mRuntimeHandle,
std::string());
}
};
template <>
struct MappingTraits<Kernel::Arg::Metadata> {
static void mapping(IO &YIO, Kernel::Arg::Metadata &MD) {
YIO.mapOptional(Kernel::Arg::Key::Name, MD.mName, std::string());
YIO.mapOptional(Kernel::Arg::Key::TypeName, MD.mTypeName, std::string());
YIO.mapRequired(Kernel::Arg::Key::Size, MD.mSize);
YIO.mapRequired(Kernel::Arg::Key::Align, MD.mAlign);
YIO.mapRequired(Kernel::Arg::Key::ValueKind, MD.mValueKind);
YIO.mapRequired(Kernel::Arg::Key::ValueType, MD.mValueType);
YIO.mapOptional(Kernel::Arg::Key::PointeeAlign, MD.mPointeeAlign,
uint32_t(0));
YIO.mapOptional(Kernel::Arg::Key::AddrSpaceQual, MD.mAddrSpaceQual,
AddressSpaceQualifier::Unknown);
YIO.mapOptional(Kernel::Arg::Key::AccQual, MD.mAccQual,
AccessQualifier::Unknown);
YIO.mapOptional(Kernel::Arg::Key::ActualAccQual, MD.mActualAccQual,
AccessQualifier::Unknown);
YIO.mapOptional(Kernel::Arg::Key::IsConst, MD.mIsConst, false);
YIO.mapOptional(Kernel::Arg::Key::IsRestrict, MD.mIsRestrict, false);
YIO.mapOptional(Kernel::Arg::Key::IsVolatile, MD.mIsVolatile, false);
YIO.mapOptional(Kernel::Arg::Key::IsPipe, MD.mIsPipe, false);
}
};
template <>
struct MappingTraits<Kernel::CodeProps::Metadata> {
static void mapping(IO &YIO, Kernel::CodeProps::Metadata &MD) {
YIO.mapRequired(Kernel::CodeProps::Key::KernargSegmentSize,
MD.mKernargSegmentSize);
YIO.mapRequired(Kernel::CodeProps::Key::GroupSegmentFixedSize,
MD.mGroupSegmentFixedSize);
YIO.mapRequired(Kernel::CodeProps::Key::PrivateSegmentFixedSize,
MD.mPrivateSegmentFixedSize);
YIO.mapRequired(Kernel::CodeProps::Key::KernargSegmentAlign,
MD.mKernargSegmentAlign);
YIO.mapRequired(Kernel::CodeProps::Key::WavefrontSize,
MD.mWavefrontSize);
YIO.mapOptional(Kernel::CodeProps::Key::NumSGPRs,
MD.mNumSGPRs, uint16_t(0));
YIO.mapOptional(Kernel::CodeProps::Key::NumVGPRs,
MD.mNumVGPRs, uint16_t(0));
YIO.mapOptional(Kernel::CodeProps::Key::MaxFlatWorkGroupSize,
MD.mMaxFlatWorkGroupSize, uint32_t(0));
YIO.mapOptional(Kernel::CodeProps::Key::IsDynamicCallStack,
MD.mIsDynamicCallStack, false);
YIO.mapOptional(Kernel::CodeProps::Key::IsXNACKEnabled,
MD.mIsXNACKEnabled, false);
YIO.mapOptional(Kernel::CodeProps::Key::NumSpilledSGPRs,
MD.mNumSpilledSGPRs, uint16_t(0));
YIO.mapOptional(Kernel::CodeProps::Key::NumSpilledVGPRs,
MD.mNumSpilledVGPRs, uint16_t(0));
}
};
template <>
struct MappingTraits<Kernel::DebugProps::Metadata> {
static void mapping(IO &YIO, Kernel::DebugProps::Metadata &MD) {
YIO.mapOptional(Kernel::DebugProps::Key::DebuggerABIVersion,
MD.mDebuggerABIVersion, std::vector<uint32_t>());
YIO.mapOptional(Kernel::DebugProps::Key::ReservedNumVGPRs,
MD.mReservedNumVGPRs, uint16_t(0));
YIO.mapOptional(Kernel::DebugProps::Key::ReservedFirstVGPR,
MD.mReservedFirstVGPR, uint16_t(-1));
YIO.mapOptional(Kernel::DebugProps::Key::PrivateSegmentBufferSGPR,
MD.mPrivateSegmentBufferSGPR, uint16_t(-1));
YIO.mapOptional(Kernel::DebugProps::Key::WavefrontPrivateSegmentOffsetSGPR,
MD.mWavefrontPrivateSegmentOffsetSGPR, uint16_t(-1));
}
};
template <>
struct MappingTraits<Kernel::Metadata> {
static void mapping(IO &YIO, Kernel::Metadata &MD) {
YIO.mapRequired(Kernel::Key::Name, MD.mName);
YIO.mapRequired(Kernel::Key::SymbolName, MD.mSymbolName);
YIO.mapOptional(Kernel::Key::Language, MD.mLanguage, std::string());
YIO.mapOptional(Kernel::Key::LanguageVersion, MD.mLanguageVersion,
std::vector<uint32_t>());
if (!MD.mAttrs.empty() || !YIO.outputting())
YIO.mapOptional(Kernel::Key::Attrs, MD.mAttrs);
if (!MD.mArgs.empty() || !YIO.outputting())
YIO.mapOptional(Kernel::Key::Args, MD.mArgs);
if (!MD.mCodeProps.empty() || !YIO.outputting())
YIO.mapOptional(Kernel::Key::CodeProps, MD.mCodeProps);
if (!MD.mDebugProps.empty() || !YIO.outputting())
YIO.mapOptional(Kernel::Key::DebugProps, MD.mDebugProps);
}
};
template <>
struct MappingTraits<HSAMD::Metadata> {
static void mapping(IO &YIO, HSAMD::Metadata &MD) {
YIO.mapRequired(Key::Version, MD.mVersion);
YIO.mapOptional(Key::Printf, MD.mPrintf, std::vector<std::string>());
if (!MD.mKernels.empty() || !YIO.outputting())
YIO.mapOptional(Key::Kernels, MD.mKernels);
}
};
} // end namespace yaml
namespace AMDGPU {
namespace HSAMD {
std::error_code fromString(std::string String, Metadata &HSAMetadata) {
yaml::Input YamlInput(String);
YamlInput >> HSAMetadata;
return YamlInput.error();
}
std::error_code toString(Metadata HSAMetadata, std::string &String) {
raw_string_ostream YamlStream(String);
yaml::Output YamlOutput(YamlStream, nullptr, std::numeric_limits<int>::max());
YamlOutput << HSAMetadata;
return std::error_code();
}
} // end namespace HSAMD
namespace PALMD {
std::error_code toString(const Metadata &PALMetadata, std::string &String) {
raw_string_ostream Stream(String);
for (auto I = PALMetadata.begin(), E = PALMetadata.end(); I != E; ++I) {
Stream << Twine(I == PALMetadata.begin() ? " 0x" : ",0x");
Stream << Twine::utohexstr(*I);
}
Stream.flush();
return std::error_code();
}
} // end namespace PALMD
} // end namespace AMDGPU
} // end namespace llvm

View File

@ -1 +0,0 @@
3489feb93a02b059aed0c9c30e510fe457fef6cc

File diff suppressed because it is too large Load Diff

View File

@ -1,43 +0,0 @@
//===-- llvm/ADT/APSInt.cpp - Arbitrary Precision Signed Int ---*- C++ -*--===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements the APSInt class, which is a simple class that
// represents an arbitrary sized integer that knows its signedness.
//
//===----------------------------------------------------------------------===//
#include "llvm/ADT/APSInt.h"
#include "llvm/ADT/FoldingSet.h"
#include "llvm/ADT/StringRef.h"
using namespace llvm;
APSInt::APSInt(StringRef Str) {
assert(!Str.empty() && "Invalid string length");
// (Over-)estimate the required number of bits.
unsigned NumBits = ((Str.size() * 64) / 19) + 2;
APInt Tmp(NumBits, Str, /*Radix=*/10);
if (Str[0] == '-') {
unsigned MinBits = Tmp.getMinSignedBits();
if (MinBits > 0 && MinBits < NumBits)
Tmp = Tmp.trunc(MinBits);
*this = APSInt(Tmp, /*IsUnsigned=*/false);
return;
}
unsigned ActiveBits = Tmp.getActiveBits();
if (ActiveBits > 0 && ActiveBits < NumBits)
Tmp = Tmp.trunc(ActiveBits);
*this = APSInt(Tmp, /*IsUnsigned=*/true);
}
void APSInt::Profile(FoldingSetNodeID& ID) const {
ID.AddInteger((unsigned) (IsUnsigned ? 1 : 0));
APInt::Profile(ID);
}

File diff suppressed because it is too large Load Diff

View File

@ -1,102 +0,0 @@
//===-- ARMBuildAttrs.cpp - ARM Build Attributes --------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/ARMBuildAttributes.h"
using namespace llvm;
namespace {
const struct {
ARMBuildAttrs::AttrType Attr;
StringRef TagName;
} ARMAttributeTags[] = {
{ ARMBuildAttrs::File, "Tag_File" },
{ ARMBuildAttrs::Section, "Tag_Section" },
{ ARMBuildAttrs::Symbol, "Tag_Symbol" },
{ ARMBuildAttrs::CPU_raw_name, "Tag_CPU_raw_name" },
{ ARMBuildAttrs::CPU_name, "Tag_CPU_name" },
{ ARMBuildAttrs::CPU_arch, "Tag_CPU_arch" },
{ ARMBuildAttrs::CPU_arch_profile, "Tag_CPU_arch_profile" },
{ ARMBuildAttrs::ARM_ISA_use, "Tag_ARM_ISA_use" },
{ ARMBuildAttrs::THUMB_ISA_use, "Tag_THUMB_ISA_use" },
{ ARMBuildAttrs::FP_arch, "Tag_FP_arch" },
{ ARMBuildAttrs::WMMX_arch, "Tag_WMMX_arch" },
{ ARMBuildAttrs::Advanced_SIMD_arch, "Tag_Advanced_SIMD_arch" },
{ ARMBuildAttrs::PCS_config, "Tag_PCS_config" },
{ ARMBuildAttrs::ABI_PCS_R9_use, "Tag_ABI_PCS_R9_use" },
{ ARMBuildAttrs::ABI_PCS_RW_data, "Tag_ABI_PCS_RW_data" },
{ ARMBuildAttrs::ABI_PCS_RO_data, "Tag_ABI_PCS_RO_data" },
{ ARMBuildAttrs::ABI_PCS_GOT_use, "Tag_ABI_PCS_GOT_use" },
{ ARMBuildAttrs::ABI_PCS_wchar_t, "Tag_ABI_PCS_wchar_t" },
{ ARMBuildAttrs::ABI_FP_rounding, "Tag_ABI_FP_rounding" },
{ ARMBuildAttrs::ABI_FP_denormal, "Tag_ABI_FP_denormal" },
{ ARMBuildAttrs::ABI_FP_exceptions, "Tag_ABI_FP_exceptions" },
{ ARMBuildAttrs::ABI_FP_user_exceptions, "Tag_ABI_FP_user_exceptions" },
{ ARMBuildAttrs::ABI_FP_number_model, "Tag_ABI_FP_number_model" },
{ ARMBuildAttrs::ABI_align_needed, "Tag_ABI_align_needed" },
{ ARMBuildAttrs::ABI_align_preserved, "Tag_ABI_align_preserved" },
{ ARMBuildAttrs::ABI_enum_size, "Tag_ABI_enum_size" },
{ ARMBuildAttrs::ABI_HardFP_use, "Tag_ABI_HardFP_use" },
{ ARMBuildAttrs::ABI_VFP_args, "Tag_ABI_VFP_args" },
{ ARMBuildAttrs::ABI_WMMX_args, "Tag_ABI_WMMX_args" },
{ ARMBuildAttrs::ABI_optimization_goals, "Tag_ABI_optimization_goals" },
{ ARMBuildAttrs::ABI_FP_optimization_goals, "Tag_ABI_FP_optimization_goals" },
{ ARMBuildAttrs::compatibility, "Tag_compatibility" },
{ ARMBuildAttrs::CPU_unaligned_access, "Tag_CPU_unaligned_access" },
{ ARMBuildAttrs::FP_HP_extension, "Tag_FP_HP_extension" },
{ ARMBuildAttrs::ABI_FP_16bit_format, "Tag_ABI_FP_16bit_format" },
{ ARMBuildAttrs::MPextension_use, "Tag_MPextension_use" },
{ ARMBuildAttrs::DIV_use, "Tag_DIV_use" },
{ ARMBuildAttrs::DSP_extension, "Tag_DSP_extension" },
{ ARMBuildAttrs::nodefaults, "Tag_nodefaults" },
{ ARMBuildAttrs::also_compatible_with, "Tag_also_compatible_with" },
{ ARMBuildAttrs::T2EE_use, "Tag_T2EE_use" },
{ ARMBuildAttrs::conformance, "Tag_conformance" },
{ ARMBuildAttrs::Virtualization_use, "Tag_Virtualization_use" },
// Legacy Names
{ ARMBuildAttrs::FP_arch, "Tag_VFP_arch" },
{ ARMBuildAttrs::FP_HP_extension, "Tag_VFP_HP_extension" },
{ ARMBuildAttrs::ABI_align_needed, "Tag_ABI_align8_needed" },
{ ARMBuildAttrs::ABI_align_preserved, "Tag_ABI_align8_preserved" },
};
}
namespace llvm {
namespace ARMBuildAttrs {
StringRef AttrTypeAsString(unsigned Attr, bool HasTagPrefix) {
return AttrTypeAsString(static_cast<AttrType>(Attr), HasTagPrefix);
}
StringRef AttrTypeAsString(AttrType Attr, bool HasTagPrefix) {
for (unsigned TI = 0, TE = sizeof(ARMAttributeTags) / sizeof(*ARMAttributeTags);
TI != TE; ++TI)
if (ARMAttributeTags[TI].Attr == Attr) {
auto TagName = ARMAttributeTags[TI].TagName;
return HasTagPrefix ? TagName : TagName.drop_front(4);
}
return "";
}
int AttrTypeFromString(StringRef Tag) {
bool HasTagPrefix = Tag.startswith("Tag_");
for (unsigned TI = 0,
TE = sizeof(ARMAttributeTags) / sizeof(*ARMAttributeTags);
TI != TE; ++TI) {
auto TagName = ARMAttributeTags[TI].TagName;
if (TagName.drop_front(HasTagPrefix ? 0 : 4) == Tag) {
return ARMAttributeTags[TI].Attr;
}
}
return -1;
}
}
}

View File

@ -1,38 +0,0 @@
//===-- ARMWinEH.cpp - Windows on ARM EH Support Functions ------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "llvm/Support/ARMWinEH.h"
#include "llvm/Support/raw_ostream.h"
namespace llvm {
namespace ARM {
namespace WinEH {
std::pair<uint16_t, uint32_t> SavedRegisterMask(const RuntimeFunction &RF) {
uint8_t NumRegisters = RF.Reg();
uint8_t RegistersVFP = RF.R();
uint8_t LinkRegister = RF.L();
uint8_t ChainedFrame = RF.C();
uint16_t GPRMask = (ChainedFrame << 11) | (LinkRegister << 14);
uint32_t VFPMask = 0;
if (RegistersVFP)
VFPMask |= (((1 << ((NumRegisters + 1) % 8)) - 1) << 8);
else
GPRMask |= (((1 << (NumRegisters + 1)) - 1) << 4);
if (PrologueFolding(RF))
GPRMask |= (((1 << (NumRegisters + 1)) - 1) << (~RF.StackAdjust() & 0x3));
return std::make_pair(GPRMask, VFPMask);
}
}
}
}

View File

@ -1,40 +0,0 @@
//===--- Allocator.cpp - Simple memory allocation abstraction -------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements the BumpPtrAllocator interface.
//
//===----------------------------------------------------------------------===//
#include "llvm/Support/Allocator.h"
#include "llvm/Support/raw_ostream.h"
namespace llvm {
namespace detail {
void printBumpPtrAllocatorStats(unsigned NumSlabs, size_t BytesAllocated,
size_t TotalMemory) {
errs() << "\nNumber of memory regions: " << NumSlabs << '\n'
<< "Bytes used: " << BytesAllocated << '\n'
<< "Bytes allocated: " << TotalMemory << '\n'
<< "Bytes wasted: " << (TotalMemory - BytesAllocated)
<< " (includes alignment, etc)\n";
}
} // End namespace detail.
void PrintRecyclerStats(size_t Size,
size_t Align,
size_t FreeListSize) {
errs() << "Recycler element size: " << Size << '\n'
<< "Recycler element alignment: " << Align << '\n'
<< "Number of elements free for recycling: " << FreeListSize << '\n';
}
}

View File

@ -1,60 +0,0 @@
//===-- Atomic.cpp - Atomic Operations --------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements atomic operations.
//
//===----------------------------------------------------------------------===//
#include "llvm/Support/Atomic.h"
#include "llvm/Config/llvm-config.h"
using namespace llvm;
#if defined(_MSC_VER)
#include <intrin.h>
// We must include windows.h after intrin.h.
#include <windows.h>
#undef MemoryFence
#endif
#if defined(__GNUC__) || (defined(__IBMCPP__) && __IBMCPP__ >= 1210)
#define GNU_ATOMICS
#endif
void sys::MemoryFence() {
#if LLVM_HAS_ATOMICS == 0
return;
#else
# if defined(GNU_ATOMICS)
__sync_synchronize();
# elif defined(_MSC_VER)
MemoryBarrier();
# else
# error No memory fence implementation for your platform!
# endif
#endif
}
sys::cas_flag sys::CompareAndSwap(volatile sys::cas_flag* ptr,
sys::cas_flag new_value,
sys::cas_flag old_value) {
#if LLVM_HAS_ATOMICS == 0
sys::cas_flag result = *ptr;
if (result == old_value)
*ptr = new_value;
return result;
#elif defined(GNU_ATOMICS)
return __sync_val_compare_and_swap(ptr, old_value, new_value);
#elif defined(_MSC_VER)
return InterlockedCompareExchange(ptr, new_value, old_value);
#else
# error No compare-and-swap implementation for your platform!
#endif
}

View File

@ -1,56 +0,0 @@
//===- BinaryStreamError.cpp - Error extensions for streams -----*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "llvm/Support/BinaryStreamError.h"
#include "llvm/Support/ErrorHandling.h"
using namespace llvm;
char BinaryStreamError::ID = 0;
BinaryStreamError::BinaryStreamError(stream_error_code C)
: BinaryStreamError(C, "") {}
BinaryStreamError::BinaryStreamError(StringRef Context)
: BinaryStreamError(stream_error_code::unspecified, Context) {}
BinaryStreamError::BinaryStreamError(stream_error_code C, StringRef Context)
: Code(C) {
ErrMsg = "Stream Error: ";
switch (C) {
case stream_error_code::unspecified:
ErrMsg += "An unspecified error has occurred.";
break;
case stream_error_code::stream_too_short:
ErrMsg += "The stream is too short to perform the requested operation.";
break;
case stream_error_code::invalid_array_size:
ErrMsg += "The buffer size is not a multiple of the array element size.";
break;
case stream_error_code::invalid_offset:
ErrMsg += "The specified offset is invalid for the current stream.";
break;
case stream_error_code::filesystem_error:
ErrMsg += "An I/O error occurred on the file system.";
break;
}
if (!Context.empty()) {
ErrMsg += " ";
ErrMsg += Context;
}
}
void BinaryStreamError::log(raw_ostream &OS) const { OS << ErrMsg << "\n"; }
StringRef BinaryStreamError::getErrorMessage() const { return ErrMsg; }
std::error_code BinaryStreamError::convertToErrorCode() const {
return inconvertibleErrorCode();
}

View File

@ -1,149 +0,0 @@
//===- BinaryStreamReader.cpp - Reads objects from a binary stream --------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "llvm/Support/BinaryStreamReader.h"
#include "llvm/Support/BinaryStreamError.h"
#include "llvm/Support/BinaryStreamRef.h"
using namespace llvm;
using endianness = llvm::support::endianness;
BinaryStreamReader::BinaryStreamReader(BinaryStreamRef Ref) : Stream(Ref) {}
BinaryStreamReader::BinaryStreamReader(BinaryStream &Stream) : Stream(Stream) {}
BinaryStreamReader::BinaryStreamReader(ArrayRef<uint8_t> Data,
endianness Endian)
: Stream(Data, Endian) {}
BinaryStreamReader::BinaryStreamReader(StringRef Data, endianness Endian)
: Stream(Data, Endian) {}
Error BinaryStreamReader::readLongestContiguousChunk(
ArrayRef<uint8_t> &Buffer) {
if (auto EC = Stream.readLongestContiguousChunk(Offset, Buffer))
return EC;
Offset += Buffer.size();
return Error::success();
}
Error BinaryStreamReader::readBytes(ArrayRef<uint8_t> &Buffer, uint32_t Size) {
if (auto EC = Stream.readBytes(Offset, Size, Buffer))
return EC;
Offset += Size;
return Error::success();
}
Error BinaryStreamReader::readCString(StringRef &Dest) {
uint32_t OriginalOffset = getOffset();
uint32_t FoundOffset = 0;
while (true) {
uint32_t ThisOffset = getOffset();
ArrayRef<uint8_t> Buffer;
if (auto EC = readLongestContiguousChunk(Buffer))
return EC;
StringRef S(reinterpret_cast<const char *>(Buffer.begin()), Buffer.size());
size_t Pos = S.find_first_of('\0');
if (LLVM_LIKELY(Pos != StringRef::npos)) {
FoundOffset = Pos + ThisOffset;
break;
}
}
assert(FoundOffset >= OriginalOffset);
setOffset(OriginalOffset);
size_t Length = FoundOffset - OriginalOffset;
if (auto EC = readFixedString(Dest, Length))
return EC;
// Now set the offset back to after the null terminator.
setOffset(FoundOffset + 1);
return Error::success();
}
Error BinaryStreamReader::readWideString(ArrayRef<UTF16> &Dest) {
uint32_t Length = 0;
uint32_t OriginalOffset = getOffset();
const UTF16 *C;
while (true) {
if (auto EC = readObject(C))
return EC;
if (*C == 0x0000)
break;
++Length;
}
uint32_t NewOffset = getOffset();
setOffset(OriginalOffset);
if (auto EC = readArray(Dest, Length))
return EC;
setOffset(NewOffset);
return Error::success();
}
Error BinaryStreamReader::readFixedString(StringRef &Dest, uint32_t Length) {
ArrayRef<uint8_t> Bytes;
if (auto EC = readBytes(Bytes, Length))
return EC;
Dest = StringRef(reinterpret_cast<const char *>(Bytes.begin()), Bytes.size());
return Error::success();
}
Error BinaryStreamReader::readStreamRef(BinaryStreamRef &Ref) {
return readStreamRef(Ref, bytesRemaining());
}
Error BinaryStreamReader::readStreamRef(BinaryStreamRef &Ref, uint32_t Length) {
if (bytesRemaining() < Length)
return make_error<BinaryStreamError>(stream_error_code::stream_too_short);
Ref = Stream.slice(Offset, Length);
Offset += Length;
return Error::success();
}
Error BinaryStreamReader::readSubstream(BinarySubstreamRef &Stream,
uint32_t Size) {
Stream.Offset = getOffset();
return readStreamRef(Stream.StreamData, Size);
}
Error BinaryStreamReader::skip(uint32_t Amount) {
if (Amount > bytesRemaining())
return make_error<BinaryStreamError>(stream_error_code::stream_too_short);
Offset += Amount;
return Error::success();
}
Error BinaryStreamReader::padToAlignment(uint32_t Align) {
uint32_t NewOffset = alignTo(Offset, Align);
return skip(NewOffset - Offset);
}
uint8_t BinaryStreamReader::peek() const {
ArrayRef<uint8_t> Buffer;
auto EC = Stream.readBytes(Offset, 1, Buffer);
assert(!EC && "Cannot peek an empty buffer!");
llvm::consumeError(std::move(EC));
return Buffer[0];
}
std::pair<BinaryStreamReader, BinaryStreamReader>
BinaryStreamReader::split(uint32_t Off) const {
assert(getLength() >= Off);
BinaryStreamRef First = Stream.drop_front(Offset);
BinaryStreamRef Second = First.drop_front(Off);
First = First.keep_front(Off);
BinaryStreamReader W1{First};
BinaryStreamReader W2{Second};
return std::make_pair(W1, W2);
}

View File

@ -1,131 +0,0 @@
//===- BinaryStreamRef.cpp - ----------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "llvm/Support/BinaryStreamRef.h"
#include "llvm/Support/BinaryByteStream.h"
using namespace llvm;
using namespace llvm::support;
namespace {
class ArrayRefImpl : public BinaryStream {
public:
ArrayRefImpl(ArrayRef<uint8_t> Data, endianness Endian) : BBS(Data, Endian) {}
llvm::support::endianness getEndian() const override {
return BBS.getEndian();
}
Error readBytes(uint32_t Offset, uint32_t Size,
ArrayRef<uint8_t> &Buffer) override {
return BBS.readBytes(Offset, Size, Buffer);
}
Error readLongestContiguousChunk(uint32_t Offset,
ArrayRef<uint8_t> &Buffer) override {
return BBS.readLongestContiguousChunk(Offset, Buffer);
}
uint32_t getLength() override { return BBS.getLength(); }
private:
BinaryByteStream BBS;
};
class MutableArrayRefImpl : public WritableBinaryStream {
public:
MutableArrayRefImpl(MutableArrayRef<uint8_t> Data, endianness Endian)
: BBS(Data, Endian) {}
// Inherited via WritableBinaryStream
llvm::support::endianness getEndian() const override {
return BBS.getEndian();
}
Error readBytes(uint32_t Offset, uint32_t Size,
ArrayRef<uint8_t> &Buffer) override {
return BBS.readBytes(Offset, Size, Buffer);
}
Error readLongestContiguousChunk(uint32_t Offset,
ArrayRef<uint8_t> &Buffer) override {
return BBS.readLongestContiguousChunk(Offset, Buffer);
}
uint32_t getLength() override { return BBS.getLength(); }
Error writeBytes(uint32_t Offset, ArrayRef<uint8_t> Data) override {
return BBS.writeBytes(Offset, Data);
}
Error commit() override { return BBS.commit(); }
private:
MutableBinaryByteStream BBS;
};
}
BinaryStreamRef::BinaryStreamRef(BinaryStream &Stream)
: BinaryStreamRefBase(Stream) {}
BinaryStreamRef::BinaryStreamRef(BinaryStream &Stream, uint32_t Offset,
Optional<uint32_t> Length)
: BinaryStreamRefBase(Stream, Offset, Length) {}
BinaryStreamRef::BinaryStreamRef(ArrayRef<uint8_t> Data, endianness Endian)
: BinaryStreamRefBase(std::make_shared<ArrayRefImpl>(Data, Endian), 0,
Data.size()) {}
BinaryStreamRef::BinaryStreamRef(StringRef Data, endianness Endian)
: BinaryStreamRef(makeArrayRef(Data.bytes_begin(), Data.bytes_end()),
Endian) {}
Error BinaryStreamRef::readBytes(uint32_t Offset, uint32_t Size,
ArrayRef<uint8_t> &Buffer) const {
if (auto EC = checkOffsetForRead(Offset, Size))
return EC;
return BorrowedImpl->readBytes(ViewOffset + Offset, Size, Buffer);
}
Error BinaryStreamRef::readLongestContiguousChunk(
uint32_t Offset, ArrayRef<uint8_t> &Buffer) const {
if (auto EC = checkOffsetForRead(Offset, 1))
return EC;
if (auto EC =
BorrowedImpl->readLongestContiguousChunk(ViewOffset + Offset, Buffer))
return EC;
// This StreamRef might refer to a smaller window over a larger stream. In
// that case we will have read out more bytes than we should return, because
// we should not read past the end of the current view.
uint32_t MaxLength = getLength() - Offset;
if (Buffer.size() > MaxLength)
Buffer = Buffer.slice(0, MaxLength);
return Error::success();
}
WritableBinaryStreamRef::WritableBinaryStreamRef(WritableBinaryStream &Stream)
: BinaryStreamRefBase(Stream) {}
WritableBinaryStreamRef::WritableBinaryStreamRef(WritableBinaryStream &Stream,
uint32_t Offset,
Optional<uint32_t> Length)
: BinaryStreamRefBase(Stream, Offset, Length) {}
WritableBinaryStreamRef::WritableBinaryStreamRef(MutableArrayRef<uint8_t> Data,
endianness Endian)
: BinaryStreamRefBase(std::make_shared<MutableArrayRefImpl>(Data, Endian),
0, Data.size()) {}
Error WritableBinaryStreamRef::writeBytes(uint32_t Offset,
ArrayRef<uint8_t> Data) const {
if (auto EC = checkOffsetForWrite(Offset, Data.size()))
return EC;
return BorrowedImpl->writeBytes(ViewOffset + Offset, Data);
}
WritableBinaryStreamRef::operator BinaryStreamRef() const {
return BinaryStreamRef(*BorrowedImpl, ViewOffset, Length);
}
/// \brief For buffered streams, commits changes to the backing store.
Error WritableBinaryStreamRef::commit() { return BorrowedImpl->commit(); }

View File

@ -1,91 +0,0 @@
//===- BinaryStreamWriter.cpp - Writes objects to a BinaryStream ----------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "llvm/Support/BinaryStreamWriter.h"
#include "llvm/Support/BinaryStreamError.h"
#include "llvm/Support/BinaryStreamReader.h"
#include "llvm/Support/BinaryStreamRef.h"
using namespace llvm;
BinaryStreamWriter::BinaryStreamWriter(WritableBinaryStreamRef Ref)
: Stream(Ref) {}
BinaryStreamWriter::BinaryStreamWriter(WritableBinaryStream &Stream)
: Stream(Stream) {}
BinaryStreamWriter::BinaryStreamWriter(MutableArrayRef<uint8_t> Data,
llvm::support::endianness Endian)
: Stream(Data, Endian) {}
Error BinaryStreamWriter::writeBytes(ArrayRef<uint8_t> Buffer) {
if (auto EC = Stream.writeBytes(Offset, Buffer))
return EC;
Offset += Buffer.size();
return Error::success();
}
Error BinaryStreamWriter::writeCString(StringRef Str) {
if (auto EC = writeFixedString(Str))
return EC;
if (auto EC = writeObject('\0'))
return EC;
return Error::success();
}
Error BinaryStreamWriter::writeFixedString(StringRef Str) {
return writeBytes(arrayRefFromStringRef(Str));
}
Error BinaryStreamWriter::writeStreamRef(BinaryStreamRef Ref) {
return writeStreamRef(Ref, Ref.getLength());
}
Error BinaryStreamWriter::writeStreamRef(BinaryStreamRef Ref, uint32_t Length) {
BinaryStreamReader SrcReader(Ref.slice(0, Length));
// This is a bit tricky. If we just call readBytes, we are requiring that it
// return us the entire stream as a contiguous buffer. There is no guarantee
// this can be satisfied by returning a reference straight from the buffer, as
// an implementation may not store all data in a single contiguous buffer. So
// we iterate over each contiguous chunk, writing each one in succession.
while (SrcReader.bytesRemaining() > 0) {
ArrayRef<uint8_t> Chunk;
if (auto EC = SrcReader.readLongestContiguousChunk(Chunk))
return EC;
if (auto EC = writeBytes(Chunk))
return EC;
}
return Error::success();
}
std::pair<BinaryStreamWriter, BinaryStreamWriter>
BinaryStreamWriter::split(uint32_t Off) const {
assert(getLength() >= Off);
WritableBinaryStreamRef First = Stream.drop_front(Offset);
WritableBinaryStreamRef Second = First.drop_front(Off);
First = First.keep_front(Off);
BinaryStreamWriter W1{First};
BinaryStreamWriter W2{Second};
return std::make_pair(W1, W2);
}
Error BinaryStreamWriter::padToAlignment(uint32_t Align) {
uint32_t NewOffset = alignTo(Offset, Align);
if (NewOffset > getLength())
return make_error<BinaryStreamError>(stream_error_code::stream_too_short);
while (Offset < NewOffset)
if (auto EC = writeInteger('\0'))
return EC;
return Error::success();
}

View File

@ -1,83 +0,0 @@
//====--------------- lib/Support/BlockFrequency.cpp -----------*- C++ -*-====//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements Block Frequency class.
//
//===----------------------------------------------------------------------===//
#include "llvm/Support/BlockFrequency.h"
#include <cassert>
using namespace llvm;
BlockFrequency &BlockFrequency::operator*=(BranchProbability Prob) {
Frequency = Prob.scale(Frequency);
return *this;
}
BlockFrequency BlockFrequency::operator*(BranchProbability Prob) const {
BlockFrequency Freq(Frequency);
Freq *= Prob;
return Freq;
}
BlockFrequency &BlockFrequency::operator/=(BranchProbability Prob) {
Frequency = Prob.scaleByInverse(Frequency);
return *this;
}
BlockFrequency BlockFrequency::operator/(BranchProbability Prob) const {
BlockFrequency Freq(Frequency);
Freq /= Prob;
return Freq;
}
BlockFrequency &BlockFrequency::operator+=(BlockFrequency Freq) {
uint64_t Before = Freq.Frequency;
Frequency += Freq.Frequency;
// If overflow, set frequency to the maximum value.
if (Frequency < Before)
Frequency = UINT64_MAX;
return *this;
}
BlockFrequency BlockFrequency::operator+(BlockFrequency Freq) const {
BlockFrequency NewFreq(Frequency);
NewFreq += Freq;
return NewFreq;
}
BlockFrequency &BlockFrequency::operator-=(BlockFrequency Freq) {
// If underflow, set frequency to 0.
if (Frequency <= Freq.Frequency)
Frequency = 0;
else
Frequency -= Freq.Frequency;
return *this;
}
BlockFrequency BlockFrequency::operator-(BlockFrequency Freq) const {
BlockFrequency NewFreq(Frequency);
NewFreq -= Freq;
return NewFreq;
}
BlockFrequency &BlockFrequency::operator>>=(const unsigned count) {
// Frequency can never be 0 by design.
assert(Frequency != 0);
// Shift right by count.
Frequency >>= count;
// Saturate to 1 if we are 0.
Frequency |= Frequency == 0;
return *this;
}

View File

@ -1,116 +0,0 @@
//===-------------- lib/Support/BranchProbability.cpp -----------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements Branch Probability class.
//
//===----------------------------------------------------------------------===//
#include "llvm/Support/BranchProbability.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/raw_ostream.h"
#include <cassert>
using namespace llvm;
const uint32_t BranchProbability::D;
raw_ostream &BranchProbability::print(raw_ostream &OS) const {
if (isUnknown())
return OS << "?%";
// Get a percentage rounded to two decimal digits. This avoids
// implementation-defined rounding inside printf.
double Percent = rint(((double)N / D) * 100.0 * 100.0) / 100.0;
return OS << format("0x%08" PRIx32 " / 0x%08" PRIx32 " = %.2f%%", N, D,
Percent);
}
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
LLVM_DUMP_METHOD void BranchProbability::dump() const { print(dbgs()) << '\n'; }
#endif
BranchProbability::BranchProbability(uint32_t Numerator, uint32_t Denominator) {
assert(Denominator > 0 && "Denominator cannot be 0!");
assert(Numerator <= Denominator && "Probability cannot be bigger than 1!");
if (Denominator == D)
N = Numerator;
else {
uint64_t Prob64 =
(Numerator * static_cast<uint64_t>(D) + Denominator / 2) / Denominator;
N = static_cast<uint32_t>(Prob64);
}
}
BranchProbability
BranchProbability::getBranchProbability(uint64_t Numerator,
uint64_t Denominator) {
assert(Numerator <= Denominator && "Probability cannot be bigger than 1!");
// Scale down Denominator to fit in a 32-bit integer.
int Scale = 0;
while (Denominator > UINT32_MAX) {
Denominator >>= 1;
Scale++;
}
return BranchProbability(Numerator >> Scale, Denominator);
}
// If ConstD is not zero, then replace D by ConstD so that division and modulo
// operations by D can be optimized, in case this function is not inlined by the
// compiler.
template <uint32_t ConstD>
static uint64_t scale(uint64_t Num, uint32_t N, uint32_t D) {
if (ConstD > 0)
D = ConstD;
assert(D && "divide by 0");
// Fast path for multiplying by 1.0.
if (!Num || D == N)
return Num;
// Split Num into upper and lower parts to multiply, then recombine.
uint64_t ProductHigh = (Num >> 32) * N;
uint64_t ProductLow = (Num & UINT32_MAX) * N;
// Split into 32-bit digits.
uint32_t Upper32 = ProductHigh >> 32;
uint32_t Lower32 = ProductLow & UINT32_MAX;
uint32_t Mid32Partial = ProductHigh & UINT32_MAX;
uint32_t Mid32 = Mid32Partial + (ProductLow >> 32);
// Carry.
Upper32 += Mid32 < Mid32Partial;
// Check for overflow.
if (Upper32 >= D)
return UINT64_MAX;
uint64_t Rem = (uint64_t(Upper32) << 32) | Mid32;
uint64_t UpperQ = Rem / D;
// Check for overflow.
if (UpperQ > UINT32_MAX)
return UINT64_MAX;
Rem = ((Rem % D) << 32) | Lower32;
uint64_t LowerQ = Rem / D;
uint64_t Q = (UpperQ << 32) + LowerQ;
// Check for overflow.
return Q < LowerQ ? UINT64_MAX : Q;
}
uint64_t BranchProbability::scale(uint64_t Num) const {
return ::scale<D>(Num, N, D);
}
uint64_t BranchProbability::scaleByInverse(uint64_t Num) const {
return ::scale<0>(Num, D, N);
}

View File

@ -1,154 +0,0 @@
set(system_libs)
if ( LLVM_ENABLE_ZLIB AND HAVE_LIBZ )
set(system_libs ${system_libs} ${ZLIB_LIBRARIES})
endif()
if( MSVC OR MINGW )
# libuuid required for FOLDERID_Profile usage in lib/Support/Windows/Path.inc.
# advapi32 required for CryptAcquireContextW in lib/Support/Windows/Path.inc.
set(system_libs ${system_libs} psapi shell32 ole32 uuid advapi32)
elseif( CMAKE_HOST_UNIX )
if( HAVE_LIBRT )
set(system_libs ${system_libs} rt)
endif()
if( HAVE_LIBDL )
set(system_libs ${system_libs} ${CMAKE_DL_LIBS})
endif()
if( HAVE_BACKTRACE )
set(system_libs ${system_libs} ${Backtrace_LIBRARIES})
endif()
if(LLVM_ENABLE_TERMINFO)
if(HAVE_TERMINFO)
set(system_libs ${system_libs} ${TERMINFO_LIBS})
endif()
endif()
if( LLVM_ENABLE_THREADS AND HAVE_LIBATOMIC )
set(system_libs ${system_libs} atomic)
endif()
set(system_libs ${system_libs} ${LLVM_PTHREAD_LIB})
if( UNIX AND NOT (BEOS OR HAIKU) )
set(system_libs ${system_libs} m)
endif()
endif( MSVC OR MINGW )
add_llvm_library(LLVMSupport
AMDGPUMetadata.cpp
APFloat.cpp
APInt.cpp
APSInt.cpp
ARMBuildAttrs.cpp
ARMAttributeParser.cpp
ARMWinEH.cpp
Allocator.cpp
BinaryStreamError.cpp
BinaryStreamReader.cpp
BinaryStreamRef.cpp
BinaryStreamWriter.cpp
BlockFrequency.cpp
BranchProbability.cpp
CachePruning.cpp
circular_raw_ostream.cpp
Chrono.cpp
COM.cpp
CodeGenCoverage.cpp
CommandLine.cpp
Compression.cpp
ConvertUTF.cpp
ConvertUTFWrapper.cpp
CrashRecoveryContext.cpp
DataExtractor.cpp
Debug.cpp
DebugCounter.cpp
DeltaAlgorithm.cpp
DAGDeltaAlgorithm.cpp
Error.cpp
ErrorHandling.cpp
FileUtilities.cpp
FileOutputBuffer.cpp
FoldingSet.cpp
FormattedStream.cpp
FormatVariadic.cpp
GlobPattern.cpp
GraphWriter.cpp
Hashing.cpp
IntEqClasses.cpp
IntervalMap.cpp
JamCRC.cpp
KnownBits.cpp
LEB128.cpp
LineIterator.cpp
Locale.cpp
LockFileManager.cpp
LowLevelType.cpp
ManagedStatic.cpp
MathExtras.cpp
MemoryBuffer.cpp
MD5.cpp
NativeFormatting.cpp
Options.cpp
Parallel.cpp
PluginLoader.cpp
PrettyStackTrace.cpp
RandomNumberGenerator.cpp
Regex.cpp
ScaledNumber.cpp
ScopedPrinter.cpp
SHA1.cpp
SmallPtrSet.cpp
SmallVector.cpp
SourceMgr.cpp
SpecialCaseList.cpp
Statistic.cpp
StringExtras.cpp
StringMap.cpp
StringPool.cpp
StringSaver.cpp
StringRef.cpp
SystemUtils.cpp
TarWriter.cpp
TargetParser.cpp
ThreadPool.cpp
Timer.cpp
ToolOutputFile.cpp
TrigramIndex.cpp
Triple.cpp
Twine.cpp
Unicode.cpp
YAMLParser.cpp
YAMLTraits.cpp
raw_os_ostream.cpp
raw_ostream.cpp
regcomp.c
regerror.c
regexec.c
regfree.c
regstrlcpy.c
xxhash.cpp
# System
Atomic.cpp
DynamicLibrary.cpp
Errno.cpp
Host.cpp
Memory.cpp
Mutex.cpp
Path.cpp
Process.cpp
Program.cpp
RWMutex.cpp
Signals.cpp
TargetRegistry.cpp
ThreadLocal.cpp
Threading.cpp
Valgrind.cpp
Watchdog.cpp
ADDITIONAL_HEADER_DIRS
Unix
Windows
${LLVM_MAIN_INCLUDE_DIR}/llvm/ADT
${LLVM_MAIN_INCLUDE_DIR}/llvm/Support
${Backtrace_INCLUDE_DIRS}
LINK_LIBS ${system_libs}
)
set_property(TARGET LLVMSupport PROPERTY LLVM_SYSTEM_LIBS "${system_libs}")

View File

@ -1,23 +0,0 @@
//===-- COM.cpp - Implement COM utility classes -----------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements utility classes related to COM.
//
//===----------------------------------------------------------------------===//
#include "llvm/Support/COM.h"
#include "llvm/Config/config.h"
// Include the platform-specific parts of this class.
#ifdef LLVM_ON_UNIX
#include "Unix/COM.inc"
#elif LLVM_ON_WIN32
#include "Windows/COM.inc"
#endif

View File

@ -1,54 +0,0 @@
$OpenBSD: COPYRIGHT,v 1.3 2003/06/02 20:18:36 millert Exp $
Copyright 1992, 1993, 1994 Henry Spencer. All rights reserved.
This software is not subject to any license of the American Telephone
and Telegraph Company or of the Regents of the University of California.
Permission is granted to anyone to use this software for any purpose on
any computer system, and to alter it and redistribute it, subject
to the following restrictions:
1. The author is not responsible for the consequences of use of this
software, no matter how awful, even if they arise from flaws in it.
2. The origin of this software must not be misrepresented, either by
explicit claim or by omission. Since few users ever read sources,
credits must appear in the documentation.
3. Altered versions must be plainly marked as such, and must not be
misrepresented as being the original software. Since few users
ever read sources, credits must appear in the documentation.
4. This notice may not be removed or altered.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
/*-
* Copyright (c) 1994
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)COPYRIGHT 8.1 (Berkeley) 3/16/94
*/

View File

@ -1,275 +0,0 @@
//===-CachePruning.cpp - LLVM Cache Directory Pruning ---------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements the pruning of a directory based on least recently used.
//
//===----------------------------------------------------------------------===//
#include "llvm/Support/CachePruning.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/Errc.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/raw_ostream.h"
#define DEBUG_TYPE "cache-pruning"
#include <set>
#include <system_error>
using namespace llvm;
/// Write a new timestamp file with the given path. This is used for the pruning
/// interval option.
static void writeTimestampFile(StringRef TimestampFile) {
std::error_code EC;
raw_fd_ostream Out(TimestampFile.str(), EC, sys::fs::F_None);
}
static Expected<std::chrono::seconds> parseDuration(StringRef Duration) {
if (Duration.empty())
return make_error<StringError>("Duration must not be empty",
inconvertibleErrorCode());
StringRef NumStr = Duration.slice(0, Duration.size()-1);
uint64_t Num;
if (NumStr.getAsInteger(0, Num))
return make_error<StringError>("'" + NumStr + "' not an integer",
inconvertibleErrorCode());
switch (Duration.back()) {
case 's':
return std::chrono::seconds(Num);
case 'm':
return std::chrono::minutes(Num);
case 'h':
return std::chrono::hours(Num);
default:
return make_error<StringError>("'" + Duration +
"' must end with one of 's', 'm' or 'h'",
inconvertibleErrorCode());
}
}
Expected<CachePruningPolicy>
llvm::parseCachePruningPolicy(StringRef PolicyStr) {
CachePruningPolicy Policy;
std::pair<StringRef, StringRef> P = {"", PolicyStr};
while (!P.second.empty()) {
P = P.second.split(':');
StringRef Key, Value;
std::tie(Key, Value) = P.first.split('=');
if (Key == "prune_interval") {
auto DurationOrErr = parseDuration(Value);
if (!DurationOrErr)
return DurationOrErr.takeError();
Policy.Interval = *DurationOrErr;
} else if (Key == "prune_after") {
auto DurationOrErr = parseDuration(Value);
if (!DurationOrErr)
return DurationOrErr.takeError();
Policy.Expiration = *DurationOrErr;
} else if (Key == "cache_size") {
if (Value.back() != '%')
return make_error<StringError>("'" + Value + "' must be a percentage",
inconvertibleErrorCode());
StringRef SizeStr = Value.drop_back();
uint64_t Size;
if (SizeStr.getAsInteger(0, Size))
return make_error<StringError>("'" + SizeStr + "' not an integer",
inconvertibleErrorCode());
if (Size > 100)
return make_error<StringError>("'" + SizeStr +
"' must be between 0 and 100",
inconvertibleErrorCode());
Policy.MaxSizePercentageOfAvailableSpace = Size;
} else if (Key == "cache_size_bytes") {
uint64_t Mult = 1;
switch (tolower(Value.back())) {
case 'k':
Mult = 1024;
Value = Value.drop_back();
break;
case 'm':
Mult = 1024 * 1024;
Value = Value.drop_back();
break;
case 'g':
Mult = 1024 * 1024 * 1024;
Value = Value.drop_back();
break;
}
uint64_t Size;
if (Value.getAsInteger(0, Size))
return make_error<StringError>("'" + Value + "' not an integer",
inconvertibleErrorCode());
Policy.MaxSizeBytes = Size * Mult;
} else if (Key == "cache_size_files") {
if (Value.getAsInteger(0, Policy.MaxSizeFiles))
return make_error<StringError>("'" + Value + "' not an integer",
inconvertibleErrorCode());
} else {
return make_error<StringError>("Unknown key: '" + Key + "'",
inconvertibleErrorCode());
}
}
return Policy;
}
/// Prune the cache of files that haven't been accessed in a long time.
bool llvm::pruneCache(StringRef Path, CachePruningPolicy Policy) {
using namespace std::chrono;
if (Path.empty())
return false;
bool isPathDir;
if (sys::fs::is_directory(Path, isPathDir))
return false;
if (!isPathDir)
return false;
Policy.MaxSizePercentageOfAvailableSpace =
std::min(Policy.MaxSizePercentageOfAvailableSpace, 100u);
if (Policy.Expiration == seconds(0) &&
Policy.MaxSizePercentageOfAvailableSpace == 0 &&
Policy.MaxSizeBytes == 0 && Policy.MaxSizeFiles == 0) {
DEBUG(dbgs() << "No pruning settings set, exit early\n");
// Nothing will be pruned, early exit
return false;
}
// Try to stat() the timestamp file.
SmallString<128> TimestampFile(Path);
sys::path::append(TimestampFile, "llvmcache.timestamp");
sys::fs::file_status FileStatus;
const auto CurrentTime = system_clock::now();
if (auto EC = sys::fs::status(TimestampFile, FileStatus)) {
if (EC == errc::no_such_file_or_directory) {
// If the timestamp file wasn't there, create one now.
writeTimestampFile(TimestampFile);
} else {
// Unknown error?
return false;
}
} else {
if (!Policy.Interval)
return false;
if (Policy.Interval != seconds(0)) {
// Check whether the time stamp is older than our pruning interval.
// If not, do nothing.
const auto TimeStampModTime = FileStatus.getLastModificationTime();
auto TimeStampAge = CurrentTime - TimeStampModTime;
if (TimeStampAge <= *Policy.Interval) {
DEBUG(dbgs() << "Timestamp file too recent ("
<< duration_cast<seconds>(TimeStampAge).count()
<< "s old), do not prune.\n");
return false;
}
}
// Write a new timestamp file so that nobody else attempts to prune.
// There is a benign race condition here, if two processes happen to
// notice at the same time that the timestamp is out-of-date.
writeTimestampFile(TimestampFile);
}
// Keep track of space. Needs to be kept ordered by size for determinism.
std::set<std::pair<uint64_t, std::string>> FileSizes;
uint64_t TotalSize = 0;
// Walk the entire directory cache, looking for unused files.
std::error_code EC;
SmallString<128> CachePathNative;
sys::path::native(Path, CachePathNative);
// Walk all of the files within this directory.
for (sys::fs::directory_iterator File(CachePathNative, EC), FileEnd;
File != FileEnd && !EC; File.increment(EC)) {
// Ignore any files not beginning with the string "llvmcache-". This
// includes the timestamp file as well as any files created by the user.
// This acts as a safeguard against data loss if the user specifies the
// wrong directory as their cache directory.
if (!sys::path::filename(File->path()).startswith("llvmcache-"))
continue;
// Look at this file. If we can't stat it, there's nothing interesting
// there.
ErrorOr<sys::fs::basic_file_status> StatusOrErr = File->status();
if (!StatusOrErr) {
DEBUG(dbgs() << "Ignore " << File->path() << " (can't stat)\n");
continue;
}
// If the file hasn't been used recently enough, delete it
const auto FileAccessTime = StatusOrErr->getLastAccessedTime();
auto FileAge = CurrentTime - FileAccessTime;
if (Policy.Expiration != seconds(0) && FileAge > Policy.Expiration) {
DEBUG(dbgs() << "Remove " << File->path() << " ("
<< duration_cast<seconds>(FileAge).count() << "s old)\n");
sys::fs::remove(File->path());
continue;
}
// Leave it here for now, but add it to the list of size-based pruning.
TotalSize += StatusOrErr->getSize();
FileSizes.insert({StatusOrErr->getSize(), std::string(File->path())});
}
auto FileAndSize = FileSizes.rbegin();
size_t NumFiles = FileSizes.size();
auto RemoveCacheFile = [&]() {
// Remove the file.
sys::fs::remove(FileAndSize->second);
// Update size
TotalSize -= FileAndSize->first;
NumFiles--;
DEBUG(dbgs() << " - Remove " << FileAndSize->second << " (size "
<< FileAndSize->first << "), new occupancy is " << TotalSize
<< "%\n");
++FileAndSize;
};
// Prune for number of files.
if (Policy.MaxSizeFiles)
while (NumFiles > Policy.MaxSizeFiles)
RemoveCacheFile();
// Prune for size now if needed
if (Policy.MaxSizePercentageOfAvailableSpace > 0 || Policy.MaxSizeBytes > 0) {
auto ErrOrSpaceInfo = sys::fs::disk_space(Path);
if (!ErrOrSpaceInfo) {
report_fatal_error("Can't get available size");
}
sys::fs::space_info SpaceInfo = ErrOrSpaceInfo.get();
auto AvailableSpace = TotalSize + SpaceInfo.free;
if (Policy.MaxSizePercentageOfAvailableSpace == 0)
Policy.MaxSizePercentageOfAvailableSpace = 100;
if (Policy.MaxSizeBytes == 0)
Policy.MaxSizeBytes = AvailableSpace;
auto TotalSizeTarget = std::min<uint64_t>(
AvailableSpace * Policy.MaxSizePercentageOfAvailableSpace / 100ull,
Policy.MaxSizeBytes);
DEBUG(dbgs() << "Occupancy: " << ((100 * TotalSize) / AvailableSpace)
<< "% target is: " << Policy.MaxSizePercentageOfAvailableSpace
<< "%, " << Policy.MaxSizeBytes << " bytes\n");
// Remove the oldest accessed files first, till we get below the threshold.
while (TotalSize > TotalSizeTarget && FileAndSize != FileSizes.rend())
RemoveCacheFile();
}
return true;
}

View File

@ -1,94 +0,0 @@
//===- Support/Chrono.cpp - Utilities for Timing Manipulation ---*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "llvm/Support/Chrono.h"
#include "llvm/Config/config.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/raw_ostream.h"
namespace llvm {
using namespace sys;
const char llvm::detail::unit<std::ratio<3600>>::value[] = "h";
const char llvm::detail::unit<std::ratio<60>>::value[] = "m";
const char llvm::detail::unit<std::ratio<1>>::value[] = "s";
const char llvm::detail::unit<std::milli>::value[] = "ms";
const char llvm::detail::unit<std::micro>::value[] = "us";
const char llvm::detail::unit<std::nano>::value[] = "ns";
static inline struct tm getStructTM(TimePoint<> TP) {
struct tm Storage;
std::time_t OurTime = toTimeT(TP);
#if defined(LLVM_ON_UNIX)
struct tm *LT = ::localtime_r(&OurTime, &Storage);
assert(LT);
(void)LT;
#endif
#if defined(LLVM_ON_WIN32)
int Error = ::localtime_s(&Storage, &OurTime);
assert(!Error);
(void)Error;
#endif
return Storage;
}
raw_ostream &operator<<(raw_ostream &OS, TimePoint<> TP) {
struct tm LT = getStructTM(TP);
char Buffer[sizeof("YYYY-MM-DD HH:MM:SS")];
strftime(Buffer, sizeof(Buffer), "%Y-%m-%d %H:%M:%S", &LT);
return OS << Buffer << '.'
<< format("%.9lu",
long((TP.time_since_epoch() % std::chrono::seconds(1))
.count()));
}
void format_provider<TimePoint<>>::format(const TimePoint<> &T, raw_ostream &OS,
StringRef Style) {
using namespace std::chrono;
TimePoint<seconds> Truncated = time_point_cast<seconds>(T);
auto Fractional = T - Truncated;
struct tm LT = getStructTM(Truncated);
// Handle extensions first. strftime mangles unknown %x on some platforms.
if (Style.empty()) Style = "%Y-%m-%d %H:%M:%S.%N";
std::string Format;
raw_string_ostream FStream(Format);
for (unsigned I = 0; I < Style.size(); ++I) {
if (Style[I] == '%' && Style.size() > I + 1) switch (Style[I + 1]) {
case 'L': // Milliseconds, from Ruby.
FStream << llvm::format(
"%.3lu", (long)duration_cast<milliseconds>(Fractional).count());
++I;
continue;
case 'f': // Microseconds, from Python.
FStream << llvm::format(
"%.6lu", (long)duration_cast<microseconds>(Fractional).count());
++I;
continue;
case 'N': // Nanoseconds, from date(1).
FStream << llvm::format(
"%.6lu", (long)duration_cast<nanoseconds>(Fractional).count());
++I;
continue;
case '%': // Consume %%, so %%f parses as (%%)f not %(%f)
FStream << "%%";
++I;
continue;
}
FStream << Style[I];
}
FStream.flush();
char Buffer[256]; // Should be enough for anywhen.
size_t Len = strftime(Buffer, sizeof(Buffer), Format.c_str(), &LT);
OS << (Len ? Buffer : "BAD-DATE-FORMAT");
}
} // namespace llvm

Some files were not shown because too many files have changed in this diff Show More