diff options
author | David L. Jones <dlj@google.com> | 2017-11-15 01:40:05 +0000 |
---|---|---|
committer | David L. Jones <dlj@google.com> | 2017-11-15 01:40:05 +0000 |
commit | d5c2cca72463233df77a065f201db31b140eb44d (patch) | |
tree | 3f9a978131033302a58b7db7db1ecf2a4622bad2 /lib/Support | |
parent | ce7676b8db6bac096dad4c4ad62e9e6bb8aa1064 (diff) | |
parent | dcf64df89bc6d775e266ebd6b0134d135f47a35b (diff) | |
download | llvm-testing.tar.gz |
Creating branches/google/testing and tags/google/testing/2017-11-14 from r317716testing
git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/google/testing@318248 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support')
-rw-r--r-- | lib/Support/Chrono.cpp | 6 | ||||
-rw-r--r-- | lib/Support/FileOutputBuffer.cpp | 28 | ||||
-rw-r--r-- | lib/Support/Host.cpp | 93 | ||||
-rw-r--r-- | lib/Support/LowLevelType.cpp | 2 | ||||
-rw-r--r-- | lib/Support/SpecialCaseList.cpp | 83 | ||||
-rw-r--r-- | lib/Support/Unix/Path.inc | 2 |
6 files changed, 87 insertions, 127 deletions
diff --git a/lib/Support/Chrono.cpp b/lib/Support/Chrono.cpp index a39b485bd138..84f5aab6fc45 100644 --- a/lib/Support/Chrono.cpp +++ b/lib/Support/Chrono.cpp @@ -65,17 +65,17 @@ void format_provider<TimePoint<>>::format(const TimePoint<> &T, raw_ostream &OS, if (Style[I] == '%' && Style.size() > I + 1) switch (Style[I + 1]) { case 'L': // Milliseconds, from Ruby. FStream << llvm::format( - "%.3lu", duration_cast<milliseconds>(Fractional).count()); + "%.3lu", (long)duration_cast<milliseconds>(Fractional).count()); ++I; continue; case 'f': // Microseconds, from Python. FStream << llvm::format( - "%.6lu", duration_cast<microseconds>(Fractional).count()); + "%.6lu", (long)duration_cast<microseconds>(Fractional).count()); ++I; continue; case 'N': // Nanoseconds, from date(1). FStream << llvm::format( - "%.6lu", duration_cast<nanoseconds>(Fractional).count()); + "%.6lu", (long)duration_cast<nanoseconds>(Fractional).count()); ++I; continue; case '%': // Consume %%, so %%f parses as (%%)f not %(%f) diff --git a/lib/Support/FileOutputBuffer.cpp b/lib/Support/FileOutputBuffer.cpp index 1e20b01fc4aa..8906be3aaa25 100644 --- a/lib/Support/FileOutputBuffer.cpp +++ b/lib/Support/FileOutputBuffer.cpp @@ -38,7 +38,7 @@ public: std::unique_ptr<fs::mapped_file_region> Buf) : FileOutputBuffer(Path), Buffer(std::move(Buf)), TempPath(TempPath) {} - static ErrorOr<std::unique_ptr<OnDiskBuffer>> + static Expected<std::unique_ptr<OnDiskBuffer>> create(StringRef Path, size_t Size, unsigned Mode); uint8_t *getBufferStart() const override { return (uint8_t *)Buffer->data(); } @@ -49,14 +49,14 @@ public: size_t getBufferSize() const override { return Buffer->size(); } - std::error_code commit() override { + Error commit() override { // Unmap buffer, letting OS flush dirty pages to file on disk. Buffer.reset(); // Atomically replace the existing file with the new one. auto EC = fs::rename(TempPath, FinalPath); sys::DontRemoveFileOnSignal(TempPath); - return EC; + return errorCodeToError(EC); } ~OnDiskBuffer() override { @@ -78,13 +78,13 @@ public: InMemoryBuffer(StringRef Path, MemoryBlock Buf, unsigned Mode) : FileOutputBuffer(Path), Buffer(Buf), Mode(Mode) {} - static ErrorOr<std::unique_ptr<InMemoryBuffer>> + static Expected<std::unique_ptr<InMemoryBuffer>> create(StringRef Path, size_t Size, unsigned Mode) { std::error_code EC; MemoryBlock MB = Memory::allocateMappedMemory( Size, nullptr, sys::Memory::MF_READ | sys::Memory::MF_WRITE, EC); if (EC) - return EC; + return errorCodeToError(EC); return llvm::make_unique<InMemoryBuffer>(Path, MB, Mode); } @@ -96,14 +96,14 @@ public: size_t getBufferSize() const override { return Buffer.size(); } - std::error_code commit() override { + Error commit() override { int FD; std::error_code EC; if (auto EC = openFileForWrite(FinalPath, FD, fs::F_None, Mode)) - return EC; + return errorCodeToError(EC); raw_fd_ostream OS(FD, /*shouldClose=*/true, /*unbuffered=*/true); OS << StringRef((const char *)Buffer.base(), Buffer.size()); - return std::error_code(); + return Error::success(); } private: @@ -111,13 +111,13 @@ private: unsigned Mode; }; -ErrorOr<std::unique_ptr<OnDiskBuffer>> +Expected<std::unique_ptr<OnDiskBuffer>> OnDiskBuffer::create(StringRef Path, size_t Size, unsigned Mode) { // Create new file in same directory but with random name. SmallString<128> TempPath; int FD; if (auto EC = fs::createUniqueFile(Path + ".tmp%%%%%%%", FD, TempPath, Mode)) - return EC; + return errorCodeToError(EC); sys::RemoveFileOnSignal(TempPath); @@ -128,7 +128,7 @@ OnDiskBuffer::create(StringRef Path, size_t Size, unsigned Mode) { // pretty slow just like it writes specified amount of bytes, // so we should avoid calling that function. if (auto EC = fs::resize_file(FD, Size)) - return EC; + return errorCodeToError(EC); #endif // Mmap it. @@ -137,12 +137,12 @@ OnDiskBuffer::create(StringRef Path, size_t Size, unsigned Mode) { FD, fs::mapped_file_region::readwrite, Size, 0, EC); close(FD); if (EC) - return EC; + return errorCodeToError(EC); return llvm::make_unique<OnDiskBuffer>(Path, TempPath, std::move(MappedFile)); } // Create an instance of FileOutputBuffer. -ErrorOr<std::unique_ptr<FileOutputBuffer>> +Expected<std::unique_ptr<FileOutputBuffer>> FileOutputBuffer::create(StringRef Path, size_t Size, unsigned Flags) { unsigned Mode = fs::all_read | fs::all_write; if (Flags & F_executable) @@ -161,7 +161,7 @@ FileOutputBuffer::create(StringRef Path, size_t Size, unsigned Flags) { // destination file and write to it on commit(). switch (Stat.type()) { case fs::file_type::directory_file: - return errc::is_a_directory; + return errorCodeToError(errc::is_a_directory); case fs::file_type::regular_file: case fs::file_type::file_not_found: case fs::file_type::status_error: diff --git a/lib/Support/Host.cpp b/lib/Support/Host.cpp index d8fb3e1dc1d6..5b2a0f1d0c2c 100644 --- a/lib/Support/Host.cpp +++ b/lib/Support/Host.cpp @@ -351,12 +351,14 @@ enum ProcessorTypes { INTEL_PENTIUM_IV, INTEL_PENTIUM_M, INTEL_CORE_DUO, - INTEL_X86_64, INTEL_NOCONA, INTEL_PRESCOTT, AMD_i486, AMDPENTIUM, - AMDATHLON, + AMD_ATHLON, + AMD_ATHLON_XP, + AMD_K8, + AMD_K8SSE3, INTEL_GOLDMONT, CPU_TYPE_MAX }; @@ -385,10 +387,6 @@ enum ProcessorSubtypes { AMDPENTIUM_K62, AMDPENTIUM_K63, AMDPENTIUM_GEODE, - AMDATHLON_CLASSIC, - AMDATHLON_XP, - AMDATHLON_K8, - AMDATHLON_K8SSE3, CPU_SUBTYPE_MAX }; @@ -794,8 +792,13 @@ getIntelProcessorTypeAndSubtype(unsigned Family, unsigned Model, break; } if (Features2 & (1 << (FEATURE_EM64T - 32))) { - *Type = INTEL_X86_64; - break; // x86-64 + *Type = INTEL_CORE2; // "core2" + *Subtype = INTEL_CORE2_65; + break; + } + if (Features & (1 << FEATURE_SSE3)) { + *Type = INTEL_CORE_DUO; + break; } if (Features & (1 << FEATURE_SSE2)) { *Type = INTEL_PENTIUM_M; @@ -814,40 +817,15 @@ getIntelProcessorTypeAndSubtype(unsigned Family, unsigned Model, } break; case 15: { - switch (Model) { - case 0: // Pentium 4 processor, Intel Xeon processor. All processors are - // model 00h and manufactured using the 0.18 micron process. - case 1: // Pentium 4 processor, Intel Xeon processor, Intel Xeon - // processor MP, and Intel Celeron processor. All processors are - // model 01h and manufactured using the 0.18 micron process. - case 2: // Pentium 4 processor, Mobile Intel Pentium 4 processor - M, - // Intel Xeon processor, Intel Xeon processor MP, Intel Celeron - // processor, and Mobile Intel Celeron processor. All processors - // are model 02h and manufactured using the 0.13 micron process. - *Type = ((Features2 & (1 << (FEATURE_EM64T - 32))) ? INTEL_X86_64 - : INTEL_PENTIUM_IV); + if (Features2 & (1 << (FEATURE_EM64T - 32))) { + *Type = INTEL_NOCONA; break; - - case 3: // Pentium 4 processor, Intel Xeon processor, Intel Celeron D - // processor. All processors are model 03h and manufactured using - // the 90 nm process. - case 4: // Pentium 4 processor, Pentium 4 processor Extreme Edition, - // Pentium D processor, Intel Xeon processor, Intel Xeon - // processor MP, Intel Celeron D processor. All processors are - // model 04h and manufactured using the 90 nm process. - case 6: // Pentium 4 processor, Pentium D processor, Pentium processor - // Extreme Edition, Intel Xeon processor, Intel Xeon processor - // MP, Intel Celeron D processor. All processors are model 06h - // and manufactured using the 65 nm process. - *Type = ((Features2 & (1 << (FEATURE_EM64T - 32))) ? INTEL_NOCONA - : INTEL_PRESCOTT); - break; - - default: - *Type = ((Features2 & (1 << (FEATURE_EM64T - 32))) ? INTEL_X86_64 - : INTEL_PENTIUM_IV); + } + if (Features & (1 << FEATURE_SSE3)) { + *Type = INTEL_PRESCOTT; break; } + *Type = INTEL_PENTIUM_IV; break; } default: @@ -885,20 +863,18 @@ static void getAMDProcessorTypeAndSubtype(unsigned Family, unsigned Model, } break; case 6: - *Type = AMDATHLON; if (Features & (1 << FEATURE_SSE)) { - *Subtype = AMDATHLON_XP; + *Type = AMD_ATHLON_XP; break; // "athlon-xp" } - *Subtype = AMDATHLON_CLASSIC; + *Type = AMD_ATHLON; break; // "athlon" case 15: - *Type = AMDATHLON; if (Features & (1 << FEATURE_SSE3)) { - *Subtype = AMDATHLON_K8SSE3; + *Type = AMD_K8SSE3; break; // "k8-sse3" } - *Subtype = AMDATHLON_K8; + *Type = AMD_K8; break; // "k8" case 16: *Type = AMDFAM10H; // "amdfam10" @@ -1078,8 +1054,8 @@ StringRef sys::getHostCPUName() { detectX86FamilyModel(EAX, &Family, &Model); getAvailableFeatures(ECX, EDX, MaxLeaf, &Features, &Features2); - unsigned Type; - unsigned Subtype; + unsigned Type = 0; + unsigned Subtype = 0; if (Vendor == SIG_INTEL) { getIntelProcessorTypeAndSubtype(Family, Model, Brand_id, Features, @@ -1145,8 +1121,6 @@ StringRef sys::getHostCPUName() { return "knl"; case INTEL_KNM: return "knm"; - case INTEL_X86_64: - return "x86-64"; case INTEL_NOCONA: return "nocona"; case INTEL_PRESCOTT: @@ -1172,19 +1146,14 @@ StringRef sys::getHostCPUName() { default: return "pentium"; } - case AMDATHLON: - switch (Subtype) { - case AMDATHLON_CLASSIC: - return "athlon"; - case AMDATHLON_XP: - return "athlon-xp"; - case AMDATHLON_K8: - return "k8"; - case AMDATHLON_K8SSE3: - return "k8-sse3"; - default: - llvm_unreachable("Unexpected subtype!"); - } + case AMD_ATHLON: + return "athlon"; + case AMD_ATHLON_XP: + return "athlon-xp"; + case AMD_K8: + return "k8"; + case AMD_K8SSE3: + return "k8-sse3"; case AMDFAM10H: return "amdfam10"; case AMD_BTVER1: diff --git a/lib/Support/LowLevelType.cpp b/lib/Support/LowLevelType.cpp index 0ee3f1d0119e..cb2187405d6b 100644 --- a/lib/Support/LowLevelType.cpp +++ b/lib/Support/LowLevelType.cpp @@ -43,7 +43,7 @@ void LLT::print(raw_ostream &OS) const { assert(isScalar() && "unexpected type"); OS << "s" << getScalarSizeInBits(); } else - llvm_unreachable("trying to print an invalid type"); + OS << "LLT_invalid"; } const constexpr LLT::BitFieldInfo LLT::ScalarSizeFieldInfo; diff --git a/lib/Support/SpecialCaseList.cpp b/lib/Support/SpecialCaseList.cpp index a659a2afee6a..bf807e66e02c 100644 --- a/lib/Support/SpecialCaseList.cpp +++ b/lib/Support/SpecialCaseList.cpp @@ -27,6 +27,7 @@ namespace llvm { bool SpecialCaseList::Matcher::insert(std::string Regexp, + unsigned LineNumber, std::string &REError) { if (Regexp.empty()) { REError = "Supplied regexp was blank"; @@ -34,7 +35,7 @@ bool SpecialCaseList::Matcher::insert(std::string Regexp, } if (Regex::isLiteralERE(Regexp)) { - Strings.insert(Regexp); + Strings[Regexp] = LineNumber; return true; } Trigrams.insert(Regexp); @@ -45,34 +46,30 @@ bool SpecialCaseList::Matcher::insert(std::string Regexp, Regexp.replace(pos, strlen("*"), ".*"); } + Regexp = (Twine("^(") + StringRef(Regexp) + ")$").str(); + // Check that the regexp is valid. Regex CheckRE(Regexp); if (!CheckRE.isValid(REError)) return false; - if (!UncompiledRegEx.empty()) - UncompiledRegEx += "|"; - UncompiledRegEx += "^(" + Regexp + ")$"; + RegExes.emplace_back( + std::make_pair(make_unique<Regex>(std::move(CheckRE)), LineNumber)); return true; } -void SpecialCaseList::Matcher::compile() { - if (!UncompiledRegEx.empty()) { - RegEx.reset(new Regex(UncompiledRegEx)); - UncompiledRegEx.clear(); - } -} - -bool SpecialCaseList::Matcher::match(StringRef Query) const { - if (Strings.count(Query)) - return true; +unsigned SpecialCaseList::Matcher::match(StringRef Query) const { + auto It = Strings.find(Query); + if (It != Strings.end()) + return It->second; if (Trigrams.isDefinitelyOut(Query)) return false; - return RegEx && RegEx->match(Query); + for (auto& RegExKV : RegExes) + if (RegExKV.first->match(Query)) + return RegExKV.second; + return 0; } -SpecialCaseList::SpecialCaseList() : Sections(), IsCompiled(false) {} - std::unique_ptr<SpecialCaseList> SpecialCaseList::create(const std::vector<std::string> &Paths, std::string &Error) { @@ -114,7 +111,6 @@ bool SpecialCaseList::createInternal(const std::vector<std::string> &Paths, return false; } } - compile(); return true; } @@ -123,7 +119,6 @@ bool SpecialCaseList::createInternal(const MemoryBuffer *MB, StringMap<size_t> Sections; if (!parse(MB, Sections, Error)) return false; - compile(); return true; } @@ -132,11 +127,13 @@ bool SpecialCaseList::parse(const MemoryBuffer *MB, std::string &Error) { // Iterate through each line in the blacklist file. SmallVector<StringRef, 16> Lines; - SplitString(MB->getBuffer(), Lines, "\n\r"); + MB->getBuffer().split(Lines, '\n'); - int LineNo = 1; + unsigned LineNo = 1; StringRef Section = "*"; + for (auto I = Lines.begin(), E = Lines.end(); I != E; ++I, ++LineNo) { + *I = I->trim(); // Ignore empty lines and lines starting with "#" if (I->empty() || I->startswith("#")) continue; @@ -181,11 +178,10 @@ bool SpecialCaseList::parse(const MemoryBuffer *MB, if (SectionsMap.find(Section) == SectionsMap.end()) { std::unique_ptr<Matcher> M = make_unique<Matcher>(); std::string REError; - if (!M->insert(Section, REError)) { + if (!M->insert(Section, LineNo, REError)) { Error = (Twine("malformed section ") + Section + ": '" + REError).str(); return false; } - M->compile(); SectionsMap[Section] = Sections.size(); Sections.emplace_back(std::move(M)); @@ -193,7 +189,7 @@ bool SpecialCaseList::parse(const MemoryBuffer *MB, auto &Entry = Sections[SectionsMap[Section]].Entries[Prefix][Category]; std::string REError; - if (!Entry.insert(std::move(Regexp), REError)) { + if (!Entry.insert(std::move(Regexp), LineNo, REError)) { Error = (Twine("malformed regex in line ") + Twine(LineNo) + ": '" + SplitLine.second + "': " + REError).str(); return false; @@ -202,38 +198,33 @@ bool SpecialCaseList::parse(const MemoryBuffer *MB, return true; } -void SpecialCaseList::compile() { - assert(!IsCompiled && "compile() should only be called once"); - // Iterate through every section compiling regular expressions for every query - // and creating Section entries. - for (auto &Section : Sections) - for (auto &Prefix : Section.Entries) - for (auto &Category : Prefix.getValue()) - Category.getValue().compile(); - - IsCompiled = true; -} - SpecialCaseList::~SpecialCaseList() {} bool SpecialCaseList::inSection(StringRef Section, StringRef Prefix, StringRef Query, StringRef Category) const { - assert(IsCompiled && "SpecialCaseList::compile() was not called!"); + return inSectionBlame(Section, Prefix, Query, Category); +} +unsigned SpecialCaseList::inSectionBlame(StringRef Section, StringRef Prefix, + StringRef Query, + StringRef Category) const { for (auto &SectionIter : Sections) - if (SectionIter.SectionMatcher->match(Section) && - inSection(SectionIter.Entries, Prefix, Query, Category)) - return true; - - return false; + if (SectionIter.SectionMatcher->match(Section)) { + unsigned Blame = + inSectionBlame(SectionIter.Entries, Prefix, Query, Category); + if (Blame) + return Blame; + } + return 0; } -bool SpecialCaseList::inSection(const SectionEntries &Entries, StringRef Prefix, - StringRef Query, StringRef Category) const { +unsigned SpecialCaseList::inSectionBlame(const SectionEntries &Entries, + StringRef Prefix, StringRef Query, + StringRef Category) const { SectionEntries::const_iterator I = Entries.find(Prefix); - if (I == Entries.end()) return false; + if (I == Entries.end()) return 0; StringMap<Matcher>::const_iterator II = I->second.find(Category); - if (II == I->second.end()) return false; + if (II == I->second.end()) return 0; return II->getValue().match(Query); } diff --git a/lib/Support/Unix/Path.inc b/lib/Support/Unix/Path.inc index 781a911ed57c..2ecb97316c87 100644 --- a/lib/Support/Unix/Path.inc +++ b/lib/Support/Unix/Path.inc @@ -426,7 +426,7 @@ std::error_code resize_file(int FD, uint64_t Size) { // If we have posix_fallocate use it. Unlike ftruncate it always allocates // space, so we get an error if the disk is full. if (int Err = ::posix_fallocate(FD, 0, Size)) { - if (Err != EOPNOTSUPP) + if (Err != EINVAL && Err != EOPNOTSUPP) return std::error_code(Err, std::generic_category()); } #endif |