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 FuncsToClone.push_back(&F);
47 for (Function *F : FuncsToClone) {
48 ValueToValueMapTy VMap;
49 Function *NewFunc = CloneFunction(F, VMap, false);
50 NewFunc->setLinkage(GlobalValue::InternalLinkage);
51 F->getParent()->getFunctionList().push_back(NewFunc);
52 F->replaceAllUsesWith(NewFunc);
55 for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) {
57 if (F.hasLocalLinkage()) {
58 F.addFnAttr(Attribute::AlwaysInline);
64 ModulePass *llvm::createAMDGPUAlwaysInlinePass() {
65 return new AMDGPUAlwaysInline();