blob: f168b846fdaf4232690805a74186e359f2fe77b7 [file] [log] [blame]
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001//===- SelectionDAGAddressAnalysis.h - DAG Address Analysis -----*- C++ -*-===//
2//
Andrew Walbran16937d02019-10-22 13:54:20 +01003// 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
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01006//
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
15namespace llvm {
16
17class 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)))))
32class BaseIndexOffset {
33private:
34 SDValue Base;
35 SDValue Index;
36 int64_t Offset = 0;
37 bool IsIndexSignExt = false;
38
39public:
40 BaseIndexOffset() = default;
41 BaseIndexOffset(SDValue Base, SDValue Index, int64_t Offset,
42 bool IsIndexSignExt)
43 : Base(Base), Index(Index), Offset(Offset),
44 IsIndexSignExt(IsIndexSignExt) {}
45
46 SDValue getBase() { return Base; }
Andrew Walbran16937d02019-10-22 13:54:20 +010047 SDValue getBase() const { return Base; }
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010048 SDValue getIndex() { return Index; }
Andrew Walbran16937d02019-10-22 13:54:20 +010049 SDValue getIndex() const { return Index; }
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010050
Andrew Walbran16937d02019-10-22 13:54:20 +010051 bool equalBaseIndex(const BaseIndexOffset &Other,
52 const SelectionDAG &DAG) const {
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010053 int64_t Off;
54 return equalBaseIndex(Other, DAG, Off);
55 }
56
Andrew Walbran16937d02019-10-22 13:54:20 +010057 bool equalBaseIndex(const BaseIndexOffset &Other, const SelectionDAG &DAG,
58 int64_t &Off) const;
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010059
60 /// Parses tree in Ptr for base, index, offset addresses.
Andrew Walbran16937d02019-10-22 13:54:20 +010061 static BaseIndexOffset match(const LSBaseSDNode *N, const SelectionDAG &DAG);
62
63 void print(raw_ostream& OS) const;
64 void dump() const;
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010065};
66
67} // end namespace llvm
68
69#endif // LLVM_CODEGEN_SELECTIONDAGADDRESSANALYSIS_H