[Mlir-commits] [mlir] 4ab36d8 - [IR][NFC] Inline Value::getContext() (#176662)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Sun Jan 18 22:55:52 PST 2026


Author: Alexis Engelke
Date: 2026-01-19T06:55:46Z
New Revision: 4ab36d89a85a01994637077a8e7bacc2561a4db3

URL: https://github.com/llvm/llvm-project/commit/4ab36d89a85a01994637077a8e7bacc2561a4db3
DIFF: https://github.com/llvm/llvm-project/commit/4ab36d89a85a01994637077a8e7bacc2561a4db3.diff

LOG: [IR][NFC] Inline Value::getContext() (#176662)

For non-LTO builds, this is a frequently called function consisting of
just two instructions. Most files that include Value.h also include
Type.h, so the added compile time cost is very low.

Added: 
    

Modified: 
    llvm/include/llvm/IR/Value.h
    llvm/lib/IR/Value.cpp
    mlir/unittests/IR/RemarkTest.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/IR/Value.h b/llvm/include/llvm/IR/Value.h
index 58822a0645747..4a15251f0b945 100644
--- a/llvm/include/llvm/IR/Value.h
+++ b/llvm/include/llvm/IR/Value.h
@@ -17,6 +17,7 @@
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/iterator_range.h"
+#include "llvm/IR/Type.h"
 #include "llvm/IR/Use.h"
 #include "llvm/Support/Alignment.h"
 #include "llvm/Support/CBindingWrapping.h"
@@ -50,7 +51,6 @@ class ModuleSlotTracker;
 class raw_ostream;
 template<typename ValueTy> class StringMapEntry;
 class Twine;
-class Type;
 class User;
 
 using ValueName = StringMapEntry<Value *>;
@@ -256,7 +256,7 @@ class Value {
   Type *getType() const { return VTy; }
 
   /// All values hold a context through their type.
-  LLVM_ABI LLVMContext &getContext() const;
+  LLVMContext &getContext() const { return VTy->getContext(); }
 
   // All values can potentially be named.
   bool hasName() const { return HasName; }

diff  --git a/llvm/lib/IR/Value.cpp b/llvm/lib/IR/Value.cpp
index a43d63077bf9f..81a6ddec4918c 100644
--- a/llvm/lib/IR/Value.cpp
+++ b/llvm/lib/IR/Value.cpp
@@ -1103,8 +1103,6 @@ const Value *Value::DoPHITranslation(const BasicBlock *CurBB,
   return this;
 }
 
-LLVMContext &Value::getContext() const { return VTy->getContext(); }
-
 void Value::reverseUseList() {
   if (!UseList || !UseList->Next)
     // No need to reverse 0 or 1 uses.

diff  --git a/mlir/unittests/IR/RemarkTest.cpp b/mlir/unittests/IR/RemarkTest.cpp
index f33d3caebad37..dca86632071d4 100644
--- a/mlir/unittests/IR/RemarkTest.cpp
+++ b/mlir/unittests/IR/RemarkTest.cpp
@@ -23,7 +23,6 @@
 #include "gtest/gtest.h"
 #include <optional>
 
-using namespace llvm;
 using namespace mlir;
 using namespace testing;
 namespace {
@@ -35,9 +34,9 @@ TEST(Remark, TestOutputOptimizationRemark) {
   std::string categoryInliner("Inliner");
   std::string categoryReroller("Reroller");
   std::string myPassname1("myPass1");
-  SmallString<64> tmpPathStorage;
-  sys::fs::createUniquePath("remarks-%%%%%%.yaml", tmpPathStorage,
-                            /*MakeAbsolute=*/true);
+  llvm::SmallString<64> tmpPathStorage;
+  llvm::sys::fs::createUniquePath("remarks-%%%%%%.yaml", tmpPathStorage,
+                                  /*MakeAbsolute=*/true);
   std::string yamlFile =
       std::string(tmpPathStorage.data(), tmpPathStorage.size());
   ASSERT_FALSE(yamlFile.empty());
@@ -96,7 +95,7 @@ TEST(Remark, TestOutputOptimizationRemark) {
   }
 
   // Read the file
-  auto bufferOrErr = MemoryBuffer::getFile(yamlFile);
+  auto bufferOrErr = llvm::MemoryBuffer::getFile(yamlFile);
   ASSERT_TRUE(static_cast<bool>(bufferOrErr)) << "Failed to open remarks file";
   std::string content = bufferOrErr.get()->getBuffer().str();
 
@@ -154,8 +153,8 @@ TEST(Remark, TestNoOutputOptimizationRemark) {
   std::string categoryFailName("myImportantCategory");
   std::string myPassname1("myPass1");
   SmallString<64> tmpPathStorage;
-  sys::fs::createUniquePath("remarks-%%%%%%.yaml", tmpPathStorage,
-                            /*MakeAbsolute=*/true);
+  llvm::sys::fs::createUniquePath("remarks-%%%%%%.yaml", tmpPathStorage,
+                                  /*MakeAbsolute=*/true);
   std::string yamlFile =
       std::string(tmpPathStorage.data(), tmpPathStorage.size());
   ASSERT_FALSE(yamlFile.empty());
@@ -383,7 +382,7 @@ TEST(Remark, TestRemarkFinal) {
 TEST(Remark, TestArgWithAttribute) {
   MLIRContext context;
 
-  SmallVector<Attribute> elements;
+  llvm::SmallVector<Attribute> elements;
   elements.push_back(IntegerAttr::get(IntegerType::get(&context, 32), 1));
   elements.push_back(IntegerAttr::get(IntegerType::get(&context, 32), 2));
   elements.push_back(IntegerAttr::get(IntegerType::get(&context, 32), 3));


        


More information about the Mlir-commits mailing list