[AMDGPU] Add GlobalOpt parameter to Always Inliner pass

If set to false it does not remove global aliases. With this parameter
set to false it should be safe to run the pass before link.

Differential Revision: https://reviews.llvm.org/D31489

llvm-svn: 299108
This commit is contained in:
Stanislav Mekhanoshin 2017-03-30 20:16:02 +00:00
parent 346dcaf1fa
commit 89653dfd2a
4 changed files with 14 additions and 7 deletions

View File

@ -98,7 +98,7 @@ extern char &AMDGPUPromoteAllocaID;
Pass *createAMDGPUStructurizeCFGPass();
FunctionPass *createAMDGPUISelDag(TargetMachine &TM,
CodeGenOpt::Level OptLevel);
ModulePass *createAMDGPUAlwaysInlinePass();
ModulePass *createAMDGPUAlwaysInlinePass(bool GlobalOpt = true);
ModulePass *createAMDGPUOpenCLImageTypeLoweringPass();
FunctionPass *createAMDGPUAnnotateUniformValues();

View File

@ -24,8 +24,10 @@ namespace {
class AMDGPUAlwaysInline : public ModulePass {
static char ID;
bool GlobalOpt;
public:
AMDGPUAlwaysInline() : ModulePass(ID) { }
AMDGPUAlwaysInline(bool GlobalOpt) : ModulePass(ID), GlobalOpt(GlobalOpt) { }
bool runOnModule(Module &M) override;
StringRef getPassName() const override { return "AMDGPU Always Inline Pass"; }
};
@ -45,9 +47,11 @@ bool AMDGPUAlwaysInline::runOnModule(Module &M) {
}
}
if (GlobalOpt) {
for (GlobalAlias* A : AliasesToRemove) {
A->eraseFromParent();
}
}
for (Function &F : M) {
if (!F.hasLocalLinkage() && !F.isDeclaration() && !F.use_empty() &&
@ -70,6 +74,6 @@ bool AMDGPUAlwaysInline::runOnModule(Module &M) {
return false;
}
ModulePass *llvm::createAMDGPUAlwaysInlinePass() {
return new AMDGPUAlwaysInline();
ModulePass *llvm::createAMDGPUAlwaysInlinePass(bool GlobalOpt) {
return new AMDGPUAlwaysInline(GlobalOpt);
}

View File

@ -315,7 +315,7 @@ void AMDGPUTargetMachine::adjustPassManager(PassManagerBuilder &Builder) {
PM.add(createGlobalDCEPass());
}
if (EarlyInline)
PM.add(createAMDGPUAlwaysInlinePass());
PM.add(createAMDGPUAlwaysInlinePass(false));
});
Builder.addExtension(

View File

@ -1,5 +1,8 @@
; RUN: opt -mtriple=amdgcn-- -O1 -S -inline-threshold=1 -amdgpu-early-inline-all %s | FileCheck %s
; CHECK: @c_alias
@c_alias = alias i32 (i32), i32 (i32)* @callee
define i32 @callee(i32 %x) {
entry:
%mul1 = mul i32 %x, %x