Path: blob/main/contrib/llvm-project/llvm/lib/Transforms/Utils/DXILUpgrade.cpp
35271 views
//===- DXILUpgrade.cpp - Upgrade DXIL metadata to LLVM constructs ---------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "llvm/Transforms/Utils/DXILUpgrade.h"9#include "llvm/IR/Constants.h"10#include "llvm/IR/Metadata.h"11#include "llvm/IR/Module.h"12#include "llvm/Support/Debug.h"1314using namespace llvm;1516#define DEBUG_TYPE "dxil-upgrade"1718static bool handleValVerMetadata(Module &M) {19NamedMDNode *ValVer = M.getNamedMetadata("dx.valver");20if (!ValVer)21return false;2223LLVM_DEBUG({24MDNode *N = ValVer->getOperand(0);25auto X = mdconst::extract<ConstantInt>(N->getOperand(0))->getZExtValue();26auto Y = mdconst::extract<ConstantInt>(N->getOperand(1))->getZExtValue();27dbgs() << "DXIL: validation version: " << X << "." << Y << "\n";28});29// We don't need the validation version internally, so we drop it.30ValVer->dropAllReferences();31ValVer->eraseFromParent();32return true;33}3435PreservedAnalyses DXILUpgradePass::run(Module &M, ModuleAnalysisManager &AM) {36PreservedAnalyses PA;37// We never add, remove, or change functions here.38PA.preserve<FunctionAnalysisManagerModuleProxy>();39PA.preserveSet<AllAnalysesOn<Function>>();4041bool Changed = false;42Changed |= handleValVerMetadata(M);4344if (!Changed)45return PreservedAnalyses::all();46return PA;47}484950