File: BuiltInFuncImport.h

package info (click to toggle)
intel-graphics-compiler2 2.16.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 106,644 kB
  • sloc: cpp: 805,640; lisp: 287,672; ansic: 16,414; python: 3,952; yacc: 2,588; lex: 1,666; pascal: 313; sh: 186; makefile: 35
file content (118 lines) | stat: -rw-r--r-- 4,197 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*========================== begin_copyright_notice ============================

Copyright (C) 2017-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 "common/LLVMWarningsPop.hpp"

#include "AdaptorOCL/CLElfLib/ElfReader.h"

#include <vector>
#include <set>
#include <queue>

namespace IGC {
/// This pass imports built-in functions from source module to destination module.
class BIImport : public llvm::ModulePass {
public:
  // Pass identification, replacement for typeid.
  static char ID;

  /// @brief Constructor
  BIImport();

  /// @brief analyses used
  virtual void getAnalysisUsage(llvm::AnalysisUsage &AU) const override {
    AU.addRequired<MetaDataUtilsWrapper>();
    AU.addRequired<CodeGenContextWrapper>();
  }

  /// @brief Provides name of pass
  virtual llvm::StringRef getPassName() const override { return "BIImport"; }

  /// @brief Main entry point.
  ///        Find all builtins to import, and import them along with callees and globals.
  /// @param M The destination module.
  bool runOnModule(llvm::Module &M) override;

  static void supportOldManglingSchemes(llvm::Module &M);
  static std::unique_ptr<llvm::Module> Construct(llvm::Module &M, CLElfLib::CElfReader *pElfReader, bool hasSizet);

protected:
  // Type used to hold a vector of Functions and augment it during traversal.
  typedef std::vector<llvm::Function *> TFunctionsVec;
  /// @brief Get all the functions called by given function.
  /// @param [IN] pFunc The given function.
  /// @param [OUT] calledFuncs The list of all functions called by pFunc.
  static void GetCalledFunctions(const llvm::Function *pFunc, TFunctionsVec &calledFuncs);

  /// @brief  Remove function bitcasts that sometimes may appear due to the changed in the way
  ///         the BiFs are linked. We can remove this code once llvm implements typeless pointers.
  void removeFunctionBitcasts(llvm::Module &M);

  /// @brief  Initialize values for global flags needed for the built-ins (FlushDenormal).
  ///         Only initializes flags that the built-ins need.
  void InitializeBIFlags(llvm::Module &M);

  /// @brief  Search through all builtin modules for the specified function.
  /// @param  funcName - name of func to search for.
  static llvm::Function *GetBuiltinFunction(llvm::StringRef funcName, llvm::Module *GenericModule);
  /// @brief  Read elf Header file that is constructed by Build Packager and write to a DenseMap.
  static void WriteElfHeaderToMap(llvm::DenseMap<llvm::StringRef, int> &Map, char *pData, size_t dataSize);

  /// @brief Fix SPIR builtins return type
  void fixSPIRFunctionsReturnType(llvm::Module &M);

  /// @brief Fix invalid bitcasts generated by older Clang
  void fixInvalidBitcasts(llvm::Module &M);
};

} // namespace IGC

extern "C" llvm::ModulePass *createBuiltInImportPass();

namespace IGC {
class PreBIImportAnalysis : public llvm::ModulePass {
public:
  // Pass identification, replacement for typeid
  static char ID;

  /// @brief  Constructor
  PreBIImportAnalysis();

  /// @brief  Destructor
  ~PreBIImportAnalysis() {}

  /// @brief  Provides name of pass
  virtual llvm::StringRef getPassName() const override { return "PreBIImportAnalysis"; }

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

  /// @brief  Main entry point.
  /// @param  M The destination module.
  virtual bool runOnModule(llvm::Module &M) override;

  static const llvm::StringRef OCL_GET_GLOBAL_OFFSET;
  static const llvm::StringRef OCL_GET_LOCAL_ID;
  static const llvm::StringRef OCL_GET_GROUP_ID;
  static const llvm::StringRef OCL_GET_SUBGROUP_ID_IGC_SPVIR;
  static const llvm::StringRef OCL_GET_SUBGROUP_ID_KHR_SPVIR;
  static const llvm::StringRef OCL_GET_SUBGROUP_ID;
  static const llvm::StringRef OCL_SUBGROUP_BLOCK_PREFIX;
  static const llvm::StringRef OCL_SUBGROUP_IMAGE_BLOCK_PREFIX;
};

} // namespace IGC