Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 1 addition & 15 deletions clang/lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3956,21 +3956,7 @@ void CompilerInvocationBase::GenerateLangArgs(const LangOptions &Opts,
std::to_string(*Opts.AllocTokenMax));

if (Opts.AllocTokenMode) {
StringRef S;
switch (*Opts.AllocTokenMode) {
case llvm::AllocTokenMode::Increment:
S = "increment";
break;
case llvm::AllocTokenMode::Random:
S = "random";
break;
case llvm::AllocTokenMode::TypeHash:
S = "typehash";
break;
case llvm::AllocTokenMode::TypeHashPointerSplit:
S = "typehashpointersplit";
break;
}
StringRef S = llvm::getAllocTokenModeAsString(*Opts.AllocTokenMode);
GenerateArg(Consumer, OPT_falloc_token_mode_EQ, S);
}
}
Expand Down
3 changes: 3 additions & 0 deletions llvm/include/llvm/Support/AllocToken.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ inline constexpr AllocTokenMode DefaultAllocTokenMode =
LLVM_ABI std::optional<AllocTokenMode>
getAllocTokenModeFromString(StringRef Name);

/// Returns the canonical string name for the given AllocTokenMode.
LLVM_ABI StringRef getAllocTokenModeAsString(AllocTokenMode Mode);

/// Metadata about an allocation used to generate a token ID.
struct AllocTokenMetadata {
SmallString<64> TypeName;
Expand Down
14 changes: 14 additions & 0 deletions llvm/lib/Support/AllocToken.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,20 @@ llvm::getAllocTokenModeFromString(StringRef Name) {
.Default(std::nullopt);
}

StringRef llvm::getAllocTokenModeAsString(AllocTokenMode Mode) {
switch (Mode) {
case AllocTokenMode::Increment:
return "increment";
case AllocTokenMode::Random:
return "random";
case AllocTokenMode::TypeHash:
return "typehash";
case AllocTokenMode::TypeHashPointerSplit:
return "typehashpointersplit";
}
llvm_unreachable("Unknown AllocTokenMode");
}

static uint64_t getStableHash(const AllocTokenMetadata &Metadata,
uint64_t MaxTokens) {
return getStableSipHash(Metadata.TypeName) % MaxTokens;
Expand Down
Loading