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) {
22
23 // Collect non-entry and non-exported functions to set to internal linkage.
24 for (Function &EF : M.functions()) {
25 if (EF.isIntrinsic())
26 continue;
27 if (EF.hasFnAttribute("hlsl.shader") || EF.hasFnAttribute("hlsl.export"))
28 continue;
29 Funcs.insert(&EF);
30 }
31
32 for (Function *F : Funcs) {
33 if (F->getLinkage() == GlobalValue::ExternalLinkage)
35 if (F->isDefTriviallyDead())
36 M.getFunctionList().erase(F);
37 }
38
39 return false;
40}
41
44 if (finalizeLinkage(M))
47}
48
50 return finalizeLinkage(M);
51}
52
54
56 "DXIL Finalize Linkage", false, false)
58 "DXIL Finalize Linkage", false, false)
59
61 return new DXILFinalizeLinkageLegacy();
62}
static bool finalizeLinkage(Module &M)
#define DEBUG_TYPE
Module.h This file contains the declarations for the Module class.
#define F(x, y, z)
Definition: MD5.cpp:55
This file contains the declarations for metadata subclasses.
#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:384
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
Definition: SmallPtrSet.h:519
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
ModulePass * createDXILFinalizeLinkageLegacyPass()
Pass to finalize linkage of functions.