This is an archive of the discontinued LLVM Phabricator instance.

[ADT] Simplify llvm::bit_cast (NFC)
ClosedPublic

Authored by kazu on Aug 21 2022, 8:54 AM.

Details

Summary

This patch removes macro tricks to check GCC versions.

The commit message from 19262fc5966ab569f21f3d440f8b001bca666f17
states that "is_trivially_copyable is only in GCC 5.1 and later".
Note that we now require GCC 7.1 or higher.

Since both std::is_trivially_constructible and
std::is_trivially_copyable are C++11 features, and we now require
C++17, we probably don't need to worry about the availability of the
C++11 features.

Diff Detail

Event Timeline

kazu created this revision.Aug 21 2022, 8:54 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 21 2022, 8:54 AM
kazu requested review of this revision.Aug 21 2022, 8:54 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 21 2022, 8:54 AM
MaskRay accepted this revision.Aug 21 2022, 9:18 AM
This revision is now accepted and ready to land.Aug 21 2022, 9:18 AM
jloser added a subscriber: jloser.Aug 21 2022, 9:46 AM
jloser added inline comments.
llvm/include/llvm/ADT/bit.h
16–17

I believe that we can remove this include now if you'd like to, right?

kazu updated this revision to Diff 454327.Aug 21 2022, 10:25 AM

Remove #include "llvm/Support/Compiler.h"

kazu marked an inline comment as done.Aug 21 2022, 10:26 AM
kazu added inline comments.
llvm/include/llvm/ADT/bit.h
16–17

Good point!

This revision was landed with ongoing or failed builds.Aug 21 2022, 10:39 AM
This revision was automatically updated to reflect the committed changes.
kazu marked an inline comment as done.
RKSimon added inline comments.
llvm/include/llvm/ADT/bit.h
34

Could we use the __builtin_bit_cast if its available?

kazu added inline comments.Aug 23 2022, 10:44 AM
llvm/include/llvm/ADT/bit.h
34

Could we use the __builtin_bit_cast if its available?

We should be able to. Would that lead to better code?

RKSimon added inline comments.Aug 23 2022, 11:07 AM
llvm/include/llvm/ADT/bit.h
34

That's unlikely although if it allows us to remove the <cstring> we get a reduction in build costs.

MathExtras.h has overtaken <string> as one of the largest include build costs and I've been curious how easily we could reduce this by using ADT/bit.h directly (possibly with more missing c++20 equivalent <bit> methods):

https://commondatastorage.googleapis.com/chromium-browser-clang/llvm-include-analysis.html

I'll continue looking at ways to reduce MathExtras.h use for now - thanks anyway.