File: AliasAnalysis.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 (80 lines) | stat: -rw-r--r-- 2,795 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
/*========================== begin_copyright_notice ============================

Copyright (C) 2021 Intel Corporation

SPDX-License-Identifier: MIT

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

#ifndef IGCLLVM_ANALYSIS_ALIASANALYSIS_H
#define IGCLLVM_ANALYSIS_ALIASANALYSIS_H

#include "llvm/Config/llvm-config.h"
#include "llvm/Analysis/AliasAnalysis.h"
#include "llvm/ADT/Triple.h"
#include "Probe/Assertion.h"

namespace IGCLLVM {
template <typename T>
class AAResultBaseWrapper : public llvm::AAResultBase
#if LLVM_VERSION_MAJOR < 16
                            <T>
#endif // LLVM_VERSION_MAJOR
{
public:
  // On LLVMs <16 this llvm::Instruction parameter is not used, but since
  // LLVM source code operates on 3 parameters on LLVMs below 16 and on 4 patameters on LLVM >=16
  // (Here: llvm\Analysis\AliasAnalysis.h - "return Result.alias(LocA, LocB, AAQI);")
  //
  // Then this approach allows us to:
  // 1) Pass 4th argument without failing compilation on both LLVMs,
  // 2) On LLVM 14 Instruction* is optional - we cannot make it required since LLVM's code expects it to have just 3
  // args,
  //    but it is fine since we will be discarding/ignoring it here anyway,
  // 3) On LLVM 16 Instruction* is required and will fail to build without it (desired behaviour),
  // 3) Is easy to refactor in future - just replace this whole macro with "const llvm::Instruction* CtxI" (update
  // callers and their headers too).
  llvm::AliasResult alias(const llvm::MemoryLocation &LocA, const llvm::MemoryLocation &LocB, llvm::AAQueryInfo &AAQI,
#if LLVM_VERSION_MAJOR < 16
                          const llvm::Instruction *CtxI = nullptr
#else
                          const llvm::Instruction *CtxI
#endif
  ) {
#if LLVM_VERSION_MAJOR >= 16
    return llvm::AAResultBase::alias(LocA, LocB, AAQI, CtxI);
#else
    return llvm::AAResultBase<T>::alias(LocA, LocB, AAQI);
#endif
  }

  bool pointsToConstantMemory(const llvm::MemoryLocation &Loc, llvm::AAQueryInfo &AAQI, bool OrLocal) {
#if LLVM_VERSION_MAJOR < 16
    return llvm::AAResultBase<T>::pointsToConstantMemory(Loc, AAQI, OrLocal);
#else
    return isNoModRef(llvm::AAResultBase::getModRefInfoMask(Loc, AAQI, OrLocal));
#endif
  }
};

#if LLVM_VERSION_MAJOR < 13
using AliasResultEnum = llvm::AliasResult;
#else
using AliasResultEnum = llvm::AliasResult::Kind;
#endif

using SimpleAAQueryInfo =
#if LLVM_VERSION_MAJOR < 14
    llvm::AAQueryInfo;
#else
    llvm::SimpleAAQueryInfo;
#endif

#if LLVM_VERSION_MAJOR >= 16
inline SimpleAAQueryInfo createSimpleAAQueryInfo(llvm::AAResults &AAResults) { return SimpleAAQueryInfo(AAResults); }
#else
inline SimpleAAQueryInfo createSimpleAAQueryInfo(llvm::AAResults &AAResults) { return SimpleAAQueryInfo{}; }
#endif
} // namespace IGCLLVM

#endif