1 //===- DXILUpgrade.cpp - Upgrade DXIL metadata to LLVM constructs ---------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "llvm/Transforms/Utils/DXILUpgrade.h"
10 #include "llvm/IR/Constants.h"
11 #include "llvm/IR/Metadata.h"
12 #include "llvm/IR/Module.h"
13 #include "llvm/Support/Debug.h"
17 #define DEBUG_TYPE "dxil-upgrade"
19 static bool handleValVerMetadata(Module
&M
) {
20 NamedMDNode
*ValVer
= M
.getNamedMetadata("dx.valver");
25 MDNode
*N
= ValVer
->getOperand(0);
26 auto X
= mdconst::extract
<ConstantInt
>(N
->getOperand(0))->getZExtValue();
27 auto Y
= mdconst::extract
<ConstantInt
>(N
->getOperand(1))->getZExtValue();
28 dbgs() << "DXIL: validation version: " << X
<< "." << Y
<< "\n";
30 // We don't need the validation version internally, so we drop it.
31 ValVer
->dropAllReferences();
32 ValVer
->eraseFromParent();
36 PreservedAnalyses
DXILUpgradePass::run(Module
&M
, ModuleAnalysisManager
&AM
) {
38 // We never add, remove, or change functions here.
39 PA
.preserve
<FunctionAnalysisManagerModuleProxy
>();
40 PA
.preserveSet
<AllAnalysesOn
<Function
>>();
43 Changed
|= handleValVerMetadata(M
);
46 return PreservedAnalyses::all();