Skip to content

Commit ee02884

Browse files
grey-eminencesys_zuul
authored and
sys_zuul
committedMay 8, 2020
Add AnnotateUniformAllocas pass - third attempt, had issues with CFG Simplification.
Change-Id: I85ddfa3a7db4b5b2f3d393cb18fa9febc2641bcf
1 parent 9a23d30 commit ee02884

File tree

6 files changed

+154
-15
lines changed

6 files changed

+154
-15
lines changed
 

Diff for: ‎IGC/Compiler/CISACodeGen/AnnotateUniformAllocas.cpp

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*===================== begin_copyright_notice ==================================
2+
3+
Copyright (c) 2017 Intel Corporation
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a
6+
copy of this software and associated documentation files (the
7+
"Software"), to deal in the Software without restriction, including
8+
without limitation the rights to use, copy, modify, merge, publish,
9+
distribute, sublicense, and/or sell copies of the Software, and to
10+
permit persons to whom the Software is furnished to do so, subject to
11+
the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included
14+
in all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23+
24+
25+
======================= end_copyright_notice ==================================*/
26+
27+
#include "AnnotateUniformAllocas.h"
28+
#include "Compiler/IGCPassSupport.h"
29+
#include "IGCIRBuilder.h"
30+
#include "common/LLVMWarningsPush.hpp"
31+
#include <llvm/IR/Function.h>
32+
#include "common/LLVMWarningsPop.hpp"
33+
34+
using namespace llvm;
35+
using namespace IGC;
36+
37+
#define PASS_FLAG "annotate_uniform_allocas"
38+
#define PASS_DESCRIPTION "Annotate uniform allocas"
39+
#define PASS_CFG_ONLY false
40+
#define PASS_ANALYSIS false
41+
IGC_INITIALIZE_PASS_BEGIN(AnnotateUniformAllocas, PASS_FLAG, PASS_DESCRIPTION, PASS_CFG_ONLY, PASS_ANALYSIS)
42+
IGC_INITIALIZE_PASS_END(AnnotateUniformAllocas, PASS_FLAG, PASS_DESCRIPTION, PASS_CFG_ONLY, PASS_ANALYSIS)
43+
44+
namespace IGC
45+
{
46+
char AnnotateUniformAllocas::ID = 0;
47+
48+
AnnotateUniformAllocas::AnnotateUniformAllocas() : FunctionPass(ID)
49+
{
50+
initializeAnnotateUniformAllocasPass(*PassRegistry::getPassRegistry());
51+
}
52+
53+
llvm::FunctionPass* createAnnotateUniformAllocasPass()
54+
{
55+
return new AnnotateUniformAllocas();
56+
}
57+
58+
bool AnnotateUniformAllocas::runOnFunction(Function& F)
59+
{
60+
WI = &getAnalysis<WIAnalysis>();
61+
IGC_ASSERT(WI != nullptr);
62+
visit(F);
63+
return m_changed;
64+
}
65+
66+
void AnnotateUniformAllocas::visitAllocaInst(AllocaInst& I)
67+
{
68+
bool isUniformAlloca = WI->whichDepend(&I) == WIAnalysis::UNIFORM;
69+
if (isUniformAlloca)
70+
{
71+
IRBuilder<> builder(&I);
72+
MDNode* node = MDNode::get(I.getContext(), ConstantAsMetadata::get(builder.getInt1(true)));
73+
I.setMetadata("uniform", node);
74+
m_changed = true;
75+
}
76+
}
77+
}

Diff for: ‎IGC/Compiler/CISACodeGen/AnnotateUniformAllocas.h

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*===================== begin_copyright_notice ==================================
2+
3+
Copyright (c) 2017 Intel Corporation
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a
6+
copy of this software and associated documentation files (the
7+
"Software"), to deal in the Software without restriction, including
8+
without limitation the rights to use, copy, modify, merge, publish,
9+
distribute, sublicense, and/or sell copies of the Software, and to
10+
permit persons to whom the Software is furnished to do so, subject to
11+
the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included
14+
in all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23+
24+
25+
======================= end_copyright_notice ==================================*/
26+
#pragma once
27+
28+
#include "Compiler/CISACodeGen/WIAnalysis.hpp"
29+
#include "common/LLVMWarningsPush.hpp"
30+
#include <llvm/Pass.h>
31+
#include <llvm/IR/InstVisitor.h>
32+
#include "common/LLVMWarningsPop.hpp"
33+
34+
namespace IGC
35+
{
36+
llvm::FunctionPass* createAnnotateUniformAllocasPass();
37+
38+
class AnnotateUniformAllocas : public llvm::FunctionPass, public llvm::InstVisitor<AnnotateUniformAllocas>
39+
{
40+
public:
41+
static char ID;
42+
43+
AnnotateUniformAllocas();
44+
45+
virtual llvm::StringRef getPassName() const override
46+
{
47+
return "Annotate Uniform Allocas Pass";
48+
}
49+
50+
virtual void getAnalysisUsage(llvm::AnalysisUsage& AU) const override
51+
{
52+
AU.addRequired<WIAnalysis>();
53+
AU.setPreservesCFG();
54+
}
55+
56+
virtual bool runOnFunction(llvm::Function& F) override;
57+
void visitAllocaInst(llvm::AllocaInst& I);
58+
59+
private:
60+
WIAnalysis* WI;
61+
bool m_changed = false;
62+
};
63+
} // namespace IGC

Diff for: ‎IGC/Compiler/CISACodeGen/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ include_directories("${CMAKE_CURRENT_SOURCE_DIR}")
44
set(IGC_BUILD__SRC__CISACodeGen_Common
55
"${CMAKE_CURRENT_SOURCE_DIR}/AdvCodeMotion.cpp"
66
"${CMAKE_CURRENT_SOURCE_DIR}/AdvMemOpt.cpp"
7+
"${CMAKE_CURRENT_SOURCE_DIR}/AnnotateUniformAllocas.cpp"
78
"${CMAKE_CURRENT_SOURCE_DIR}/BlockCoalescing.cpp"
89
"${CMAKE_CURRENT_SOURCE_DIR}/CheckInstrTypes.cpp"
910
"${CMAKE_CURRENT_SOURCE_DIR}/CISABuilder.cpp"
@@ -94,6 +95,7 @@ set(IGC_BUILD__SRC__Compiler_CISACodeGen
9495
set(IGC_BUILD__HDR__CISACodeGen_Common
9596
"${CMAKE_CURRENT_SOURCE_DIR}/AdvCodeMotion.h"
9697
"${CMAKE_CURRENT_SOURCE_DIR}/AdvMemOpt.h"
98+
"${CMAKE_CURRENT_SOURCE_DIR}/AnnotateUniformAllocas.h"
9799
"${CMAKE_CURRENT_SOURCE_DIR}/BlockCoalescing.hpp"
98100
"${CMAKE_CURRENT_SOURCE_DIR}/CheckInstrTypes.hpp"
99101
"${CMAKE_CURRENT_SOURCE_DIR}/CISABuilder.hpp"

Diff for: ‎IGC/Compiler/CISACodeGen/LowerGEPForPrivMem.cpp

+1-10
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2727
#include "Compiler/CodeGenContextWrapper.hpp"
2828
#include "Compiler/MetaDataUtilsWrapper.h"
2929
#include "Compiler/CISACodeGen/RegisterPressureEstimate.hpp"
30-
#include "Compiler/CISACodeGen/WIAnalysis.hpp"
3130
#include "common/LLVMUtils.h"
3231
#include "Compiler/CISACodeGen/LowerGEPForPrivMem.hpp"
3332
#include "Compiler/CodeGenPublic.h"
@@ -70,7 +69,6 @@ namespace IGC {
7069
AU.addRequired<RegisterPressureEstimate>();
7170
AU.addRequired<MetaDataUtilsWrapper>();
7271
AU.addRequired<CodeGenContextWrapper>();
73-
AU.addRequired<WIAnalysis>();
7472
AU.addRequired<DominatorTreeWrapperPass>();
7573
AU.setPreservesCFG();
7674
}
@@ -252,14 +250,7 @@ bool LowerGEPForPrivMem::IsNativeType(Type* type)
252250

253251
bool LowerGEPForPrivMem::CheckIfAllocaPromotable(llvm::AllocaInst* pAlloca)
254252
{
255-
auto WI = &getAnalysis<WIAnalysis>();
256-
bool isUniformAlloca = WI->whichDepend(pAlloca) == WIAnalysis::UNIFORM;
257-
if (isUniformAlloca)
258-
{
259-
IRBuilder<> builder(pAlloca);
260-
MDNode* node = MDNode::get(pAlloca->getContext(), ConstantAsMetadata::get(builder.getInt1(true)));
261-
pAlloca->setMetadata("uniform", node);
262-
}
253+
bool isUniformAlloca = pAlloca->getMetadata("uniform") != nullptr;
263254
unsigned int allocaSize = extractAllocaSize(pAlloca);
264255
unsigned int allowedAllocaSizeInBytes = MAX_ALLOCA_PROMOTE_GRF_NUM * 4;
265256

Diff for: ‎IGC/Compiler/CISACodeGen/ShaderCodeGen.cpp

+10-5
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
161161
#include "Compiler/Optimizer/IGCInstCombiner/IGCInstructionCombining.hpp"
162162
#include "DebugInfo.hpp"
163163
#include "Compiler/CISACodeGen/HalfPromotion.h"
164+
#include "Compiler/CISACodeGen/AnnotateUniformAllocas.h"
164165
#include "Probe/Assertion.h"
165166

166167
/***********************************************************************************
@@ -460,13 +461,17 @@ namespace IGC
460461
// Resolve the Private memory to register pass
461462
if (!isOptDisabled)
462463
{
463-
if (IGC_IS_FLAG_DISABLED(DisablePromotePrivMem) &&
464-
ctx.m_instrTypes.hasNonPrimitiveAlloca &&
465-
ctx.m_retryManager.AllowPromotePrivateMemory())
464+
if (ctx.m_instrTypes.hasNonPrimitiveAlloca)
466465
{
467466
mpm.add(createBreakCriticalEdgesPass());
468-
mpm.add(createPromotePrivateArrayToReg());
469-
mpm.add(createCFGSimplificationPass());
467+
mpm.add(createAnnotateUniformAllocasPass());
468+
469+
if (IGC_IS_FLAG_DISABLED(DisablePromotePrivMem) &&
470+
ctx.m_retryManager.AllowPromotePrivateMemory())
471+
{
472+
mpm.add(createPromotePrivateArrayToReg());
473+
mpm.add(createCFGSimplificationPass());
474+
}
470475
}
471476
mpm.add(createPromoteMemoryToRegisterPass());
472477
}

Diff for: ‎IGC/Compiler/InitializePasses.h

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ namespace llvm {
3232
// The following declarations are placed according to alphabetic order for simplicity
3333
void initializeAddImplicitArgsPass(llvm::PassRegistry&);
3434
void initializeAddressSpaceAliasAnalysisPass(llvm::PassRegistry&);
35+
void initializeAnnotateUniformAllocasPass(llvm::PassRegistry&);
3536
void initializeAggregateArgumentsAnalysisPass(llvm::PassRegistry&);
3637
void initializeAlignmentAnalysisPass(llvm::PassRegistry&);
3738
void initializePreBIImportAnalysisPass(llvm::PassRegistry&);

0 commit comments

Comments
 (0)
Please sign in to comment.