From 38e381b5a35e54cd9942acd40de2f86fc320c840 Mon Sep 17 00:00:00 2001 From: Stanislav Mekhanoshin Date: Thu, 30 Mar 2017 20:16:02 +0000 Subject: [PATCH] [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 --- lib/Target/AMDGPU/AMDGPU.h | 2 +- lib/Target/AMDGPU/AMDGPUAlwaysInlinePass.cpp | 14 +++++++++----- lib/Target/AMDGPU/AMDGPUTargetMachine.cpp | 2 +- test/CodeGen/AMDGPU/early-inline.ll | 3 +++ 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/lib/Target/AMDGPU/AMDGPU.h b/lib/Target/AMDGPU/AMDGPU.h index 4e2f0af5a20..1acfbf5c5a8 100644 --- a/lib/Target/AMDGPU/AMDGPU.h +++ b/lib/Target/AMDGPU/AMDGPU.h @@ -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(); diff --git a/lib/Target/AMDGPU/AMDGPUAlwaysInlinePass.cpp b/lib/Target/AMDGPU/AMDGPUAlwaysInlinePass.cpp index 067a16a2af7..1d03714874e 100644 --- a/lib/Target/AMDGPU/AMDGPUAlwaysInlinePass.cpp +++ b/lib/Target/AMDGPU/AMDGPUAlwaysInlinePass.cpp @@ -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,8 +47,10 @@ bool AMDGPUAlwaysInline::runOnModule(Module &M) { } } - for (GlobalAlias* A : AliasesToRemove) { - A->eraseFromParent(); + if (GlobalOpt) { + for (GlobalAlias* A : AliasesToRemove) { + A->eraseFromParent(); + } } for (Function &F : M) { @@ -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); } diff --git a/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp b/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp index c5302f7942f..c6c20b81352 100644 --- a/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp +++ b/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp @@ -315,7 +315,7 @@ void AMDGPUTargetMachine::adjustPassManager(PassManagerBuilder &Builder) { PM.add(createGlobalDCEPass()); } if (EarlyInline) - PM.add(createAMDGPUAlwaysInlinePass()); + PM.add(createAMDGPUAlwaysInlinePass(false)); }); Builder.addExtension( diff --git a/test/CodeGen/AMDGPU/early-inline.ll b/test/CodeGen/AMDGPU/early-inline.ll index 8d1d7642d5f..db397d9e11b 100644 --- a/test/CodeGen/AMDGPU/early-inline.ll +++ b/test/CodeGen/AMDGPU/early-inline.ll @@ -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 -- 2.40.0