[llvm] [llvm] Improve the RelLookupTableConverter pass (PR #93355)

via llvm-commits llvm-commits at lists.llvm.org
Fri May 24 16:31:59 PDT 2024


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff 73eb9b33147ba5157cbf5d8276ee718629dfbbda 5db4041ec8db59b6bade5a9727b3949a6b244084 -- llvm/lib/Transforms/Utils/RelLookupTableConverter.cpp
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/llvm/lib/Transforms/Utils/RelLookupTableConverter.cpp b/llvm/lib/Transforms/Utils/RelLookupTableConverter.cpp
index b55e5aeb76..4a7f1c05ad 100644
--- a/llvm/lib/Transforms/Utils/RelLookupTableConverter.cpp
+++ b/llvm/lib/Transforms/Utils/RelLookupTableConverter.cpp
@@ -13,8 +13,8 @@
 
 #include "llvm/Transforms/Utils/RelLookupTableConverter.h"
 #include "llvm/Analysis/ConstantFolding.h"
-#include "llvm/Analysis/SimplifyQuery.h"
 #include "llvm/Analysis/InstructionSimplify.h"
+#include "llvm/Analysis/SimplifyQuery.h"
 #include "llvm/Analysis/TargetTransformInfo.h"
 #include "llvm/IR/BasicBlock.h"
 #include "llvm/IR/IRBuilder.h"
@@ -85,7 +85,8 @@ static bool isValidGEP(const GlobalVariable *GV, const GetElementPtrInst *GEP) {
 static bool shouldConvertToRelLookupTable(Module &M, GlobalVariable &GV) {
   // The global should look something like this:
   //
-  //   @symbols = dso_local constant [3 x ptr] [ptr @.str, ptr @.str.1, ptr @.str.2]
+  //   @symbols = dso_local constant [3 x ptr] [ptr @.str, ptr @.str.1, ptr
+  //   @.str.2]
   //
   // This definition must be the one we know will persist at link/runtime.
   if (!GV.hasExactDefinition())
@@ -159,7 +160,7 @@ static GlobalVariable *createRelLookupTable(Module &M, GlobalVariable &GV) {
   size_t NumOperands = Initializer->getNumOperands();
   Type *OffsetTy = Type::getInt32Ty(M.getContext());
 
-  Type *ReplacementTy = [&]() -> Type *{
+  Type *ReplacementTy = [&]() -> Type * {
     if (Initializer->getType()->isStructTy()) {
       SmallVector<Type *, 8> ElemTys(NumOperands, OffsetTy);
       return llvm::StructType::create(ElemTys);
@@ -169,12 +170,13 @@ static GlobalVariable *createRelLookupTable(Module &M, GlobalVariable &GV) {
     llvm_unreachable("An aggregate type should be one of a struct or array");
   }();
 
-  GlobalVariable *Replacement = new GlobalVariable(M, ReplacementTy, /*isConstant=*/true,
-      GV.getLinkage(), /*Initializer=*/nullptr);
+  GlobalVariable *Replacement =
+      new GlobalVariable(M, ReplacementTy, /*isConstant=*/true, GV.getLinkage(),
+                         /*Initializer=*/nullptr);
   Replacement->takeName(&GV); // Take over the old global's name
   Replacement->setUnnamedAddr(GV.getUnnamedAddr());
   Replacement->setVisibility(GV.getVisibility());
-  Replacement->setAlignment(llvm::Align(4));  // Unconditional 4-byte alignment
+  Replacement->setAlignment(llvm::Align(4)); // Unconditional 4-byte alignment
 
   SmallVector<Constant *, 8> members(NumOperands);
   for (size_t i = 0; i < NumOperands; ++i) {
@@ -192,9 +194,11 @@ static GlobalVariable *createRelLookupTable(Module &M, GlobalVariable &GV) {
   }
 
   Constant *ReplacementInit = [&]() -> Constant * {
-    // TODO: Is there any value in keeping this as a struct still since all elements will be the same type?
+    // TODO: Is there any value in keeping this as a struct still since all
+    // elements will be the same type?
     if (Initializer->getType()->isStructTy())
-      return llvm::ConstantStruct::get(cast<StructType>(ReplacementTy), members);
+      return llvm::ConstantStruct::get(cast<StructType>(ReplacementTy),
+                                       members);
     else if (Initializer->getType()->isArrayTy())
       return llvm::ConstantArray::get(cast<ArrayType>(ReplacementTy), members);
     llvm_unreachable("An aggregate type should be one of a struct or array");

``````````

</details>


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


More information about the llvm-commits mailing list