Skip to content

Commit 0ab0f81

Browse files
admitricigcbot
authored andcommitted
[Autobackout][FuncReg]Revert of change: 0107b40
Enable loop sinking of loads Enable loop sinking of loads when it's beneficial for register pressure reduction and rework CodeSinking pass CodeSinking pass rework: - Make loop sinking multi-pass to ensure all the beneficial instructions are sinked - Use Uniform and AA information - Add options to force loop sinking for perf tuning - Disable multi-level loop-sinking (across 2 loop bounds) - Remove flag-register pressure reduction heuristics - Add naive load scheduling in local sink - Make heuristic to decide if the instruction is beneficial to sink aware of the data size - Change the code style to LLVM in the most parts of the changed functions
1 parent 3c6d49c commit 0ab0f81

File tree

8 files changed

+230
-900
lines changed

8 files changed

+230
-900
lines changed

IGC/Compiler/CISACodeGen/CodeSinking.cpp

Lines changed: 220 additions & 461 deletions
Large diffs are not rendered by default.

IGC/Compiler/CISACodeGen/CodeSinking.hpp

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,19 @@ See LICENSE.TXT for details.
1414
============================= end_copyright_notice ===========================*/
1515

1616
#pragma once
17-
#include "Compiler/CISACodeGen/WIAnalysis.hpp"
1817
#include "common/LLVMWarningsPush.hpp"
1918
#include <llvm/Analysis/PostDominators.h>
2019
#include <llvm/Analysis/LoopInfo.h>
2120
#include "common/LLVMWarningsPop.hpp"
2221

2322
namespace IGC {
2423

24+
#define CODE_SINKING_MIN_SIZE 32
25+
2526
class CodeSinking : public llvm::FunctionPass {
2627
llvm::DominatorTree* DT;
2728
llvm::PostDominatorTree* PDT;
2829
llvm::LoopInfo* LI;
29-
llvm::AliasAnalysis* AA;
30-
WIAnalysis* WI;
31-
3230
const llvm::DataLayout* DL; // to estimate register pressure
3331
CodeGenContext* CTX;
3432
public:
@@ -40,19 +38,13 @@ namespace IGC {
4038

4139
virtual void getAnalysisUsage(llvm::AnalysisUsage& AU) const override {
4240
AU.setPreservesCFG();
43-
4441
AU.addRequired<llvm::DominatorTreeWrapperPass>();
4542
AU.addRequired<llvm::PostDominatorTreeWrapperPass>();
4643
AU.addRequired<llvm::LoopInfoWrapperPass>();
47-
AU.addRequired<llvm::AAResultsWrapperPass>();
48-
AU.addRequired<WIAnalysis>();
4944
AU.addRequired<CodeGenContextWrapper>();
50-
5145
AU.addPreserved<llvm::DominatorTreeWrapperPass>();
5246
AU.addPreserved<llvm::PostDominatorTreeWrapperPass>();
5347
AU.addPreserved<llvm::LoopInfoWrapperPass>();
54-
AU.addPreserved<llvm::AAResultsWrapperPass>();
55-
AU.addPreservedID(WIAnalysis::ID);
5648
}
5749
private:
5850
bool ProcessBlock(llvm::BasicBlock& blk);
@@ -69,14 +61,12 @@ namespace IGC {
6961
bool isSafeToMove(llvm::Instruction* inst,
7062
bool& reducePressure, bool& hasAliasConcern,
7163
llvm::SmallPtrSetImpl<llvm::Instruction*>& Stores);
72-
bool isSafeToLoopSinkLoad(llvm::Instruction* I, llvm::Loop* Loop, llvm::AliasAnalysis* AA);
73-
bool isAlwaysSinkInstruction(llvm::Instruction* I);
7464

7565
/// local processing
7666
bool LocalSink(llvm::BasicBlock* blk);
7767
/// data members for local-sinking
78-
llvm::SmallPtrSet<llvm::BasicBlock*, 8> LocalBlkSet;
79-
llvm::SmallPtrSet<llvm::Instruction*, 8> LocalInstSet;
68+
llvm::SmallPtrSet<llvm::BasicBlock*, 8> localBlkSet;
69+
llvm::SmallPtrSet<llvm::Instruction*, 8> localInstSet;
8070
/// data members for undo
8171
std::vector<llvm::Instruction*> movedInsts;
8272
std::vector<llvm::Instruction*> undoLocas;
@@ -98,12 +88,6 @@ namespace IGC {
9888
typedef std::pair<llvm::Instruction*, llvm::Instruction*> InstPair;
9989
typedef smallvector<llvm::Instruction*, 4> InstVec;
10090

101-
// memoize all possible stores for every loop that is a candidate for sinking
102-
typedef llvm::SmallVector<llvm::Instruction*, 32> StoresVec;
103-
llvm::DenseMap<llvm::Loop*, StoresVec> MemoizedStoresInLoops;
104-
llvm::SmallPtrSet<llvm::Loop*, 8> BlacklistedLoops;
105-
const StoresVec getAllStoresInLoop(llvm::Loop* L);
106-
10791
void appendIfNotExist(InstPair src, std::vector<InstPair> &instMap)
10892
{
10993
if (std::find(instMap.begin(), instMap.end(), src) == instMap.end())
@@ -139,14 +123,12 @@ namespace IGC {
139123
bool hoistCongruentPhi(llvm::Function& F);
140124

141125
llvm::Loop* findLoopAsPreheader(llvm::BasicBlock& blk);
142-
// move LI back into loop
143-
bool loopSink(llvm::Loop* LoopWithPressure);
126+
// move LI back into loops
127+
bool loopSink(llvm::Loop* LoopWithPressure, bool SinkMultipleLevel);
144128
// pre-condition to sink an instruction into a loop
145-
bool isLoopSinkCandidate(llvm::Instruction* I, llvm::Loop* L);
146-
bool loopSinkInstructions(
147-
llvm::SmallVector<llvm::Instruction*, 64>& SinkCandidates,
148-
llvm::SmallPtrSet<llvm::Instruction*, 32>& LoadChains,
149-
llvm::Loop* L);
129+
bool canLoopSink(llvm::Instruction* I, llvm::Loop* L);
130+
bool LoopSinkInstructions(
131+
llvm::SmallVector<llvm::Instruction*, 64> sinkCandidates, llvm::Loop* L);
150132

151133
// Move referencing DbgValueInst intrinsics calls after defining instructions
152134
void ProcessDbgValueInst(llvm::BasicBlock& blk);

IGC/Compiler/tests/CodeSinking/LoopSinking/adds-sinking-all-uniform.ll

Lines changed: 0 additions & 92 deletions
This file was deleted.

IGC/Compiler/tests/CodeSinking/LoopSinking/adds-sinking-uniform.ll

Lines changed: 0 additions & 90 deletions
This file was deleted.

IGC/Compiler/tests/CodeSinking/LoopSinking/adds-sinking.ll

Lines changed: 0 additions & 87 deletions
This file was deleted.

0 commit comments

Comments
 (0)