[CostModel][X86] Attempt to match v4f32 shuffles that map to MOVSS/INSERTPS instruction
[llvm-project.git] / llvm / lib / Transforms / Utils / DXILUpgrade.cpp
blob09991f628224cefde4e99716339993900e344b13
1 //===- DXILUpgrade.cpp - Upgrade DXIL metadata to LLVM constructs ---------===//
2 //
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
6 //
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"
15 using namespace llvm;
17 #define DEBUG_TYPE "dxil-upgrade"
19 static bool handleValVerMetadata(Module &M) {
20 NamedMDNode *ValVer = M.getNamedMetadata("dx.valver");
21 if (!ValVer)
22 return false;
24 LLVM_DEBUG({
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";
29 });
30 // We don't need the validation version internally, so we drop it.
31 ValVer->dropAllReferences();
32 ValVer->eraseFromParent();
33 return true;
36 PreservedAnalyses DXILUpgradePass::run(Module &M, ModuleAnalysisManager &AM) {
37 PreservedAnalyses PA;
38 // We never add, remove, or change functions here.
39 PA.preserve<FunctionAnalysisManagerModuleProxy>();
40 PA.preserveSet<AllAnalysesOn<Function>>();
42 bool Changed = false;
43 Changed |= handleValVerMetadata(M);
45 if (!Changed)
46 return PreservedAnalyses::all();
47 return PA;