[PATCH] D125842: [DirectX backend] When cleanup module flags only remove unused flags.
Xiang Li via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu May 19 13:10:57 PDT 2022
python3kgae updated this revision to Diff 430786.
python3kgae added a comment.
Update test to make sure only 1 operand left for module flags.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D125842/new/
https://reviews.llvm.org/D125842
Files:
llvm/lib/Target/DirectX/DXILTranslateMetadata.cpp
llvm/test/CodeGen/DirectX/dxil_ver.ll
Index: llvm/test/CodeGen/DirectX/dxil_ver.ll
===================================================================
--- llvm/test/CodeGen/DirectX/dxil_ver.ll
+++ llvm/test/CodeGen/DirectX/dxil_ver.ll
@@ -2,8 +2,14 @@
target datalayout = "e-m:e-p:32:32-i1:32-i8:8-i16:16-i32:32-i64:64-f16:16-f32:32-f64:64-n8:16:32:64"
target triple = "dxil-pc-shadermodel6.3-library"
+; Make sure dx.valver metadata is generated.
; CHECK:!dx.valver = !{![[valver:[0-9]+]]}
+; Make sure module flags still exist and only have 1 operand left.
+; CHECK:!llvm.module.flags = !{{{![0-9]}}}
+; Make sure validator version is 1.1.
; CHECK:![[valver]] = !{i32 1, i32 1}
+; Make sure wchar_size still exist.
+; CHECK:!{i32 1, !"wchar_size", i32 4}
!llvm.module.flags = !{!0, !1}
!llvm.ident = !{!3}
Index: llvm/lib/Target/DirectX/DXILTranslateMetadata.cpp
===================================================================
--- llvm/lib/Target/DirectX/DXILTranslateMetadata.cpp
+++ llvm/lib/Target/DirectX/DXILTranslateMetadata.cpp
@@ -9,8 +9,10 @@
//===----------------------------------------------------------------------===//
#include "DirectX.h"
+#include "llvm/ADT/StringSet.h"
#include "llvm/ADT/Triple.h"
#include "llvm/IR/Constants.h"
+#include "llvm/IR/Metadata.h"
#include "llvm/IR/Module.h"
#include "llvm/Pass.h"
@@ -56,10 +58,32 @@
return VersionTuple(Major, Minor);
}
-static void cleanModule(Module &M) {
- M.getOrInsertModuleFlagsMetadata()->eraseFromParent();
+static void cleanModuleFlags(Module &M) {
+ constexpr StringLiteral DeadKeys[] = {ValVerKey};
+ // Collect DeadKeys in ModuleFlags.
+ StringSet<> DeadKeySet;
+ for (auto &Key : DeadKeys) {
+ if (M.getModuleFlag(Key))
+ DeadKeySet.insert(Key);
+ }
+ if (DeadKeySet.empty())
+ return;
+
+ SmallVector<Module::ModuleFlagEntry, 8> ModuleFlags;
+ M.getModuleFlagsMetadata(ModuleFlags);
+ NamedMDNode *MDFlags = M.getModuleFlagsMetadata();
+ MDFlags->eraseFromParent();
+ // Add ModuleFlag which not dead.
+ for (auto &Flag : ModuleFlags) {
+ StringRef Key = Flag.Key->getString();
+ if (DeadKeySet.contains(Key))
+ continue;
+ M.addModuleFlag(Flag.Behavior, Key, Flag.Val);
+ }
}
+static void cleanModule(Module &M) { cleanModuleFlags(M); }
+
namespace {
class DXILTranslateMetadata : public ModulePass {
public:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D125842.430786.patch
Type: text/x-patch
Size: 2329 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220519/774f584a/attachment.bin>
More information about the llvm-commits
mailing list