1 /*========================== begin_copyright_notice ============================
2 
3 Copyright (C) 2017-2021 Intel Corporation
4 
5 SPDX-License-Identifier: MIT
6 
7 ============================= end_copyright_notice ===========================*/
8 
9 #pragma once
10 
11 #include "common/LLVMWarningsPush.hpp"
12 #include "llvm/Pass.h"
13 #include "llvm/Analysis/LoopInfo.h"
14 #include "common/LLVMWarningsPop.hpp"
15 
16 #include "Compiler/CodeGenPublic.h"
17 #include "Compiler/CISACodeGen/WIAnalysis.hpp"
18 
19 namespace IGC
20 {
21     namespace IGCMD {
22         class MetaDataUtils;
23     }
24 
25     /// @brief  This pass implements a heuristic to determine whether SIMD32 is profitable.
26     class Simd32ProfitabilityAnalysis : public llvm::FunctionPass
27     {
28     public:
29         static char ID;
30 
31         Simd32ProfitabilityAnalysis();
32 
~Simd32ProfitabilityAnalysis()33         ~Simd32ProfitabilityAnalysis() {}
34 
getPassName() const35         virtual llvm::StringRef getPassName() const override
36         {
37             return "Simd32Profitability";
38         }
39 
40         virtual bool runOnFunction(llvm::Function& F) override;
41 
getAnalysisUsage(llvm::AnalysisUsage & AU) const42         virtual void getAnalysisUsage(llvm::AnalysisUsage& AU) const override
43         {
44             AU.setPreservesAll();
45             AU.addRequired<WIAnalysis>();
46             AU.addRequired<llvm::LoopInfoWrapperPass>();
47             AU.addRequired<llvm::PostDominatorTreeWrapperPass>();
48             AU.addRequired<MetaDataUtilsWrapper>();
49             AU.addRequired<CodeGenContextWrapper>();
50         }
51 
isSimd32Profitable() const52         bool isSimd32Profitable() const { return m_isSimd32Profitable; }
isSimd16Profitable() const53         bool isSimd16Profitable() const { return m_isSimd16Profitable; }
54 
55     private:
56         llvm::Function* F;
57         llvm::PostDominatorTree* PDT;
58         llvm::LoopInfo* LI;
59         IGCMD::MetaDataUtils* pMdUtils;
60         WIAnalysis* WI;
61         bool m_isSimd32Profitable;
62         bool m_isSimd16Profitable;
63 
64         unsigned getLoopCyclomaticComplexity();
65         bool checkSimd32Profitable(CodeGenContext*);
66         bool checkSimd16Profitable(CodeGenContext*);
67 
68         unsigned estimateLoopCount(llvm::Loop* L);
69         unsigned estimateLoopCount_CASE1(llvm::Loop* L);
70         unsigned estimateLoopCount_CASE2(llvm::Loop* L);
71 
72         bool isSelectBasedOnGlobalIdX(llvm::Value*);
73 
74         bool checkPSSimd32Profitable();
75     };
76 
77 } // namespace IGC
78