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 //===----------------------------------------------------------------------===// 8 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" 14 15 using namespace llvm; 16 17 #define DEBUG_TYPE "dxil-upgrade" 18 19 static bool handleValVerMetadata(Module &M) { 20 NamedMDNode *ValVer = M.getNamedMetadata("dx.valver"); 21 if (!ValVer) 22 return false; 23 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; 34 } 35 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>>(); 41 42 bool Changed = false; 43 Changed |= handleValVerMetadata(M); 44 45 if (!Changed) 46 return PreservedAnalyses::all(); 47 return PA; 48 } 49