From f1bc39bfda00d0cb0bc613224e9204a216d22573 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Mon, 8 Sep 2025 12:38:55 +0200 Subject: [PATCH] [TypeSize] Inline conversion to uint64_t (NFC) After #156336 this cast operator has become trivial, so inline it into the header. This is a minor compile-time improvement. --- llvm/include/llvm/Support/TypeSize.h | 10 +++++++++- llvm/lib/Support/CMakeLists.txt | 1 - llvm/lib/Support/TypeSize.cpp | 22 ---------------------- 3 files changed, 9 insertions(+), 24 deletions(-) delete mode 100644 llvm/lib/Support/TypeSize.cpp diff --git a/llvm/include/llvm/Support/TypeSize.h b/llvm/include/llvm/Support/TypeSize.h index b6926e6fdeeb6..29d1c6894b4b6 100644 --- a/llvm/include/llvm/Support/TypeSize.h +++ b/llvm/include/llvm/Support/TypeSize.h @@ -16,6 +16,7 @@ #define LLVM_SUPPORT_TYPESIZE_H #include "llvm/Support/Compiler.h" +#include "llvm/Support/ErrorHandling.h" #include "llvm/Support/MathExtras.h" #include "llvm/Support/raw_ostream.h" @@ -371,7 +372,14 @@ class TypeSize : public details::FixedOrScalableQuantity { // else // bail out early for scalable vectors and use getFixedValue() // } - LLVM_ABI operator ScalarTy() const; + operator ScalarTy() const { + if (isScalable()) { + reportFatalInternalError( + "Cannot implicitly convert a scalable size to a fixed-width size in " + "`TypeSize::operator ScalarTy()`"); + } + return getFixedValue(); + } // Additional operators needed to avoid ambiguous parses // because of the implicit conversion hack. diff --git a/llvm/lib/Support/CMakeLists.txt b/llvm/lib/Support/CMakeLists.txt index 381ec19563732..2528e8bd1142a 100644 --- a/llvm/lib/Support/CMakeLists.txt +++ b/llvm/lib/Support/CMakeLists.txt @@ -265,7 +265,6 @@ add_llvm_component_library(LLVMSupport ToolOutputFile.cpp TrieRawHashMap.cpp Twine.cpp - TypeSize.cpp Unicode.cpp UnicodeCaseFold.cpp UnicodeNameToCodepoint.cpp diff --git a/llvm/lib/Support/TypeSize.cpp b/llvm/lib/Support/TypeSize.cpp deleted file mode 100644 index 3dbb00880faca..0000000000000 --- a/llvm/lib/Support/TypeSize.cpp +++ /dev/null @@ -1,22 +0,0 @@ -//===- TypeSize.cpp - Wrapper around type sizes------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include "llvm/Support/TypeSize.h" -#include "llvm/Support/Error.h" - -using namespace llvm; - -TypeSize::operator TypeSize::ScalarTy() const { - if (isScalable()) { - reportFatalInternalError( - "Cannot implicitly convert a scalable size to a fixed-width size in " - "`TypeSize::operator ScalarTy()`"); - return getKnownMinValue(); - } - return getFixedValue(); -}