File: CodeAssumption.hpp

package info (click to toggle)
intel-graphics-compiler2 2.20.5-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 107,552 kB
  • sloc: cpp: 807,012; lisp: 287,936; ansic: 16,397; python: 4,010; yacc: 2,588; lex: 1,666; pascal: 313; sh: 186; makefile: 37
file content (70 lines) | stat: -rw-r--r-- 2,093 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*========================== begin_copyright_notice ============================

Copyright (C) 2018-2021 Intel Corporation

SPDX-License-Identifier: MIT

============================= end_copyright_notice ===========================*/

#pragma once
#include "Compiler/MetaDataUtilsWrapper.h"
#include "Compiler/CodeGenContextWrapper.hpp"

#include "common/LLVMWarningsPush.hpp"
#include <llvm/Pass.h>
#include "llvm/IR/Instructions.h"
#include <llvm/IR/Function.h>
#include "llvm/IR/Module.h"
#include <llvm/Analysis/AssumptionCache.h>
#include "common/LLVMWarningsPop.hpp"

namespace IGC {
// forward decl
namespace IGCMD {
class MetaDataUtils;
}

//
// CodeAssumption inserts llvm.assume to make sure some of code's
// attributes holds. For example, OCL's get_global_id() will be
// always positive, so we insert llvm.assume for its return value.
// This llvm.assume will help value tracking (verifying whether an
// value is positive or not). Currently, value tracking is used
// by StatelessToStateful optimization.
//
class CodeAssumption : public llvm::ModulePass {
public:
  static char ID;

  CodeAssumption() : ModulePass(ID), m_changed(false) {}

  llvm::StringRef getPassName() const override { return "CodeAssumption"; }

  bool runOnModule(llvm::Module &) override;

  void getAnalysisUsage(llvm::AnalysisUsage &AU) const override {
    AU.setPreservesCFG();
    AU.addRequired<MetaDataUtilsWrapper>();
    AU.addRequired<CodeGenContextWrapper>();
  }

  // APIs used directly
  static bool addAssumption(llvm::Function *F, llvm::AssumptionCache *AC);

  static bool IsSGIdUniform(IGCMD::MetaDataUtils *pMDU, ModuleMetaData *modMD, llvm::Function *F);

private:
  bool m_changed{};

  IGCMD::MetaDataUtils *m_pMDUtils = nullptr;

  // Simple change to help uniform analysis (later).
  void uniformHelper(llvm::Module *M);

  // Add llvm.assume to assist other optimization such statelessToStateful
  void addAssumption(llvm::Module *M);

  // helpers
  static bool isPositiveIndVar(llvm::PHINode *PN, const llvm::DataLayout *DL, llvm::AssumptionCache *AC);
};
} // namespace IGC