[llvm] [SPIRV] Add shadow function when only global variable declared in the module  (PR #164829)
    via llvm-commits 
    llvm-commits at lists.llvm.org
       
    Thu Oct 23 07:46:32 PDT 2025
    
    
  
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 origin/main HEAD --extensions cpp -- llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp --diff_from_common_commit
``````````
:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp b/llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp
index f39670f5a..2182d4ad0 100644
--- a/llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp
@@ -3025,25 +3025,25 @@ bool SPIRVEmitIntrinsics::runOnModule(Module &M) {
 
   Function *ShadowFunc = nullptr;
   if (!HasAnyFunction) {
-      for (auto GI = M.global_begin(), GE = M.global_end(); GI != GE; ) {
-          GlobalVariable *GV = &*GI++;
-          if (GV->hasInternalLinkage()) {
-              GV->eraseFromParent();
-              Changed = true;
-          } else if (ShadowFunc == nullptr) {
-              LLVMContext &Ctx = M.getContext();
-              auto *FTy = FunctionType::get(Type::getVoidTy(Ctx), /*isVarArg=*/false);
-              ShadowFunc = Function::Create(
-                  FTy, GlobalValue::InternalLinkage, "__spirv_globals_entry", &M);
-
-              // Create a basic block and insert a ret void
-              BasicBlock *BB = BasicBlock::Create(Ctx, "entry", ShadowFunc);
-              IRBuilder<> B(BB);
-              B.CreateRetVoid();
-
-              Changed = true;
-          }
+    for (auto GI = M.global_begin(), GE = M.global_end(); GI != GE;) {
+      GlobalVariable *GV = &*GI++;
+      if (GV->hasInternalLinkage()) {
+        GV->eraseFromParent();
+        Changed = true;
+      } else if (ShadowFunc == nullptr) {
+        LLVMContext &Ctx = M.getContext();
+        auto *FTy = FunctionType::get(Type::getVoidTy(Ctx), /*isVarArg=*/false);
+        ShadowFunc = Function::Create(FTy, GlobalValue::InternalLinkage,
+                                      "__spirv_globals_entry", &M);
+
+        // Create a basic block and insert a ret void
+        BasicBlock *BB = BasicBlock::Create(Ctx, "entry", ShadowFunc);
+        IRBuilder<> B(BB);
+        B.CreateRetVoid();
+
+        Changed = true;
       }
+    }
   }
 
   TodoType.clear();
``````````
</details>
https://github.com/llvm/llvm-project/pull/164829
    
    
More information about the llvm-commits
mailing list