LLVM 19.0.0git
SelectionDAGAddressAnalysis.h
Go to the documentation of this file.
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
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)))))
33private:
36 std::optional<int64_t> Offset;
37 bool IsIndexSignExt = false;
38
39public:
40 BaseIndexOffset() = default;
44 bool IsIndexSignExt)
47
48 SDValue getBase() { return Base; }
49 SDValue getBase() const { return Base; }
50 SDValue getIndex() { return Index; }
51 SDValue getIndex() const { return Index; }
52 void addToOffset(int64_t VectorOff) {
53 Offset = Offset.value_or(0) + VectorOff;
54 }
55 bool hasValidOffset() const { return Offset.has_value(); }
56 int64_t getOffset() const { return *Offset; }
57
58 // Returns true if `Other` and `*this` are both some offset from the same base
59 // pointer. In that case, `Off` is set to the offset between `*this` and
60 // `Other` (negative if `Other` is before `*this`).
61 bool equalBaseIndex(const BaseIndexOffset &Other, const SelectionDAG &DAG,
62 int64_t &Off) const;
63
65 const SelectionDAG &DAG) const {
66 int64_t Off;
67 return equalBaseIndex(Other, DAG, Off);
68 }
69
70 // Returns true if `Other` (with size `OtherSize`) can be proven to be fully
71 // contained in `*this` (with size `Size`).
72 bool contains(const SelectionDAG &DAG, int64_t BitSize,
73 const BaseIndexOffset &Other, int64_t OtherBitSize,
74 int64_t &BitOffset) const;
75
76 bool contains(const SelectionDAG &DAG, int64_t BitSize,
77 const BaseIndexOffset &Other, int64_t OtherBitSize) const {
78 int64_t BitOffset;
79 return contains(DAG, BitSize, Other, OtherBitSize, BitOffset);
80 }
81
82 // Returns true `Op0` and `Op1` can be proven to alias/not alias, in
83 // which case `IsAlias` is set to true/false.
84 static bool computeAliasing(const SDNode *Op0,
85 const std::optional<int64_t> NumBytes0,
86 const SDNode *Op1,
87 const std::optional<int64_t> NumBytes1,
88 const SelectionDAG &DAG, bool &IsAlias);
89
90 /// Parses tree in N for base, index, offset addresses.
91 static BaseIndexOffset match(const SDNode *N, const SelectionDAG &DAG);
92
93 void print(raw_ostream& OS) const;
94 void dump() const;
95};
96
97} // end namespace llvm
98
99#endif // LLVM_CODEGEN_SELECTIONDAGADDRESSANALYSIS_H
raw_pwrite_stream & OS
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
Definition: Value.cpp:469
void addToOffset(int64_t VectorOff)
BaseIndexOffset(SDValue Base, SDValue Index, int64_t Offset, bool IsIndexSignExt)
bool equalBaseIndex(const BaseIndexOffset &Other, const SelectionDAG &DAG) const
bool contains(const SelectionDAG &DAG, int64_t BitSize, const BaseIndexOffset &Other, int64_t OtherBitSize) const
BaseIndexOffset(SDValue Base, SDValue Index, bool IsIndexSignExt)
bool equalBaseIndex(const BaseIndexOffset &Other, const SelectionDAG &DAG, int64_t &Off) const
Represents one node in the SelectionDAG.
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation.
This is used to represent a portion of an LLVM function in a low-level Data Dependence DAG representa...
Definition: SelectionDAG.h:225
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
bool match(Val *V, const Pattern &P)
Definition: PatternMatch.h:49
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
Printable print(const GCNRegPressure &RP, const GCNSubtarget *ST=nullptr)
@ Other
Any other memory.
#define N
Helper struct to store a base, index and offset that forms an address.
Definition: LoadStoreOpt.h:38