2014-11-04 03:49:05 +08: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-14 03:08:36 +08:00
|
|
|
std::vector<Function *> FuncsToClone;
|
2014-11-04 03:49:05 +08:00
|
|
|
|
2015-07-14 03:08:36 +08:00
|
|
|
for (Function &F : M) {
|
2015-04-23 01:10:44 +08:00
|
|
|
if (!F.hasLocalLinkage() && !F.isDeclaration() && !F.use_empty() &&
|
|
|
|
!F.hasFnAttribute(Attribute::NoInline))
|
2014-11-04 03:49:05 +08:00
|
|
|
FuncsToClone.push_back(&F);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (Function *F : FuncsToClone) {
|
|
|
|
ValueToValueMapTy VMap;
|
2016-05-11 04:23:24 +08:00
|
|
|
Function *NewFunc = CloneFunction(F, VMap);
|
2014-11-04 03:49:05 +08:00
|
|
|
NewFunc->setLinkage(GlobalValue::InternalLinkage);
|
|
|
|
F->replaceAllUsesWith(NewFunc);
|
|
|
|
}
|
|
|
|
|
2015-07-14 03:08:36 +08:00
|
|
|
for (Function &F : M) {
|
2015-04-23 01:10:44 +08:00
|
|
|
if (F.hasLocalLinkage() && !F.hasFnAttribute(Attribute::NoInline)) {
|
2014-11-04 03:49:05 +08:00
|
|
|
F.addFnAttr(Attribute::AlwaysInline);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ModulePass *llvm::createAMDGPUAlwaysInlinePass() {
|
|
|
|
return new AMDGPUAlwaysInline();
|
|
|
|
}
|