[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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@299108 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Stanislav Mekhanoshin 2017-03-30 20:16:02 +00:00
parent 70eccef966
commit 38e381b5a3
4 changed files with 14 additions and 7 deletions

View File

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

View File

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

View File

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

View File

@ -1,5 +1,8 @@
; RUN: opt -mtriple=amdgcn-- -O1 -S -inline-threshold=1 -amdgpu-early-inline-all %s | FileCheck %s ; 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) { define i32 @callee(i32 %x) {
entry: entry:
%mul1 = mul i32 %x, %x %mul1 = mul i32 %x, %x