Coverage Report

Created: 2019-02-21 13:17

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/CodeGen/SelectionDAGAddressAnalysis.h
Line
Count
Source (jump to first uncovered line)
1
//===- SelectionDAGAddressAnalysis.h - DAG Address Analysis -----*- C++ -*-===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
9
#ifndef LLVM_CODEGEN_SELECTIONDAGADDRESSANALYSIS_H
10
#define LLVM_CODEGEN_SELECTIONDAGADDRESSANALYSIS_H
11
12
#include "llvm/CodeGen/SelectionDAGNodes.h"
13
#include <cstdint>
14
15
namespace llvm {
16
17
class SelectionDAG;
18
19
/// Helper struct to parse and store a memory address as base + index + offset.
20
/// We ignore sign extensions when it is safe to do so.
21
/// The following two expressions are not equivalent. To differentiate we need
22
/// to store whether there was a sign extension involved in the index
23
/// computation.
24
///  (load (i64 add (i64 copyfromreg %c)
25
///                 (i64 signextend (add (i8 load %index)
26
///                                      (i8 1))))
27
/// vs
28
///
29
/// (load (i64 add (i64 copyfromreg %c)
30
///                (i64 signextend (i32 add (i32 signextend (i8 load %index))
31
///                                         (i32 1)))))
32
class BaseIndexOffset {
33
private:
34
  SDValue Base;
35
  SDValue Index;
36
  int64_t Offset = 0;
37
  bool IsIndexSignExt = false;
38
39
public:
40
8.88M
  BaseIndexOffset() = default;
41
  BaseIndexOffset(SDValue Base, SDValue Index, int64_t Offset,
42
                  bool IsIndexSignExt)
43
      : Base(Base), Index(Index), Offset(Offset),
44
21.2M
        IsIndexSignExt(IsIndexSignExt) {}
45
46
2.45M
  SDValue getBase() { return Base; }
47
40.4M
  SDValue getBase() const { return Base; }
48
0
  SDValue getIndex() { return Index; }
49
5.04M
  SDValue getIndex() const { return Index; }
50
51
  // Returns true if `Other` and `*this` are both some offset from the same base
52
  // pointer. In that case, `Off` is set to the offset between `*this` and
53
  // `Other` (negative if `Other` is before `*this`).
54
  bool equalBaseIndex(const BaseIndexOffset &Other, const SelectionDAG &DAG,
55
                      int64_t &Off) const;
56
57
  bool equalBaseIndex(const BaseIndexOffset &Other,
58
332k
                      const SelectionDAG &DAG) const {
59
332k
    int64_t Off;
60
332k
    return equalBaseIndex(Other, DAG, Off);
61
332k
  }
62
63
  // Returns true if `Other` (with size `OtherSize`) can be proven to be fully
64
  // contained in `*this` (with size `Size`).
65
  bool contains(int64_t Size, const BaseIndexOffset &Other, int64_t OtherSize,
66
                const SelectionDAG &DAG) const;
67
68
  // Returns true `BasePtr0` and `BasePtr1` can be proven to alias/not alias, in
69
  // which case `IsAlias` is set to true/false.
70
  static bool computeAliasing(const BaseIndexOffset &BasePtr0,
71
                              const int64_t NumBytes0,
72
                              const BaseIndexOffset &BasePtr1,
73
                              const int64_t NumBytes1, const SelectionDAG &DAG,
74
                              bool &IsAlias);
75
76
  /// Parses tree in Ptr for base, index, offset addresses.
77
  static BaseIndexOffset match(const LSBaseSDNode *N, const SelectionDAG &DAG);
78
79
  void print(raw_ostream& OS) const;
80
  void dump() const;
81
};
82
83
} // end namespace llvm
84
85
#endif // LLVM_CODEGEN_SELECTIONDAGADDRESSANALYSIS_H