Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle wrapper #123795

Closed
wants to merge 6 commits into from
Closed

handle wrapper #123795

wants to merge 6 commits into from

Conversation

s-perron
Copy link
Contributor

  • [SPIRV] Expand RWBuffer load and store from HLSL
  • Move type deduction for getpointer into CallInst case.
  • Remove unused table entry.
  • Move DXILFinalizeLinkage out of backend to clang.
  • Modify FinalizeLinkage to chagen global variables.
  • Add global opt pass to remove dead store to global.

The code pattern that clang will generate for HLSL has changed from the
original plan. This allows the SPIR-V backend to generate code for the
current code generation.

It looks for patterns of the form:

```
%1 = @llvm.spv.resource.handlefrombinding
%2 = @llvm.spv.resource.getpointer(%1, index)
load/store %2
```

These three llvm-ir instruction are treated as a single unit that will

1. Generate or find the global variable identified by the call to
   `resource.handlefrombinding`.
2. Generate an OpLoad of the variable to get the handle to the image.
3. Generate an OpImageRead or OpImageWrite using that handle with the
   given index.

This will generate the OpLoad in the same BB as the read/write.

Note: Now that `resource.handlefrombinding` is not processed on its own,
many existing tests had to be removed. We do not have intrinsics that
are able to use handles to sampled images, input attachments, etc., so
we cannot generate the load of the handle. These tests are removed for
now, and will be added when those resource types are fully implemented.
@s-perron s-perron closed this Jan 21, 2025
Copy link

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
git-clang-format --diff 6518b121f037717fd211c36659f7b25266424719 64265ebd451b09a0703d360aa8dbe822382eda60 --extensions cpp,h -- clang/lib/CodeGen/BackendUtil.cpp llvm/lib/Target/DirectX/DirectXTargetMachine.cpp llvm/lib/Target/SPIRV/SPIRVTargetMachine.cpp llvm/include/llvm/Transforms/HLSL/DXILFinalizeLinkage.h llvm/lib/Transforms/HLSL/DXILFinalizeLinkage.cpp
View the diff from clang-format here.
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp
index 23445ebc36..e67dd8a875 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -56,9 +56,10 @@
 #include "llvm/Target/TargetOptions.h"
 #include "llvm/TargetParser/SubtargetFeature.h"
 #include "llvm/TargetParser/Triple.h"
-#include "llvm/Transforms/HipStdPar/HipStdPar.h"
 #include "llvm/Transforms/HLSL/DXILFinalizeLinkage.h"
+#include "llvm/Transforms/HipStdPar/HipStdPar.h"
 #include "llvm/Transforms/IPO/EmbedBitcodePass.h"
+#include "llvm/Transforms/IPO/GlobalOpt.h"
 #include "llvm/Transforms/IPO/LowerTypeTests.h"
 #include "llvm/Transforms/IPO/ThinLTOBitcodeWriter.h"
 #include "llvm/Transforms/InstCombine/InstCombine.h"
@@ -83,7 +84,6 @@
 #include "llvm/Transforms/ObjCARC.h"
 #include "llvm/Transforms/Scalar/EarlyCSE.h"
 #include "llvm/Transforms/Scalar/GVN.h"
-#include "llvm/Transforms/IPO/GlobalOpt.h"
 #include "llvm/Transforms/Scalar/JumpThreading.h"
 #include "llvm/Transforms/Utils/Debugify.h"
 #include "llvm/Transforms/Utils/ModuleUtils.h"
diff --git a/llvm/lib/Transforms/HLSL/DXILFinalizeLinkage.cpp b/llvm/lib/Transforms/HLSL/DXILFinalizeLinkage.cpp
index c0dc4a6aa7..a1d53d0498 100644
--- a/llvm/lib/Transforms/HLSL/DXILFinalizeLinkage.cpp
+++ b/llvm/lib/Transforms/HLSL/DXILFinalizeLinkage.cpp
@@ -18,7 +18,7 @@ using namespace llvm;
 static bool finalizeLinkage(Module &M) {
   SmallPtrSet<Function *, 8> Funcs;
 
-  for(auto &Var : M.globals()) {
+  for (auto &Var : M.globals()) {
     if (Var.getLinkage() == GlobalValue::ExternalLinkage) {
       Var.setLinkage(GlobalValue::InternalLinkage);
     }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant