LLVM  3.7.0
AMDGPUAlwaysInlinePass.cpp
Go to the documentation of this file.
1 //===-- AMDGPUAlwaysInlinePass.cpp - Promote Allocas ----------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 /// \file
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.
13 //
14 //===----------------------------------------------------------------------===//
15 
16 #include "AMDGPU.h"
17 #include "llvm/IR/Module.h"
19 
20 using namespace llvm;
21 
22 namespace {
23 
24 class AMDGPUAlwaysInline : public ModulePass {
25  static char ID;
26 
27 public:
28  AMDGPUAlwaysInline() : ModulePass(ID) { }
29  bool runOnModule(Module &M) override;
30  const char *getPassName() const override { return "AMDGPU Always Inline Pass"; }
31 };
32 
33 } // End anonymous namespace
34 
35 char AMDGPUAlwaysInline::ID = 0;
36 
37 bool AMDGPUAlwaysInline::runOnModule(Module &M) {
38  std::vector<Function *> FuncsToClone;
39 
40  for (Function &F : M) {
41  if (!F.hasLocalLinkage() && !F.isDeclaration() && !F.use_empty() &&
42  !F.hasFnAttribute(Attribute::NoInline))
43  FuncsToClone.push_back(&F);
44  }
45 
46  for (Function *F : FuncsToClone) {
47  ValueToValueMapTy VMap;
48  Function *NewFunc = CloneFunction(F, VMap, false);
50  M.getFunctionList().push_back(NewFunc);
51  F->replaceAllUsesWith(NewFunc);
52  }
53 
54  for (Function &F : M) {
55  if (F.hasLocalLinkage() && !F.hasFnAttribute(Attribute::NoInline)) {
56  F.addFnAttr(Attribute::AlwaysInline);
57  }
58  }
59  return false;
60 }
61 
63  return new AMDGPUAlwaysInline();
64 }
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:114
F(f)
ModulePass * createAMDGPUAlwaysInlinePass()
Module.h This file contains the declarations for the Module class.
void setLinkage(LinkageTypes LT)
Definition: GlobalValue.h:284
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
Definition: Pass.h:236
Rename collisions when linking (static functions).
Definition: GlobalValue.h:47
Function * CloneFunction(const Function *F, ValueToValueMapTy &VMap, bool ModuleLevelChanges, ClonedCodeInfo *CodeInfo=nullptr)
CloneFunction - Return a copy of the specified function, but without embedding the function into anot...