Skip to content

Conversation

nikic
Copy link
Contributor

@nikic nikic commented Sep 8, 2025

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

After llvm#156336 this cast operator has become trivial, so inline it
into the header. This is a minor compile-time improvement.
@llvmbot
Copy link
Member

llvmbot commented Sep 8, 2025

@llvm/pr-subscribers-llvm-support

Author: Nikita Popov (nikic)

Changes

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 --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();
-}

@nikic nikic merged commit 3eb8a5a into llvm:main Sep 8, 2025
11 checks passed
@nikic nikic deleted the type-size-inline branch September 8, 2025 15:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants