File: ResourceLoopAnalysis.h

package info (click to toggle)
intel-graphics-compiler2 2.22.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 107,676 kB
  • sloc: cpp: 809,645; lisp: 288,070; ansic: 16,397; python: 4,010; yacc: 2,588; lex: 1,666; pascal: 314; sh: 186; makefile: 38
file content (88 lines) | stat: -rw-r--r-- 2,632 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*========================== begin_copyright_notice ============================

Copyright (C) 2022 Intel Corporation

SPDX-License-Identifier: MIT

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

#pragma once
#include "Compiler/CISACodeGen/WIAnalysis.hpp"
#include "Compiler/CISACodeGen/CVariable.hpp"
#include "Compiler/CodeGenContextWrapper.hpp"

#include "common/LLVMWarningsPush.hpp"
#include "llvm/ADT/DenseMap.h"
#include <llvm/IR/Function.h>
#include <llvm/IR/Instructions.h>
#include "llvm/Pass.h"
#include "llvm/Support/raw_ostream.h"
#include "common/LLVMWarningsPop.hpp"

namespace IGC {

// figure out when to start a loop for lane-varying resource access,
// and when to end such loop. So we can wrap around multiple lane-varying
// resource access with single loop to hide latency and save instructions
class ResourceLoopAnalysis : public llvm::FunctionPass {
public:
  enum {
    MarkResourceLoopOutside = 0,
    MarkResourceLoopStart = 1,
    MarkResourceLoopInside = 2,
    MarkResourceLoopEnd = 4,
  };

  static char ID;

  ResourceLoopAnalysis();
  ~ResourceLoopAnalysis() {}

  virtual llvm::StringRef getPassName() const override { return "Resource Loop Analysis"; }

  virtual bool runOnFunction(llvm::Function &F) override;

  virtual void getAnalysisUsage(llvm::AnalysisUsage &AU) const override {
    AU.setPreservesAll();
    AU.addRequired<WIAnalysis>();
    AU.addRequired<CodeGenContextWrapper>();
  }

  void SaveStateLoopStart(ResourceDescriptor res, SamplerDescriptor samp, CVariable *f, unsigned l) {
    resource = res;
    sampler = samp;
    flag = f;
    label = l;
  }
  void ClearStateLoopEnd() {
    resource.m_resource = nullptr;
    sampler.m_sampler = nullptr;
    flag = nullptr;
    label = 0;
  }
  ResourceDescriptor &GetResourceLoopResource() { return resource; }
  SamplerDescriptor &GetResourceLoopSampler() { return sampler; }
  unsigned GetResourceLoopLabel() { return label; }
  CVariable *GetResourceLoopFlag() { return flag; }

  unsigned GetResourceLoopMarker(llvm::Instruction *inst) {
    if (LoopMap.find(inst) == LoopMap.end())
      return MarkResourceLoopOutside;
    return LoopMap[inst];
  }
  ///
  void printResourceLoops(llvm::raw_ostream &OS, llvm::Function *F = nullptr) const;

private:
  CodeGenContext *CTX = nullptr;
  // analysis result
  llvm::DenseMap<llvm::Instruction *, unsigned> LoopMap;
  // recording state for loop emission
  ResourceDescriptor resource;
  SamplerDescriptor sampler;
  CVariable *flag = nullptr;
  uint32_t label = 0;
};

llvm::FunctionPass *createResourceLoopAnalysisPass();
} // namespace IGC