[PATCH] D137173: Add deduction guides for IRBuilder

Krzysztof Parzyszek via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 9 07:19:14 PST 2022


kparzysz updated this revision to Diff 474264.
kparzysz added a comment.

Added `static_assert` tests to the unit tests.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137173/new/

https://reviews.llvm.org/D137173

Files:
  llvm/include/llvm/IR/IRBuilder.h
  llvm/unittests/IR/IRBuilderTest.cpp


Index: llvm/unittests/IR/IRBuilderTest.cpp
===================================================================
--- llvm/unittests/IR/IRBuilderTest.cpp
+++ llvm/unittests/IR/IRBuilderTest.cpp
@@ -6,6 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "llvm/Analysis/InstSimplifyFolder.h"
 #include "llvm/IR/IRBuilder.h"
 #include "llvm/IR/BasicBlock.h"
 #include "llvm/IR/DIBuilder.h"
@@ -21,6 +22,8 @@
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
+#include <type_traits>
+
 using namespace llvm;
 using ::testing::UnorderedElementsAre;
 
@@ -1156,4 +1159,30 @@
       Builder.CreateAdd(Builder.getInt32(1), Builder.getInt32(2), "add");
   EXPECT_EQ(Add->getName(), "add");
 }
+
+TEST_F(IRBuilderTest, CTAD) {
+  struct TestInserter : public IRBuilderDefaultInserter {
+    TestInserter() = default;
+  };
+  InstSimplifyFolder Folder(M->getDataLayout());
+
+  IRBuilder Builder1(Ctx, Folder, TestInserter());
+  static_assert(std::is_same_v<decltype(Builder1),
+                               IRBuilder<InstSimplifyFolder, TestInserter>>);
+  IRBuilder Builder2(Ctx);
+  static_assert(std::is_same_v<decltype(Builder2), IRBuilder<>>);
+  IRBuilder Builder3(BB, Folder);
+  static_assert(
+      std::is_same_v<decltype(Builder3), IRBuilder<InstSimplifyFolder>>);
+  IRBuilder Builder4(BB);
+  static_assert(std::is_same_v<decltype(Builder4), IRBuilder<>>);
+  // The block BB is empty, so don't test this one.
+  // IRBuilder Builder5(BB->getTerminator());
+  // static_assert(std::is_same_v<decltype(Builder5), IRBuilder<>>);
+  IRBuilder Builder6(BB, BB->end(), Folder);
+  static_assert(
+      std::is_same_v<decltype(Builder6), IRBuilder<InstSimplifyFolder>>);
+  IRBuilder Builder7(BB, BB->end());
+  static_assert(std::is_same_v<decltype(Builder7), IRBuilder<>>);
+}
 }
Index: llvm/include/llvm/IR/IRBuilder.h
===================================================================
--- llvm/include/llvm/IR/IRBuilder.h
+++ llvm/include/llvm/IR/IRBuilder.h
@@ -2583,6 +2583,22 @@
   InserterTy &getInserter() { return Inserter; }
 };
 
+template <typename FolderTy, typename InserterTy>
+IRBuilder(LLVMContext &, FolderTy, InserterTy, MDNode *,
+          ArrayRef<OperandBundleDef>) -> IRBuilder<FolderTy, InserterTy>;
+IRBuilder(LLVMContext &, MDNode *, ArrayRef<OperandBundleDef>) -> IRBuilder<>;
+template <typename FolderTy>
+IRBuilder(BasicBlock *, FolderTy, MDNode *, ArrayRef<OperandBundleDef>)
+    -> IRBuilder<FolderTy>;
+IRBuilder(BasicBlock *, MDNode *, ArrayRef<OperandBundleDef>) -> IRBuilder<>;
+IRBuilder(Instruction *, MDNode *, ArrayRef<OperandBundleDef>) -> IRBuilder<>;
+template <typename FolderTy>
+IRBuilder(BasicBlock *, BasicBlock::iterator, FolderTy, MDNode *,
+          ArrayRef<OperandBundleDef>) -> IRBuilder<FolderTy>;
+IRBuilder(BasicBlock *, BasicBlock::iterator, MDNode *,
+          ArrayRef<OperandBundleDef>) -> IRBuilder<>;
+
+
 // Create wrappers for C Binding types (see CBindingWrapping.h).
 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(IRBuilder<>, LLVMBuilderRef)
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137173.474264.patch
Type: text/x-patch
Size: 3066 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221109/494352d8/attachment-0001.bin>


More information about the llvm-commits mailing list