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 {
29 AMDGPUAlwaysInline() : ModulePass(ID) { }
30 bool runOnModule(Module &M) override;
31 const char *getPassName() const override { return "AMDGPU Always Inline Pass"; }
34 } // End anonymous namespace
36 char AMDGPUAlwaysInline::ID = 0;
38 bool AMDGPUAlwaysInline::runOnModule(Module &M) {
40 std::vector<Function*> FuncsToClone;
41 for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) {
43 if (!F.hasLocalLinkage() && !F.isDeclaration() && !F.use_empty() &&
44 !F.hasFnAttribute(Attribute::NoInline))
45 FuncsToClone.push_back(&F);
48 for (Function *F : FuncsToClone) {
49 ValueToValueMapTy VMap;
50 Function *NewFunc = CloneFunction(F, VMap, false);
51 NewFunc->setLinkage(GlobalValue::InternalLinkage);
52 F->getParent()->getFunctionList().push_back(NewFunc);
53 F->replaceAllUsesWith(NewFunc);
56 for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) {
58 if (F.hasLocalLinkage() && !F.hasFnAttribute(Attribute::NoInline)) {
59 F.addFnAttr(Attribute::AlwaysInline);
65 ModulePass *llvm::createAMDGPUAlwaysInlinePass() {
66 return new AMDGPUAlwaysInline();