]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/include/llvm/CodeGen/SelectionDAGAddressAnalysis.h
Merge llvm, clang, lld, lldb, compiler-rt and libc++ r306956, and update
[FreeBSD/FreeBSD.git] / contrib / llvm / include / llvm / CodeGen / SelectionDAGAddressAnalysis.h
1 //===-- llvm/CodeGen/SelectionDAGAddressAnalysis.h  ------- DAG Address Analysis
2 //---*- C++ -*-===//
3 //
4 //                     The LLVM Compiler Infrastructure
5 //
6 // This file is distributed under the University of Illinois Open Source
7 // License. See LICENSE.TXT for details.
8 //
9 //===----------------------------------------------------------------------===//
10 //
11
12 #ifndef LLVM_CODEGEN_SELECTIONDAGADDRESSANALYSIS_H
13 #define LLVM_CODEGEN_SELECTIONDAGADDRESSANALYSIS_H
14
15 #include "llvm/CodeGen/ISDOpcodes.h"
16 #include "llvm/CodeGen/SelectionDAG.h"
17 #include "llvm/CodeGen/SelectionDAGNodes.h"
18
19 namespace llvm {
20 /// Helper struct to parse and store a memory address as base + index + offset.
21 /// We ignore sign extensions when it is safe to do so.
22 /// The following two expressions are not equivalent. To differentiate we need
23 /// to store whether there was a sign extension involved in the index
24 /// computation.
25 ///  (load (i64 add (i64 copyfromreg %c)
26 ///                 (i64 signextend (add (i8 load %index)
27 ///                                      (i8 1))))
28 /// vs
29 ///
30 /// (load (i64 add (i64 copyfromreg %c)
31 ///                (i64 signextend (i32 add (i32 signextend (i8 load %index))
32 ///                                         (i32 1)))))
33 class BaseIndexOffset {
34 private:
35   SDValue Base;
36   SDValue Index;
37   int64_t Offset;
38   bool IsIndexSignExt;
39
40 public:
41   BaseIndexOffset() : Offset(0), IsIndexSignExt(false) {}
42
43   BaseIndexOffset(SDValue Base, SDValue Index, int64_t Offset,
44                   bool IsIndexSignExt)
45       : Base(Base), Index(Index), Offset(Offset),
46         IsIndexSignExt(IsIndexSignExt) {}
47
48   SDValue getBase() { return Base; }
49   SDValue getIndex() { return Index; }
50
51   bool equalBaseIndex(BaseIndexOffset &Other, const SelectionDAG &DAG) {
52     int64_t Off;
53     return equalBaseIndex(Other, DAG, Off);
54   }
55
56   bool equalBaseIndex(BaseIndexOffset &Other, const SelectionDAG &DAG,
57                       int64_t &Off);
58
59   /// Parses tree in Ptr for base, index, offset addresses.
60   static BaseIndexOffset match(SDValue Ptr, const SelectionDAG &DAG);
61 };
62 } // namespace llvm
63
64 #endif