llvm-project/llvm/lib/Target/DirectX/DXILTranslateMetadata.cpp
Chris Bieneman 618e5006a5 [DirectX] Generate dx.resources metadata entry
This code adds initial support for generating the HLSL resources
metadata entries. It has a lot of `FIXMEs` laying around because there
is a lot more work to do here, but this lays a solid groundwork and can
accurately handle some trivial cases.

I've filed a swath of issues covering the deficiencies here and left the
issues in comments so that we can easily follow them.

One big change to make sooner rather than later is to move some of this
code into a new libLLVMFrontendHLSL so that we can share it with the
Clang CodeGen layer.

Reviewed By: python3kgae

Differential Revision: https://reviews.llvm.org/D134682
2022-10-04 12:36:39 -05:00

56 lines
1.5 KiB
C++

//===- DXILTranslateMetadata.cpp - Pass to emit DXIL metadata ---*- 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
//
//===----------------------------------------------------------------------===//
///
//===----------------------------------------------------------------------===//
#include "DXILMetadata.h"
#include "DXILResource.h"
#include "DirectX.h"
#include "llvm/ADT/StringSet.h"
#include "llvm/ADT/Triple.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/Metadata.h"
#include "llvm/IR/Module.h"
#include "llvm/Pass.h"
using namespace llvm;
namespace {
class DXILTranslateMetadata : public ModulePass {
public:
static char ID; // Pass identification, replacement for typeid
explicit DXILTranslateMetadata() : ModulePass(ID) {}
StringRef getPassName() const override { return "DXIL Metadata Emit"; }
bool runOnModule(Module &M) override;
};
} // namespace
bool DXILTranslateMetadata::runOnModule(Module &M) {
dxil::ValidatorVersionMD ValVerMD(M);
if (ValVerMD.isEmpty())
ValVerMD.update(VersionTuple(1, 0));
dxil::createShaderModelMD(M);
dxil::Resources Res(M);
Res.write();
return false;
}
char DXILTranslateMetadata::ID = 0;
ModulePass *llvm::createDXILTranslateMetadataPass() {
return new DXILTranslateMetadata();
}
INITIALIZE_PASS(DXILTranslateMetadata, "dxil-metadata-emit",
"DXIL Metadata Emit", false, false)