[Transforms][DXIL] Wire up a basic DXILUpgrade pass (#66275)

This pass will upgrade DXIL-style llvm constructs (which are mostly
metadata) into the representations we use in LLVM for the same concepts.

For now we just strip the valver metadata, which we don't need. Later
changes will make this pass more useful, and then we should be able to
wire it into clang and possibly the DirectX backend's AsmParser.
This commit is contained in:
Justin Bogner 2023-09-14 11:02:31 -07:00 committed by GitHub
parent a5a2a5a3ec
commit 71e3642619
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 81 additions and 0 deletions

View File

@ -0,0 +1,24 @@
//===- DXILUpgrade.h - Upgrade DXIL metadata to LLVM constructs -*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_TRANSFORMS_UTILS_DXILUPGRADE_H
#define LLVM_TRANSFORMS_UTILS_DXILUPGRADE_H
#include "llvm/IR/PassManager.h"
namespace llvm {
/// Upgrade DXIL-style metadata into their LLVM representations
class DXILUpgradePass : public PassInfoMixin<DXILUpgradePass> {
public:
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
};
} // namespace llvm
#endif // LLVM_TRANSFORMS_UTILS_DXILUPGRADE_H

View File

@ -233,6 +233,7 @@
#include "llvm/Transforms/Utils/CanonicalizeFreezeInLoops.h"
#include "llvm/Transforms/Utils/CountVisits.h"
#include "llvm/Transforms/Utils/Debugify.h"
#include "llvm/Transforms/Utils/DXILUpgrade.h"
#include "llvm/Transforms/Utils/EntryExitInstrumenter.h"
#include "llvm/Transforms/Utils/FixIrreducible.h"
#include "llvm/Transforms/Utils/HelloWorld.h"

View File

@ -57,6 +57,7 @@ MODULE_PASS("cross-dso-cfi", CrossDSOCFIPass())
MODULE_PASS("deadargelim", DeadArgumentEliminationPass())
MODULE_PASS("debugify", NewPMDebugifyPass())
MODULE_PASS("dot-callgraph", CallGraphDOTPrinterPass())
MODULE_PASS("dxil-upgrade", DXILUpgradePass())
MODULE_PASS("elim-avail-extern", EliminateAvailableExternallyPass())
MODULE_PASS("extract-blocks", BlockExtractorPass({}, false))
MODULE_PASS("forceattrs", ForceFunctionAttrsPass())

View File

@ -20,6 +20,7 @@ add_llvm_component_library(LLVMTransformUtils
CountVisits.cpp
Debugify.cpp
DemoteRegToStack.cpp
DXILUpgrade.cpp
EntryExitInstrumenter.cpp
EscapeEnumerator.cpp
Evaluator.cpp

View File

@ -0,0 +1,36 @@
//===- DXILUpgrade.cpp - Upgrade DXIL metadata to LLVM constructs ---------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "llvm/Transforms/Utils/DXILUpgrade.h"
using namespace llvm;
static bool handleValVerMetadata(Module &M) {
NamedMDNode *ValVer = M.getNamedMetadata("dx.valver");
if (!ValVer)
return false;
// We don't need the validation version internally, so we drop it.
ValVer->dropAllReferences();
ValVer->eraseFromParent();
return true;
}
PreservedAnalyses DXILUpgradePass::run(Module &M, ModuleAnalysisManager &AM) {
PreservedAnalyses PA;
// We never add, remove, or change functions here.
PA.preserve<FunctionAnalysisManagerModuleProxy>();
PA.preserveSet<AllAnalysesOn<Function>>();
bool Changed = false;
Changed |= handleValVerMetadata(M);
if (!Changed)
return PreservedAnalyses::all();
return PA;
}

View File

@ -0,0 +1,18 @@
; RUN: opt -passes=dxil-upgrade -S < %s | FileCheck %s
; Ensure that both the valver metadata and its operand are removed.
; CHECK: !unrelated_md1 = !{!0}
; CHECK-NOT: !dx.valver
; CHECK: !unrelated_md2 = !{!1}
;
; CHECK: !0 = !{i32 1234}
; CHECK-NOT: !{i32 1, i32 7}
; CHECK: !1 = !{i32 4321}
!unrelated_md1 = !{!0}
!dx.valver = !{!1}
!unrelated_md2 = !{!2}
!0 = !{i32 1234}
!1 = !{i32 1, i32 7}
!2 = !{i32 4321}