File: Function.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 (124 lines) | stat: -rw-r--r-- 3,662 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
119
120
121
122
123
124
/*========================== begin_copyright_notice ============================

Copyright (C) 2018-2021 Intel Corporation

SPDX-License-Identifier: MIT

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

#ifndef IGCLLVM_IR_FUNCTION_H
#define IGCLLVM_IR_FUNCTION_H

#include <iterator>
#include "llvm/IR/Function.h"
#include "llvmWrapper/Support/ModRef.h"
#include "Probe/Assertion.h"

namespace IGCLLVM {

inline llvm::Argument *getArg(const llvm::Function &F, unsigned ArgNo) {
  IGC_ASSERT(F.arg_size() > ArgNo);
  llvm::Argument *Arg = nullptr;

#if LLVM_VERSION_MAJOR < 10
  // similar to lvm::Function::getArg implementation
  auto ArgIt = F.arg_begin();
  std::advance(ArgIt, ArgNo);
  Arg = const_cast<llvm::Argument *>(&*ArgIt);
#else
  Arg = F.getArg(ArgNo);
#endif

  return Arg;
}

inline bool onlyWritesMemory(llvm::Function *F) {
#if LLVM_VERSION_MAJOR < 14
  return F->doesNotReadMemory();
#else
  return F->onlyWritesMemory();
#endif
}

inline void pushBackBasicBlock(llvm::Function *F, llvm::BasicBlock *BB) {
#if LLVM_VERSION_MAJOR < 16
  F->getBasicBlockList().push_back(BB);
#else
  F->insert(F->end(), BB);
#endif
}

inline void splice(llvm::Function *pNewFunc, llvm::Function::iterator it, llvm::Function *pOldFunc) {
#if LLVM_VERSION_MAJOR < 16
  pNewFunc->getBasicBlockList().splice(it, pOldFunc->getBasicBlockList());
#else
  pNewFunc->splice(it, pOldFunc);
#endif
}

inline void splice(llvm::Function *pNewFunc, llvm::Function::iterator it, llvm::Function *pOldFunc,
                   llvm::BasicBlock *BB) {
#if LLVM_VERSION_MAJOR < 16
  pNewFunc->getBasicBlockList().splice(it, pOldFunc->getBasicBlockList(), BB);
#else
  pNewFunc->splice(it, pOldFunc, BB->getIterator());
#endif
}

inline void splice(llvm::Function *pNewFunc, llvm::Function::iterator it, llvm::Function *pOldFunc,
                   llvm::Function::iterator itBegin, llvm::Function::iterator itEnd) {
#if LLVM_VERSION_MAJOR < 16
  pNewFunc->getBasicBlockList().splice(it, pOldFunc->getBasicBlockList(), itBegin, itEnd);
#else
  pNewFunc->splice(it, pOldFunc, itBegin, itEnd);
#endif
}

inline auto rbegin(llvm::Function *pFunc) {
#if LLVM_VERSION_MAJOR < 16
  return pFunc->getBasicBlockList().rbegin();
#else
  return std::make_reverse_iterator(pFunc->end());
#endif
}

inline auto rend(llvm::Function *pFunc) {
#if LLVM_VERSION_MAJOR < 16
  return pFunc->getBasicBlockList().rend();
#else
  return std::make_reverse_iterator(pFunc->begin());
#endif
}

inline void insertBasicBlock(llvm::Function *pFunc, llvm::Function::iterator it, llvm::BasicBlock *BB) {
#if LLVM_VERSION_MAJOR < 16
  pFunc->getBasicBlockList().insert(it, BB);
#else
  pFunc->insert(it, BB);
#endif
}

inline void setMemoryEffects(llvm::Function &F, IGCLLVM::MemoryEffects ME) {
  F.removeFnAttrs(ME.getOverridenAttrKinds());
  F.addFnAttrs(ME.getAsAttrBuilder(F.getContext()));
}

inline void setDoesNotAccessMemory(llvm::Function &F) { setMemoryEffects(F, IGCLLVM::MemoryEffects::none()); }

inline void setOnlyReadsMemory(llvm::Function &F) { setMemoryEffects(F, IGCLLVM::MemoryEffects::readOnly()); }

inline void setOnlyWritesMemory(llvm::Function &F) { setMemoryEffects(F, IGCLLVM::MemoryEffects::writeOnly()); }

inline void setOnlyAccessesArgMemory(llvm::Function &F) { setMemoryEffects(F, IGCLLVM::MemoryEffects::argMemOnly()); }

inline void setOnlyAccessesInaccessibleMemory(llvm::Function &F) {
  setMemoryEffects(F, IGCLLVM::MemoryEffects::inaccessibleMemOnly());
}

inline void setOnlyAccessesInaccessibleMemOrArgMem(llvm::Function &F) {
  setMemoryEffects(F, IGCLLVM::MemoryEffects::inaccessibleOrArgMemOnly());
}

} // namespace IGCLLVM

#endif