mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
runtime: prune LLVMSupport
Reduce LLVMSupport to the subset required for the runtime. This reduces the TCB and the overheads of the runtime. The inline namespace's preservation ensures that ODR violations do not occur.
This commit is contained in:
committed by
Saleem Abdulrasool
parent
b72788c27a
commit
bb102707ed
@@ -7,11 +7,7 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
#include "llvm/ADT/APFloat.h"
|
||||
#include "llvm/ADT/APInt.h"
|
||||
#include "llvm/ADT/Hashing.h"
|
||||
#include "llvm/ADT/StringExtras.h"
|
||||
#include "llvm/ADT/edit_distance.h"
|
||||
#include "llvm/Support/Error.h"
|
||||
#include <bitset>
|
||||
|
||||
@@ -91,16 +87,6 @@ int StringRef::compare_numeric(StringRef RHS) const {
|
||||
return Length < RHS.Length ? -1 : 1;
|
||||
}
|
||||
|
||||
// Compute the edit distance between the two given strings.
|
||||
unsigned StringRef::edit_distance(llvm::StringRef Other,
|
||||
bool AllowReplacements,
|
||||
unsigned MaxEditDistance) const {
|
||||
return llvm::ComputeEditDistance(
|
||||
makeArrayRef(data(), size()),
|
||||
makeArrayRef(Other.data(), Other.size()),
|
||||
AllowReplacements, MaxEditDistance);
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// String Operations
|
||||
//===----------------------------------------------------------------------===//
|
||||
@@ -511,97 +497,6 @@ bool __swift::__runtime::llvm::getAsSignedInteger(
|
||||
return !Str.empty();
|
||||
}
|
||||
|
||||
bool StringRef::getAsInteger(unsigned Radix, APInt &Result) const {
|
||||
StringRef Str = *this;
|
||||
|
||||
// Autosense radix if not specified.
|
||||
if (Radix == 0)
|
||||
Radix = GetAutoSenseRadix(Str);
|
||||
|
||||
assert(Radix > 1 && Radix <= 36);
|
||||
|
||||
// Empty strings (after the radix autosense) are invalid.
|
||||
if (Str.empty()) return true;
|
||||
|
||||
// Skip leading zeroes. This can be a significant improvement if
|
||||
// it means we don't need > 64 bits.
|
||||
while (!Str.empty() && Str.front() == '0')
|
||||
Str = Str.substr(1);
|
||||
|
||||
// If it was nothing but zeroes....
|
||||
if (Str.empty()) {
|
||||
Result = APInt(64, 0);
|
||||
return false;
|
||||
}
|
||||
|
||||
// (Over-)estimate the required number of bits.
|
||||
unsigned Log2Radix = 0;
|
||||
while ((1U << Log2Radix) < Radix) Log2Radix++;
|
||||
bool IsPowerOf2Radix = ((1U << Log2Radix) == Radix);
|
||||
|
||||
unsigned BitWidth = Log2Radix * Str.size();
|
||||
if (BitWidth < Result.getBitWidth())
|
||||
BitWidth = Result.getBitWidth(); // don't shrink the result
|
||||
else if (BitWidth > Result.getBitWidth())
|
||||
Result = Result.zext(BitWidth);
|
||||
|
||||
APInt RadixAP, CharAP; // unused unless !IsPowerOf2Radix
|
||||
if (!IsPowerOf2Radix) {
|
||||
// These must have the same bit-width as Result.
|
||||
RadixAP = APInt(BitWidth, Radix);
|
||||
CharAP = APInt(BitWidth, 0);
|
||||
}
|
||||
|
||||
// Parse all the bytes of the string given this radix.
|
||||
Result = 0;
|
||||
while (!Str.empty()) {
|
||||
unsigned CharVal;
|
||||
if (Str[0] >= '0' && Str[0] <= '9')
|
||||
CharVal = Str[0]-'0';
|
||||
else if (Str[0] >= 'a' && Str[0] <= 'z')
|
||||
CharVal = Str[0]-'a'+10;
|
||||
else if (Str[0] >= 'A' && Str[0] <= 'Z')
|
||||
CharVal = Str[0]-'A'+10;
|
||||
else
|
||||
return true;
|
||||
|
||||
// If the parsed value is larger than the integer radix, the string is
|
||||
// invalid.
|
||||
if (CharVal >= Radix)
|
||||
return true;
|
||||
|
||||
// Add in this character.
|
||||
if (IsPowerOf2Radix) {
|
||||
Result <<= Log2Radix;
|
||||
Result |= CharVal;
|
||||
} else {
|
||||
Result *= RadixAP;
|
||||
CharAP = CharVal;
|
||||
Result += CharAP;
|
||||
}
|
||||
|
||||
Str = Str.substr(1);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool StringRef::getAsDouble(double &Result, bool AllowInexact) const {
|
||||
APFloat F(0.0);
|
||||
auto StatusOrErr = F.convertFromString(*this, APFloat::rmNearestTiesToEven);
|
||||
if (errorToBool(StatusOrErr.takeError()))
|
||||
return true;
|
||||
|
||||
APFloat::opStatus Status = *StatusOrErr;
|
||||
if (Status != APFloat::opOK) {
|
||||
if (!AllowInexact || !(Status & APFloat::opInexact))
|
||||
return true;
|
||||
}
|
||||
|
||||
Result = F.convertToDouble();
|
||||
return false;
|
||||
}
|
||||
|
||||
// Implementation of StringRef hashing.
|
||||
hash_code __swift::__runtime::llvm::hash_value(StringRef S) {
|
||||
return hash_combine_range(S.begin(), S.end());
|
||||
|
||||
Reference in New Issue
Block a user