mirror of
https://github.com/RPCSX/llvm.git
synced 2025-01-30 00:32:53 +00:00
5b50326ddb
Summary: Simply replace usage of aliases to functions with aliasee. This came up when bitcode linking to builtin library and calls to aliases not being resolved. Also made minor improvements to existing test. Reviewers: tstellarAMD, alex-t, vpykhtin Subscribers: arsenm, wdng, rampitec Differential Revision: https://reviews.llvm.org/D24023 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@280221 91177308-0d34-0410-b5e6-96231b3b80d8
76 lines
2.0 KiB
C++
76 lines
2.0 KiB
C++
//===-- 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) {
|
|
std::vector<GlobalAlias*> AliasesToRemove;
|
|
std::vector<Function *> FuncsToClone;
|
|
|
|
for (GlobalAlias &A : M.aliases()) {
|
|
if (Function* F = dyn_cast<Function>(A.getAliasee())) {
|
|
A.replaceAllUsesWith(F);
|
|
AliasesToRemove.push_back(&A);
|
|
}
|
|
}
|
|
|
|
for (GlobalAlias* A : AliasesToRemove) {
|
|
A->eraseFromParent();
|
|
}
|
|
|
|
for (Function &F : M) {
|
|
if (!F.hasLocalLinkage() && !F.isDeclaration() && !F.use_empty() &&
|
|
!F.hasFnAttribute(Attribute::NoInline))
|
|
FuncsToClone.push_back(&F);
|
|
}
|
|
|
|
for (Function *F : FuncsToClone) {
|
|
ValueToValueMapTy VMap;
|
|
Function *NewFunc = CloneFunction(F, VMap);
|
|
NewFunc->setLinkage(GlobalValue::InternalLinkage);
|
|
F->replaceAllUsesWith(NewFunc);
|
|
}
|
|
|
|
for (Function &F : M) {
|
|
if (F.hasLocalLinkage() && !F.hasFnAttribute(Attribute::NoInline)) {
|
|
F.addFnAttr(Attribute::AlwaysInline);
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
ModulePass *llvm::createAMDGPUAlwaysInlinePass() {
|
|
return new AMDGPUAlwaysInline();
|
|
}
|