diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2017-06-10 13:44:06 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2017-06-10 13:44:06 +0000 |
commit | 7ab83427af0f77b59941ceba41d509d7d097b065 (patch) | |
tree | cc41c05b1db454e3d802f34df75e636ee922ad87 /lib/Support | |
parent | d288ef4c1788d3a951a7558c68312c2d320612b1 (diff) |
Diffstat (limited to 'lib/Support')
37 files changed, 302 insertions, 773 deletions
diff --git a/lib/Support/AMDGPUCodeObjectMetadata.cpp b/lib/Support/AMDGPUCodeObjectMetadata.cpp new file mode 100644 index 000000000000..a00e371415a3 --- /dev/null +++ b/lib/Support/AMDGPUCodeObjectMetadata.cpp @@ -0,0 +1,218 @@ +//===--- AMDGPUCodeObjectMetadata.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 Code Object Metadata definitions and in-memory +/// representations. +/// +// +//===----------------------------------------------------------------------===// + +#include "llvm/Support/AMDGPUCodeObjectMetadata.h" +#include "llvm/Support/YAMLTraits.h" + +using namespace llvm::AMDGPU; +using namespace llvm::AMDGPU::CodeObject; + +LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(uint32_t) +LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(std::string) +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()); + } +}; + +template <> +struct MappingTraits<Kernel::Arg::Metadata> { + static void mapping(IO &YIO, Kernel::Arg::Metadata &MD) { + 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::AccQual, MD.mAccQual, + AccessQualifier::Unknown); + YIO.mapOptional(Kernel::Arg::Key::AddrSpaceQual, MD.mAddrSpaceQual, + AddressSpaceQualifier::Unknown); + YIO.mapOptional(Kernel::Arg::Key::IsConst, MD.mIsConst, false); + YIO.mapOptional(Kernel::Arg::Key::IsPipe, MD.mIsPipe, false); + YIO.mapOptional(Kernel::Arg::Key::IsRestrict, MD.mIsRestrict, false); + YIO.mapOptional(Kernel::Arg::Key::IsVolatile, MD.mIsVolatile, false); + YIO.mapOptional(Kernel::Arg::Key::Name, MD.mName, std::string()); + YIO.mapOptional(Kernel::Arg::Key::TypeName, MD.mTypeName, std::string()); + } +}; + +template <> +struct MappingTraits<Kernel::CodeProps::Metadata> { + static void mapping(IO &YIO, Kernel::CodeProps::Metadata &MD) { + YIO.mapOptional(Kernel::CodeProps::Key::KernargSegmentSize, + MD.mKernargSegmentSize, uint64_t(0)); + YIO.mapOptional(Kernel::CodeProps::Key::WorkgroupGroupSegmentSize, + MD.mWorkgroupGroupSegmentSize, uint32_t(0)); + YIO.mapOptional(Kernel::CodeProps::Key::WorkitemPrivateSegmentSize, + MD.mWorkitemPrivateSegmentSize, uint32_t(0)); + YIO.mapOptional(Kernel::CodeProps::Key::WavefrontNumSGPRs, + MD.mWavefrontNumSGPRs, uint16_t(0)); + YIO.mapOptional(Kernel::CodeProps::Key::WorkitemNumVGPRs, + MD.mWorkitemNumVGPRs, uint16_t(0)); + YIO.mapOptional(Kernel::CodeProps::Key::KernargSegmentAlign, + MD.mKernargSegmentAlign, uint8_t(0)); + YIO.mapOptional(Kernel::CodeProps::Key::GroupSegmentAlign, + MD.mGroupSegmentAlign, uint8_t(0)); + YIO.mapOptional(Kernel::CodeProps::Key::PrivateSegmentAlign, + MD.mPrivateSegmentAlign, uint8_t(0)); + YIO.mapOptional(Kernel::CodeProps::Key::WavefrontSize, + MD.mWavefrontSize, uint8_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.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<CodeObject::Metadata> { + static void mapping(IO &YIO, CodeObject::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 CodeObject { + +/* static */ +std::error_code Metadata::fromYamlString( + std::string YamlString, Metadata &CodeObjectMetadata) { + yaml::Input YamlInput(YamlString); + YamlInput >> CodeObjectMetadata; + return YamlInput.error(); +} + +/* static */ +std::error_code Metadata::toYamlString( + Metadata CodeObjectMetadata, std::string &YamlString) { + raw_string_ostream YamlStream(YamlString); + yaml::Output YamlOutput(YamlStream, nullptr, std::numeric_limits<int>::max()); + YamlOutput << CodeObjectMetadata; + return std::error_code(); +} + +} // end namespace CodeObject +} // end namespace AMDGPU +} // end namespace llvm diff --git a/lib/Support/ARMAttributeParser.cpp b/lib/Support/ARMAttributeParser.cpp index 63e800a5b78b..a9a0c1d1a4d3 100644 --- a/lib/Support/ARMAttributeParser.cpp +++ b/lib/Support/ARMAttributeParser.cpp @@ -7,9 +7,9 @@ // //===----------------------------------------------------------------------===// +#include "llvm/Support/ARMAttributeParser.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringExtras.h" -#include "llvm/Support/ARMAttributeParser.h" #include "llvm/Support/LEB128.h" #include "llvm/Support/ScopedPrinter.h" diff --git a/lib/Support/ARMBuildAttrs.cpp b/lib/Support/ARMBuildAttrs.cpp index 134ef8b587b7..8f18e9eb24ed 100644 --- a/lib/Support/ARMBuildAttrs.cpp +++ b/lib/Support/ARMBuildAttrs.cpp @@ -7,8 +7,8 @@ // //===----------------------------------------------------------------------===// -#include "llvm/Support/ARMBuildAttributes.h" #include "llvm/ADT/StringRef.h" +#include "llvm/Support/ARMBuildAttributes.h" using namespace llvm; diff --git a/lib/Support/Atomic.cpp b/lib/Support/Atomic.cpp index 80550e2b46a7..55910c489faf 100644 --- a/lib/Support/Atomic.cpp +++ b/lib/Support/Atomic.cpp @@ -18,6 +18,8 @@ using namespace llvm; #if defined(_MSC_VER) #include <Intrin.h> + +// We must include windows.h after Intrin.h. #include <windows.h> #undef MemoryFence #endif diff --git a/lib/Support/CMakeLists.txt b/lib/Support/CMakeLists.txt index a12ba4fbfda8..0a8e3897cce9 100644 --- a/lib/Support/CMakeLists.txt +++ b/lib/Support/CMakeLists.txt @@ -30,6 +30,7 @@ elseif( CMAKE_HOST_UNIX ) endif( MSVC OR MINGW ) add_llvm_library(LLVMSupport + AMDGPUCodeObjectMetadata.cpp APFloat.cpp APInt.cpp APSInt.cpp @@ -57,7 +58,6 @@ add_llvm_library(LLVMSupport DebugCounter.cpp DeltaAlgorithm.cpp DAGDeltaAlgorithm.cpp - Dwarf.cpp Error.cpp ErrorHandling.cpp FileUtilities.cpp diff --git a/lib/Support/CommandLine.cpp b/lib/Support/CommandLine.cpp index 34345901eab1..de0ca940b405 100644 --- a/lib/Support/CommandLine.cpp +++ b/lib/Support/CommandLine.cpp @@ -2042,9 +2042,9 @@ void CommandLineParser::printOptionValues() { Opts[i].second->printOptionValue(MaxArgLen, PrintAllOptions); } -static void (*OverrideVersionPrinter)() = nullptr; +static VersionPrinterTy OverrideVersionPrinter = nullptr; -static std::vector<void (*)()> *ExtraVersionPrinters = nullptr; +static std::vector<VersionPrinterTy> *ExtraVersionPrinters = nullptr; namespace { class VersionPrinter { @@ -2084,7 +2084,7 @@ public: return; if (OverrideVersionPrinter != nullptr) { - (*OverrideVersionPrinter)(); + OverrideVersionPrinter(outs()); exit(0); } print(); @@ -2093,10 +2093,8 @@ public: // information. if (ExtraVersionPrinters != nullptr) { outs() << '\n'; - for (std::vector<void (*)()>::iterator I = ExtraVersionPrinters->begin(), - E = ExtraVersionPrinters->end(); - I != E; ++I) - (*I)(); + for (auto I : *ExtraVersionPrinters) + I(outs()); } exit(0); @@ -2134,11 +2132,11 @@ void cl::PrintHelpMessage(bool Hidden, bool Categorized) { /// Utility function for printing version number. void cl::PrintVersionMessage() { VersionPrinterInstance.print(); } -void cl::SetVersionPrinter(void (*func)()) { OverrideVersionPrinter = func; } +void cl::SetVersionPrinter(VersionPrinterTy func) { OverrideVersionPrinter = func; } -void cl::AddExtraVersionPrinter(void (*func)()) { +void cl::AddExtraVersionPrinter(VersionPrinterTy func) { if (!ExtraVersionPrinters) - ExtraVersionPrinters = new std::vector<void (*)()>; + ExtraVersionPrinters = new std::vector<VersionPrinterTy>; ExtraVersionPrinters->push_back(func); } diff --git a/lib/Support/ConvertUTF.cpp b/lib/Support/ConvertUTF.cpp index aa9507c189ed..e56854a3ae42 100644 --- a/lib/Support/ConvertUTF.cpp +++ b/lib/Support/ConvertUTF.cpp @@ -46,14 +46,12 @@ ------------------------------------------------------------------------ */ - #include "llvm/Support/ConvertUTF.h" #ifdef CVTUTF_DEBUG #include <stdio.h> #endif #include <assert.h> - /* * This code extensively uses fall-through switches. * Keep the compiler from warning about that. diff --git a/lib/Support/ConvertUTFWrapper.cpp b/lib/Support/ConvertUTFWrapper.cpp index 217cedb24df6..6cb4f6376250 100644 --- a/lib/Support/ConvertUTFWrapper.cpp +++ b/lib/Support/ConvertUTFWrapper.cpp @@ -7,9 +7,9 @@ // //===----------------------------------------------------------------------===// -#include "llvm/Support/ConvertUTF.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/StringRef.h" +#include "llvm/Support/ConvertUTF.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/SwapByteOrder.h" #include <string> diff --git a/lib/Support/Dwarf.cpp b/lib/Support/Dwarf.cpp deleted file mode 100644 index 200546857de7..000000000000 --- a/lib/Support/Dwarf.cpp +++ /dev/null @@ -1,541 +0,0 @@ -//===-- llvm/Support/Dwarf.cpp - Dwarf Framework ----------------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This file contains support for generic dwarf information. -// -//===----------------------------------------------------------------------===// - -#include "llvm/Support/Dwarf.h" -#include "llvm/ADT/StringSwitch.h" -#include "llvm/Support/ErrorHandling.h" - -using namespace llvm; -using namespace dwarf; - -StringRef llvm::dwarf::TagString(unsigned Tag) { - switch (Tag) { - default: - return StringRef(); -#define HANDLE_DW_TAG(ID, NAME, VERSION, VENDOR) \ - case DW_TAG_##NAME: \ - return "DW_TAG_" #NAME; -#include "llvm/Support/Dwarf.def" - } -} - -unsigned llvm::dwarf::getTag(StringRef TagString) { - return StringSwitch<unsigned>(TagString) -#define HANDLE_DW_TAG(ID, NAME, VERSION, VENDOR) \ - .Case("DW_TAG_" #NAME, DW_TAG_##NAME) -#include "llvm/Support/Dwarf.def" - .Default(DW_TAG_invalid); -} - -unsigned llvm::dwarf::TagVersion(dwarf::Tag Tag) { - switch (Tag) { - default: - return 0; -#define HANDLE_DW_TAG(ID, NAME, VERSION, VENDOR) \ - case DW_TAG_##NAME: \ - return VERSION; -#include "llvm/Support/Dwarf.def" - } -} - -unsigned llvm::dwarf::TagVendor(dwarf::Tag Tag) { - switch (Tag) { - default: - return 0; -#define HANDLE_DW_TAG(ID, NAME, VERSION, VENDOR) \ - case DW_TAG_##NAME: \ - return DWARF_VENDOR_##VENDOR; -#include "llvm/Support/Dwarf.def" - } -} - -StringRef llvm::dwarf::ChildrenString(unsigned Children) { - switch (Children) { - case DW_CHILDREN_no: return "DW_CHILDREN_no"; - case DW_CHILDREN_yes: return "DW_CHILDREN_yes"; - } - return StringRef(); -} - -StringRef llvm::dwarf::AttributeString(unsigned Attribute) { - switch (Attribute) { - default: - return StringRef(); -#define HANDLE_DW_AT(ID, NAME, VERSION, VENDOR) \ - case DW_AT_##NAME: \ - return "DW_AT_" #NAME; -#include "llvm/Support/Dwarf.def" - } -} - -unsigned llvm::dwarf::AttributeVersion(dwarf::Attribute Attribute) { - switch (Attribute) { - default: - return 0; -#define HANDLE_DW_AT(ID, NAME, VERSION, VENDOR) \ - case DW_AT_##NAME: \ - return VERSION; -#include "llvm/Support/Dwarf.def" - } -} - -unsigned llvm::dwarf::AttributeVendor(dwarf::Attribute Attribute) { - switch (Attribute) { - default: - return 0; -#define HANDLE_DW_AT(ID, NAME, VERSION, VENDOR) \ - case DW_AT_##NAME: \ - return DWARF_VENDOR_##VENDOR; -#include "llvm/Support/Dwarf.def" - } -} - -StringRef llvm::dwarf::FormEncodingString(unsigned Encoding) { - switch (Encoding) { - default: - return StringRef(); -#define HANDLE_DW_FORM(ID, NAME, VERSION, VENDOR) \ - case DW_FORM_##NAME: \ - return "DW_FORM_" #NAME; -#include "llvm/Support/Dwarf.def" - } -} - -unsigned llvm::dwarf::FormVersion(dwarf::Form Form) { - switch (Form) { - default: - return 0; -#define HANDLE_DW_FORM(ID, NAME, VERSION, VENDOR) \ - case DW_FORM_##NAME: \ - return VERSION; -#include "llvm/Support/Dwarf.def" - } -} - -unsigned llvm::dwarf::FormVendor(dwarf::Form Form) { - switch (Form) { - default: - return 0; -#define HANDLE_DW_FORM(ID, NAME, VERSION, VENDOR) \ - case DW_FORM_##NAME: \ - return DWARF_VENDOR_##VENDOR; -#include "llvm/Support/Dwarf.def" - } -} - -StringRef llvm::dwarf::OperationEncodingString(unsigned Encoding) { - switch (Encoding) { - default: - return StringRef(); -#define HANDLE_DW_OP(ID, NAME, VERSION, VENDOR) \ - case DW_OP_##NAME: \ - return "DW_OP_" #NAME; -#include "llvm/Support/Dwarf.def" - case DW_OP_LLVM_fragment: - return "DW_OP_LLVM_fragment"; - } -} - -unsigned llvm::dwarf::getOperationEncoding(StringRef OperationEncodingString) { - return StringSwitch<unsigned>(OperationEncodingString) -#define HANDLE_DW_OP(ID, NAME, VERSION, VENDOR) \ - .Case("DW_OP_" #NAME, DW_OP_##NAME) -#include "llvm/Support/Dwarf.def" - .Case("DW_OP_LLVM_fragment", DW_OP_LLVM_fragment) - .Default(0); -} - -unsigned llvm::dwarf::OperationVersion(dwarf::LocationAtom Op) { - switch (Op) { - default: - return 0; -#define HANDLE_DW_OP(ID, NAME, VERSION, VENDOR) \ - case DW_OP_##NAME: \ - return VERSION; -#include "llvm/Support/Dwarf.def" - } -} - -unsigned llvm::dwarf::OperationVendor(dwarf::LocationAtom Op) { - switch (Op) { - default: - return 0; -#define HANDLE_DW_OP(ID, NAME, VERSION, VENDOR) \ - case DW_OP_##NAME: \ - return DWARF_VENDOR_##VENDOR; -#include "llvm/Support/Dwarf.def" - } -} - -StringRef llvm::dwarf::AttributeEncodingString(unsigned Encoding) { - switch (Encoding) { - default: - return StringRef(); -#define HANDLE_DW_ATE(ID, NAME, VERSION, VENDOR) \ - case DW_ATE_##NAME: \ - return "DW_ATE_" #NAME; -#include "llvm/Support/Dwarf.def" - } -} - -unsigned llvm::dwarf::getAttributeEncoding(StringRef EncodingString) { - return StringSwitch<unsigned>(EncodingString) -#define HANDLE_DW_ATE(ID, NAME, VERSION, VENDOR) \ - .Case("DW_ATE_" #NAME, DW_ATE_##NAME) -#include "llvm/Support/Dwarf.def" - .Default(0); -} - -unsigned llvm::dwarf::AttributeEncodingVersion(dwarf::TypeKind ATE) { - switch (ATE) { - default: - return 0; -#define HANDLE_DW_ATE(ID, NAME, VERSION, VENDOR) \ - case DW_ATE_##NAME: \ - return VERSION; -#include "llvm/Support/Dwarf.def" - } -} - -unsigned llvm::dwarf::AttributeEncodingVendor(dwarf::TypeKind ATE) { - switch (ATE) { - default: - return 0; -#define HANDLE_DW_ATE(ID, NAME, VERSION, VENDOR) \ - case DW_ATE_##NAME: \ - return DWARF_VENDOR_##VENDOR; -#include "llvm/Support/Dwarf.def" - } -} - -StringRef llvm::dwarf::DecimalSignString(unsigned Sign) { - switch (Sign) { - case DW_DS_unsigned: return "DW_DS_unsigned"; - case DW_DS_leading_overpunch: return "DW_DS_leading_overpunch"; - case DW_DS_trailing_overpunch: return "DW_DS_trailing_overpunch"; - case DW_DS_leading_separate: return "DW_DS_leading_separate"; - case DW_DS_trailing_separate: return "DW_DS_trailing_separate"; - } - return StringRef(); -} - -StringRef llvm::dwarf::EndianityString(unsigned Endian) { - switch (Endian) { - case DW_END_default: return "DW_END_default"; - case DW_END_big: return "DW_END_big"; - case DW_END_little: return "DW_END_little"; - case DW_END_lo_user: return "DW_END_lo_user"; - case DW_END_hi_user: return "DW_END_hi_user"; - } - return StringRef(); -} - -StringRef llvm::dwarf::AccessibilityString(unsigned Access) { - switch (Access) { - // Accessibility codes - case DW_ACCESS_public: return "DW_ACCESS_public"; - case DW_ACCESS_protected: return "DW_ACCESS_protected"; - case DW_ACCESS_private: return "DW_ACCESS_private"; - } - return StringRef(); -} - -StringRef llvm::dwarf::VisibilityString(unsigned Visibility) { - switch (Visibility) { - case DW_VIS_local: return "DW_VIS_local"; - case DW_VIS_exported: return "DW_VIS_exported"; - case DW_VIS_qualified: return "DW_VIS_qualified"; - } - return StringRef(); -} - -StringRef llvm::dwarf::VirtualityString(unsigned Virtuality) { - switch (Virtuality) { - default: - return StringRef(); -#define HANDLE_DW_VIRTUALITY(ID, NAME) \ - case DW_VIRTUALITY_##NAME: \ - return "DW_VIRTUALITY_" #NAME; -#include "llvm/Support/Dwarf.def" - } -} - -unsigned llvm::dwarf::getVirtuality(StringRef VirtualityString) { - return StringSwitch<unsigned>(VirtualityString) -#define HANDLE_DW_VIRTUALITY(ID, NAME) \ - .Case("DW_VIRTUALITY_" #NAME, DW_VIRTUALITY_##NAME) -#include "llvm/Support/Dwarf.def" - .Default(DW_VIRTUALITY_invalid); -} - -StringRef llvm::dwarf::LanguageString(unsigned Language) { - switch (Language) { - default: - return StringRef(); -#define HANDLE_DW_LANG(ID, NAME, VERSION, VENDOR) \ - case DW_LANG_##NAME: \ - return "DW_LANG_" #NAME; -#include "llvm/Support/Dwarf.def" - } -} - -unsigned llvm::dwarf::getLanguage(StringRef LanguageString) { - return StringSwitch<unsigned>(LanguageString) -#define HANDLE_DW_LANG(ID, NAME, VERSION, VENDOR) \ - .Case("DW_LANG_" #NAME, DW_LANG_##NAME) -#include "llvm/Support/Dwarf.def" - .Default(0); -} - -unsigned llvm::dwarf::LanguageVersion(dwarf::SourceLanguage Lang) { - switch (Lang) { - default: - return 0; -#define HANDLE_DW_LANG(ID, NAME, VERSION, VENDOR) \ - case DW_LANG_##NAME: \ - return VERSION; -#include "llvm/Support/Dwarf.def" - } -} - -unsigned llvm::dwarf::LanguageVendor(dwarf::SourceLanguage Lang) { - switch (Lang) { - default: - return 0; -#define HANDLE_DW_LANG(ID, NAME, VERSION, VENDOR) \ - case DW_LANG_##NAME: \ - return DWARF_VENDOR_##VENDOR; -#include "llvm/Support/Dwarf.def" - } -} - -StringRef llvm::dwarf::CaseString(unsigned Case) { - switch (Case) { - case DW_ID_case_sensitive: return "DW_ID_case_sensitive"; - case DW_ID_up_case: return "DW_ID_up_case"; - case DW_ID_down_case: return "DW_ID_down_case"; - case DW_ID_case_insensitive: return "DW_ID_case_insensitive"; - } - return StringRef(); -} - -StringRef llvm::dwarf::ConventionString(unsigned CC) { - switch (CC) { - default: - return StringRef(); -#define HANDLE_DW_CC(ID, NAME) \ - case DW_CC_##NAME: \ - return "DW_CC_" #NAME; -#include "llvm/Support/Dwarf.def" - } -} - -unsigned llvm::dwarf::getCallingConvention(StringRef CCString) { - return StringSwitch<unsigned>(CCString) -#define HANDLE_DW_CC(ID, NAME) .Case("DW_CC_" #NAME, DW_CC_##NAME) -#include "llvm/Support/Dwarf.def" - .Default(0); -} - -StringRef llvm::dwarf::InlineCodeString(unsigned Code) { - switch (Code) { - case DW_INL_not_inlined: return "DW_INL_not_inlined"; - case DW_INL_inlined: return "DW_INL_inlined"; - case DW_INL_declared_not_inlined: return "DW_INL_declared_not_inlined"; - case DW_INL_declared_inlined: return "DW_INL_declared_inlined"; - } - return StringRef(); -} - -StringRef llvm::dwarf::ArrayOrderString(unsigned Order) { - switch (Order) { - case DW_ORD_row_major: return "DW_ORD_row_major"; - case DW_ORD_col_major: return "DW_ORD_col_major"; - } - return StringRef(); -} - -StringRef llvm::dwarf::DiscriminantString(unsigned Discriminant) { - switch (Discriminant) { - case DW_DSC_label: return "DW_DSC_label"; - case DW_DSC_range: return "DW_DSC_range"; - } - return StringRef(); -} - -StringRef llvm::dwarf::LNStandardString(unsigned Standard) { - switch (Standard) { - default: - return StringRef(); -#define HANDLE_DW_LNS(ID, NAME) \ - case DW_LNS_##NAME: \ - return "DW_LNS_" #NAME; -#include "llvm/Support/Dwarf.def" - } -} - -StringRef llvm::dwarf::LNExtendedString(unsigned Encoding) { - switch (Encoding) { - default: - return StringRef(); -#define HANDLE_DW_LNE(ID, NAME) \ - case DW_LNE_##NAME: \ - return "DW_LNE_" #NAME; -#include "llvm/Support/Dwarf.def" - } -} - -StringRef llvm::dwarf::MacinfoString(unsigned Encoding) { - switch (Encoding) { - // Macinfo Type Encodings - case DW_MACINFO_define: return "DW_MACINFO_define"; - case DW_MACINFO_undef: return "DW_MACINFO_undef"; - case DW_MACINFO_start_file: return "DW_MACINFO_start_file"; - case DW_MACINFO_end_file: return "DW_MACINFO_end_file"; - case DW_MACINFO_vendor_ext: return "DW_MACINFO_vendor_ext"; - case DW_MACINFO_invalid: return "DW_MACINFO_invalid"; - } - return StringRef(); -} - -unsigned llvm::dwarf::getMacinfo(StringRef MacinfoString) { - return StringSwitch<unsigned>(MacinfoString) - .Case("DW_MACINFO_define", DW_MACINFO_define) - .Case("DW_MACINFO_undef", DW_MACINFO_undef) - .Case("DW_MACINFO_start_file", DW_MACINFO_start_file) - .Case("DW_MACINFO_end_file", DW_MACINFO_end_file) - .Case("DW_MACINFO_vendor_ext", DW_MACINFO_vendor_ext) - .Default(DW_MACINFO_invalid); -} - -StringRef llvm::dwarf::CallFrameString(unsigned Encoding) { - switch (Encoding) { - default: - return StringRef(); -#define HANDLE_DW_CFA(ID, NAME) \ - case DW_CFA_##NAME: \ - return "DW_CFA_" #NAME; -#include "llvm/Support/Dwarf.def" - } -} - -StringRef llvm::dwarf::ApplePropertyString(unsigned Prop) { - switch (Prop) { - default: - return StringRef(); -#define HANDLE_DW_APPLE_PROPERTY(ID, NAME) \ - case DW_APPLE_PROPERTY_##NAME: \ - return "DW_APPLE_PROPERTY_" #NAME; -#include "llvm/Support/Dwarf.def" - } -} - -StringRef llvm::dwarf::UnitTypeString(unsigned UT) { - switch (UT) { - default: - return StringRef(); -#define HANDLE_DW_UT(ID, NAME) \ - case DW_UT_##NAME: \ - return "DW_UT_" #NAME; -#include "llvm/Support/Dwarf.def" - } -} - -StringRef llvm::dwarf::AtomTypeString(unsigned AT) { - switch (AT) { - case dwarf::DW_ATOM_null: - return "DW_ATOM_null"; - case dwarf::DW_ATOM_die_offset: - return "DW_ATOM_die_offset"; - case DW_ATOM_cu_offset: - return "DW_ATOM_cu_offset"; - case DW_ATOM_die_tag: - return "DW_ATOM_die_tag"; - case DW_ATOM_type_flags: - return "DW_ATOM_type_flags"; - } - return StringRef(); -} - -StringRef llvm::dwarf::GDBIndexEntryKindString(GDBIndexEntryKind Kind) { - switch (Kind) { - case GIEK_NONE: - return "NONE"; - case GIEK_TYPE: - return "TYPE"; - case GIEK_VARIABLE: - return "VARIABLE"; - case GIEK_FUNCTION: - return "FUNCTION"; - case GIEK_OTHER: - return "OTHER"; - case GIEK_UNUSED5: - return "UNUSED5"; - case GIEK_UNUSED6: - return "UNUSED6"; - case GIEK_UNUSED7: - return "UNUSED7"; - } - llvm_unreachable("Unknown GDBIndexEntryKind value"); -} - -StringRef -llvm::dwarf::GDBIndexEntryLinkageString(GDBIndexEntryLinkage Linkage) { - switch (Linkage) { - case GIEL_EXTERNAL: - return "EXTERNAL"; - case GIEL_STATIC: - return "STATIC"; - } - llvm_unreachable("Unknown GDBIndexEntryLinkage value"); -} - -StringRef llvm::dwarf::AttributeValueString(uint16_t Attr, unsigned Val) { - switch (Attr) { - case DW_AT_accessibility: - return AccessibilityString(Val); - case DW_AT_virtuality: - return VirtualityString(Val); - case DW_AT_language: - return LanguageString(Val); - case DW_AT_encoding: - return AttributeEncodingString(Val); - case DW_AT_decimal_sign: - return DecimalSignString(Val); - case DW_AT_endianity: - return EndianityString(Val); - case DW_AT_visibility: - return VisibilityString(Val); - case DW_AT_identifier_case: - return CaseString(Val); - case DW_AT_calling_convention: - return ConventionString(Val); - case DW_AT_inline: - return InlineCodeString(Val); - case DW_AT_ordering: - return ArrayOrderString(Val); - case DW_AT_discr_value: - return DiscriminantString(Val); - } - - return StringRef(); -} - -bool llvm::dwarf::isValidFormForVersion(Form F, unsigned Version, - bool ExtensionsOk) { - if (FormVendor(F) == DWARF_VENDOR_DWARF) { - unsigned FV = FormVersion(F); - return FV > 0 && FV <= Version; - } - return ExtensionsOk; -} diff --git a/lib/Support/Errno.cpp b/lib/Support/Errno.cpp index 3ba2a1277d05..10be9b391b49 100644 --- a/lib/Support/Errno.cpp +++ b/lib/Support/Errno.cpp @@ -12,7 +12,7 @@ //===----------------------------------------------------------------------===// #include "llvm/Support/Errno.h" -#include "llvm/Config/config.h" // Get autoconf configuration settings +#include "llvm/Config/config.h" // Get autoconf configuration settings #include "llvm/Support/raw_ostream.h" #include <string.h> diff --git a/lib/Support/Error.cpp b/lib/Support/Error.cpp index 4730c0b26ba0..bb02c03ff2b6 100644 --- a/lib/Support/Error.cpp +++ b/lib/Support/Error.cpp @@ -13,7 +13,6 @@ #include "llvm/Support/ManagedStatic.h" #include <system_error> - using namespace llvm; namespace { diff --git a/lib/Support/FormattedStream.cpp b/lib/Support/FormattedStream.cpp index c01659604444..a9f4409f5dde 100644 --- a/lib/Support/FormattedStream.cpp +++ b/lib/Support/FormattedStream.cpp @@ -11,8 +11,8 @@ // //===----------------------------------------------------------------------===// -#include "llvm/Support/Debug.h" #include "llvm/Support/FormattedStream.h" +#include "llvm/Support/Debug.h" #include "llvm/Support/raw_ostream.h" #include <algorithm> diff --git a/lib/Support/LockFileManager.cpp b/lib/Support/LockFileManager.cpp index 8be9879fbc24..3ee3af7731e6 100644 --- a/lib/Support/LockFileManager.cpp +++ b/lib/Support/LockFileManager.cpp @@ -15,15 +15,15 @@ #include "llvm/Support/ErrorOr.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/MemoryBuffer.h" -#include "llvm/Support/raw_ostream.h" #include "llvm/Support/Signals.h" +#include "llvm/Support/raw_ostream.h" #include <cerrno> #include <ctime> #include <memory> -#include <tuple> -#include <system_error> #include <sys/stat.h> #include <sys/types.h> +#include <system_error> +#include <tuple> #if LLVM_ON_WIN32 #include <windows.h> #endif diff --git a/lib/Support/MD5.cpp b/lib/Support/MD5.cpp index bdbf1d677938..545a64cfc767 100644 --- a/lib/Support/MD5.cpp +++ b/lib/Support/MD5.cpp @@ -37,11 +37,11 @@ * compile-time configuration. */ +#include "llvm/Support/MD5.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/Endian.h" #include "llvm/Support/Format.h" -#include "llvm/Support/MD5.h" #include "llvm/Support/raw_ostream.h" #include <array> #include <cstdint> diff --git a/lib/Support/Mutex.cpp b/lib/Support/Mutex.cpp index c8d3844d0c96..bdd02105f6f0 100644 --- a/lib/Support/Mutex.cpp +++ b/lib/Support/Mutex.cpp @@ -11,8 +11,8 @@ // //===----------------------------------------------------------------------===// -#include "llvm/Config/config.h" #include "llvm/Support/Mutex.h" +#include "llvm/Config/config.h" //===----------------------------------------------------------------------===// //=== WARNING: Implementation here must contain only TRULY operating system diff --git a/lib/Support/Path.cpp b/lib/Support/Path.cpp index 80bef558258d..e58f856ca244 100644 --- a/lib/Support/Path.cpp +++ b/lib/Support/Path.cpp @@ -13,12 +13,12 @@ #include "llvm/Support/Path.h" #include "llvm/ADT/ArrayRef.h" -#include "llvm/Support/COFF.h" +#include "llvm/BinaryFormat/COFF.h" +#include "llvm/BinaryFormat/MachO.h" #include "llvm/Support/Endian.h" #include "llvm/Support/Errc.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/FileSystem.h" -#include "llvm/Support/MachO.h" #include "llvm/Support/Process.h" #include <cctype> #include <cstring> @@ -1027,178 +1027,6 @@ void directory_entry::replace_filename(const Twine &filename, file_status st) { Status = st; } -template <size_t N> -static bool startswith(StringRef Magic, const char (&S)[N]) { - return Magic.startswith(StringRef(S, N - 1)); -} - -/// @brief Identify the magic in magic. -file_magic identify_magic(StringRef Magic) { - if (Magic.size() < 4) - return file_magic::unknown; - switch ((unsigned char)Magic[0]) { - case 0x00: { - // COFF bigobj, CL.exe's LTO object file, or short import library file - if (startswith(Magic, "\0\0\xFF\xFF")) { - size_t MinSize = offsetof(COFF::BigObjHeader, UUID) + sizeof(COFF::BigObjMagic); - if (Magic.size() < MinSize) - return file_magic::coff_import_library; - - const char *Start = Magic.data() + offsetof(COFF::BigObjHeader, UUID); - if (memcmp(Start, COFF::BigObjMagic, sizeof(COFF::BigObjMagic)) == 0) - return file_magic::coff_object; - if (memcmp(Start, COFF::ClGlObjMagic, sizeof(COFF::BigObjMagic)) == 0) - return file_magic::coff_cl_gl_object; - return file_magic::coff_import_library; - } - // Windows resource file - if (startswith(Magic, "\0\0\0\0\x20\0\0\0\xFF")) - return file_magic::windows_resource; - // 0x0000 = COFF unknown machine type - if (Magic[1] == 0) - return file_magic::coff_object; - if (startswith(Magic, "\0asm")) - return file_magic::wasm_object; - break; - } - case 0xDE: // 0x0B17C0DE = BC wraper - if (startswith(Magic, "\xDE\xC0\x17\x0B")) - return file_magic::bitcode; - break; - case 'B': - if (startswith(Magic, "BC\xC0\xDE")) - return file_magic::bitcode; - break; - case '!': - if (startswith(Magic, "!<arch>\n") || startswith(Magic, "!<thin>\n")) - return file_magic::archive; - break; - - case '\177': - if (startswith(Magic, "\177ELF") && Magic.size() >= 18) { - bool Data2MSB = Magic[5] == 2; - unsigned high = Data2MSB ? 16 : 17; - unsigned low = Data2MSB ? 17 : 16; - if (Magic[high] == 0) { - switch (Magic[low]) { - default: return file_magic::elf; - case 1: return file_magic::elf_relocatable; - case 2: return file_magic::elf_executable; - case 3: return file_magic::elf_shared_object; - case 4: return file_magic::elf_core; - } - } - // It's still some type of ELF file. - return file_magic::elf; - } - break; - - case 0xCA: - if (startswith(Magic, "\xCA\xFE\xBA\xBE") || - startswith(Magic, "\xCA\xFE\xBA\xBF")) { - // This is complicated by an overlap with Java class files. - // See the Mach-O section in /usr/share/file/magic for details. - if (Magic.size() >= 8 && Magic[7] < 43) - return file_magic::macho_universal_binary; - } - break; - - // The two magic numbers for mach-o are: - // 0xfeedface - 32-bit mach-o - // 0xfeedfacf - 64-bit mach-o - case 0xFE: - case 0xCE: - case 0xCF: { - uint16_t type = 0; - if (startswith(Magic, "\xFE\xED\xFA\xCE") || - startswith(Magic, "\xFE\xED\xFA\xCF")) { - /* Native endian */ - size_t MinSize; - if (Magic[3] == char(0xCE)) - MinSize = sizeof(MachO::mach_header); - else - MinSize = sizeof(MachO::mach_header_64); - if (Magic.size() >= MinSize) - type = Magic[12] << 24 | Magic[13] << 12 | Magic[14] << 8 | Magic[15]; - } else if (startswith(Magic, "\xCE\xFA\xED\xFE") || - startswith(Magic, "\xCF\xFA\xED\xFE")) { - /* Reverse endian */ - size_t MinSize; - if (Magic[0] == char(0xCE)) - MinSize = sizeof(MachO::mach_header); - else - MinSize = sizeof(MachO::mach_header_64); - if (Magic.size() >= MinSize) - type = Magic[15] << 24 | Magic[14] << 12 |Magic[13] << 8 | Magic[12]; - } - switch (type) { - default: break; - case 1: return file_magic::macho_object; - case 2: return file_magic::macho_executable; - case 3: return file_magic::macho_fixed_virtual_memory_shared_lib; - case 4: return file_magic::macho_core; - case 5: return file_magic::macho_preload_executable; - case 6: return file_magic::macho_dynamically_linked_shared_lib; - case 7: return file_magic::macho_dynamic_linker; - case 8: return file_magic::macho_bundle; - case 9: return file_magic::macho_dynamically_linked_shared_lib_stub; - case 10: return file_magic::macho_dsym_companion; - case 11: return file_magic::macho_kext_bundle; - } - break; - } - case 0xF0: // PowerPC Windows - case 0x83: // Alpha 32-bit - case 0x84: // Alpha 64-bit - case 0x66: // MPS R4000 Windows - case 0x50: // mc68K - case 0x4c: // 80386 Windows - case 0xc4: // ARMNT Windows - if (Magic[1] == 0x01) - return file_magic::coff_object; - LLVM_FALLTHROUGH; - - case 0x90: // PA-RISC Windows - case 0x68: // mc68K Windows - if (Magic[1] == 0x02) - return file_magic::coff_object; - break; - - case 'M': // Possible MS-DOS stub on Windows PE file - if (startswith(Magic, "MZ")) { - uint32_t off = read32le(Magic.data() + 0x3c); - // PE/COFF file, either EXE or DLL. - if (off < Magic.size() && - memcmp(Magic.data()+off, COFF::PEMagic, sizeof(COFF::PEMagic)) == 0) - return file_magic::pecoff_executable; - } - break; - - case 0x64: // x86-64 Windows. - if (Magic[1] == char(0x86)) - return file_magic::coff_object; - break; - - default: - break; - } - return file_magic::unknown; -} - -std::error_code identify_magic(const Twine &Path, file_magic &Result) { - int FD; - if (std::error_code EC = openFileForRead(Path, FD)) - return EC; - - char Buffer[32]; - int Length = read(FD, Buffer, sizeof(Buffer)); - if (close(FD) != 0 || Length < 0) - return std::error_code(errno, std::generic_category()); - - Result = identify_magic(StringRef(Buffer, Length)); - return std::error_code(); -} - std::error_code directory_entry::status(file_status &result) const { return fs::status(Path, result, FollowSymlinks); } diff --git a/lib/Support/PrettyStackTrace.cpp b/lib/Support/PrettyStackTrace.cpp index abf61b73a70d..a18e9cc50040 100644 --- a/lib/Support/PrettyStackTrace.cpp +++ b/lib/Support/PrettyStackTrace.cpp @@ -15,7 +15,7 @@ #include "llvm/Support/PrettyStackTrace.h" #include "llvm-c/ErrorHandling.h" #include "llvm/ADT/SmallString.h" -#include "llvm/Config/config.h" // Get autoconf configuration settings +#include "llvm/Config/config.h" // Get autoconf configuration settings #include "llvm/Support/Compiler.h" #include "llvm/Support/Signals.h" #include "llvm/Support/Watchdog.h" diff --git a/lib/Support/Process.cpp b/lib/Support/Process.cpp index 290c30f4968f..caec993ee165 100644 --- a/lib/Support/Process.cpp +++ b/lib/Support/Process.cpp @@ -11,11 +11,11 @@ // //===----------------------------------------------------------------------===// +#include "llvm/Support/Process.h" #include "llvm/ADT/StringExtras.h" #include "llvm/Config/config.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/Path.h" -#include "llvm/Support/Process.h" #include "llvm/Support/Program.h" using namespace llvm; diff --git a/lib/Support/RWMutex.cpp b/lib/Support/RWMutex.cpp index 6c9781c4e2d6..83c6d1d52b4c 100644 --- a/lib/Support/RWMutex.cpp +++ b/lib/Support/RWMutex.cpp @@ -11,8 +11,8 @@ // //===----------------------------------------------------------------------===// -#include "llvm/Config/config.h" #include "llvm/Support/RWMutex.h" +#include "llvm/Config/config.h" //===----------------------------------------------------------------------===// //=== WARNING: Implementation here must contain only TRULY operating system diff --git a/lib/Support/SHA1.cpp b/lib/Support/SHA1.cpp index 0eefd998cd75..20f41c5ff447 100644 --- a/lib/Support/SHA1.cpp +++ b/lib/Support/SHA1.cpp @@ -15,9 +15,9 @@ // //===----------------------------------------------------------------------===// -#include "llvm/Support/Host.h" #include "llvm/Support/SHA1.h" #include "llvm/ADT/ArrayRef.h" +#include "llvm/Support/Host.h" using namespace llvm; #include <stdint.h> diff --git a/lib/Support/Signals.cpp b/lib/Support/Signals.cpp index 57f36bf175b3..256a22dee87b 100644 --- a/lib/Support/Signals.cpp +++ b/lib/Support/Signals.cpp @@ -12,6 +12,7 @@ // //===----------------------------------------------------------------------===// +#include "llvm/Support/Signals.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringRef.h" #include "llvm/Config/config.h" @@ -23,18 +24,23 @@ #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Mutex.h" #include "llvm/Support/Program.h" -#include "llvm/Support/Signals.h" #include "llvm/Support/StringSaver.h" #include "llvm/Support/raw_ostream.h" +#include "llvm/Support/Options.h" #include <vector> -namespace llvm { - //===----------------------------------------------------------------------===// //=== WARNING: Implementation here must contain only TRULY operating system //=== independent code. //===----------------------------------------------------------------------===// +using namespace llvm; + +static cl::opt<bool> + DisableSymbolication("disable-symbolication", + cl::desc("Disable symbolizing crash backtraces."), + cl::init(false), cl::Hidden); + static ManagedStatic<std::vector<std::pair<void (*)(void *), void *>>> CallBacksToRun; void sys::RunSignalHandlers() { @@ -44,9 +50,6 @@ void sys::RunSignalHandlers() { I.first(I.second); CallBacksToRun->clear(); } -} - -using namespace llvm; static bool findModulesAndOffsets(void **StackTrace, int Depth, const char **Modules, intptr_t *Offsets, @@ -70,6 +73,9 @@ static bool printSymbolizedStackTrace(StringRef Argv0, static bool printSymbolizedStackTrace(StringRef Argv0, void **StackTrace, int Depth, llvm::raw_ostream &OS) { + if (DisableSymbolication) + return false; + // Don't recursively invoke the llvm-symbolizer binary. if (Argv0.find("llvm-symbolizer") != std::string::npos) return false; diff --git a/lib/Support/SourceMgr.cpp b/lib/Support/SourceMgr.cpp index 5199fad7d9e9..b0609d4fe047 100644 --- a/lib/Support/SourceMgr.cpp +++ b/lib/Support/SourceMgr.cpp @@ -13,18 +13,18 @@ // //===----------------------------------------------------------------------===// +#include "llvm/Support/SourceMgr.h" #include "llvm/ADT/ArrayRef.h" -#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/Twine.h" #include "llvm/Support/ErrorOr.h" #include "llvm/Support/Locale.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Path.h" -#include "llvm/Support/raw_ostream.h" #include "llvm/Support/SMLoc.h" -#include "llvm/Support/SourceMgr.h" +#include "llvm/Support/raw_ostream.h" #include <algorithm> #include <cassert> #include <cstddef> diff --git a/lib/Support/SpecialCaseList.cpp b/lib/Support/SpecialCaseList.cpp index df524b352351..05886eaa8aee 100644 --- a/lib/Support/SpecialCaseList.cpp +++ b/lib/Support/SpecialCaseList.cpp @@ -15,12 +15,12 @@ //===----------------------------------------------------------------------===// #include "llvm/Support/SpecialCaseList.h" -#include "llvm/Support/TrigramIndex.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringSet.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Regex.h" +#include "llvm/Support/TrigramIndex.h" #include <string> #include <system_error> #include <utility> diff --git a/lib/Support/Statistic.cpp b/lib/Support/Statistic.cpp index 0c50dfd27d61..72ca22806c43 100644 --- a/lib/Support/Statistic.cpp +++ b/lib/Support/Statistic.cpp @@ -30,8 +30,8 @@ #include "llvm/Support/ManagedStatic.h" #include "llvm/Support/Mutex.h" #include "llvm/Support/Timer.h" -#include "llvm/Support/raw_ostream.h" #include "llvm/Support/YAMLTraits.h" +#include "llvm/Support/raw_ostream.h" #include <algorithm> #include <cstring> using namespace llvm; diff --git a/lib/Support/StringExtras.cpp b/lib/Support/StringExtras.cpp index 3e2420f67760..b2f42dfcc04d 100644 --- a/lib/Support/StringExtras.cpp +++ b/lib/Support/StringExtras.cpp @@ -11,8 +11,8 @@ // //===----------------------------------------------------------------------===// -#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringExtras.h" +#include "llvm/ADT/SmallVector.h" using namespace llvm; /// StrInStrNoCase - Portable version of strcasestr. Locates the first diff --git a/lib/Support/TargetRegistry.cpp b/lib/Support/TargetRegistry.cpp index bed9ed64f802..b5c283253117 100644 --- a/lib/Support/TargetRegistry.cpp +++ b/lib/Support/TargetRegistry.cpp @@ -114,7 +114,7 @@ static int TargetArraySortFn(const std::pair<StringRef, const Target *> *LHS, return LHS->first.compare(RHS->first); } -void TargetRegistry::printRegisteredTargetsForVersion() { +void TargetRegistry::printRegisteredTargetsForVersion(raw_ostream &OS) { std::vector<std::pair<StringRef, const Target*> > Targets; size_t Width = 0; for (const auto &T : TargetRegistry::targets()) { @@ -123,7 +123,6 @@ void TargetRegistry::printRegisteredTargetsForVersion() { } array_pod_sort(Targets.begin(), Targets.end(), TargetArraySortFn); - raw_ostream &OS = outs(); OS << " Registered Targets:\n"; for (unsigned i = 0, e = Targets.size(); i != e; ++i) { OS << " " << Targets[i].first; diff --git a/lib/Support/ThreadLocal.cpp b/lib/Support/ThreadLocal.cpp index 9da1603080a2..9a75c02b351f 100644 --- a/lib/Support/ThreadLocal.cpp +++ b/lib/Support/ThreadLocal.cpp @@ -11,9 +11,9 @@ // //===----------------------------------------------------------------------===// +#include "llvm/Support/ThreadLocal.h" #include "llvm/Config/config.h" #include "llvm/Support/Compiler.h" -#include "llvm/Support/ThreadLocal.h" //===----------------------------------------------------------------------===// //=== WARNING: Implementation here must contain only TRULY operating system diff --git a/lib/Support/Timer.cpp b/lib/Support/Timer.cpp index dec6baf7bf47..3386f2660f31 100644 --- a/lib/Support/Timer.cpp +++ b/lib/Support/Timer.cpp @@ -20,8 +20,8 @@ #include "llvm/Support/ManagedStatic.h" #include "llvm/Support/Mutex.h" #include "llvm/Support/Process.h" -#include "llvm/Support/raw_ostream.h" #include "llvm/Support/YAMLTraits.h" +#include "llvm/Support/raw_ostream.h" using namespace llvm; // This ugly hack is brought to you courtesy of constructor/destructor ordering diff --git a/lib/Support/TrigramIndex.cpp b/lib/Support/TrigramIndex.cpp index 85ab5287566b..721763c88525 100644 --- a/lib/Support/TrigramIndex.cpp +++ b/lib/Support/TrigramIndex.cpp @@ -18,9 +18,9 @@ #include "llvm/Support/TrigramIndex.h" #include "llvm/ADT/SmallVector.h" -#include <unordered_map> #include <set> #include <string> +#include <unordered_map> using namespace llvm; diff --git a/lib/Support/Triple.cpp b/lib/Support/Triple.cpp index f7b7ad89e959..320aede79fbb 100644 --- a/lib/Support/Triple.cpp +++ b/lib/Support/Triple.cpp @@ -12,8 +12,8 @@ #include "llvm/ADT/SmallString.h" #include "llvm/ADT/StringSwitch.h" #include "llvm/Support/ErrorHandling.h" -#include "llvm/Support/TargetParser.h" #include "llvm/Support/Host.h" +#include "llvm/Support/TargetParser.h" #include <cstring> using namespace llvm; @@ -877,6 +877,10 @@ std::string Triple::normalize(StringRef Str) { } } + // SUSE uses "gnueabi" to mean "gnueabihf" + if (Vendor == Triple::SUSE && Environment == llvm::Triple::GNUEABI) + Components[3] = "gnueabihf"; + if (OS == Triple::Win32) { Components.resize(4); Components[2] = "windows"; @@ -1484,6 +1488,21 @@ bool Triple::isLittleEndian() const { } bool Triple::isCompatibleWith(const Triple &Other) const { + // ARM and Thumb triples are compatible, if subarch, vendor and OS match. + if ((getArch() == Triple::thumb && Other.getArch() == Triple::arm) || + (getArch() == Triple::arm && Other.getArch() == Triple::thumb) || + (getArch() == Triple::thumbeb && Other.getArch() == Triple::armeb) || + (getArch() == Triple::armeb && Other.getArch() == Triple::thumbeb)) { + if (getVendor() == Triple::Apple) + return getSubArch() == Other.getSubArch() && + getVendor() == Other.getVendor() && getOS() == Other.getOS(); + else + return getSubArch() == Other.getSubArch() && + getVendor() == Other.getVendor() && getOS() == Other.getOS() && + getEnvironment() == Other.getEnvironment() && + getObjectFormat() == Other.getObjectFormat(); + } + // If vendor is apple, ignore the version number. if (getVendor() == Triple::Apple) return getArch() == Other.getArch() && getSubArch() == Other.getSubArch() && diff --git a/lib/Support/Unix/DynamicLibrary.inc b/lib/Support/Unix/DynamicLibrary.inc index a0526fa2c1b8..aad77f19c35a 100644 --- a/lib/Support/Unix/DynamicLibrary.inc +++ b/lib/Support/Unix/DynamicLibrary.inc @@ -15,7 +15,8 @@ #include <dlfcn.h> DynamicLibrary::HandleSet::~HandleSet() { - for (void *Handle : Handles) + // Close the libraries in reverse order. + for (void *Handle : llvm::reverse(Handles)) ::dlclose(Handle); if (Process) ::dlclose(Process); @@ -101,10 +102,10 @@ static void *DoSearch(const char* SymbolName) { #define EXPLICIT_SYMBOL(SYM) \ if (!strcmp(SymbolName, #SYM)) return &SYM -// On linux we have a weird situation. The stderr/out/in symbols are both +// Under glibc we have a weird situation. The stderr/out/in symbols are both // macros and global variables because of standards requirements. So, we // boldly use the EXPLICIT_SYMBOL macro without checking for a #define first. -#if defined(__linux__) and !defined(__ANDROID__) +#if defined(__GLIBC__) { EXPLICIT_SYMBOL(stderr); EXPLICIT_SYMBOL(stdout); diff --git a/lib/Support/Unix/Path.inc b/lib/Support/Unix/Path.inc index ce638d453c19..b6774692595b 100644 --- a/lib/Support/Unix/Path.inc +++ b/lib/Support/Unix/Path.inc @@ -75,8 +75,8 @@ #define STATVFS_F_FRSIZE(vfs) vfs.f_frsize #else #if defined(__OpenBSD__) || defined(__FreeBSD__) -#include <sys/param.h> #include <sys/mount.h> +#include <sys/param.h> #elif defined(__linux__) #if defined(HAVE_LINUX_MAGIC_H) #include <linux/magic.h> diff --git a/lib/Support/Unix/Signals.inc b/lib/Support/Unix/Signals.inc index 88ad21e9806e..aaf760c5b616 100644 --- a/lib/Support/Unix/Signals.inc +++ b/lib/Support/Unix/Signals.inc @@ -15,9 +15,9 @@ #include "Unix.h" #include "llvm/ADT/STLExtras.h" #include "llvm/Demangle/Demangle.h" -#include "llvm/Support/Format.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/FileUtilities.h" +#include "llvm/Support/Format.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Mutex.h" #include "llvm/Support/Program.h" diff --git a/lib/Support/Unix/Threading.inc b/lib/Support/Unix/Threading.inc index 407b194e1b6a..267af388ecdb 100644 --- a/lib/Support/Unix/Threading.inc +++ b/lib/Support/Unix/Threading.inc @@ -26,19 +26,19 @@ #endif #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) +#include <errno.h> #include <sys/sysctl.h> #include <sys/user.h> -#include <errno.h> #include <unistd.h> #endif #if defined(__NetBSD__) -#include <lwp.h> // For _lwp_self() +#include <lwp.h> // For _lwp_self() #endif #if defined(__linux__) -#include <unistd.h> // For syscall() -#include <sys/syscall.h> // For syscall codes +#include <sys/syscall.h> // For syscall codes +#include <unistd.h> // For syscall() #endif namespace { diff --git a/lib/Support/Windows/DynamicLibrary.inc b/lib/Support/Windows/DynamicLibrary.inc index 0b54b5dfdbc5..caf1a0a658de 100644 --- a/lib/Support/Windows/DynamicLibrary.inc +++ b/lib/Support/Windows/DynamicLibrary.inc @@ -23,7 +23,7 @@ DynamicLibrary::HandleSet::~HandleSet() { - for (void *Handle : Handles) + for (void *Handle : llvm::reverse(Handles)) FreeLibrary(HMODULE(Handle)); // 'Process' should not be released on Windows. diff --git a/lib/Support/Windows/WindowsSupport.h b/lib/Support/Windows/WindowsSupport.h index c358b99ab96a..d4599dca044e 100644 --- a/lib/Support/Windows/WindowsSupport.h +++ b/lib/Support/Windows/WindowsSupport.h @@ -45,7 +45,9 @@ #include <string> #include <system_error> #include <windows.h> -#include <wincrypt.h> // Must be included after windows.h + +// Must be included after windows.h +#include <wincrypt.h> /// Determines if the program is running on Windows 8 or newer. This /// reimplements one of the helpers in the Windows 8.1 SDK, which are intended diff --git a/lib/Support/YAMLParser.cpp b/lib/Support/YAMLParser.cpp index f1496393e55e..01ae3214453d 100644 --- a/lib/Support/YAMLParser.cpp +++ b/lib/Support/YAMLParser.cpp @@ -12,12 +12,12 @@ //===----------------------------------------------------------------------===// #include "llvm/Support/YAMLParser.h" +#include "llvm/ADT/AllocatorList.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/Twine.h" -#include "llvm/ADT/AllocatorList.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/SourceMgr.h" |