]> git.proxmox.com Git - rustc.git/blame - src/llvm/lib/Target/R600/AMDGPUAlwaysInlinePass.cpp
Imported Upstream version 1.0.0+dfsg1
[rustc.git] / src / llvm / lib / Target / R600 / AMDGPUAlwaysInlinePass.cpp
CommitLineData
85aaf69f
SL
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"
18#include "llvm/Transforms/Utils/Cloning.h"
19
20using namespace llvm;
21
22namespace {
23
24class AMDGPUAlwaysInline : public ModulePass {
25
26 static char ID;
27
28public:
29 AMDGPUAlwaysInline() : ModulePass(ID) { }
30 bool runOnModule(Module &M) override;
31 const char *getPassName() const override { return "AMDGPU Always Inline Pass"; }
32};
33
34} // End anonymous namespace
35
36char AMDGPUAlwaysInline::ID = 0;
37
38bool AMDGPUAlwaysInline::runOnModule(Module &M) {
39
40 std::vector<Function*> FuncsToClone;
41 for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) {
42 Function &F = *I;
43 if (!F.hasLocalLinkage() && !F.isDeclaration() && !F.use_empty())
44 FuncsToClone.push_back(&F);
45 }
46
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);
53 }
54
55 for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) {
56 Function &F = *I;
57 if (F.hasLocalLinkage()) {
58 F.addFnAttr(Attribute::AlwaysInline);
59 }
60 }
61 return false;
62}
63
64ModulePass *llvm::createAMDGPUAlwaysInlinePass() {
65 return new AMDGPUAlwaysInline();
66}