Skip to content

Commit

Permalink
Merged main:dc129d6f715c into amd-gfx:bedba19995b8
Browse files Browse the repository at this point in the history
Local branch amd-gfx bedba19 Merged main:ea2036e1e56b into amd-gfx:e1b9ddbd68c9
Remote branch main dc129d6 [libc++] Add std::fpclassify overloads for floating-point. (llvm#67913)
  • Loading branch information
SC llvm team authored and SC llvm team committed Oct 5, 2023
2 parents bedba19 + dc129d6 commit a1fa683
Show file tree
Hide file tree
Showing 63 changed files with 385 additions and 738 deletions.
2 changes: 2 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,8 @@ Bug Fixes in This Version
- Fix a crash when evaluating value-dependent structured binding
variables at compile time.
Fixes (`#67690 <https://github.com/llvm/llvm-project/issues/67690>`_)
- Fixes a ``clang-17`` regression where ``LLVM_UNREACHABLE_OPTIMIZE=OFF``
cannot be used with ``Release`` mode builds. (`#68237 <https://github.com/llvm/llvm-project/issues/68237>`_).

Bug Fixes to Compiler Builtins
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
1 change: 0 additions & 1 deletion clang/include/clang/Serialization/ASTWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,6 @@ class ASTWriter : public ASTDeserializationListener,
/// the module but currently is merely a random 32-bit number.
ASTFileSignature WriteAST(Sema &SemaRef, StringRef OutputFile,
Module *WritingModule, StringRef isysroot,
bool hasErrors = false,
bool ShouldCacheASTInMemory = false);

/// Emit a token.
Expand Down
17 changes: 5 additions & 12 deletions clang/lib/Frontend/ASTUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2341,12 +2341,9 @@ bool ASTUnit::Save(StringRef File) {
return false;
}

static bool serializeUnit(ASTWriter &Writer,
SmallVectorImpl<char> &Buffer,
Sema &S,
bool hasErrors,
raw_ostream &OS) {
Writer.WriteAST(S, std::string(), nullptr, "", hasErrors);
static bool serializeUnit(ASTWriter &Writer, SmallVectorImpl<char> &Buffer,
Sema &S, raw_ostream &OS) {
Writer.WriteAST(S, std::string(), nullptr, "");

// Write the generated bitstream to "Out".
if (!Buffer.empty())
Expand All @@ -2356,18 +2353,14 @@ static bool serializeUnit(ASTWriter &Writer,
}

bool ASTUnit::serialize(raw_ostream &OS) {
// For serialization we are lenient if the errors were only warn-as-error kind.
bool hasErrors = getDiagnostics().hasUncompilableErrorOccurred();

if (WriterData)
return serializeUnit(WriterData->Writer, WriterData->Buffer,
getSema(), hasErrors, OS);
return serializeUnit(WriterData->Writer, WriterData->Buffer, getSema(), OS);

SmallString<128> Buffer;
llvm::BitstreamWriter Stream(Buffer);
InMemoryModuleCache ModuleCache;
ASTWriter Writer(Stream, Buffer, ModuleCache, {});
return serializeUnit(Writer, Buffer, getSema(), hasErrors, OS);
return serializeUnit(Writer, Buffer, getSema(), OS);
}

using SLocRemap = ContinuousRangeMap<unsigned, int, 2>;
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/Serialization/ASTWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4622,12 +4622,12 @@ time_t ASTWriter::getTimestampForOutput(const FileEntry *E) const {

ASTFileSignature ASTWriter::WriteAST(Sema &SemaRef, StringRef OutputFile,
Module *WritingModule, StringRef isysroot,
bool hasErrors,
bool ShouldCacheASTInMemory) {
llvm::TimeTraceScope scope("WriteAST", OutputFile);
WritingAST = true;

ASTHasCompilerErrors = hasErrors;
ASTHasCompilerErrors =
SemaRef.PP.getDiagnostics().hasUncompilableErrorOccurred();

// Emit the file header.
Stream.Emit((unsigned)'C', 8);
Expand Down
8 changes: 2 additions & 6 deletions clang/lib/Serialization/GeneratePCH.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,8 @@ void PCHGenerator::HandleTranslationUnit(ASTContext &Ctx) {

// Emit the PCH file to the Buffer.
assert(SemaPtr && "No Sema?");
Buffer->Signature =
Writer.WriteAST(*SemaPtr, OutputFile, Module, isysroot,
// For serialization we are lenient if the errors were
// only warn-as-error kind.
PP.getDiagnostics().hasUncompilableErrorOccurred(),
ShouldCacheASTInMemory);
Buffer->Signature = Writer.WriteAST(*SemaPtr, OutputFile, Module, isysroot,
ShouldCacheASTInMemory);

Buffer->IsComplete = true;
}
Expand Down
17 changes: 11 additions & 6 deletions clang/utils/TableGen/ClangAttrEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2690,23 +2690,28 @@ static void emitAttributes(RecordKeeper &Records, raw_ostream &OS,
OS << ", ";
emitFormInitializer(OS, Spellings[0], "0");
} else {
OS << ", (\n";
OS << ", [&]() {\n";
OS << " switch (S) {\n";
std::set<std::string> Uniques;
unsigned Idx = 0;
for (auto I = Spellings.begin(), E = Spellings.end(); I != E;
++I, ++Idx) {
const FlattenedSpelling &S = *I;
const auto &Name = SemanticToSyntacticMap[Idx];
if (Uniques.insert(Name).second) {
OS << " S == " << Name << " ? AttributeCommonInfo::Form";
OS << " case " << Name << ":\n";
OS << " return AttributeCommonInfo::Form";
emitFormInitializer(OS, S, Name);
OS << " :\n";
OS << ";\n";
}
}
OS << " (llvm_unreachable(\"Unknown attribute spelling!\"), "
<< " AttributeCommonInfo::Form";
OS << " default:\n";
OS << " llvm_unreachable(\"Unknown attribute spelling!\");\n"
<< " return AttributeCommonInfo::Form";
emitFormInitializer(OS, Spellings[0], "0");
OS << "))";
OS << ";\n"
<< " }\n"
<< " }()";
}

OS << ");\n";
Expand Down
15 changes: 13 additions & 2 deletions libcxx/include/math.h
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,19 @@ namespace __math {

// fpclassify

template <class _A1, std::__enable_if_t<std::is_floating_point<_A1>::value, int> = 0>
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI int fpclassify(_A1 __x) _NOEXCEPT {
// template on non-double overloads to make them weaker than same overloads from MSVC runtime
template <class = int>
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI int fpclassify(float __x) _NOEXCEPT {
return __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, __x);
}

template <class = int>
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI int fpclassify(double __x) _NOEXCEPT {
return __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, __x);
}

template <class = int>
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI int fpclassify(long double __x) _NOEXCEPT {
return __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, __x);
}

Expand Down
8 changes: 8 additions & 0 deletions libcxx/test/std/numerics/c.math/cmath.pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -603,12 +603,20 @@ void test_fpclassify()
static_assert((std::is_same<decltype(std::fpclassify(0)), int>::value), "");
static_assert((std::is_same<decltype(std::fpclassify((long double)0)), int>::value), "");
static_assert((std::is_same<decltype(fpclassify(Ambiguous())), Ambiguous>::value), "");
static_assert((std::is_same<decltype(fpclassify(Value<float>())), int>::value), "");
static_assert((std::is_same<decltype(fpclassify(Value<double>())), int>::value), "");
static_assert((std::is_same<decltype(fpclassify(Value<long double>())), int>::value), "");
ASSERT_NOEXCEPT(std::fpclassify((float)0));
ASSERT_NOEXCEPT(std::fpclassify((double)0));
ASSERT_NOEXCEPT(std::fpclassify((long double)0));
ASSERT_NOEXCEPT(std::fpclassify(0));
assert(std::fpclassify(-1.0) == FP_NORMAL);
assert(std::fpclassify(0) == FP_ZERO);
assert(std::fpclassify(1) == FP_NORMAL);
assert(std::fpclassify(-1) == FP_NORMAL);
assert(std::fpclassify(std::numeric_limits<int>::max()) == FP_NORMAL);
assert(std::fpclassify(std::numeric_limits<int>::min()) == FP_NORMAL);
assert(std::fpclassify(Value<double, 1>()) == FP_NORMAL);
}

void test_isfinite()
Expand Down
10 changes: 5 additions & 5 deletions llvm/include/llvm/Analysis/BlockFrequencyInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,19 @@ class BlockFrequencyInfo {
/// Returns the estimated profile count of \p Freq.
/// This uses the frequency \p Freq and multiplies it by
/// the enclosing function's count (if available) and returns the value.
std::optional<uint64_t> getProfileCountFromFreq(uint64_t Freq) const;
std::optional<uint64_t> getProfileCountFromFreq(BlockFrequency Freq) const;

/// Returns true if \p BB is an irreducible loop header
/// block. Otherwise false.
bool isIrrLoopHeader(const BasicBlock *BB);

// Set the frequency of the given basic block.
void setBlockFreq(const BasicBlock *BB, uint64_t Freq);
void setBlockFreq(const BasicBlock *BB, BlockFrequency Freq);

/// Set the frequency of \p ReferenceBB to \p Freq and scale the frequencies
/// of the blocks in \p BlocksToScale such that their frequencies relative
/// to \p ReferenceBB remain unchanged.
void setBlockFreqAndScale(const BasicBlock *ReferenceBB, uint64_t Freq,
void setBlockFreqAndScale(const BasicBlock *ReferenceBB, BlockFrequency Freq,
SmallPtrSetImpl<BasicBlock *> &BlocksToScale);

/// calculate - compute block frequency info for the given function.
Expand All @@ -94,13 +94,13 @@ class BlockFrequencyInfo {

// Print the block frequency Freq to OS using the current functions entry
// frequency to convert freq into a relative decimal form.
raw_ostream &printBlockFreq(raw_ostream &OS, const BlockFrequency Freq) const;
raw_ostream &printBlockFreq(raw_ostream &OS, BlockFrequency Freq) const;

// Convenience method that attempts to look up the frequency associated with
// BB and print it to OS.
raw_ostream &printBlockFreq(raw_ostream &OS, const BasicBlock *BB) const;

uint64_t getEntryFreq() const;
BlockFrequency getEntryFreq() const;
void releaseMemory();
void print(raw_ostream &OS) const;

Expand Down
20 changes: 10 additions & 10 deletions llvm/include/llvm/Analysis/BlockFrequencyInfoImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -527,19 +527,18 @@ class BlockFrequencyInfoImplBase {
getBlockProfileCount(const Function &F, const BlockNode &Node,
bool AllowSynthetic = false) const;
std::optional<uint64_t>
getProfileCountFromFreq(const Function &F, uint64_t Freq,
getProfileCountFromFreq(const Function &F, BlockFrequency Freq,
bool AllowSynthetic = false) const;
bool isIrrLoopHeader(const BlockNode &Node);

void setBlockFreq(const BlockNode &Node, uint64_t Freq);
void setBlockFreq(const BlockNode &Node, BlockFrequency Freq);

raw_ostream &printBlockFreq(raw_ostream &OS, const BlockNode &Node) const;
raw_ostream &printBlockFreq(raw_ostream &OS,
const BlockFrequency &Freq) const;
raw_ostream &printBlockFreq(raw_ostream &OS, BlockFrequency Freq) const;

uint64_t getEntryFreq() const {
BlockFrequency getEntryFreq() const {
assert(!Freqs.empty());
return Freqs[0].Integer;
return BlockFrequency(Freqs[0].Integer);
}
};

Expand Down Expand Up @@ -1029,7 +1028,7 @@ template <class BT> class BlockFrequencyInfoImpl : BlockFrequencyInfoImplBase {
}

std::optional<uint64_t>
getProfileCountFromFreq(const Function &F, uint64_t Freq,
getProfileCountFromFreq(const Function &F, BlockFrequency Freq,
bool AllowSynthetic = false) const {
return BlockFrequencyInfoImplBase::getProfileCountFromFreq(F, Freq,
AllowSynthetic);
Expand All @@ -1039,7 +1038,7 @@ template <class BT> class BlockFrequencyInfoImpl : BlockFrequencyInfoImplBase {
return BlockFrequencyInfoImplBase::isIrrLoopHeader(getNode(BB));
}

void setBlockFreq(const BlockT *BB, uint64_t Freq);
void setBlockFreq(const BlockT *BB, BlockFrequency Freq);

void forgetBlock(const BlockT *BB) {
// We don't erase corresponding items from `Freqs`, `RPOT` and other to
Expand Down Expand Up @@ -1145,12 +1144,13 @@ void BlockFrequencyInfoImpl<BT>::calculate(const FunctionT &F,
// blocks and unknown blocks.
for (const BlockT &BB : F)
if (!Nodes.count(&BB))
setBlockFreq(&BB, 0);
setBlockFreq(&BB, BlockFrequency());
}
}

template <class BT>
void BlockFrequencyInfoImpl<BT>::setBlockFreq(const BlockT *BB, uint64_t Freq) {
void BlockFrequencyInfoImpl<BT>::setBlockFreq(const BlockT *BB,
BlockFrequency Freq) {
if (Nodes.count(BB))
BlockFrequencyInfoImplBase::setBlockFreq(getNode(BB), Freq);
else {
Expand Down
4 changes: 2 additions & 2 deletions llvm/include/llvm/Analysis/ProfileSummaryInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ class ProfileSummaryInfo {

template <typename BFIT>
bool isColdBlock(BlockFrequency BlockFreq, const BFIT *BFI) const {
auto Count = BFI->getProfileCountFromFreq(BlockFreq.getFrequency());
auto Count = BFI->getProfileCountFromFreq(BlockFreq);
return Count && isColdCount(*Count);
}

Expand Down Expand Up @@ -315,7 +315,7 @@ class ProfileSummaryInfo {
bool isHotOrColdBlockNthPercentile(int PercentileCutoff,
BlockFrequency BlockFreq,
BFIT *BFI) const {
auto Count = BFI->getProfileCountFromFreq(BlockFreq.getFrequency());
auto Count = BFI->getProfileCountFromFreq(BlockFreq);
if (isHot)
return Count && isHotCountNthPercentile(PercentileCutoff, *Count);
else
Expand Down
35 changes: 7 additions & 28 deletions llvm/include/llvm/CodeGen/AccelTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ namespace llvm {
class AsmPrinter;
class DwarfCompileUnit;
class DwarfDebug;
class DwarfTypeUnit;
class MCSymbol;
class raw_ostream;

Expand Down Expand Up @@ -198,9 +197,6 @@ template <typename DataT> class AccelTable : public AccelTableBase {

template <typename... Types>
void addName(DwarfStringPoolEntryRef Name, Types &&... Args);
void clear() { Entries.clear(); }
void addEntries(AccelTable<DataT> &Table);
const StringEntries getEntries() const { return Entries; }
};

template <typename AccelTableDataT>
Expand All @@ -219,16 +215,6 @@ void AccelTable<AccelTableDataT>::addName(DwarfStringPoolEntryRef Name,
AccelTableDataT(std::forward<Types>(Args)...));
}

template <typename AccelTableDataT>
void AccelTable<AccelTableDataT>::addEntries(
AccelTable<AccelTableDataT> &Table) {
for (auto &Entry : Table.getEntries()) {
for (AccelTableData *Value : Entry.second.Values)
addName(Entry.second.Name,
static_cast<AccelTableDataT *>(Value)->getDie());
}
}

/// A base class for different implementations of Data classes for Apple
/// Accelerator Tables. The columns in the table are defined by the static Atoms
/// variable defined on the subclasses.
Expand Down Expand Up @@ -264,10 +250,6 @@ class AppleAccelTableData : public AccelTableData {
/// emitDWARF5AccelTable function.
class DWARF5AccelTableData : public AccelTableData {
public:
struct AttributeEncoding {
dwarf::Index Index;
dwarf::Form Form;
};
static uint32_t hash(StringRef Name) { return caseFoldingDjbHash(Name); }

DWARF5AccelTableData(const DIE &Die) : Die(Die) {}
Expand Down Expand Up @@ -327,20 +309,17 @@ void emitAppleAccelTable(AsmPrinter *Asm, AccelTable<DataT> &Contents,
void emitDWARF5AccelTable(AsmPrinter *Asm,
AccelTable<DWARF5AccelTableData> &Contents,
const DwarfDebug &DD,
ArrayRef<std::unique_ptr<DwarfCompileUnit>> CUs,
ArrayRef<std::unique_ptr<DwarfTypeUnit>> TUs);
using GetIndexForEntryReturnType =
std::optional<std::pair<unsigned, DWARF5AccelTableData::AttributeEncoding>>;
ArrayRef<std::unique_ptr<DwarfCompileUnit>> CUs);

/// Emit a DWARFv5 Accelerator Table consisting of entries in the specified
/// AccelTable. The \p CUs contains either symbols keeping offsets to the
/// start of compilation unit, either offsets to the start of compilation
/// unit themselves.
void emitDWARF5AccelTable(AsmPrinter *Asm,
AccelTable<DWARF5AccelTableStaticData> &Contents,
ArrayRef<std::variant<MCSymbol *, uint64_t>> CUs,
llvm::function_ref<GetIndexForEntryReturnType(
const DWARF5AccelTableStaticData &)>
getIndexForEntry);
void emitDWARF5AccelTable(
AsmPrinter *Asm, AccelTable<DWARF5AccelTableStaticData> &Contents,
ArrayRef<std::variant<MCSymbol *, uint64_t>> CUs,
llvm::function_ref<unsigned(const DWARF5AccelTableStaticData &)>
getCUIndexForEntry);

/// Accelerator table data implementation for simple Apple accelerator tables
/// with just a DIE reference.
Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/CodeGen/GlobalISel/RegBankSelect.h
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ class RegBankSelect : public MachineFunctionPass {
public:
/// Create a MappingCost assuming that most of the instructions
/// will occur in a basic block with \p LocalFreq frequency.
MappingCost(const BlockFrequency &LocalFreq);
MappingCost(BlockFrequency LocalFreq);

/// Add \p Cost to the local cost.
/// \return true if this cost is saturated, false otherwise.
Expand Down
5 changes: 2 additions & 3 deletions llvm/include/llvm/CodeGen/MBFIWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,9 @@ class MBFIWrapper {

raw_ostream &printBlockFreq(raw_ostream &OS,
const MachineBasicBlock *MBB) const;
raw_ostream &printBlockFreq(raw_ostream &OS,
const BlockFrequency Freq) const;
raw_ostream &printBlockFreq(raw_ostream &OS, BlockFrequency Freq) const;
void view(const Twine &Name, bool isSimple = true);
uint64_t getEntryFreq() const;
BlockFrequency getEntryFreq() const;
const MachineBlockFrequencyInfo &getMBFI() { return MBFI; }

private:
Expand Down
Loading

0 comments on commit a1fa683

Please sign in to comment.