LLVM 20.0.0git
DXILFinalizeLinkage.cpp
Go to the documentation of this file.
1//===- DXILFinalizeLinkage.cpp - Finalize linkage of functions ------------===//
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
10#include "DirectX.h"
11#include "llvm/IR/Function.h"
12#include "llvm/IR/GlobalValue.h"
13#include "llvm/IR/Metadata.h"
14#include "llvm/IR/Module.h"
15
16#define DEBUG_TYPE "dxil-finalize-linkage"
17
18using namespace llvm;
19
20static bool finalizeLinkage(Module &M) {
21 SmallPtrSet<Function *, 8> EntriesAndExports;
22
23 // Find all entry points and export functions
24 for (Function &EF : M.functions()) {
25 if (!EF.hasFnAttribute("hlsl.shader") && !EF.hasFnAttribute("hlsl.export"))
26 continue;
27 EntriesAndExports.insert(&EF);
28 }
29
30 for (Function &F : M.functions()) {
31 if (F.getLinkage() == GlobalValue::ExternalLinkage &&
32 !EntriesAndExports.contains(&F)) {
34 }
35 }
36
37 return false;
38}
39
42 if (finalizeLinkage(M))
45}
46
48 return finalizeLinkage(M);
49}
50
52
54 "DXIL Finalize Linkage", false, false)
56 "DXIL Finalize Linkage", false, false)
57
59 return new DXILFinalizeLinkageLegacy();
60}
static bool finalizeLinkage(Module &M)
#define DEBUG_TYPE
#define F(x, y, z)
Definition: MD5.cpp:55
This file contains the declarations for metadata subclasses.
Module.h This file contains the declarations for the Module class.
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:57
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:52
A container for analyses that lazily runs them and caches their results.
Definition: PassManager.h:253
bool runOnModule(Module &M) override
runOnModule - Virtual method overriden by subclasses to process the module being operated on.
PreservedAnalyses run(Module &M, ModuleAnalysisManager &)
@ InternalLinkage
Rename collisions when linking (static functions).
Definition: GlobalValue.h:59
@ ExternalLinkage
Externally visible function.
Definition: GlobalValue.h:52
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
Definition: Pass.h:251
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
A set of analyses that are preserved following a run of a transformation pass.
Definition: Analysis.h:111
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
Definition: Analysis.h:114
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: Analysis.h:117
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
Definition: SmallPtrSet.h:367
bool contains(ConstPtrType Ptr) const
Definition: SmallPtrSet.h:441
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
Definition: SmallPtrSet.h:502
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
ModulePass * createDXILFinalizeLinkageLegacyPass()
Pass to finalize linkage of functions.