[llvm] [TypeSize] Inline conversion to uint64_t (NFC) (PR #157454)

via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 8 06:26:21 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-support

Author: Nikita Popov (nikic)

<details>
<summary>Changes</summary>

After #<!-- -->156336 this cast operator has become trivial, so inline it into the header. This is a minor compile-time improvement.

---
Full diff: https://github.com/llvm/llvm-project/pull/157454.diff


3 Files Affected:

- (modified) llvm/include/llvm/Support/TypeSize.h (+9-1) 
- (modified) llvm/lib/Support/CMakeLists.txt (-1) 
- (removed) llvm/lib/Support/TypeSize.cpp (-22) 


``````````diff
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<TypeSize, uint64_t> {
   //     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();
-}

``````````

</details>


https://github.com/llvm/llvm-project/pull/157454


More information about the llvm-commits mailing list