================
@@ -229,32 +230,99 @@ struct InfosShard {
CLANG_TARGET_BUILTIN_DETAIL_STR_OFFSETS(ID, TYPE, ATTRS, FEATURE),
\
HeaderDesc::HEADER, LANG},
+/// The builtins of a target and an optional aux target: their shards, and a
+/// hash table from their names to their builtin IDs.
+///
+/// It contains every builtin of the targets, whether or not it's supported by
+/// some language options; \c Context checks that when looking a name up. It's
+/// immutable, so any number of contexts for the same targets can use it, also
+/// concurrently.
+class TargetBuiltins {
+ /// Open addressing with linear probing. A slot holds the hash of the name in
+ /// the upper 32 bits and the builtin ID in the lower 32 bits, or zero if
+ /// it's empty (zero is \c NotBuiltin).
+ std::unique_ptr<uint64_t[]> Slots;
+ size_t Mask = 0;
+
+ /// The target-independent shard, then the target's and the aux target's
+ /// shards: the order of their builtin IDs.
+ llvm::SmallVector<InfosShard, 16> Shards;
+ unsigned NumTargetShards = 0;
+
+ unsigned NumTargetBuiltins = 0;
+ unsigned NumAuxTargetBuiltins = 0;
+
+ /// Whether the builtin with \p ID is named \p Name.
+ bool hasName(unsigned ID, llvm::StringRef Name) const;
+
+public:
+ /// Collect the builtins of \p Target and \p AuxTarget, which may be null.
+ TargetBuiltins(const TargetInfo &Target, const TargetInfo *AuxTarget);
+
+ /// The shards of the target's builtins.
+ llvm::ArrayRef<InfosShard> getTargetShards() const {
+ return llvm::ArrayRef(Shards).slice(1, NumTargetShards);
+ }
+
+ /// The shards of the aux target's builtins.
+ llvm::ArrayRef<InfosShard> getAuxTargetShards() const {
+ return llvm::ArrayRef(Shards).drop_front(1 + NumTargetShards);
+ }
+
+ unsigned getNumTargetBuiltins() const { return NumTargetBuiltins; }
+ unsigned getNumAuxTargetBuiltins() const { return NumAuxTargetBuiltins; }
+
+ /// Return the shard of the builtin with \p ID and its info.
+ std::pair<const InfosShard &, const Info &>
+ getShardAndInfo(unsigned ID) const;
+
+ /// Return the IDs of all builtins named \p Name, in no particular order.
+ llvm::SmallVector<unsigned, 2> lookup(llvm::StringRef Name) const;
+};
+
/// Holds information about both target-independent and
/// target-specific builtins, allowing easy queries by clients.
///
-/// Builtins from an optional auxiliary target are stored in
-/// AuxTSRecords. Their IDs are shifted up by TSRecords.size() and need to
-/// be translated back with getAuxBuiltinID() before use.
+/// Builtins from an optional auxiliary target follow the target's builtins.
+/// Their IDs are shifted up by the number of target builtins and need to be
+/// translated back with getAuxBuiltinID() before use.
class Context {
- llvm::SmallVector<InfosShard> BuiltinShards;
-
- llvm::SmallVector<InfosShard> TargetShards;
- llvm::SmallVector<InfosShard> AuxTargetShards;
+ /// The builtins of the target and the aux target. Null for a context without
+ /// a target, which only has the target-independent builtins.
+ std::shared_ptr<const TargetBuiltins> Builtins;
+ /// Copies of the counts in Builtins, so that the inline isAuxBuiltinID() and
+ /// getAuxBuiltinID() don't need to go through it.
unsigned NumTargetBuiltins = 0;
unsigned NumAuxTargetBuiltins = 0;
public:
+ /// Create a context with only the target-independent builtins. It doesn't
+ /// know any builtin names: \c lookupBuiltinID() always returns
+ /// \c NotBuiltin.
Context();
- /// Perform target-specific initialization
- /// \param AuxTarget Target info to incorporate builtins from. May be
nullptr.
- void InitializeTarget(const TargetInfo &Target, const TargetInfo *AuxTarget);
-
- /// Mark the identifiers for all the builtins with their
- /// appropriate builtin ID # and mark any non-portable builtin identifiers as
- /// such.
- void initializeBuiltins(IdentifierTable &Table, const LangOptions& LangOpts);
----------------
cyndyishida wrote:
Maybe I'm missing something but the PR description says
> The existing calls to initializeBuiltins() keep working but are now redundant.
But the definition looks removed.
https://github.com/llvm/llvm-project/pull/243274
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits