1 /*========================== begin_copyright_notice ============================ 2 3 Copyright (C) 2019-2021 Intel Corporation 4 5 SPDX-License-Identifier: MIT 6 7 ============================= end_copyright_notice ===========================*/ 8 9 #pragma once 10 #include "common/LLVMWarningsPush.hpp" 11 #include "llvm/Pass.h" 12 #include <llvm/IR/InstVisitor.h> 13 #include "common/LLVMWarningsPop.hpp" 14 15 #include "Compiler/CISACodeGen/WIAnalysis.hpp" 16 17 namespace IGC { 18 19 class UniformAssumptions : public llvm::FunctionPass, public llvm::InstVisitor<UniformAssumptions> 20 { 21 22 public: 23 static char ID; // Pass identification 24 25 UniformAssumptions(); 26 27 virtual bool runOnFunction(llvm::Function& F) override; 28 29 void visitCallInst(llvm::CallInst& CI); 30 getAnalysisUsage(llvm::AnalysisUsage & AU) const31 virtual void getAnalysisUsage(llvm::AnalysisUsage& AU) const override { 32 AU.setPreservesCFG(); 33 AU.addRequired<WIAnalysis>(); 34 AU.addRequired<CodeGenContextWrapper>(); 35 } 36 37 private: 38 static const int s_cMaxRecursion = 16; 39 40 bool IsAssumedUniform(llvm::Value* V, int recursionLevel = 0) const; 41 void MakeUniformResourceOperand(llvm::Value* V, llvm::CallInst* CI); 42 void HoistAssumptions(llvm::Function& F); 43 void CollectAssumptions(llvm::Function& F); 44 void OptimizeResourceAccesses(llvm::Function& F); 45 46 bool m_changed = false; 47 WIAnalysis* m_WIAnalysis = nullptr; 48 CodeGenContext* m_pCodeGenContext = nullptr; 49 50 bool m_collectingAssumptions = false; 51 llvm::SmallVector<llvm::GenIntrinsicInst*, 8> m_assumptions; 52 }; 53 void initializeUniformAssumptionsPass(llvm::PassRegistry&); 54 55 } 56 57