1 //===-- AMDGPUAlwaysInlinePass.cpp - Promote Allocas ----------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 /// This pass marks all internal functions as always_inline and creates
12 /// duplicates of all other functions a marks the duplicates as always_inline.
14 //===----------------------------------------------------------------------===//
17 #include "llvm/IR/Module.h"
18 #include "llvm/Transforms/Utils/Cloning.h"
24 class AMDGPUAlwaysInline : public ModulePass {
28 AMDGPUAlwaysInline() : ModulePass(ID) { }
29 bool runOnModule(Module &M) override;
30 StringRef getPassName() const override { return "AMDGPU Always Inline Pass"; }
33 } // End anonymous namespace
35 char AMDGPUAlwaysInline::ID = 0;
37 bool AMDGPUAlwaysInline::runOnModule(Module &M) {
38 std::vector<GlobalAlias*> AliasesToRemove;
39 std::vector<Function *> FuncsToClone;
41 for (GlobalAlias &A : M.aliases()) {
42 if (Function* F = dyn_cast<Function>(A.getAliasee())) {
43 A.replaceAllUsesWith(F);
44 AliasesToRemove.push_back(&A);
48 for (GlobalAlias* A : AliasesToRemove) {
52 for (Function &F : M) {
53 if (!F.hasLocalLinkage() && !F.isDeclaration() && !F.use_empty() &&
54 !F.hasFnAttribute(Attribute::NoInline))
55 FuncsToClone.push_back(&F);
58 for (Function *F : FuncsToClone) {
59 ValueToValueMapTy VMap;
60 Function *NewFunc = CloneFunction(F, VMap);
61 NewFunc->setLinkage(GlobalValue::InternalLinkage);
62 F->replaceAllUsesWith(NewFunc);
65 for (Function &F : M) {
66 if (F.hasLocalLinkage() && !F.hasFnAttribute(Attribute::NoInline)) {
67 F.addFnAttr(Attribute::AlwaysInline);
73 ModulePass *llvm::createAMDGPUAlwaysInlinePass() {
74 return new AMDGPUAlwaysInline();