2014-11-03 19:49:05 +00:00
|
|
|
//===-- AMDGPUAlwaysInlinePass.cpp - Promote Allocas ----------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
/// \file
|
|
|
|
/// This pass marks all internal functions as always_inline and creates
|
|
|
|
/// duplicates of all other functions a marks the duplicates as always_inline.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "AMDGPU.h"
|
|
|
|
#include "llvm/IR/Module.h"
|
|
|
|
#include "llvm/Transforms/Utils/Cloning.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
class AMDGPUAlwaysInline : public ModulePass {
|
|
|
|
static char ID;
|
|
|
|
|
|
|
|
public:
|
|
|
|
AMDGPUAlwaysInline() : ModulePass(ID) { }
|
|
|
|
bool runOnModule(Module &M) override;
|
|
|
|
const char *getPassName() const override { return "AMDGPU Always Inline Pass"; }
|
|
|
|
};
|
|
|
|
|
|
|
|
} // End anonymous namespace
|
|
|
|
|
|
|
|
char AMDGPUAlwaysInline::ID = 0;
|
|
|
|
|
|
|
|
bool AMDGPUAlwaysInline::runOnModule(Module &M) {
|
2015-07-13 19:08:36 +00:00
|
|
|
std::vector<Function *> FuncsToClone;
|
2014-11-03 19:49:05 +00:00
|
|
|
|
2015-07-13 19:08:36 +00:00
|
|
|
for (Function &F : M) {
|
2015-04-22 17:10:44 +00:00
|
|
|
if (!F.hasLocalLinkage() && !F.isDeclaration() && !F.use_empty() &&
|
|
|
|
!F.hasFnAttribute(Attribute::NoInline))
|
2014-11-03 19:49:05 +00:00
|
|
|
FuncsToClone.push_back(&F);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (Function *F : FuncsToClone) {
|
|
|
|
ValueToValueMapTy VMap;
|
|
|
|
Function *NewFunc = CloneFunction(F, VMap, false);
|
|
|
|
NewFunc->setLinkage(GlobalValue::InternalLinkage);
|
2015-07-13 19:08:36 +00:00
|
|
|
M.getFunctionList().push_back(NewFunc);
|
2014-11-03 19:49:05 +00:00
|
|
|
F->replaceAllUsesWith(NewFunc);
|
|
|
|
}
|
|
|
|
|
2015-07-13 19:08:36 +00:00
|
|
|
for (Function &F : M) {
|
2015-04-22 17:10:44 +00:00
|
|
|
if (F.hasLocalLinkage() && !F.hasFnAttribute(Attribute::NoInline)) {
|
2014-11-03 19:49:05 +00:00
|
|
|
F.addFnAttr(Attribute::AlwaysInline);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ModulePass *llvm::createAMDGPUAlwaysInlinePass() {
|
|
|
|
return new AMDGPUAlwaysInline();
|
|
|
|
}
|