Skip to content

Commit a1fa683

Browse files
SC llvm teamSC llvm team
SC llvm team
authored and
SC llvm team
committed
Merged main:dc129d6f715c into amd-gfx:bedba19995b8
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)
2 parents bedba19 + dc129d6 commit a1fa683

File tree

63 files changed

+385
-738
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+385
-738
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,8 @@ Bug Fixes in This Version
343343
- Fix a crash when evaluating value-dependent structured binding
344344
variables at compile time.
345345
Fixes (`#67690 <https://github.com/llvm/llvm-project/issues/67690>`_)
346+
- Fixes a ``clang-17`` regression where ``LLVM_UNREACHABLE_OPTIMIZE=OFF``
347+
cannot be used with ``Release`` mode builds. (`#68237 <https://github.com/llvm/llvm-project/issues/68237>`_).
346348

347349
Bug Fixes to Compiler Builtins
348350
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

clang/include/clang/Serialization/ASTWriter.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,6 @@ class ASTWriter : public ASTDeserializationListener,
613613
/// the module but currently is merely a random 32-bit number.
614614
ASTFileSignature WriteAST(Sema &SemaRef, StringRef OutputFile,
615615
Module *WritingModule, StringRef isysroot,
616-
bool hasErrors = false,
617616
bool ShouldCacheASTInMemory = false);
618617

619618
/// Emit a token.

clang/lib/Frontend/ASTUnit.cpp

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2341,12 +2341,9 @@ bool ASTUnit::Save(StringRef File) {
23412341
return false;
23422342
}
23432343

2344-
static bool serializeUnit(ASTWriter &Writer,
2345-
SmallVectorImpl<char> &Buffer,
2346-
Sema &S,
2347-
bool hasErrors,
2348-
raw_ostream &OS) {
2349-
Writer.WriteAST(S, std::string(), nullptr, "", hasErrors);
2344+
static bool serializeUnit(ASTWriter &Writer, SmallVectorImpl<char> &Buffer,
2345+
Sema &S, raw_ostream &OS) {
2346+
Writer.WriteAST(S, std::string(), nullptr, "");
23502347

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

23582355
bool ASTUnit::serialize(raw_ostream &OS) {
2359-
// For serialization we are lenient if the errors were only warn-as-error kind.
2360-
bool hasErrors = getDiagnostics().hasUncompilableErrorOccurred();
2361-
23622356
if (WriterData)
2363-
return serializeUnit(WriterData->Writer, WriterData->Buffer,
2364-
getSema(), hasErrors, OS);
2357+
return serializeUnit(WriterData->Writer, WriterData->Buffer, getSema(), OS);
23652358

23662359
SmallString<128> Buffer;
23672360
llvm::BitstreamWriter Stream(Buffer);
23682361
InMemoryModuleCache ModuleCache;
23692362
ASTWriter Writer(Stream, Buffer, ModuleCache, {});
2370-
return serializeUnit(Writer, Buffer, getSema(), hasErrors, OS);
2363+
return serializeUnit(Writer, Buffer, getSema(), OS);
23712364
}
23722365

23732366
using SLocRemap = ContinuousRangeMap<unsigned, int, 2>;

clang/lib/Serialization/ASTWriter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4622,12 +4622,12 @@ time_t ASTWriter::getTimestampForOutput(const FileEntry *E) const {
46224622

46234623
ASTFileSignature ASTWriter::WriteAST(Sema &SemaRef, StringRef OutputFile,
46244624
Module *WritingModule, StringRef isysroot,
4625-
bool hasErrors,
46264625
bool ShouldCacheASTInMemory) {
46274626
llvm::TimeTraceScope scope("WriteAST", OutputFile);
46284627
WritingAST = true;
46294628

4630-
ASTHasCompilerErrors = hasErrors;
4629+
ASTHasCompilerErrors =
4630+
SemaRef.PP.getDiagnostics().hasUncompilableErrorOccurred();
46314631

46324632
// Emit the file header.
46334633
Stream.Emit((unsigned)'C', 8);

clang/lib/Serialization/GeneratePCH.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,8 @@ void PCHGenerator::HandleTranslationUnit(ASTContext &Ctx) {
6565

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

7571
Buffer->IsComplete = true;
7672
}

clang/utils/TableGen/ClangAttrEmitter.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2690,23 +2690,28 @@ static void emitAttributes(RecordKeeper &Records, raw_ostream &OS,
26902690
OS << ", ";
26912691
emitFormInitializer(OS, Spellings[0], "0");
26922692
} else {
2693-
OS << ", (\n";
2693+
OS << ", [&]() {\n";
2694+
OS << " switch (S) {\n";
26942695
std::set<std::string> Uniques;
26952696
unsigned Idx = 0;
26962697
for (auto I = Spellings.begin(), E = Spellings.end(); I != E;
26972698
++I, ++Idx) {
26982699
const FlattenedSpelling &S = *I;
26992700
const auto &Name = SemanticToSyntacticMap[Idx];
27002701
if (Uniques.insert(Name).second) {
2701-
OS << " S == " << Name << " ? AttributeCommonInfo::Form";
2702+
OS << " case " << Name << ":\n";
2703+
OS << " return AttributeCommonInfo::Form";
27022704
emitFormInitializer(OS, S, Name);
2703-
OS << " :\n";
2705+
OS << ";\n";
27042706
}
27052707
}
2706-
OS << " (llvm_unreachable(\"Unknown attribute spelling!\"), "
2707-
<< " AttributeCommonInfo::Form";
2708+
OS << " default:\n";
2709+
OS << " llvm_unreachable(\"Unknown attribute spelling!\");\n"
2710+
<< " return AttributeCommonInfo::Form";
27082711
emitFormInitializer(OS, Spellings[0], "0");
2709-
OS << "))";
2712+
OS << ";\n"
2713+
<< " }\n"
2714+
<< " }()";
27102715
}
27112716

27122717
OS << ");\n";

libcxx/include/math.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,8 +387,19 @@ namespace __math {
387387

388388
// fpclassify
389389

390-
template <class _A1, std::__enable_if_t<std::is_floating_point<_A1>::value, int> = 0>
391-
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI int fpclassify(_A1 __x) _NOEXCEPT {
390+
// template on non-double overloads to make them weaker than same overloads from MSVC runtime
391+
template <class = int>
392+
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI int fpclassify(float __x) _NOEXCEPT {
393+
return __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, __x);
394+
}
395+
396+
template <class = int>
397+
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI int fpclassify(double __x) _NOEXCEPT {
398+
return __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, __x);
399+
}
400+
401+
template <class = int>
402+
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI int fpclassify(long double __x) _NOEXCEPT {
392403
return __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, __x);
393404
}
394405

libcxx/test/std/numerics/c.math/cmath.pass.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,12 +603,20 @@ void test_fpclassify()
603603
static_assert((std::is_same<decltype(std::fpclassify(0)), int>::value), "");
604604
static_assert((std::is_same<decltype(std::fpclassify((long double)0)), int>::value), "");
605605
static_assert((std::is_same<decltype(fpclassify(Ambiguous())), Ambiguous>::value), "");
606+
static_assert((std::is_same<decltype(fpclassify(Value<float>())), int>::value), "");
607+
static_assert((std::is_same<decltype(fpclassify(Value<double>())), int>::value), "");
608+
static_assert((std::is_same<decltype(fpclassify(Value<long double>())), int>::value), "");
609+
ASSERT_NOEXCEPT(std::fpclassify((float)0));
610+
ASSERT_NOEXCEPT(std::fpclassify((double)0));
611+
ASSERT_NOEXCEPT(std::fpclassify((long double)0));
612+
ASSERT_NOEXCEPT(std::fpclassify(0));
606613
assert(std::fpclassify(-1.0) == FP_NORMAL);
607614
assert(std::fpclassify(0) == FP_ZERO);
608615
assert(std::fpclassify(1) == FP_NORMAL);
609616
assert(std::fpclassify(-1) == FP_NORMAL);
610617
assert(std::fpclassify(std::numeric_limits<int>::max()) == FP_NORMAL);
611618
assert(std::fpclassify(std::numeric_limits<int>::min()) == FP_NORMAL);
619+
assert(std::fpclassify(Value<double, 1>()) == FP_NORMAL);
612620
}
613621

614622
void test_isfinite()

llvm/include/llvm/Analysis/BlockFrequencyInfo.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,19 +73,19 @@ class BlockFrequencyInfo {
7373
/// Returns the estimated profile count of \p Freq.
7474
/// This uses the frequency \p Freq and multiplies it by
7575
/// the enclosing function's count (if available) and returns the value.
76-
std::optional<uint64_t> getProfileCountFromFreq(uint64_t Freq) const;
76+
std::optional<uint64_t> getProfileCountFromFreq(BlockFrequency Freq) const;
7777

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

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

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

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

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

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

103-
uint64_t getEntryFreq() const;
103+
BlockFrequency getEntryFreq() const;
104104
void releaseMemory();
105105
void print(raw_ostream &OS) const;
106106

llvm/include/llvm/Analysis/BlockFrequencyInfoImpl.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -527,19 +527,18 @@ class BlockFrequencyInfoImplBase {
527527
getBlockProfileCount(const Function &F, const BlockNode &Node,
528528
bool AllowSynthetic = false) const;
529529
std::optional<uint64_t>
530-
getProfileCountFromFreq(const Function &F, uint64_t Freq,
530+
getProfileCountFromFreq(const Function &F, BlockFrequency Freq,
531531
bool AllowSynthetic = false) const;
532532
bool isIrrLoopHeader(const BlockNode &Node);
533533

534-
void setBlockFreq(const BlockNode &Node, uint64_t Freq);
534+
void setBlockFreq(const BlockNode &Node, BlockFrequency Freq);
535535

536536
raw_ostream &printBlockFreq(raw_ostream &OS, const BlockNode &Node) const;
537-
raw_ostream &printBlockFreq(raw_ostream &OS,
538-
const BlockFrequency &Freq) const;
537+
raw_ostream &printBlockFreq(raw_ostream &OS, BlockFrequency Freq) const;
539538

540-
uint64_t getEntryFreq() const {
539+
BlockFrequency getEntryFreq() const {
541540
assert(!Freqs.empty());
542-
return Freqs[0].Integer;
541+
return BlockFrequency(Freqs[0].Integer);
543542
}
544543
};
545544

@@ -1029,7 +1028,7 @@ template <class BT> class BlockFrequencyInfoImpl : BlockFrequencyInfoImplBase {
10291028
}
10301029

10311030
std::optional<uint64_t>
1032-
getProfileCountFromFreq(const Function &F, uint64_t Freq,
1031+
getProfileCountFromFreq(const Function &F, BlockFrequency Freq,
10331032
bool AllowSynthetic = false) const {
10341033
return BlockFrequencyInfoImplBase::getProfileCountFromFreq(F, Freq,
10351034
AllowSynthetic);
@@ -1039,7 +1038,7 @@ template <class BT> class BlockFrequencyInfoImpl : BlockFrequencyInfoImplBase {
10391038
return BlockFrequencyInfoImplBase::isIrrLoopHeader(getNode(BB));
10401039
}
10411040

1042-
void setBlockFreq(const BlockT *BB, uint64_t Freq);
1041+
void setBlockFreq(const BlockT *BB, BlockFrequency Freq);
10431042

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

11521151
template <class BT>
1153-
void BlockFrequencyInfoImpl<BT>::setBlockFreq(const BlockT *BB, uint64_t Freq) {
1152+
void BlockFrequencyInfoImpl<BT>::setBlockFreq(const BlockT *BB,
1153+
BlockFrequency Freq) {
11541154
if (Nodes.count(BB))
11551155
BlockFrequencyInfoImplBase::setBlockFreq(getNode(BB), Freq);
11561156
else {

llvm/include/llvm/Analysis/ProfileSummaryInfo.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ class ProfileSummaryInfo {
209209

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

@@ -315,7 +315,7 @@ class ProfileSummaryInfo {
315315
bool isHotOrColdBlockNthPercentile(int PercentileCutoff,
316316
BlockFrequency BlockFreq,
317317
BFIT *BFI) const {
318-
auto Count = BFI->getProfileCountFromFreq(BlockFreq.getFrequency());
318+
auto Count = BFI->getProfileCountFromFreq(BlockFreq);
319319
if (isHot)
320320
return Count && isHotCountNthPercentile(PercentileCutoff, *Count);
321321
else

llvm/include/llvm/CodeGen/AccelTable.h

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ namespace llvm {
106106
class AsmPrinter;
107107
class DwarfCompileUnit;
108108
class DwarfDebug;
109-
class DwarfTypeUnit;
110109
class MCSymbol;
111110
class raw_ostream;
112111

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

199198
template <typename... Types>
200199
void addName(DwarfStringPoolEntryRef Name, Types &&... Args);
201-
void clear() { Entries.clear(); }
202-
void addEntries(AccelTable<DataT> &Table);
203-
const StringEntries getEntries() const { return Entries; }
204200
};
205201

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

222-
template <typename AccelTableDataT>
223-
void AccelTable<AccelTableDataT>::addEntries(
224-
AccelTable<AccelTableDataT> &Table) {
225-
for (auto &Entry : Table.getEntries()) {
226-
for (AccelTableData *Value : Entry.second.Values)
227-
addName(Entry.second.Name,
228-
static_cast<AccelTableDataT *>(Value)->getDie());
229-
}
230-
}
231-
232218
/// A base class for different implementations of Data classes for Apple
233219
/// Accelerator Tables. The columns in the table are defined by the static Atoms
234220
/// variable defined on the subclasses.
@@ -264,10 +250,6 @@ class AppleAccelTableData : public AccelTableData {
264250
/// emitDWARF5AccelTable function.
265251
class DWARF5AccelTableData : public AccelTableData {
266252
public:
267-
struct AttributeEncoding {
268-
dwarf::Index Index;
269-
dwarf::Form Form;
270-
};
271253
static uint32_t hash(StringRef Name) { return caseFoldingDjbHash(Name); }
272254

273255
DWARF5AccelTableData(const DIE &Die) : Die(Die) {}
@@ -327,20 +309,17 @@ void emitAppleAccelTable(AsmPrinter *Asm, AccelTable<DataT> &Contents,
327309
void emitDWARF5AccelTable(AsmPrinter *Asm,
328310
AccelTable<DWARF5AccelTableData> &Contents,
329311
const DwarfDebug &DD,
330-
ArrayRef<std::unique_ptr<DwarfCompileUnit>> CUs,
331-
ArrayRef<std::unique_ptr<DwarfTypeUnit>> TUs);
332-
using GetIndexForEntryReturnType =
333-
std::optional<std::pair<unsigned, DWARF5AccelTableData::AttributeEncoding>>;
312+
ArrayRef<std::unique_ptr<DwarfCompileUnit>> CUs);
313+
334314
/// Emit a DWARFv5 Accelerator Table consisting of entries in the specified
335315
/// AccelTable. The \p CUs contains either symbols keeping offsets to the
336316
/// start of compilation unit, either offsets to the start of compilation
337317
/// unit themselves.
338-
void emitDWARF5AccelTable(AsmPrinter *Asm,
339-
AccelTable<DWARF5AccelTableStaticData> &Contents,
340-
ArrayRef<std::variant<MCSymbol *, uint64_t>> CUs,
341-
llvm::function_ref<GetIndexForEntryReturnType(
342-
const DWARF5AccelTableStaticData &)>
343-
getIndexForEntry);
318+
void emitDWARF5AccelTable(
319+
AsmPrinter *Asm, AccelTable<DWARF5AccelTableStaticData> &Contents,
320+
ArrayRef<std::variant<MCSymbol *, uint64_t>> CUs,
321+
llvm::function_ref<unsigned(const DWARF5AccelTableStaticData &)>
322+
getCUIndexForEntry);
344323

345324
/// Accelerator table data implementation for simple Apple accelerator tables
346325
/// with just a DIE reference.

llvm/include/llvm/CodeGen/GlobalISel/RegBankSelect.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ class RegBankSelect : public MachineFunctionPass {
440440
public:
441441
/// Create a MappingCost assuming that most of the instructions
442442
/// will occur in a basic block with \p LocalFreq frequency.
443-
MappingCost(const BlockFrequency &LocalFreq);
443+
MappingCost(BlockFrequency LocalFreq);
444444

445445
/// Add \p Cost to the local cost.
446446
/// \return true if this cost is saturated, false otherwise.

llvm/include/llvm/CodeGen/MBFIWrapper.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,9 @@ class MBFIWrapper {
3535

3636
raw_ostream &printBlockFreq(raw_ostream &OS,
3737
const MachineBasicBlock *MBB) const;
38-
raw_ostream &printBlockFreq(raw_ostream &OS,
39-
const BlockFrequency Freq) const;
38+
raw_ostream &printBlockFreq(raw_ostream &OS, BlockFrequency Freq) const;
4039
void view(const Twine &Name, bool isSimple = true);
41-
uint64_t getEntryFreq() const;
40+
BlockFrequency getEntryFreq() const;
4241
const MachineBlockFrequencyInfo &getMBFI() { return MBFI; }
4342

4443
private:

0 commit comments

Comments
 (0)