1 //===- SelectionDAGAddressAnalysis.h - DAG Address Analysis -----*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_CODEGEN_SELECTIONDAGADDRESSANALYSIS_H
10 #define LLVM_CODEGEN_SELECTIONDAGADDRESSANALYSIS_H
12 #include "llvm/CodeGen/SelectionDAGNodes.h"
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
24 /// (load (i64 add (i64 copyfromreg %c)
25 /// (i64 signextend (add (i8 load %index)
29 /// (load (i64 add (i64 copyfromreg %c)
30 /// (i64 signextend (i32 add (i32 signextend (i8 load %index))
32 class BaseIndexOffset
{
37 bool IsIndexSignExt
= false;
40 BaseIndexOffset() = default;
41 BaseIndexOffset(SDValue Base
, SDValue Index
, int64_t Offset
,
43 : Base(Base
), Index(Index
), Offset(Offset
),
44 IsIndexSignExt(IsIndexSignExt
) {}
46 SDValue
getBase() { return Base
; }
47 SDValue
getBase() const { return Base
; }
48 SDValue
getIndex() { return Index
; }
49 SDValue
getIndex() const { return Index
; }
51 bool equalBaseIndex(const BaseIndexOffset
&Other
,
52 const SelectionDAG
&DAG
) const {
54 return equalBaseIndex(Other
, DAG
, Off
);
57 bool equalBaseIndex(const BaseIndexOffset
&Other
, const SelectionDAG
&DAG
,
60 /// Parses tree in Ptr for base, index, offset addresses.
61 static BaseIndexOffset
match(const LSBaseSDNode
*N
, const SelectionDAG
&DAG
);
63 void print(raw_ostream
& OS
) const;
67 } // end namespace llvm
69 #endif // LLVM_CODEGEN_SELECTIONDAGADDRESSANALYSIS_H