/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/CodeGen/CGHLSLRuntime.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | //===----- CGHLSLRuntime.cpp - Interface to HLSL Runtimes -----------------===// |
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 | | // This provides an abstract class for HLSL code generation. Concrete |
10 | | // subclasses of this implement code generation for specific HLSL |
11 | | // runtime libraries. |
12 | | // |
13 | | //===----------------------------------------------------------------------===// |
14 | | |
15 | | #include "CGHLSLRuntime.h" |
16 | | #include "CodeGenModule.h" |
17 | | #include "clang/Basic/TargetOptions.h" |
18 | | #include "llvm/IR/Metadata.h" |
19 | | #include "llvm/IR/Module.h" |
20 | | |
21 | | using namespace clang; |
22 | | using namespace CodeGen; |
23 | | using namespace llvm; |
24 | | |
25 | | namespace { |
26 | 5 | void addDxilValVersion(StringRef ValVersionStr, llvm::Module &M) { |
27 | | // The validation of ValVersionStr is done at HLSLToolChain::TranslateArgs. |
28 | | // Assume ValVersionStr is legal here. |
29 | 5 | VersionTuple Version; |
30 | 5 | if (Version.tryParse(ValVersionStr) || Version.getBuild() || |
31 | 5 | Version.getSubminor() || !Version.getMinor()) { |
32 | 0 | return; |
33 | 0 | } |
34 | | |
35 | 5 | uint64_t Major = Version.getMajor(); |
36 | 5 | uint64_t Minor = *Version.getMinor(); |
37 | | |
38 | 5 | auto &Ctx = M.getContext(); |
39 | 5 | IRBuilder<> B(M.getContext()); |
40 | 5 | MDNode *Val = MDNode::get(Ctx, {ConstantAsMetadata::get(B.getInt32(Major)), |
41 | 5 | ConstantAsMetadata::get(B.getInt32(Minor))}); |
42 | 5 | StringRef DxilValKey = "dx.valver"; |
43 | 5 | M.addModuleFlag(llvm::Module::ModFlagBehavior::AppendUnique, DxilValKey, Val); |
44 | 5 | } |
45 | | } // namespace |
46 | | |
47 | 5 | void CGHLSLRuntime::finishCodeGen() { |
48 | 5 | auto &TargetOpts = CGM.getTarget().getTargetOpts(); |
49 | | |
50 | 5 | llvm::Module &M = CGM.getModule(); |
51 | 5 | addDxilValVersion(TargetOpts.DxilValidatorVersion, M); |
52 | 5 | } |