aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Support
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Support')
-rw-r--r--llvm/lib/Support/AArch64TargetParser.cpp10
-rw-r--r--llvm/lib/Support/APInt.cpp2
-rw-r--r--llvm/lib/Support/ARMAttributeParser.cpp4
-rw-r--r--llvm/lib/Support/ARMTargetParser.cpp6
-rw-r--r--llvm/lib/Support/ARMWinEH.cpp1
-rw-r--r--llvm/lib/Support/BinaryStreamError.cpp2
-rw-r--r--llvm/lib/Support/BlockFrequency.cpp1
-rw-r--r--llvm/lib/Support/Caching.cpp8
-rw-r--r--llvm/lib/Support/CodeGenCoverage.cpp2
-rw-r--r--llvm/lib/Support/CommandLine.cpp85
-rw-r--r--llvm/lib/Support/CrashRecoveryContext.cpp5
-rw-r--r--llvm/lib/Support/DAGDeltaAlgorithm.cpp1
-rw-r--r--llvm/lib/Support/DataExtractor.cpp1
-rw-r--r--llvm/lib/Support/DivisionByConstantInfo.cpp6
-rw-r--r--llvm/lib/Support/ELFAttributeParser.cpp2
-rw-r--r--llvm/lib/Support/FileOutputBuffer.cpp2
-rw-r--r--llvm/lib/Support/FileUtilities.cpp4
-rw-r--r--llvm/lib/Support/GraphWriter.cpp7
-rw-r--r--llvm/lib/Support/Host.cpp9
-rw-r--r--llvm/lib/Support/InitLLVM.cpp7
-rw-r--r--llvm/lib/Support/JSON.cpp1
-rw-r--r--llvm/lib/Support/LowLevelType.cpp2
-rw-r--r--llvm/lib/Support/MD5.cpp11
-rw-r--r--llvm/lib/Support/MSP430AttributeParser.cpp3
-rw-r--r--llvm/lib/Support/MemAlloc.cpp1
-rw-r--r--llvm/lib/Support/MemoryBuffer.cpp27
-rw-r--r--llvm/lib/Support/NativeFormatting.cpp1
-rw-r--r--llvm/lib/Support/Parallel.cpp32
-rw-r--r--llvm/lib/Support/Path.cpp23
-rw-r--r--llvm/lib/Support/PrettyStackTrace.cpp5
-rw-r--r--llvm/lib/Support/RISCVISAInfo.cpp208
-rw-r--r--llvm/lib/Support/ScopedPrinter.cpp1
-rw-r--r--llvm/lib/Support/Signals.cpp1
-rw-r--r--llvm/lib/Support/Signposts.cpp1
-rw-r--r--llvm/lib/Support/SmallPtrSet.cpp1
-rw-r--r--llvm/lib/Support/SmallVector.cpp1
-rw-r--r--llvm/lib/Support/SpecialCaseList.cpp1
-rw-r--r--llvm/lib/Support/StringMap.cpp1
-rw-r--r--llvm/lib/Support/StringRef.cpp8
-rw-r--r--llvm/lib/Support/SymbolRemappingReader.cpp1
-rw-r--r--llvm/lib/Support/TargetParser.cpp4
-rw-r--r--llvm/lib/Support/ThreadPool.cpp8
-rw-r--r--llvm/lib/Support/TimeProfiler.cpp4
-rw-r--r--llvm/lib/Support/ToolOutputFile.cpp1
-rw-r--r--llvm/lib/Support/Triple.cpp6
-rw-r--r--llvm/lib/Support/TypeSize.cpp1
-rw-r--r--llvm/lib/Support/Unix/Path.inc25
-rw-r--r--llvm/lib/Support/VirtualFileSystem.cpp112
-rw-r--r--llvm/lib/Support/Windows/Path.inc38
-rw-r--r--llvm/lib/Support/Windows/Process.inc8
-rw-r--r--llvm/lib/Support/Windows/Program.inc8
-rw-r--r--llvm/lib/Support/X86TargetParser.cpp1
-rw-r--r--llvm/lib/Support/YAMLParser.cpp1
-rw-r--r--llvm/lib/Support/YAMLTraits.cpp14
-rw-r--r--llvm/lib/Support/raw_ostream.cpp23
55 files changed, 522 insertions, 227 deletions
diff --git a/llvm/lib/Support/AArch64TargetParser.cpp b/llvm/lib/Support/AArch64TargetParser.cpp
index 4bc9c8487131..cdf7c8ade9aa 100644
--- a/llvm/lib/Support/AArch64TargetParser.cpp
+++ b/llvm/lib/Support/AArch64TargetParser.cpp
@@ -114,6 +114,12 @@ bool AArch64::getExtensionFeatures(uint64_t Extensions,
Features.push_back("+sme-f64");
if (Extensions & AArch64::AEK_SMEI64)
Features.push_back("+sme-i64");
+ if (Extensions & AArch64::AEK_HBC)
+ Features.push_back("+hbc");
+ if (Extensions & AArch64::AEK_MOPS)
+ Features.push_back("+mops");
+ if (Extensions & AArch64::AEK_PERFMON)
+ Features.push_back("+perfmon");
return true;
}
@@ -136,12 +142,16 @@ bool AArch64::getArchFeatures(AArch64::ArchKind AK,
Features.push_back("+v8.6a");
if (AK == AArch64::ArchKind::ARMV8_7A)
Features.push_back("+v8.7a");
+ if (AK == AArch64::ArchKind::ARMV8_8A)
+ Features.push_back("+v8.8a");
if (AK == AArch64::ArchKind::ARMV9A)
Features.push_back("+v9a");
if (AK == AArch64::ArchKind::ARMV9_1A)
Features.push_back("+v9.1a");
if (AK == AArch64::ArchKind::ARMV9_2A)
Features.push_back("+v9.2a");
+ if (AK == AArch64::ArchKind::ARMV9_3A)
+ Features.push_back("+v9.3a");
if(AK == AArch64::ArchKind::ARMV8R)
Features.push_back("+v8r");
diff --git a/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp
index 4940b61602d1..b536e9a9a6d0 100644
--- a/llvm/lib/Support/APInt.cpp
+++ b/llvm/lib/Support/APInt.cpp
@@ -24,9 +24,7 @@
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/raw_ostream.h"
-#include <climits>
#include <cmath>
-#include <cstdlib>
#include <cstring>
using namespace llvm;
diff --git a/llvm/lib/Support/ARMAttributeParser.cpp b/llvm/lib/Support/ARMAttributeParser.cpp
index 241cfb1eedbe..908e56319025 100644
--- a/llvm/lib/Support/ARMAttributeParser.cpp
+++ b/llvm/lib/Support/ARMAttributeParser.cpp
@@ -9,8 +9,6 @@
#include "llvm/Support/ARMAttributeParser.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringExtras.h"
-#include "llvm/Support/Errc.h"
-#include "llvm/Support/LEB128.h"
#include "llvm/Support/ScopedPrinter.h"
using namespace llvm;
@@ -70,7 +68,7 @@ const ARMAttributeParser::DisplayHandler ARMAttributeParser::displayRoutines[] =
Error ARMAttributeParser::stringAttribute(AttrType tag) {
StringRef tagName =
- ELFAttrs::attrTypeAsString(tag, tagToStringMap, /*TagPrefix=*/false);
+ ELFAttrs::attrTypeAsString(tag, tagToStringMap, /*hasTagPrefix=*/false);
StringRef desc = de.getCStrRef(cursor);
if (sw) {
diff --git a/llvm/lib/Support/ARMTargetParser.cpp b/llvm/lib/Support/ARMTargetParser.cpp
index 4405ed176fe2..d7294b5b1074 100644
--- a/llvm/lib/Support/ARMTargetParser.cpp
+++ b/llvm/lib/Support/ARMTargetParser.cpp
@@ -77,6 +77,7 @@ unsigned ARM::parseArchVersion(StringRef Arch) {
case ArchKind::ARMV8_5A:
case ArchKind::ARMV8_6A:
case ArchKind::ARMV8_7A:
+ case ArchKind::ARMV8_8A:
case ArchKind::ARMV8R:
case ArchKind::ARMV8MBaseline:
case ArchKind::ARMV8MMainline:
@@ -85,6 +86,7 @@ unsigned ARM::parseArchVersion(StringRef Arch) {
case ArchKind::ARMV9A:
case ArchKind::ARMV9_1A:
case ArchKind::ARMV9_2A:
+ case ArchKind::ARMV9_3A:
return 9;
case ArchKind::INVALID:
return 0;
@@ -117,9 +119,11 @@ ARM::ProfileKind ARM::parseArchProfile(StringRef Arch) {
case ArchKind::ARMV8_5A:
case ArchKind::ARMV8_6A:
case ArchKind::ARMV8_7A:
+ case ArchKind::ARMV8_8A:
case ArchKind::ARMV9A:
case ArchKind::ARMV9_1A:
case ArchKind::ARMV9_2A:
+ case ArchKind::ARMV9_3A:
return ProfileKind::A;
case ArchKind::ARMV2:
case ArchKind::ARMV2A:
@@ -164,10 +168,12 @@ StringRef ARM::getArchSynonym(StringRef Arch) {
.Case("v8.5a", "v8.5-a")
.Case("v8.6a", "v8.6-a")
.Case("v8.7a", "v8.7-a")
+ .Case("v8.8a", "v8.8-a")
.Case("v8r", "v8-r")
.Cases("v9", "v9a", "v9-a")
.Case("v9.1a", "v9.1-a")
.Case("v9.2a", "v9.2-a")
+ .Case("v9.3a", "v9.3-a")
.Case("v8m.base", "v8-m.base")
.Case("v8m.main", "v8-m.main")
.Case("v8.1m.main", "v8.1-m.main")
diff --git a/llvm/lib/Support/ARMWinEH.cpp b/llvm/lib/Support/ARMWinEH.cpp
index 2e2fcf28451f..8e7fa1149082 100644
--- a/llvm/lib/Support/ARMWinEH.cpp
+++ b/llvm/lib/Support/ARMWinEH.cpp
@@ -7,7 +7,6 @@
//===----------------------------------------------------------------------===//
#include "llvm/Support/ARMWinEH.h"
-#include "llvm/Support/raw_ostream.h"
namespace llvm {
namespace ARM {
diff --git a/llvm/lib/Support/BinaryStreamError.cpp b/llvm/lib/Support/BinaryStreamError.cpp
index f22523f09ac8..9b8f6862b65c 100644
--- a/llvm/lib/Support/BinaryStreamError.cpp
+++ b/llvm/lib/Support/BinaryStreamError.cpp
@@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/Support/BinaryStreamError.h"
-#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/raw_ostream.h"
using namespace llvm;
diff --git a/llvm/lib/Support/BlockFrequency.cpp b/llvm/lib/Support/BlockFrequency.cpp
index 2b63294f3789..702165ac480b 100644
--- a/llvm/lib/Support/BlockFrequency.cpp
+++ b/llvm/lib/Support/BlockFrequency.cpp
@@ -11,6 +11,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/Support/BlockFrequency.h"
+#include "llvm/Support/BranchProbability.h"
#include <cassert>
using namespace llvm;
diff --git a/llvm/lib/Support/Caching.cpp b/llvm/lib/Support/Caching.cpp
index 8c685640f791..d6902f660e39 100644
--- a/llvm/lib/Support/Caching.cpp
+++ b/llvm/lib/Support/Caching.cpp
@@ -30,8 +30,6 @@ Expected<FileCache> llvm::localCache(Twine CacheNameRef,
Twine TempFilePrefixRef,
Twine CacheDirectoryPathRef,
AddBufferFn AddBuffer) {
- if (std::error_code EC = sys::fs::create_directories(CacheDirectoryPathRef))
- return errorCodeToError(EC);
// Create local copies which are safely captured-by-copy in lambdas
SmallString<64> CacheName, TempFilePrefix, CacheDirectoryPath;
@@ -140,6 +138,12 @@ Expected<FileCache> llvm::localCache(Twine CacheNameRef,
};
return [=](size_t Task) -> Expected<std::unique_ptr<CachedFileStream>> {
+ // Create the cache directory if not already done. Doing this lazily
+ // ensures the filesystem isn't mutated until the cache is.
+ if (std::error_code EC = sys::fs::create_directories(
+ CacheDirectoryPath, /*IgnoreExisting=*/true))
+ return errorCodeToError(EC);
+
// Write to a temporary to avoid race condition
SmallString<64> TempFilenameModel;
sys::path::append(TempFilenameModel, CacheDirectoryPath,
diff --git a/llvm/lib/Support/CodeGenCoverage.cpp b/llvm/lib/Support/CodeGenCoverage.cpp
index 93f386b6e23d..73e0fb3edce8 100644
--- a/llvm/lib/Support/CodeGenCoverage.cpp
+++ b/llvm/lib/Support/CodeGenCoverage.cpp
@@ -27,7 +27,7 @@ CodeGenCoverage::CodeGenCoverage() {}
void CodeGenCoverage::setCovered(uint64_t RuleID) {
if (RuleCoverage.size() <= RuleID)
- RuleCoverage.resize(RuleID + 1, 0);
+ RuleCoverage.resize(RuleID + 1, false);
RuleCoverage[RuleID] = true;
}
diff --git a/llvm/lib/Support/CommandLine.cpp b/llvm/lib/Support/CommandLine.cpp
index 4153a69abf5d..71a6ebf2a72e 100644
--- a/llvm/lib/Support/CommandLine.cpp
+++ b/llvm/lib/Support/CommandLine.cpp
@@ -22,7 +22,7 @@
#include "llvm-c/Support.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/Optional.h"
-#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/STLFunctionalExtras.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringExtras.h"
@@ -45,7 +45,6 @@
#include "llvm/Support/VirtualFileSystem.h"
#include "llvm/Support/raw_ostream.h"
#include <cstdlib>
-#include <map>
#include <string>
using namespace llvm;
using namespace cl;
@@ -1078,11 +1077,45 @@ static bool hasUTF8ByteOrderMark(ArrayRef<char> S) {
return (S.size() >= 3 && S[0] == '\xef' && S[1] == '\xbb' && S[2] == '\xbf');
}
+// Substitute <CFGDIR> with the file's base path.
+static void ExpandBasePaths(StringRef BasePath, StringSaver &Saver,
+ const char *&Arg) {
+ assert(sys::path::is_absolute(BasePath));
+ constexpr StringLiteral Token("<CFGDIR>");
+ const StringRef ArgString(Arg);
+
+ SmallString<128> ResponseFile;
+ StringRef::size_type StartPos = 0;
+ for (StringRef::size_type TokenPos = ArgString.find(Token);
+ TokenPos != StringRef::npos;
+ TokenPos = ArgString.find(Token, StartPos)) {
+ // Token may appear more than once per arg (e.g. comma-separated linker
+ // args). Support by using path-append on any subsequent appearances.
+ const StringRef LHS = ArgString.substr(StartPos, TokenPos - StartPos);
+ if (ResponseFile.empty())
+ ResponseFile = LHS;
+ else
+ llvm::sys::path::append(ResponseFile, LHS);
+ ResponseFile.append(BasePath);
+ StartPos = TokenPos + Token.size();
+ }
+
+ if (!ResponseFile.empty()) {
+ // Path-append the remaining arg substring if at least one token appeared.
+ const StringRef Remaining = ArgString.substr(StartPos);
+ if (!Remaining.empty())
+ llvm::sys::path::append(ResponseFile, Remaining);
+ Arg = Saver.save(ResponseFile.str()).data();
+ }
+}
+
// FName must be an absolute path.
-static llvm::Error ExpandResponseFile(
- StringRef FName, StringSaver &Saver, TokenizerCallback Tokenizer,
- SmallVectorImpl<const char *> &NewArgv, bool MarkEOLs, bool RelativeNames,
- llvm::vfs::FileSystem &FS) {
+static llvm::Error ExpandResponseFile(StringRef FName, StringSaver &Saver,
+ TokenizerCallback Tokenizer,
+ SmallVectorImpl<const char *> &NewArgv,
+ bool MarkEOLs, bool RelativeNames,
+ bool ExpandBasePath,
+ llvm::vfs::FileSystem &FS) {
assert(sys::path::is_absolute(FName));
llvm::ErrorOr<std::unique_ptr<MemoryBuffer>> MemBufOrErr =
FS.getBufferForFile(FName);
@@ -1116,8 +1149,15 @@ static llvm::Error ExpandResponseFile(
// file, replace the included response file names with their full paths
// obtained by required resolution.
for (auto &Arg : NewArgv) {
+ if (!Arg)
+ continue;
+
+ // Substitute <CFGDIR> with the file's base path.
+ if (ExpandBasePath)
+ ExpandBasePaths(BasePath, Saver, Arg);
+
// Skip non-rsp file arguments.
- if (!Arg || Arg[0] != '@')
+ if (Arg[0] != '@')
continue;
StringRef FileName(Arg + 1);
@@ -1129,7 +1169,7 @@ static llvm::Error ExpandResponseFile(
ResponseFile.push_back('@');
ResponseFile.append(BasePath);
llvm::sys::path::append(ResponseFile, FileName);
- Arg = Saver.save(ResponseFile.c_str()).data();
+ Arg = Saver.save(ResponseFile.str()).data();
}
return Error::success();
}
@@ -1138,7 +1178,7 @@ static llvm::Error ExpandResponseFile(
/// StringSaver and tokenization strategy.
bool cl::ExpandResponseFiles(StringSaver &Saver, TokenizerCallback Tokenizer,
SmallVectorImpl<const char *> &Argv, bool MarkEOLs,
- bool RelativeNames,
+ bool RelativeNames, bool ExpandBasePath,
llvm::Optional<llvm::StringRef> CurrentDir,
llvm::vfs::FileSystem &FS) {
bool AllExpanded = true;
@@ -1218,7 +1258,7 @@ bool cl::ExpandResponseFiles(StringSaver &Saver, TokenizerCallback Tokenizer,
SmallVector<const char *, 0> ExpandedArgv;
if (llvm::Error Err =
ExpandResponseFile(FName, Saver, Tokenizer, ExpandedArgv, MarkEOLs,
- RelativeNames, FS)) {
+ RelativeNames, ExpandBasePath, FS)) {
// We couldn't read this file, so we leave it in the argument stream and
// move on.
// TODO: The error should be propagated up the stack.
@@ -1250,11 +1290,11 @@ bool cl::ExpandResponseFiles(StringSaver &Saver, TokenizerCallback Tokenizer,
bool cl::ExpandResponseFiles(StringSaver &Saver, TokenizerCallback Tokenizer,
SmallVectorImpl<const char *> &Argv, bool MarkEOLs,
- bool RelativeNames,
+ bool RelativeNames, bool ExpandBasePath,
llvm::Optional<StringRef> CurrentDir) {
return ExpandResponseFiles(Saver, std::move(Tokenizer), Argv, MarkEOLs,
- RelativeNames, std::move(CurrentDir),
- *vfs::getRealFileSystem());
+ RelativeNames, ExpandBasePath,
+ std::move(CurrentDir), *vfs::getRealFileSystem());
}
bool cl::expandResponseFiles(int Argc, const char *const *Argv,
@@ -1281,16 +1321,17 @@ bool cl::readConfigFile(StringRef CfgFile, StringSaver &Saver,
llvm::sys::path::append(AbsPath, CfgFile);
CfgFile = AbsPath.str();
}
- if (llvm::Error Err =
- ExpandResponseFile(CfgFile, Saver, cl::tokenizeConfigFile, Argv,
- /*MarkEOLs=*/false, /*RelativeNames=*/true,
- *llvm::vfs::getRealFileSystem())) {
+ if (llvm::Error Err = ExpandResponseFile(
+ CfgFile, Saver, cl::tokenizeConfigFile, Argv,
+ /*MarkEOLs=*/false, /*RelativeNames=*/true, /*ExpandBasePath=*/true,
+ *llvm::vfs::getRealFileSystem())) {
// TODO: The error should be propagated up the stack.
llvm::consumeError(std::move(Err));
return false;
}
return ExpandResponseFiles(Saver, cl::tokenizeConfigFile, Argv,
- /*MarkEOLs=*/false, /*RelativeNames=*/true);
+ /*MarkEOLs=*/false, /*RelativeNames=*/true,
+ /*ExpandBasePath=*/true, llvm::None);
}
static void initCommonOptions();
@@ -2297,7 +2338,7 @@ public:
protected:
void printOptions(StrOptionPairVector &Opts, size_t MaxArgLen) override {
std::vector<OptionCategory *> SortedCategories;
- std::map<OptionCategory *, std::vector<Option *>> CategorizedOptions;
+ DenseMap<OptionCategory *, std::vector<Option *>> CategorizedOptions;
// Collect registered option categories into vector in preparation for
// sorting.
@@ -2309,17 +2350,13 @@ protected:
array_pod_sort(SortedCategories.begin(), SortedCategories.end(),
OptionCategoryCompare);
- // Create map to empty vectors.
- for (OptionCategory *Category : SortedCategories)
- CategorizedOptions[Category] = std::vector<Option *>();
-
// Walk through pre-sorted options and assign into categories.
// Because the options are already alphabetically sorted the
// options within categories will also be alphabetically sorted.
for (size_t I = 0, E = Opts.size(); I != E; ++I) {
Option *Opt = Opts[I].second;
for (auto &Cat : Opt->Categories) {
- assert(CategorizedOptions.count(Cat) > 0 &&
+ assert(find(SortedCategories, Cat) != SortedCategories.end() &&
"Option has an unregistered category");
CategorizedOptions[Cat].push_back(Opt);
}
diff --git a/llvm/lib/Support/CrashRecoveryContext.cpp b/llvm/lib/Support/CrashRecoveryContext.cpp
index b6aaf373a522..2ee3074b840e 100644
--- a/llvm/lib/Support/CrashRecoveryContext.cpp
+++ b/llvm/lib/Support/CrashRecoveryContext.cpp
@@ -9,7 +9,6 @@
#include "llvm/Support/CrashRecoveryContext.h"
#include "llvm/Config/llvm-config.h"
#include "llvm/Support/ErrorHandling.h"
-#include "llvm/Support/ExitCodes.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/Signals.h"
#include "llvm/Support/ThreadLocal.h"
@@ -17,6 +16,10 @@
#include <mutex>
#include <setjmp.h>
+#if !defined(_MSC_VER) && !defined(_WIN32)
+#include "llvm/Support/ExitCodes.h"
+#endif
+
using namespace llvm;
namespace {
diff --git a/llvm/lib/Support/DAGDeltaAlgorithm.cpp b/llvm/lib/Support/DAGDeltaAlgorithm.cpp
index a6daee00bd43..f1b730e2b58c 100644
--- a/llvm/lib/Support/DAGDeltaAlgorithm.cpp
+++ b/llvm/lib/Support/DAGDeltaAlgorithm.cpp
@@ -37,7 +37,6 @@
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <cassert>
-#include <iterator>
#include <map>
using namespace llvm;
diff --git a/llvm/lib/Support/DataExtractor.cpp b/llvm/lib/Support/DataExtractor.cpp
index 133d674275e8..8cf312191153 100644
--- a/llvm/lib/Support/DataExtractor.cpp
+++ b/llvm/lib/Support/DataExtractor.cpp
@@ -9,7 +9,6 @@
#include "llvm/Support/DataExtractor.h"
#include "llvm/Support/Errc.h"
#include "llvm/Support/ErrorHandling.h"
-#include "llvm/Support/Host.h"
#include "llvm/Support/LEB128.h"
#include "llvm/Support/SwapByteOrder.h"
diff --git a/llvm/lib/Support/DivisionByConstantInfo.cpp b/llvm/lib/Support/DivisionByConstantInfo.cpp
index 077629670e40..69f39386798c 100644
--- a/llvm/lib/Support/DivisionByConstantInfo.cpp
+++ b/llvm/lib/Support/DivisionByConstantInfo.cpp
@@ -67,7 +67,7 @@ UnsignedDivisonByConstantInfo::get(const APInt &D, unsigned LeadingZeros) {
unsigned P;
APInt NC, Delta, Q1, R1, Q2, R2;
struct UnsignedDivisonByConstantInfo Retval;
- Retval.IsAdd = 0; // initialize "add" indicator
+ Retval.IsAdd = false; // initialize "add" indicator
APInt AllOnes = APInt::getAllOnes(D.getBitWidth()).lshr(LeadingZeros);
APInt SignedMin = APInt::getSignedMinValue(D.getBitWidth());
APInt SignedMax = APInt::getSignedMaxValue(D.getBitWidth());
@@ -89,12 +89,12 @@ UnsignedDivisonByConstantInfo::get(const APInt &D, unsigned LeadingZeros) {
}
if ((R2 + 1).uge(D - R2)) {
if (Q2.uge(SignedMax))
- Retval.IsAdd = 1;
+ Retval.IsAdd = true;
Q2 = Q2 + Q2 + 1; // update Q2
R2 = R2 + R2 + 1 - D; // update R2
} else {
if (Q2.uge(SignedMin))
- Retval.IsAdd = 1;
+ Retval.IsAdd = true;
Q2 = Q2 + Q2; // update Q2
R2 = R2 + R2 + 1; // update R2
}
diff --git a/llvm/lib/Support/ELFAttributeParser.cpp b/llvm/lib/Support/ELFAttributeParser.cpp
index 1206553343ef..cf8a666e92bc 100644
--- a/llvm/lib/Support/ELFAttributeParser.cpp
+++ b/llvm/lib/Support/ELFAttributeParser.cpp
@@ -7,10 +7,8 @@
//===----------------------------------------------------------------------===//
#include "llvm/Support/ELFAttributeParser.h"
-#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Support/Errc.h"
-#include "llvm/Support/LEB128.h"
#include "llvm/Support/ScopedPrinter.h"
using namespace llvm;
diff --git a/llvm/lib/Support/FileOutputBuffer.cpp b/llvm/lib/Support/FileOutputBuffer.cpp
index 4b4406c4c9f4..c11ee59da0dd 100644
--- a/llvm/lib/Support/FileOutputBuffer.cpp
+++ b/llvm/lib/Support/FileOutputBuffer.cpp
@@ -11,11 +11,9 @@
//===----------------------------------------------------------------------===//
#include "llvm/Support/FileOutputBuffer.h"
-#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/Errc.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Memory.h"
-#include "llvm/Support/Path.h"
#include <system_error>
#if !defined(_MSC_VER) && !defined(__MINGW32__)
diff --git a/llvm/lib/Support/FileUtilities.cpp b/llvm/lib/Support/FileUtilities.cpp
index dbe28e56b2c3..489b8d119e6f 100644
--- a/llvm/lib/Support/FileUtilities.cpp
+++ b/llvm/lib/Support/FileUtilities.cpp
@@ -12,16 +12,12 @@
//===----------------------------------------------------------------------===//
#include "llvm/Support/FileUtilities.h"
-#include "llvm/ADT/ScopeExit.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/ErrorOr.h"
#include "llvm/Support/MemoryBuffer.h"
-#include "llvm/Support/Path.h"
#include "llvm/Support/raw_ostream.h"
-#include <cctype>
-#include <cmath>
#include <cstdint>
#include <cstdlib>
#include <cstring>
diff --git a/llvm/lib/Support/GraphWriter.cpp b/llvm/lib/Support/GraphWriter.cpp
index 696e6b7a99d8..e875e18a7e92 100644
--- a/llvm/lib/Support/GraphWriter.cpp
+++ b/llvm/lib/Support/GraphWriter.cpp
@@ -18,7 +18,6 @@
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Config/config.h"
-#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/ErrorOr.h"
@@ -26,7 +25,11 @@
#include "llvm/Support/Path.h"
#include "llvm/Support/Program.h"
#include "llvm/Support/raw_ostream.h"
-#include <cassert>
+
+#ifdef __APPLE__
+#include "llvm/Support/CommandLine.h"
+#endif
+
#include <string>
#include <system_error>
#include <vector>
diff --git a/llvm/lib/Support/Host.cpp b/llvm/lib/Support/Host.cpp
index 7b14616f6fea..9a4470289bcf 100644
--- a/llvm/lib/Support/Host.cpp
+++ b/llvm/lib/Support/Host.cpp
@@ -83,12 +83,12 @@ StringRef sys::detail::getHostCPUNameForPowerPC(StringRef ProcCpuinfoContent) {
StringRef::const_iterator CIP = CPUInfoStart;
- StringRef::const_iterator CPUStart = 0;
+ StringRef::const_iterator CPUStart = nullptr;
size_t CPULen = 0;
// We need to find the first line which starts with cpu, spaces, and a colon.
// After the colon, there may be some additional spaces and then the cpu type.
- while (CIP < CPUInfoEnd && CPUStart == 0) {
+ while (CIP < CPUInfoEnd && CPUStart == nullptr) {
if (CIP < CPUInfoEnd && *CIP == '\n')
++CIP;
@@ -118,12 +118,12 @@ StringRef sys::detail::getHostCPUNameForPowerPC(StringRef ProcCpuinfoContent) {
}
}
- if (CPUStart == 0)
+ if (CPUStart == nullptr)
while (CIP < CPUInfoEnd && *CIP != '\n')
++CIP;
}
- if (CPUStart == 0)
+ if (CPUStart == nullptr)
return generic;
return StringSwitch<const char *>(StringRef(CPUStart, CPULen))
@@ -213,6 +213,7 @@ StringRef sys::detail::getHostCPUNameForARM(StringRef ProcCpuinfoContent) {
.Case("0xd44", "cortex-x1")
.Case("0xd0c", "neoverse-n1")
.Case("0xd49", "neoverse-n2")
+ .Case("0xd40", "neoverse-v1")
.Default("generic");
}
diff --git a/llvm/lib/Support/InitLLVM.cpp b/llvm/lib/Support/InitLLVM.cpp
index 152de6ebae0a..2b7173b28940 100644
--- a/llvm/lib/Support/InitLLVM.cpp
+++ b/llvm/lib/Support/InitLLVM.cpp
@@ -7,14 +7,15 @@
//===----------------------------------------------------------------------===//
#include "llvm/Support/InitLLVM.h"
-#include "llvm/Support/Error.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/PrettyStackTrace.h"
-#include "llvm/Support/Process.h"
#include "llvm/Support/Signals.h"
-#include <string>
+#include "llvm/Support/SwapByteOrder.h"
#ifdef _WIN32
+#include "llvm/Support/Error.h"
#include "llvm/Support/Windows/WindowsSupport.h"
#endif
diff --git a/llvm/lib/Support/JSON.cpp b/llvm/lib/Support/JSON.cpp
index 17b36ed51850..20babbe56d86 100644
--- a/llvm/lib/Support/JSON.cpp
+++ b/llvm/lib/Support/JSON.cpp
@@ -12,6 +12,7 @@
#include "llvm/Support/Error.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/raw_ostream.h"
+#include "llvm/Support/NativeFormatting.h"
#include <cctype>
namespace llvm {
diff --git a/llvm/lib/Support/LowLevelType.cpp b/llvm/lib/Support/LowLevelType.cpp
index ecf557997ad1..0282cd9bd79e 100644
--- a/llvm/lib/Support/LowLevelType.cpp
+++ b/llvm/lib/Support/LowLevelType.cpp
@@ -17,7 +17,7 @@ using namespace llvm;
LLT::LLT(MVT VT) {
if (VT.isVector()) {
- bool asVector = VT.getVectorNumElements() > 1;
+ bool asVector = VT.getVectorMinNumElements() > 1;
init(/*IsPointer=*/false, asVector, /*IsScalar=*/!asVector,
VT.getVectorElementCount(), VT.getVectorElementType().getSizeInBits(),
/*AddressSpace=*/0);
diff --git a/llvm/lib/Support/MD5.cpp b/llvm/lib/Support/MD5.cpp
index 9dceb4d418cd..caadde389504 100644
--- a/llvm/lib/Support/MD5.cpp
+++ b/llvm/lib/Support/MD5.cpp
@@ -40,10 +40,9 @@
#include "llvm/Support/MD5.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Endian.h"
-#include "llvm/Support/Format.h"
-#include "llvm/Support/raw_ostream.h"
#include <array>
#include <cstdint>
#include <cstring>
@@ -281,14 +280,12 @@ StringRef MD5::result() {
SmallString<32> MD5::MD5Result::digest() const {
SmallString<32> Str;
- raw_svector_ostream Res(Str);
- for (int i = 0; i < 16; ++i)
- Res << format("%.2x", Bytes[i]);
+ toHex(Bytes, /*LowerCase*/ true, Str);
return Str;
}
-void MD5::stringifyResult(MD5Result &Result, SmallString<32> &Str) {
- Str = Result.digest();
+void MD5::stringifyResult(MD5Result &Result, SmallVectorImpl<char> &Str) {
+ toHex(Result.Bytes, /*LowerCase*/ true, Str);
}
std::array<uint8_t, 16> MD5::hash(ArrayRef<uint8_t> Data) {
diff --git a/llvm/lib/Support/MSP430AttributeParser.cpp b/llvm/lib/Support/MSP430AttributeParser.cpp
index a9948a158fc0..a230a3a70adb 100644
--- a/llvm/lib/Support/MSP430AttributeParser.cpp
+++ b/llvm/lib/Support/MSP430AttributeParser.cpp
@@ -7,7 +7,8 @@
//===----------------------------------------------------------------------===//
#include "llvm/Support/MSP430AttributeParser.h"
-#include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/Support/ErrorHandling.h"
using namespace llvm;
using namespace llvm::MSP430Attrs;
diff --git a/llvm/lib/Support/MemAlloc.cpp b/llvm/lib/Support/MemAlloc.cpp
index 7aaa0dc6e205..07a26cf26480 100644
--- a/llvm/lib/Support/MemAlloc.cpp
+++ b/llvm/lib/Support/MemAlloc.cpp
@@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/Support/MemAlloc.h"
+#include <new>
// These are out of line to have __cpp_aligned_new not affect ABI.
diff --git a/llvm/lib/Support/MemoryBuffer.cpp b/llvm/lib/Support/MemoryBuffer.cpp
index d3fa3c6f065d..7816779cca1d 100644
--- a/llvm/lib/Support/MemoryBuffer.cpp
+++ b/llvm/lib/Support/MemoryBuffer.cpp
@@ -14,16 +14,15 @@
#include "llvm/ADT/SmallString.h"
#include "llvm/Config/config.h"
#include "llvm/Support/AutoConvert.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/Errc.h"
-#include "llvm/Support/Errno.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/MathExtras.h"
-#include "llvm/Support/Path.h"
#include "llvm/Support/Process.h"
#include "llvm/Support/Program.h"
#include "llvm/Support/SmallVectorMemoryBuffer.h"
#include <cassert>
-#include <cerrno>
#include <cstring>
#include <new>
#include <sys/types.h>
@@ -220,28 +219,16 @@ public:
MemoryBuffer::BufferKind getBufferKind() const override {
return MemoryBuffer::MemoryBuffer_MMap;
}
+
+ void dontNeedIfMmap() override { MFR.dontNeed(); }
};
} // namespace
static ErrorOr<std::unique_ptr<WritableMemoryBuffer>>
getMemoryBufferForStream(sys::fs::file_t FD, const Twine &BufferName) {
- const ssize_t ChunkSize = 4096*4;
- SmallString<ChunkSize> Buffer;
-
- // Read into Buffer until we hit EOF.
- size_t Size = Buffer.size();
- for (;;) {
- Buffer.resize_for_overwrite(Size + ChunkSize);
- Expected<size_t> ReadBytes = sys::fs::readNativeFile(
- FD, makeMutableArrayRef(Buffer.begin() + Size, ChunkSize));
- if (!ReadBytes)
- return errorToErrorCode(ReadBytes.takeError());
- if (*ReadBytes == 0)
- break;
- Size += *ReadBytes;
- }
- Buffer.truncate(Size);
-
+ SmallString<sys::fs::DefaultReadChunkSize> Buffer;
+ if (Error E = sys::fs::readNativeFileToEOF(FD, Buffer))
+ return errorToErrorCode(std::move(E));
return getMemBufferCopyImpl(Buffer, BufferName);
}
diff --git a/llvm/lib/Support/NativeFormatting.cpp b/llvm/lib/Support/NativeFormatting.cpp
index 254d18d797b3..0a797046bb68 100644
--- a/llvm/lib/Support/NativeFormatting.cpp
+++ b/llvm/lib/Support/NativeFormatting.cpp
@@ -13,7 +13,6 @@
#include "llvm/Support/Format.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/raw_ostream.h"
-#include <float.h>
using namespace llvm;
diff --git a/llvm/lib/Support/Parallel.cpp b/llvm/lib/Support/Parallel.cpp
index 71e3a1362f7e..4977c188f934 100644
--- a/llvm/lib/Support/Parallel.cpp
+++ b/llvm/lib/Support/Parallel.cpp
@@ -174,3 +174,35 @@ void TaskGroup::spawn(std::function<void()> F) {
} // namespace parallel
} // namespace llvm
#endif // LLVM_ENABLE_THREADS
+
+void llvm::parallelForEachN(size_t Begin, size_t End,
+ llvm::function_ref<void(size_t)> Fn) {
+ // If we have zero or one items, then do not incur the overhead of spinning up
+ // a task group. They are surprisingly expensive, and because they do not
+ // support nested parallelism, a single entry task group can block parallel
+ // execution underneath them.
+#if LLVM_ENABLE_THREADS
+ auto NumItems = End - Begin;
+ if (NumItems > 1 && parallel::strategy.ThreadsRequested != 1) {
+ // Limit the number of tasks to MaxTasksPerGroup to limit job scheduling
+ // overhead on large inputs.
+ auto TaskSize = NumItems / parallel::detail::MaxTasksPerGroup;
+ if (TaskSize == 0)
+ TaskSize = 1;
+
+ parallel::detail::TaskGroup TG;
+ for (; Begin + TaskSize < End; Begin += TaskSize) {
+ TG.spawn([=, &Fn] {
+ for (size_t I = Begin, E = Begin + TaskSize; I != E; ++I)
+ Fn(I);
+ });
+ }
+ for (; Begin != End; ++Begin)
+ Fn(Begin);
+ return;
+ }
+#endif
+
+ for (; Begin != End; ++Begin)
+ Fn(Begin);
+}
diff --git a/llvm/lib/Support/Path.cpp b/llvm/lib/Support/Path.cpp
index 7c99d088911c..63d8d4ee4648 100644
--- a/llvm/lib/Support/Path.cpp
+++ b/llvm/lib/Support/Path.cpp
@@ -12,6 +12,7 @@
#include "llvm/Support/Path.h"
#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/ScopeExit.h"
#include "llvm/Config/config.h"
#include "llvm/Config/llvm-config.h"
#include "llvm/Support/Endian.h"
@@ -1167,6 +1168,25 @@ const char *mapped_file_region::const_data() const {
return reinterpret_cast<const char *>(Mapping);
}
+Error readNativeFileToEOF(file_t FileHandle, SmallVectorImpl<char> &Buffer,
+ ssize_t ChunkSize) {
+ // Install a handler to truncate the buffer to the correct size on exit.
+ size_t Size = Buffer.size();
+ auto TruncateOnExit = make_scope_exit([&]() { Buffer.truncate(Size); });
+
+ // Read into Buffer until we hit EOF.
+ for (;;) {
+ Buffer.resize_for_overwrite(Size + ChunkSize);
+ Expected<size_t> ReadBytes = readNativeFile(
+ FileHandle, makeMutableArrayRef(Buffer.begin() + Size, ChunkSize));
+ if (!ReadBytes)
+ return ReadBytes.takeError();
+ if (*ReadBytes == 0)
+ return Error::success();
+ Size += *ReadBytes;
+ }
+}
+
} // end namespace fs
} // end namespace sys
} // end namespace llvm
@@ -1234,7 +1254,8 @@ Error TempFile::keep(const Twine &Name) {
#ifdef _WIN32
// If we can't cancel the delete don't rename.
auto H = reinterpret_cast<HANDLE>(_get_osfhandle(FD));
- std::error_code RenameEC = setDeleteDisposition(H, false);
+ std::error_code RenameEC =
+ RemoveOnClose ? std::error_code() : setDeleteDisposition(H, false);
bool ShouldDelete = false;
if (!RenameEC) {
RenameEC = rename_handle(H, Name);
diff --git a/llvm/lib/Support/PrettyStackTrace.cpp b/llvm/lib/Support/PrettyStackTrace.cpp
index 0d07057f1df0..fa91405fee10 100644
--- a/llvm/lib/Support/PrettyStackTrace.cpp
+++ b/llvm/lib/Support/PrettyStackTrace.cpp
@@ -13,7 +13,6 @@
#include "llvm/Support/PrettyStackTrace.h"
#include "llvm-c/ErrorHandling.h"
-#include "llvm/ADT/SmallString.h"
#include "llvm/Config/config.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/SaveAndRestore.h"
@@ -21,6 +20,10 @@
#include "llvm/Support/Watchdog.h"
#include "llvm/Support/raw_ostream.h"
+#ifdef __APPLE__
+#include "llvm/ADT/SmallString.h"
+#endif
+
#include <atomic>
#include <cassert>
#include <cstdarg>
diff --git a/llvm/lib/Support/RISCVISAInfo.cpp b/llvm/lib/Support/RISCVISAInfo.cpp
index e2e4340f44e9..6c59d8a7ef04 100644
--- a/llvm/lib/Support/RISCVISAInfo.cpp
+++ b/llvm/lib/Support/RISCVISAInfo.cpp
@@ -9,6 +9,7 @@
#include "llvm/Support/RISCVISAInfo.h"
#include "llvm/ADT/None.h"
#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Errc.h"
@@ -46,25 +47,56 @@ static const RISCVSupportedExtension SupportedExtensions[] = {
{"f", RISCVExtensionVersion{2, 0}},
{"d", RISCVExtensionVersion{2, 0}},
{"c", RISCVExtensionVersion{2, 0}},
-};
-static const RISCVSupportedExtension SupportedExperimentalExtensions[] = {
- {"v", RISCVExtensionVersion{0, 10}},
+ {"zfhmin", RISCVExtensionVersion{1, 0}},
+ {"zfh", RISCVExtensionVersion{1, 0}},
+
{"zba", RISCVExtensionVersion{1, 0}},
{"zbb", RISCVExtensionVersion{1, 0}},
{"zbc", RISCVExtensionVersion{1, 0}},
+ {"zbs", RISCVExtensionVersion{1, 0}},
+
+ {"zbkb", RISCVExtensionVersion{1, 0}},
+ {"zbkc", RISCVExtensionVersion{1, 0}},
+ {"zbkx", RISCVExtensionVersion{1, 0}},
+ {"zknd", RISCVExtensionVersion{1, 0}},
+ {"zkne", RISCVExtensionVersion{1, 0}},
+ {"zknh", RISCVExtensionVersion{1, 0}},
+ {"zksed", RISCVExtensionVersion{1, 0}},
+ {"zksh", RISCVExtensionVersion{1, 0}},
+ {"zkr", RISCVExtensionVersion{1, 0}},
+ {"zkn", RISCVExtensionVersion{1, 0}},
+ {"zks", RISCVExtensionVersion{1, 0}},
+ {"zkt", RISCVExtensionVersion{1, 0}},
+ {"zk", RISCVExtensionVersion{1, 0}},
+
+ {"v", RISCVExtensionVersion{1, 0}},
+ {"zvl32b", RISCVExtensionVersion{1, 0}},
+ {"zvl64b", RISCVExtensionVersion{1, 0}},
+ {"zvl128b", RISCVExtensionVersion{1, 0}},
+ {"zvl256b", RISCVExtensionVersion{1, 0}},
+ {"zvl512b", RISCVExtensionVersion{1, 0}},
+ {"zvl1024b", RISCVExtensionVersion{1, 0}},
+ {"zvl2048b", RISCVExtensionVersion{1, 0}},
+ {"zvl4096b", RISCVExtensionVersion{1, 0}},
+ {"zvl8192b", RISCVExtensionVersion{1, 0}},
+ {"zvl16384b", RISCVExtensionVersion{1, 0}},
+ {"zvl32768b", RISCVExtensionVersion{1, 0}},
+ {"zvl65536b", RISCVExtensionVersion{1, 0}},
+ {"zve32x", RISCVExtensionVersion{1, 0}},
+ {"zve32f", RISCVExtensionVersion{1, 0}},
+ {"zve64x", RISCVExtensionVersion{1, 0}},
+ {"zve64f", RISCVExtensionVersion{1, 0}},
+ {"zve64d", RISCVExtensionVersion{1, 0}},
+};
+
+static const RISCVSupportedExtension SupportedExperimentalExtensions[] = {
{"zbe", RISCVExtensionVersion{0, 93}},
{"zbf", RISCVExtensionVersion{0, 93}},
{"zbm", RISCVExtensionVersion{0, 93}},
{"zbp", RISCVExtensionVersion{0, 93}},
{"zbr", RISCVExtensionVersion{0, 93}},
- {"zbs", RISCVExtensionVersion{1, 0}},
{"zbt", RISCVExtensionVersion{0, 93}},
-
- {"zvlsseg", RISCVExtensionVersion{0, 10}},
-
- {"zfhmin", RISCVExtensionVersion{0, 1}},
- {"zfh", RISCVExtensionVersion{0, 1}},
};
static bool stripExperimentalPrefix(StringRef &Ext) {
@@ -78,9 +110,9 @@ static bool stripExperimentalPrefix(StringRef &Ext) {
// NOTE: This function is NOT able to take empty strings or strings that only
// have version numbers and no extension name. It assumes the extension name
// will be at least more than one character.
-static size_t findFirstNonVersionCharacter(const StringRef &Ext) {
- if (Ext.size() == 0)
- llvm_unreachable("Already guarded by if-statement in ::parseArchString");
+static size_t findFirstNonVersionCharacter(StringRef Ext) {
+ assert(!Ext.empty() &&
+ "Already guarded by if-statement in ::parseArchString");
int Pos = Ext.size() - 1;
while (Pos > 0 && isDigit(Ext[Pos]))
@@ -276,16 +308,13 @@ bool RISCVISAInfo::compareExtension(const std::string &LHS,
void RISCVISAInfo::toFeatures(
std::vector<StringRef> &Features,
std::function<StringRef(const Twine &)> StrAlloc) const {
- for (auto &Ext : Exts) {
+ for (auto const &Ext : Exts) {
StringRef ExtName = Ext.first;
if (ExtName == "i")
continue;
- if (ExtName == "zvlsseg") {
- Features.push_back("+experimental-v");
- Features.push_back("+experimental-zvlsseg");
- } else if (isExperimentalExtension(ExtName)) {
+ if (isExperimentalExtension(ExtName)) {
Features.push_back(StrAlloc("+experimental-" + ExtName));
} else {
Features.push_back(StrAlloc("+" + ExtName));
@@ -434,6 +463,8 @@ RISCVISAInfo::parseFeatures(unsigned XLen,
ISAInfo->updateImplication();
ISAInfo->updateFLen();
+ ISAInfo->updateMinVLen();
+ ISAInfo->updateMaxELen();
if (Error Result = ISAInfo->checkDependency())
return std::move(Result);
@@ -657,6 +688,8 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
ISAInfo->updateImplication();
ISAInfo->updateFLen();
+ ISAInfo->updateMinVLen();
+ ISAInfo->updateMaxELen();
if (Error Result = ISAInfo->checkDependency())
return std::move(Result);
@@ -669,6 +702,12 @@ Error RISCVISAInfo::checkDependency() {
bool HasE = Exts.count("e") == 1;
bool HasD = Exts.count("d") == 1;
bool HasF = Exts.count("f") == 1;
+ bool HasZve32x = Exts.count("zve32x") == 1;
+ bool HasZve32f = Exts.count("zve32f") == 1;
+ bool HasZve64d = Exts.count("zve64d") == 1;
+ bool HasV = Exts.count("v") == 1;
+ bool HasVector = HasZve32x || HasV;
+ bool HasZvl = MinVLen != 0;
if (HasE && !IsRv32)
return createStringError(
@@ -683,6 +722,29 @@ Error RISCVISAInfo::checkDependency() {
return createStringError(errc::invalid_argument,
"d requires f extension to also be specified");
+ // FIXME: Consider Zfinx in the future
+ if (HasZve32f && !HasF)
+ return createStringError(
+ errc::invalid_argument,
+ "zve32f requires f extension to also be specified");
+
+ // FIXME: Consider Zdinx in the future
+ if (HasZve64d && !HasD)
+ return createStringError(
+ errc::invalid_argument,
+ "zve64d requires d extension to also be specified");
+
+ if (HasZvl && !HasVector)
+ return createStringError(
+ errc::invalid_argument,
+ "zvl*b requires v or zve* extension to also be specified");
+
+ // Could not implement Zve* extension and the V extension at the same time.
+ if (HasZve32x && HasV)
+ return createStringError(
+ errc::invalid_argument,
+ "It is illegal to specify the v extension with zve* extensions");
+
// Additional dependency checks.
// TODO: The 'q' extension requires rv64.
// TODO: It is illegal to specify 'e' extensions with 'f' and 'd'.
@@ -690,8 +752,27 @@ Error RISCVISAInfo::checkDependency() {
return Error::success();
}
-static const char *ImpliedExtsV[] = {"zvlsseg"};
+static const char *ImpliedExtsV[] = {"zvl128b", "f", "d"};
static const char *ImpliedExtsZfh[] = {"zfhmin"};
+static const char *ImpliedExtsZve64d[] = {"zve64f"};
+static const char *ImpliedExtsZve64f[] = {"zve64x", "zve32f"};
+static const char *ImpliedExtsZve64x[] = {"zve32x", "zvl64b"};
+static const char *ImpliedExtsZve32f[] = {"zve32x"};
+static const char *ImpliedExtsZve32x[] = {"zvl32b"};
+static const char *ImpliedExtsZvl65536b[] = {"zvl32768b"};
+static const char *ImpliedExtsZvl32768b[] = {"zvl16384b"};
+static const char *ImpliedExtsZvl16384b[] = {"zvl8192b"};
+static const char *ImpliedExtsZvl8192b[] = {"zvl4096b"};
+static const char *ImpliedExtsZvl4096b[] = {"zvl2048b"};
+static const char *ImpliedExtsZvl2048b[] = {"zvl1024b"};
+static const char *ImpliedExtsZvl1024b[] = {"zvl512b"};
+static const char *ImpliedExtsZvl512b[] = {"zvl256b"};
+static const char *ImpliedExtsZvl256b[] = {"zvl128b"};
+static const char *ImpliedExtsZvl128b[] = {"zvl64b"};
+static const char *ImpliedExtsZvl64b[] = {"zvl32b"};
+static const char *ImpliedExtsZk[] = {"zkn", "zkt", "zkr"};
+static const char *ImpliedExtsZkn[] = {"zbkb", "zbkc", "zbkx", "zkne", "zknd", "zknh"};
+static const char *ImpliedExtsZks[] = {"zbkb", "zbkc", "zbkx", "zksed", "zksh"};
struct ImpliedExtsEntry {
StringLiteral Name;
@@ -707,6 +788,25 @@ struct ImpliedExtsEntry {
static constexpr ImpliedExtsEntry ImpliedExts[] = {
{{"v"}, {ImpliedExtsV}},
{{"zfh"}, {ImpliedExtsZfh}},
+ {{"zk"}, {ImpliedExtsZk}},
+ {{"zkn"}, {ImpliedExtsZkn}},
+ {{"zks"}, {ImpliedExtsZks}},
+ {{"zve32f"}, {ImpliedExtsZve32f}},
+ {{"zve32x"}, {ImpliedExtsZve32x}},
+ {{"zve64d"}, {ImpliedExtsZve64d}},
+ {{"zve64f"}, {ImpliedExtsZve64f}},
+ {{"zve64x"}, {ImpliedExtsZve64x}},
+ {{"zvl1024b"}, {ImpliedExtsZvl1024b}},
+ {{"zvl128b"}, {ImpliedExtsZvl128b}},
+ {{"zvl16384b"}, {ImpliedExtsZvl16384b}},
+ {{"zvl2048b"}, {ImpliedExtsZvl2048b}},
+ {{"zvl256b"}, {ImpliedExtsZvl256b}},
+ {{"zvl32768b"}, {ImpliedExtsZvl32768b}},
+ {{"zvl4096b"}, {ImpliedExtsZvl4096b}},
+ {{"zvl512b"}, {ImpliedExtsZvl512b}},
+ {{"zvl64b"}, {ImpliedExtsZvl64b}},
+ {{"zvl65536b"}, {ImpliedExtsZvl65536b}},
+ {{"zvl8192b"}, {ImpliedExtsZvl8192b}},
};
void RISCVISAInfo::updateImplication() {
@@ -721,12 +821,25 @@ void RISCVISAInfo::updateImplication() {
}
assert(llvm::is_sorted(ImpliedExts) && "Table not sorted by Name");
- for (auto &Ext : Exts) {
- auto I = llvm::lower_bound(ImpliedExts, Ext.first);
- if (I != std::end(ImpliedExts) && I->Name == Ext.first) {
- for (auto &ImpliedExt : I->Exts) {
+
+ // This loop may execute over 1 iteration since implication can be layered
+ // Exits loop if no more implication is applied
+ SmallSetVector<StringRef, 16> WorkList;
+ for (auto const &Ext : Exts)
+ WorkList.insert(Ext.first);
+
+ while (!WorkList.empty()) {
+ StringRef ExtName = WorkList.pop_back_val();
+ auto I = llvm::lower_bound(ImpliedExts, ExtName);
+ if (I != std::end(ImpliedExts) && I->Name == ExtName) {
+ for (const char *ImpliedExt : I->Exts) {
+ if (WorkList.count(ImpliedExt))
+ continue;
+ if (Exts.count(ImpliedExt))
+ continue;
auto Version = findDefaultVersion(ImpliedExt);
addExtension(ImpliedExt, Version->Major, Version->Minor);
+ WorkList.insert(ImpliedExt);
}
}
}
@@ -741,6 +854,41 @@ void RISCVISAInfo::updateFLen() {
FLen = 32;
}
+void RISCVISAInfo::updateMinVLen() {
+ for (auto const &Ext : Exts) {
+ StringRef ExtName = Ext.first;
+ bool IsZvlExt = ExtName.consume_front("zvl") && ExtName.consume_back("b");
+ if (IsZvlExt) {
+ unsigned ZvlLen;
+ if (!ExtName.getAsInteger(10, ZvlLen))
+ MinVLen = std::max(MinVLen, ZvlLen);
+ }
+ }
+}
+
+void RISCVISAInfo::updateMaxELen() {
+ // handles EEW restriction by sub-extension zve
+ for (auto const &Ext : Exts) {
+ StringRef ExtName = Ext.first;
+ bool IsZveExt = ExtName.consume_front("zve");
+ if (IsZveExt) {
+ if (ExtName.back() == 'f')
+ MaxELenFp = std::max(MaxELenFp, 32u);
+ if (ExtName.back() == 'd')
+ MaxELenFp = std::max(MaxELenFp, 64u);
+ ExtName = ExtName.drop_back();
+ unsigned ZveELen;
+ ExtName.getAsInteger(10, ZveELen);
+ MaxELen = std::max(MaxELen, ZveELen);
+ }
+ if (ExtName == "v") {
+ MaxELenFp = 64;
+ MaxELen = 64;
+ return;
+ }
+ }
+}
+
std::string RISCVISAInfo::toString() const {
std::string Buffer;
raw_string_ostream Arch(Buffer);
@@ -748,7 +896,7 @@ std::string RISCVISAInfo::toString() const {
Arch << "rv" << XLen;
ListSeparator LS("_");
- for (auto &Ext : Exts) {
+ for (auto const &Ext : Exts) {
StringRef ExtName = Ext.first;
auto ExtInfo = Ext.second;
Arch << LS << ExtName;
@@ -757,3 +905,17 @@ std::string RISCVISAInfo::toString() const {
return Arch.str();
}
+
+std::vector<std::string> RISCVISAInfo::toFeatureVector() const {
+ std::vector<std::string> FeatureVector;
+ for (auto const &Ext : Exts) {
+ std::string ExtName = Ext.first;
+ if (ExtName == "i") // i is not recognized in clang -cc1
+ continue;
+ std::string Feature = isExperimentalExtension(ExtName)
+ ? "+experimental-" + ExtName
+ : "+" + ExtName;
+ FeatureVector.push_back(Feature);
+ }
+ return FeatureVector;
+}
diff --git a/llvm/lib/Support/ScopedPrinter.cpp b/llvm/lib/Support/ScopedPrinter.cpp
index ea90a24eaced..a434e50e8c1f 100644
--- a/llvm/lib/Support/ScopedPrinter.cpp
+++ b/llvm/lib/Support/ScopedPrinter.cpp
@@ -1,7 +1,6 @@
#include "llvm/Support/ScopedPrinter.h"
#include "llvm/Support/Format.h"
-#include <cctype>
using namespace llvm::support;
diff --git a/llvm/lib/Support/Signals.cpp b/llvm/lib/Support/Signals.cpp
index c018dc92bf40..5ce41c987029 100644
--- a/llvm/lib/Support/Signals.cpp
+++ b/llvm/lib/Support/Signals.cpp
@@ -28,6 +28,7 @@
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Mutex.h"
+#include "llvm/Support/Path.h"
#include "llvm/Support/Program.h"
#include "llvm/Support/StringSaver.h"
#include "llvm/Support/raw_ostream.h"
diff --git a/llvm/lib/Support/Signposts.cpp b/llvm/lib/Support/Signposts.cpp
index 58fafb26cdf3..074dddc81c80 100644
--- a/llvm/lib/Support/Signposts.cpp
+++ b/llvm/lib/Support/Signposts.cpp
@@ -7,7 +7,6 @@
//===----------------------------------------------------------------------===//
#include "llvm/Support/Signposts.h"
-#include "llvm/Support/Timer.h"
#include "llvm/Config/config.h"
#if LLVM_SUPPORT_XCODE_SIGNPOSTS
diff --git a/llvm/lib/Support/SmallPtrSet.cpp b/llvm/lib/Support/SmallPtrSet.cpp
index f6e2dfb8a6c9..cbb87ea8717c 100644
--- a/llvm/lib/Support/SmallPtrSet.cpp
+++ b/llvm/lib/Support/SmallPtrSet.cpp
@@ -13,7 +13,6 @@
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/DenseMapInfo.h"
-#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/MemAlloc.h"
#include <algorithm>
diff --git a/llvm/lib/Support/SmallVector.cpp b/llvm/lib/Support/SmallVector.cpp
index 2d7721e4e1fb..8cafbc7fad0d 100644
--- a/llvm/lib/Support/SmallVector.cpp
+++ b/llvm/lib/Support/SmallVector.cpp
@@ -12,6 +12,7 @@
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Twine.h"
+#include "llvm/Support/MemAlloc.h"
#include <cstdint>
#ifdef LLVM_ENABLE_EXCEPTIONS
#include <stdexcept>
diff --git a/llvm/lib/Support/SpecialCaseList.cpp b/llvm/lib/Support/SpecialCaseList.cpp
index 1939ed9e9547..137b37f2b1c3 100644
--- a/llvm/lib/Support/SpecialCaseList.cpp
+++ b/llvm/lib/Support/SpecialCaseList.cpp
@@ -15,7 +15,6 @@
#include "llvm/Support/SpecialCaseList.h"
#include "llvm/ADT/SmallVector.h"
-#include "llvm/ADT/StringExtras.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Regex.h"
#include "llvm/Support/VirtualFileSystem.h"
diff --git a/llvm/lib/Support/StringMap.cpp b/llvm/lib/Support/StringMap.cpp
index f65d3846623c..012c785b4351 100644
--- a/llvm/lib/Support/StringMap.cpp
+++ b/llvm/lib/Support/StringMap.cpp
@@ -11,7 +11,6 @@
//===----------------------------------------------------------------------===//
#include "llvm/ADT/StringMap.h"
-#include "llvm/ADT/StringExtras.h"
#include "llvm/Support/DJB.h"
#include "llvm/Support/MathExtras.h"
diff --git a/llvm/lib/Support/StringRef.cpp b/llvm/lib/Support/StringRef.cpp
index 652303fdb6a0..3ed08ed38661 100644
--- a/llvm/lib/Support/StringRef.cpp
+++ b/llvm/lib/Support/StringRef.cpp
@@ -597,3 +597,11 @@ bool StringRef::getAsDouble(double &Result, bool AllowInexact) const {
hash_code llvm::hash_value(StringRef S) {
return hash_combine_range(S.begin(), S.end());
}
+
+unsigned DenseMapInfo<StringRef, void>::getHashValue(StringRef Val) {
+ assert(Val.data() != getEmptyKey().data() &&
+ "Cannot hash the empty key!");
+ assert(Val.data() != getTombstoneKey().data() &&
+ "Cannot hash the tombstone key!");
+ return (unsigned)(hash_value(Val));
+}
diff --git a/llvm/lib/Support/SymbolRemappingReader.cpp b/llvm/lib/Support/SymbolRemappingReader.cpp
index 1caf0947216e..90997ab0a6ce 100644
--- a/llvm/lib/Support/SymbolRemappingReader.cpp
+++ b/llvm/lib/Support/SymbolRemappingReader.cpp
@@ -15,6 +15,7 @@
#include "llvm/ADT/StringSwitch.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Support/LineIterator.h"
+#include "llvm/Support/MemoryBuffer.h"
using namespace llvm;
diff --git a/llvm/lib/Support/TargetParser.cpp b/llvm/lib/Support/TargetParser.cpp
index bc60bdea5f62..0105cd2e8153 100644
--- a/llvm/lib/Support/TargetParser.cpp
+++ b/llvm/lib/Support/TargetParser.cpp
@@ -13,10 +13,8 @@
#include "llvm/Support/TargetParser.h"
#include "llvm/ADT/ArrayRef.h"
-#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringSwitch.h"
-#include "llvm/ADT/Twine.h"
-#include "llvm/Support/ARMBuildAttributes.h"
+#include "llvm/ADT/Triple.h"
using namespace llvm;
using namespace AMDGPU;
diff --git a/llvm/lib/Support/ThreadPool.cpp b/llvm/lib/Support/ThreadPool.cpp
index 54ea84d4bd6d..9f92ae1c7a7c 100644
--- a/llvm/lib/Support/ThreadPool.cpp
+++ b/llvm/lib/Support/ThreadPool.cpp
@@ -13,8 +13,12 @@
#include "llvm/Support/ThreadPool.h"
#include "llvm/Config/llvm-config.h"
+
+#if LLVM_ENABLE_THREADS
#include "llvm/Support/Threading.h"
+#else
#include "llvm/Support/raw_ostream.h"
+#endif
using namespace llvm;
@@ -117,6 +121,10 @@ void ThreadPool::wait() {
}
}
+bool ThreadPool::isWorkerThread() const {
+ report_fatal_error("LLVM compiled without multithreading");
+}
+
ThreadPool::~ThreadPool() { wait(); }
#endif
diff --git a/llvm/lib/Support/TimeProfiler.cpp b/llvm/lib/Support/TimeProfiler.cpp
index 2b094a4983a0..9380fa01c84a 100644
--- a/llvm/lib/Support/TimeProfiler.cpp
+++ b/llvm/lib/Support/TimeProfiler.cpp
@@ -11,10 +11,10 @@
//===----------------------------------------------------------------------===//
#include "llvm/Support/TimeProfiler.h"
-#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/STLFunctionalExtras.h"
#include "llvm/ADT/StringMap.h"
-#include "llvm/Support/CommandLine.h"
#include "llvm/Support/JSON.h"
+#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/Process.h"
#include "llvm/Support/Threading.h"
diff --git a/llvm/lib/Support/ToolOutputFile.cpp b/llvm/lib/Support/ToolOutputFile.cpp
index c192ce60f31c..c2ca97a59c62 100644
--- a/llvm/lib/Support/ToolOutputFile.cpp
+++ b/llvm/lib/Support/ToolOutputFile.cpp
@@ -11,7 +11,6 @@
//===----------------------------------------------------------------------===//
#include "llvm/Support/ToolOutputFile.h"
-#include "llvm/ADT/Triple.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Signals.h"
using namespace llvm;
diff --git a/llvm/lib/Support/Triple.cpp b/llvm/lib/Support/Triple.cpp
index 2819dc0c139a..20dea8c302a5 100644
--- a/llvm/lib/Support/Triple.cpp
+++ b/llvm/lib/Support/Triple.cpp
@@ -14,7 +14,7 @@
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/Host.h"
#include "llvm/Support/SwapByteOrder.h"
-#include "llvm/Support/TargetParser.h"
+#include "llvm/Support/ARMTargetParser.h"
#include "llvm/Support/VersionTuple.h"
#include <cassert>
#include <cstring>
@@ -663,12 +663,16 @@ static Triple::SubArchType parseSubArch(StringRef SubArchName) {
return Triple::ARMSubArch_v8_6a;
case ARM::ArchKind::ARMV8_7A:
return Triple::ARMSubArch_v8_7a;
+ case ARM::ArchKind::ARMV8_8A:
+ return Triple::ARMSubArch_v8_8a;
case ARM::ArchKind::ARMV9A:
return Triple::ARMSubArch_v9;
case ARM::ArchKind::ARMV9_1A:
return Triple::ARMSubArch_v9_1a;
case ARM::ArchKind::ARMV9_2A:
return Triple::ARMSubArch_v9_2a;
+ case ARM::ArchKind::ARMV9_3A:
+ return Triple::ARMSubArch_v9_3a;
case ARM::ArchKind::ARMV8R:
return Triple::ARMSubArch_v8r;
case ARM::ArchKind::ARMV8MBaseline:
diff --git a/llvm/lib/Support/TypeSize.cpp b/llvm/lib/Support/TypeSize.cpp
index abb81016a0ba..a80fde83e3bc 100644
--- a/llvm/lib/Support/TypeSize.cpp
+++ b/llvm/lib/Support/TypeSize.cpp
@@ -8,6 +8,7 @@
#include "llvm/Support/TypeSize.h"
#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/WithColor.h"
#include "DebugOptions.h"
diff --git a/llvm/lib/Support/Unix/Path.inc b/llvm/lib/Support/Unix/Path.inc
index f5cb5895d95d..788460d657fe 100644
--- a/llvm/lib/Support/Unix/Path.inc
+++ b/llvm/lib/Support/Unix/Path.inc
@@ -273,7 +273,7 @@ std::string getMainExecutable(const char *argv0, void *MainAddr) {
// the program, and not the eventual binary file. Therefore, call realpath
// so this behaves the same on all platforms.
#if _POSIX_VERSION >= 200112 || defined(__GLIBC__)
- if (char *real_path = realpath(exe_path, NULL)) {
+ if (char *real_path = realpath(exe_path, nullptr)) {
std::string ret = std::string(real_path);
free(real_path);
return ret;
@@ -380,20 +380,22 @@ std::error_code current_path(SmallVectorImpl<char> &result) {
return std::error_code();
}
- result.reserve(PATH_MAX);
+ result.resize_for_overwrite(PATH_MAX);
while (true) {
- if (::getcwd(result.data(), result.capacity()) == nullptr) {
+ if (::getcwd(result.data(), result.size()) == nullptr) {
// See if there was a real error.
- if (errno != ENOMEM)
+ if (errno != ENOMEM) {
+ result.clear();
return std::error_code(errno, std::generic_category());
+ }
// Otherwise there just wasn't enough space.
- result.reserve(result.capacity() * 2);
+ result.resize_for_overwrite(result.capacity() * 2);
} else
break;
}
- result.set_size(strlen(result.data()));
+ result.truncate(strlen(result.data()));
return std::error_code();
}
@@ -870,6 +872,17 @@ void mapped_file_region::unmapImpl() {
::munmap(Mapping, Size);
}
+void mapped_file_region::dontNeedImpl() {
+ assert(Mode == mapped_file_region::readonly);
+#if defined(__MVS__) || defined(_AIX)
+ // If we don't have madvise, or it isn't beneficial, treat this as a no-op.
+ return;
+#else
+ if (Mapping)
+ ::madvise(Mapping, Size, MADV_DONTNEED);
+#endif
+}
+
int mapped_file_region::alignment() {
return Process::getPageSizeEstimate();
}
diff --git a/llvm/lib/Support/VirtualFileSystem.cpp b/llvm/lib/Support/VirtualFileSystem.cpp
index bec4e8dbe06c..f15e301874c4 100644
--- a/llvm/lib/Support/VirtualFileSystem.cpp
+++ b/llvm/lib/Support/VirtualFileSystem.cpp
@@ -35,7 +35,6 @@
#include "llvm/Support/FileSystem/UniqueID.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Path.h"
-#include "llvm/Support/Process.h"
#include "llvm/Support/SMLoc.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/YAMLParser.h"
@@ -46,9 +45,7 @@
#include <cstdint>
#include <iterator>
#include <limits>
-#include <map>
#include <memory>
-#include <mutex>
#include <string>
#include <system_error>
#include <utility>
@@ -574,6 +571,11 @@ public:
}
virtual ~InMemoryNode() = default;
+ /// Return the \p Status for this node. \p RequestedName should be the name
+ /// through which the caller referred to this node. It will override
+ /// \p Status::Name in the return value, to mimic the behavior of \p RealFile.
+ virtual Status getStatus(const Twine &RequestedName) const = 0;
+
/// Get the filename of this node (the name without the directory part).
StringRef getFileName() const { return FileName; }
InMemoryNodeKind getKind() const { return Kind; }
@@ -589,10 +591,7 @@ public:
: InMemoryNode(Stat.getName(), IME_File), Stat(std::move(Stat)),
Buffer(std::move(Buffer)) {}
- /// Return the \p Status for this node. \p RequestedName should be the name
- /// through which the caller referred to this node. It will override
- /// \p Status::Name in the return value, to mimic the behavior of \p RealFile.
- Status getStatus(const Twine &RequestedName) const {
+ Status getStatus(const Twine &RequestedName) const override {
return Status::copyWithNewName(Stat, RequestedName);
}
llvm::MemoryBuffer *getBuffer() const { return Buffer.get(); }
@@ -616,6 +615,10 @@ public:
: InMemoryNode(Path, IME_HardLink), ResolvedFile(ResolvedFile) {}
const InMemoryFile &getResolvedFile() const { return ResolvedFile; }
+ Status getStatus(const Twine &RequestedName) const override {
+ return ResolvedFile.getStatus(RequestedName);
+ }
+
std::string toString(unsigned Indent) const override {
return std::string(Indent, ' ') + "HardLink to -> " +
ResolvedFile.toString(0);
@@ -668,7 +671,7 @@ public:
/// Return the \p Status for this node. \p RequestedName should be the name
/// through which the caller referred to this node. It will override
/// \p Status::Name in the return value, to mimic the behavior of \p RealFile.
- Status getStatus(const Twine &RequestedName) const {
+ Status getStatus(const Twine &RequestedName) const override {
return Status::copyWithNewName(Stat, RequestedName);
}
@@ -704,17 +707,6 @@ public:
}
};
-namespace {
-Status getNodeStatus(const InMemoryNode *Node, const Twine &RequestedName) {
- if (auto Dir = dyn_cast<detail::InMemoryDirectory>(Node))
- return Dir->getStatus(RequestedName);
- if (auto File = dyn_cast<detail::InMemoryFile>(Node))
- return File->getStatus(RequestedName);
- if (auto Link = dyn_cast<detail::InMemoryHardLink>(Node))
- return Link->getResolvedFile().getStatus(RequestedName);
- llvm_unreachable("Unknown node type");
-}
-} // namespace
} // namespace detail
// The UniqueID of in-memory files is derived from path and content.
@@ -734,6 +726,16 @@ static sys::fs::UniqueID getDirectoryID(sys::fs::UniqueID Parent,
return getUniqueID(llvm::hash_combine(Parent.getFile(), Name));
}
+Status detail::NewInMemoryNodeInfo::makeStatus() const {
+ UniqueID UID =
+ (Type == sys::fs::file_type::directory_file)
+ ? getDirectoryID(DirUID, Name)
+ : getFileID(DirUID, Name, Buffer ? Buffer->getBuffer() : "");
+
+ return Status(Path, UID, llvm::sys::toTimePoint(ModificationTime), User,
+ Group, Buffer ? Buffer->getBufferSize() : 0, Type, Perms);
+}
+
InMemoryFileSystem::InMemoryFileSystem(bool UseNormalizedPaths)
: Root(new detail::InMemoryDirectory(
Status("", getDirectoryID(llvm::sys::fs::UniqueID(), ""),
@@ -754,7 +756,7 @@ bool InMemoryFileSystem::addFile(const Twine &P, time_t ModificationTime,
Optional<uint32_t> Group,
Optional<llvm::sys::fs::file_type> Type,
Optional<llvm::sys::fs::perms> Perms,
- const detail::InMemoryFile *HardLinkTarget) {
+ MakeNodeFn MakeNode) {
SmallString<128> Path;
P.toVector(Path);
@@ -775,7 +777,6 @@ bool InMemoryFileSystem::addFile(const Twine &P, time_t ModificationTime,
const auto ResolvedGroup = Group.getValueOr(0);
const auto ResolvedType = Type.getValueOr(sys::fs::file_type::regular_file);
const auto ResolvedPerms = Perms.getValueOr(sys::fs::all_all);
- assert(!(HardLinkTarget && Buffer) && "HardLink cannot have a buffer");
// Any intermediate directories we create should be accessible by
// the owner, even if Perms says otherwise for the final path.
const auto NewDirectoryPerms = ResolvedPerms | sys::fs::owner_all;
@@ -786,27 +787,10 @@ bool InMemoryFileSystem::addFile(const Twine &P, time_t ModificationTime,
if (!Node) {
if (I == E) {
// End of the path.
- std::unique_ptr<detail::InMemoryNode> Child;
- if (HardLinkTarget)
- Child.reset(new detail::InMemoryHardLink(P.str(), *HardLinkTarget));
- else {
- // Create a new file or directory.
- Status Stat(
- P.str(),
- (ResolvedType == sys::fs::file_type::directory_file)
- ? getDirectoryID(Dir->getUniqueID(), Name)
- : getFileID(Dir->getUniqueID(), Name, Buffer->getBuffer()),
- llvm::sys::toTimePoint(ModificationTime), ResolvedUser,
- ResolvedGroup, Buffer->getBufferSize(), ResolvedType,
- ResolvedPerms);
- if (ResolvedType == sys::fs::file_type::directory_file) {
- Child.reset(new detail::InMemoryDirectory(std::move(Stat)));
- } else {
- Child.reset(
- new detail::InMemoryFile(std::move(Stat), std::move(Buffer)));
- }
- }
- Dir->addChild(Name, std::move(Child));
+ Dir->addChild(
+ Name, MakeNode({Dir->getUniqueID(), Path, Name, ModificationTime,
+ std::move(Buffer), ResolvedUser, ResolvedGroup,
+ ResolvedType, ResolvedPerms}));
return true;
}
@@ -850,7 +834,15 @@ bool InMemoryFileSystem::addFile(const Twine &P, time_t ModificationTime,
Optional<llvm::sys::fs::file_type> Type,
Optional<llvm::sys::fs::perms> Perms) {
return addFile(P, ModificationTime, std::move(Buffer), User, Group, Type,
- Perms, /*HardLinkTarget=*/nullptr);
+ Perms,
+ [](detail::NewInMemoryNodeInfo NNI)
+ -> std::unique_ptr<detail::InMemoryNode> {
+ Status Stat = NNI.makeStatus();
+ if (Stat.getType() == sys::fs::file_type::directory_file)
+ return std::make_unique<detail::InMemoryDirectory>(Stat);
+ return std::make_unique<detail::InMemoryFile>(
+ Stat, std::move(NNI.Buffer));
+ });
}
bool InMemoryFileSystem::addFileNoOwn(const Twine &P, time_t ModificationTime,
@@ -861,7 +853,15 @@ bool InMemoryFileSystem::addFileNoOwn(const Twine &P, time_t ModificationTime,
Optional<llvm::sys::fs::perms> Perms) {
return addFile(P, ModificationTime, llvm::MemoryBuffer::getMemBuffer(Buffer),
std::move(User), std::move(Group), std::move(Type),
- std::move(Perms));
+ std::move(Perms),
+ [](detail::NewInMemoryNodeInfo NNI)
+ -> std::unique_ptr<detail::InMemoryNode> {
+ Status Stat = NNI.makeStatus();
+ if (Stat.getType() == sys::fs::file_type::directory_file)
+ return std::make_unique<detail::InMemoryDirectory>(Stat);
+ return std::make_unique<detail::InMemoryFile>(
+ Stat, std::move(NNI.Buffer));
+ });
}
static ErrorOr<const detail::InMemoryNode *>
@@ -916,14 +916,17 @@ bool InMemoryFileSystem::addHardLink(const Twine &FromPath,
// before. Resolved ToPath must be a File.
if (!ToNode || FromNode || !isa<detail::InMemoryFile>(*ToNode))
return false;
- return this->addFile(FromPath, 0, nullptr, None, None, None, None,
- cast<detail::InMemoryFile>(*ToNode));
+ return addFile(FromPath, 0, nullptr, None, None, None, None,
+ [&](detail::NewInMemoryNodeInfo NNI) {
+ return std::make_unique<detail::InMemoryHardLink>(
+ NNI.Path.str(), *cast<detail::InMemoryFile>(*ToNode));
+ });
}
llvm::ErrorOr<Status> InMemoryFileSystem::status(const Twine &Path) {
auto Node = lookupInMemoryNode(*this, Root.get(), Path);
if (Node)
- return detail::getNodeStatus(*Node, Path);
+ return (*Node)->getStatus(Path);
return Node.getError();
}
@@ -1649,10 +1652,19 @@ private:
sys::path::Style::windows_backslash)) {
path_style = sys::path::Style::windows_backslash;
} else {
- assert(NameValueNode && "Name presence should be checked earlier");
- error(NameValueNode,
+ // Relative VFS root entries are made absolute to the current working
+ // directory, then we can determine the path style from that.
+ auto EC = sys::fs::make_absolute(Name);
+ if (EC) {
+ assert(NameValueNode && "Name presence should be checked earlier");
+ error(
+ NameValueNode,
"entry with relative path at the root level is not discoverable");
- return nullptr;
+ return nullptr;
+ }
+ path_style = sys::path::is_absolute(Name, sys::path::Style::posix)
+ ? sys::path::Style::posix
+ : sys::path::Style::windows_backslash;
}
}
diff --git a/llvm/lib/Support/Windows/Path.inc b/llvm/lib/Support/Windows/Path.inc
index b15e71a9ce2a..5f1a364ea1a8 100644
--- a/llvm/lib/Support/Windows/Path.inc
+++ b/llvm/lib/Support/Windows/Path.inc
@@ -132,7 +132,8 @@ const file_t kInvalidFile = INVALID_HANDLE_VALUE;
std::string getMainExecutable(const char *argv0, void *MainExecAddr) {
SmallVector<wchar_t, MAX_PATH> PathName;
- DWORD Size = ::GetModuleFileNameW(NULL, PathName.data(), PathName.capacity());
+ PathName.resize_for_overwrite(PathName.capacity());
+ DWORD Size = ::GetModuleFileNameW(NULL, PathName.data(), PathName.size());
// A zero return value indicates a failure other than insufficient space.
if (Size == 0)
@@ -145,7 +146,7 @@ std::string getMainExecutable(const char *argv0, void *MainExecAddr) {
// On success, GetModuleFileNameW returns the number of characters written to
// the buffer not including the NULL terminator.
- PathName.set_size(Size);
+ PathName.truncate(Size);
// Convert the result from UTF-16 to UTF-8.
SmallVector<char, MAX_PATH> PathNameUTF8;
@@ -201,8 +202,8 @@ std::error_code current_path(SmallVectorImpl<char> &result) {
DWORD len = MAX_PATH;
do {
- cur_path.reserve(len);
- len = ::GetCurrentDirectoryW(cur_path.capacity(), cur_path.data());
+ cur_path.resize_for_overwrite(len);
+ len = ::GetCurrentDirectoryW(cur_path.size(), cur_path.data());
// A zero return value indicates a failure other than insufficient space.
if (len == 0)
@@ -210,11 +211,11 @@ std::error_code current_path(SmallVectorImpl<char> &result) {
// If there's insufficient space, the len returned is larger than the len
// given.
- } while (len > cur_path.capacity());
+ } while (len > cur_path.size());
// On success, GetCurrentDirectoryW returns the number of characters not
// including the null-terminator.
- cur_path.set_size(len);
+ cur_path.truncate(len);
if (std::error_code EC =
UTF16ToUTF8(cur_path.begin(), cur_path.size(), result))
@@ -328,7 +329,7 @@ static std::error_code is_local_internal(SmallVectorImpl<wchar_t> &Path,
// the null terminator, it will leave the output unterminated. Push a null
// terminator onto the end to ensure that this never happens.
VolumePath.push_back(L'\0');
- VolumePath.set_size(wcslen(VolumePath.data()));
+ VolumePath.truncate(wcslen(VolumePath.data()));
const wchar_t *P = VolumePath.data();
UINT Type = ::GetDriveTypeW(P);
@@ -364,18 +365,19 @@ std::error_code is_local(const Twine &path, bool &result) {
static std::error_code realPathFromHandle(HANDLE H,
SmallVectorImpl<wchar_t> &Buffer) {
+ Buffer.resize_for_overwrite(Buffer.capacity());
DWORD CountChars = ::GetFinalPathNameByHandleW(
H, Buffer.begin(), Buffer.capacity(), FILE_NAME_NORMALIZED);
if (CountChars && CountChars >= Buffer.capacity()) {
// The buffer wasn't big enough, try again. In this case the return value
// *does* indicate the size of the null terminator.
- Buffer.reserve(CountChars);
+ Buffer.resize_for_overwrite(CountChars);
CountChars = ::GetFinalPathNameByHandleW(
- H, Buffer.begin(), Buffer.capacity(), FILE_NAME_NORMALIZED);
+ H, Buffer.begin(), Buffer.size(), FILE_NAME_NORMALIZED);
}
+ Buffer.truncate(CountChars);
if (CountChars == 0)
return mapWindowsError(GetLastError());
- Buffer.set_size(CountChars);
return std::error_code();
}
@@ -959,6 +961,8 @@ void mapped_file_region::unmapImpl() {
}
}
+void mapped_file_region::dontNeedImpl() {}
+
int mapped_file_region::alignment() {
SYSTEM_INFO SysInfo;
::GetSystemInfo(&SysInfo);
@@ -1448,14 +1452,14 @@ static bool getTempDirEnvVar(const wchar_t *Var, SmallVectorImpl<char> &Res) {
SmallVector<wchar_t, 1024> Buf;
size_t Size = 1024;
do {
- Buf.reserve(Size);
- Size = GetEnvironmentVariableW(Var, Buf.data(), Buf.capacity());
+ Buf.resize_for_overwrite(Size);
+ Size = GetEnvironmentVariableW(Var, Buf.data(), Buf.size());
if (Size == 0)
return false;
// Try again with larger buffer.
- } while (Size > Buf.capacity());
- Buf.set_size(Size);
+ } while (Size > Buf.size());
+ Buf.truncate(Size);
return !windows::UTF16ToUTF8(Buf.data(), Size, Res);
}
@@ -1504,7 +1508,7 @@ std::error_code CodePageToUTF16(unsigned codepage,
}
utf16.reserve(len + 1);
- utf16.set_size(len);
+ utf16.resize_for_overwrite(len);
len = ::MultiByteToWideChar(codepage, MB_ERR_INVALID_CHARS, original.begin(),
original.size(), utf16.begin(), utf16.size());
@@ -1544,8 +1548,8 @@ std::error_code UTF16ToCodePage(unsigned codepage, const wchar_t *utf16,
return mapWindowsError(::GetLastError());
}
- converted.reserve(len);
- converted.set_size(len);
+ converted.reserve(len + 1);
+ converted.resize_for_overwrite(len);
// Now do the actual conversion.
len = ::WideCharToMultiByte(codepage, 0, utf16, utf16_len, converted.data(),
diff --git a/llvm/lib/Support/Windows/Process.inc b/llvm/lib/Support/Windows/Process.inc
index 6732063b562e..dfaab1613de1 100644
--- a/llvm/lib/Support/Windows/Process.inc
+++ b/llvm/lib/Support/Windows/Process.inc
@@ -129,16 +129,16 @@ Optional<std::string> Process::GetEnv(StringRef Name) {
SmallVector<wchar_t, MAX_PATH> Buf;
size_t Size = MAX_PATH;
do {
- Buf.reserve(Size);
+ Buf.resize_for_overwrite(Size);
SetLastError(NO_ERROR);
Size =
- GetEnvironmentVariableW(NameUTF16.data(), Buf.data(), Buf.capacity());
+ GetEnvironmentVariableW(NameUTF16.data(), Buf.data(), Buf.size());
if (Size == 0 && GetLastError() == ERROR_ENVVAR_NOT_FOUND)
return None;
// Try again with larger buffer.
- } while (Size > Buf.capacity());
- Buf.set_size(Size);
+ } while (Size > Buf.size());
+ Buf.truncate(Size);
// Convert the result from UTF-16 to UTF-8.
SmallVector<char, MAX_PATH> Res;
diff --git a/llvm/lib/Support/Windows/Program.inc b/llvm/lib/Support/Windows/Program.inc
index a9cf2db7ec72..ee633411584f 100644
--- a/llvm/lib/Support/Windows/Program.inc
+++ b/llvm/lib/Support/Windows/Program.inc
@@ -72,7 +72,7 @@ ErrorOr<std::string> sys::findProgramByName(StringRef Name,
SmallVector<wchar_t, MAX_PATH> U16Result;
DWORD Len = MAX_PATH;
do {
- U16Result.reserve(Len);
+ U16Result.resize_for_overwrite(Len);
// Lets attach the extension manually. That is needed for files
// with a point in name like aaa.bbb. SearchPathW will not add extension
// from its argument to such files because it thinks they already had one.
@@ -82,13 +82,13 @@ ErrorOr<std::string> sys::findProgramByName(StringRef Name,
return EC;
Len = ::SearchPathW(Path, c_str(U16NameExt), nullptr,
- U16Result.capacity(), U16Result.data(), nullptr);
- } while (Len > U16Result.capacity());
+ U16Result.size(), U16Result.data(), nullptr);
+ } while (Len > U16Result.size());
if (Len == 0)
continue;
- U16Result.set_size(Len);
+ U16Result.truncate(Len);
if (std::error_code EC =
windows::UTF16ToUTF8(U16Result.data(), U16Result.size(), U8Result))
diff --git a/llvm/lib/Support/X86TargetParser.cpp b/llvm/lib/Support/X86TargetParser.cpp
index ab49ac548f89..10f9692d217e 100644
--- a/llvm/lib/Support/X86TargetParser.cpp
+++ b/llvm/lib/Support/X86TargetParser.cpp
@@ -12,7 +12,6 @@
#include "llvm/Support/X86TargetParser.h"
#include "llvm/ADT/StringSwitch.h"
-#include "llvm/ADT/Triple.h"
#include <numeric>
using namespace llvm;
diff --git a/llvm/lib/Support/YAMLParser.cpp b/llvm/lib/Support/YAMLParser.cpp
index 2adf37a511d1..200261d3ed5c 100644
--- a/llvm/lib/Support/YAMLParser.cpp
+++ b/llvm/lib/Support/YAMLParser.cpp
@@ -27,7 +27,6 @@
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/Unicode.h"
#include "llvm/Support/raw_ostream.h"
-#include <algorithm>
#include <cassert>
#include <cstddef>
#include <cstdint>
diff --git a/llvm/lib/Support/YAMLTraits.cpp b/llvm/lib/Support/YAMLTraits.cpp
index aa6163a76161..8cdd03149bcf 100644
--- a/llvm/lib/Support/YAMLTraits.cpp
+++ b/llvm/lib/Support/YAMLTraits.cpp
@@ -18,13 +18,12 @@
#include "llvm/Support/Format.h"
#include "llvm/Support/LineIterator.h"
#include "llvm/Support/MemoryBuffer.h"
-#include "llvm/Support/Unicode.h"
+#include "llvm/Support/VersionTuple.h"
#include "llvm/Support/YAMLParser.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <cassert>
#include <cstdint>
-#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>
@@ -300,7 +299,7 @@ void Input::endEnumScalar() {
bool Input::beginBitSetScalar(bool &DoClear) {
BitValuesUsed.clear();
if (SequenceHNode *SQ = dyn_cast<SequenceHNode>(CurrentNode)) {
- BitValuesUsed.insert(BitValuesUsed.begin(), SQ->Entries.size(), false);
+ BitValuesUsed.resize(SQ->Entries.size());
} else {
setError(CurrentNode, "expected sequence of bit values");
}
@@ -527,8 +526,9 @@ std::vector<StringRef> Output::keys() {
}
bool Output::preflightKey(const char *Key, bool Required, bool SameAsDefault,
- bool &UseDefault, void *&) {
+ bool &UseDefault, void *&SaveInfo) {
UseDefault = false;
+ SaveInfo = nullptr;
if (Required || !SameAsDefault || WriteDefaultValues) {
auto State = StateStack.back();
if (State == inFlowMapFirstKey || State == inFlowMapOtherKey) {
@@ -599,7 +599,8 @@ void Output::endSequence() {
StateStack.pop_back();
}
-bool Output::preflightElement(unsigned, void *&) {
+bool Output::preflightElement(unsigned, void *&SaveInfo) {
+ SaveInfo = nullptr;
return true;
}
@@ -627,7 +628,7 @@ void Output::endFlowSequence() {
outputUpToEndOfLine(" ]");
}
-bool Output::preflightFlowElement(unsigned, void *&) {
+bool Output::preflightFlowElement(unsigned, void *&SaveInfo) {
if (NeedFlowSequenceComma)
output(", ");
if (WrapColumn && Column > WrapColumn) {
@@ -637,6 +638,7 @@ bool Output::preflightFlowElement(unsigned, void *&) {
Column = ColumnAtFlowStart;
output(" ");
}
+ SaveInfo = nullptr;
return true;
}
diff --git a/llvm/lib/Support/raw_ostream.cpp b/llvm/lib/Support/raw_ostream.cpp
index 4590a3d19b0d..e4b747b68bea 100644
--- a/llvm/lib/Support/raw_ostream.cpp
+++ b/llvm/lib/Support/raw_ostream.cpp
@@ -15,6 +15,7 @@
#include "llvm/ADT/StringExtras.h"
#include "llvm/Config/config.h"
#include "llvm/Support/Compiler.h"
+#include "llvm/Support/Duration.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Format.h"
@@ -24,10 +25,8 @@
#include "llvm/Support/Process.h"
#include "llvm/Support/Program.h"
#include <algorithm>
-#include <cctype>
#include <cerrno>
#include <cstdio>
-#include <iterator>
#include <sys/stat.h>
// <fcntl.h> may provide O_BINARY.
@@ -643,13 +642,14 @@ raw_fd_ostream::raw_fd_ostream(int fd, bool shouldClose, bool unbuffered,
// Get the starting position.
off_t loc = ::lseek(FD, 0, SEEK_CUR);
-#ifdef _WIN32
- // MSVCRT's _lseek(SEEK_CUR) doesn't return -1 for pipes.
sys::fs::file_status Status;
std::error_code EC = status(FD, Status);
- SupportsSeeking = !EC && Status.type() == sys::fs::file_type::regular_file;
+ IsRegularFile = Status.type() == sys::fs::file_type::regular_file;
+#ifdef _WIN32
+ // MSVCRT's _lseek(SEEK_CUR) doesn't return -1 for pipes.
+ SupportsSeeking = !EC && IsRegularFile;
#else
- SupportsSeeking = loc != (off_t)-1;
+ SupportsSeeking = !EC && loc != (off_t)-1;
#endif
if (!SupportsSeeking)
pos = 0;
@@ -869,8 +869,8 @@ Expected<sys::fs::FileLocker> raw_fd_ostream::lock() {
}
Expected<sys::fs::FileLocker>
-raw_fd_ostream::tryLockFor(std::chrono::milliseconds Timeout) {
- std::error_code EC = sys::fs::tryLockFile(FD, Timeout);
+raw_fd_ostream::tryLockFor(Duration const& Timeout) {
+ std::error_code EC = sys::fs::tryLockFile(FD, Timeout.getDuration());
if (!EC)
return sys::fs::FileLocker(FD);
return errorCodeToError(EC);
@@ -914,8 +914,7 @@ raw_fd_stream::raw_fd_stream(StringRef Filename, std::error_code &EC)
if (EC)
return;
- // Do not support non-seekable files.
- if (!supportsSeeking())
+ if (!isRegularFile())
EC = std::make_error_code(std::errc::invalid_argument);
}
@@ -937,10 +936,6 @@ bool raw_fd_stream::classof(const raw_ostream *OS) {
// raw_string_ostream
//===----------------------------------------------------------------------===//
-raw_string_ostream::~raw_string_ostream() {
- flush();
-}
-
void raw_string_ostream::write_impl(const char *Ptr, size_t Size) {
OS.append(Ptr, Size);
}