Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:35

0001 //===- SelectionDAGAddressAnalysis.h - DAG Address Analysis -----*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLVM_CODEGEN_SELECTIONDAGADDRESSANALYSIS_H
0010 #define LLVM_CODEGEN_SELECTIONDAGADDRESSANALYSIS_H
0011 
0012 #include "llvm/Analysis/MemoryLocation.h"
0013 #include "llvm/CodeGen/SelectionDAGNodes.h"
0014 #include <cstdint>
0015 
0016 namespace llvm {
0017 
0018 class SelectionDAG;
0019 
0020 /// Helper struct to parse and store a memory address as base + index + offset.
0021 /// We ignore sign extensions when it is safe to do so.
0022 /// The following two expressions are not equivalent. To differentiate we need
0023 /// to store whether there was a sign extension involved in the index
0024 /// computation.
0025 ///  (load (i64 add (i64 copyfromreg %c)
0026 ///                 (i64 signextend (add (i8 load %index)
0027 ///                                      (i8 1))))
0028 /// vs
0029 ///
0030 /// (load (i64 add (i64 copyfromreg %c)
0031 ///                (i64 signextend (i32 add (i32 signextend (i8 load %index))
0032 ///                                         (i32 1)))))
0033 class BaseIndexOffset {
0034 private:
0035   SDValue Base;
0036   SDValue Index;
0037   std::optional<int64_t> Offset;
0038   bool IsIndexSignExt = false;
0039 
0040 public:
0041   BaseIndexOffset() = default;
0042   BaseIndexOffset(SDValue Base, SDValue Index, bool IsIndexSignExt)
0043       : Base(Base), Index(Index), IsIndexSignExt(IsIndexSignExt) {}
0044   BaseIndexOffset(SDValue Base, SDValue Index, int64_t Offset,
0045                   bool IsIndexSignExt)
0046       : Base(Base), Index(Index), Offset(Offset),
0047         IsIndexSignExt(IsIndexSignExt) {}
0048 
0049   SDValue getBase() { return Base; }
0050   SDValue getBase() const { return Base; }
0051   SDValue getIndex() { return Index; }
0052   SDValue getIndex() const { return Index; }
0053   void addToOffset(int64_t VectorOff) {
0054     Offset = Offset.value_or(0) + VectorOff;
0055   }
0056   bool hasValidOffset() const { return Offset.has_value(); }
0057   int64_t getOffset() const { return *Offset; }
0058 
0059   // Returns true if `Other` and `*this` are both some offset from the same base
0060   // pointer. In that case, `Off` is set to the offset between `*this` and
0061   // `Other` (negative if `Other` is before `*this`).
0062   bool equalBaseIndex(const BaseIndexOffset &Other, const SelectionDAG &DAG,
0063                       int64_t &Off) const;
0064 
0065   bool equalBaseIndex(const BaseIndexOffset &Other,
0066                       const SelectionDAG &DAG) const {
0067     int64_t Off;
0068     return equalBaseIndex(Other, DAG, Off);
0069   }
0070 
0071   // Returns true if `Other` (with size `OtherSize`) can be proven to be fully
0072   // contained in `*this` (with size `Size`).
0073   bool contains(const SelectionDAG &DAG, int64_t BitSize,
0074                 const BaseIndexOffset &Other, int64_t OtherBitSize,
0075                 int64_t &BitOffset) const;
0076 
0077   bool contains(const SelectionDAG &DAG, int64_t BitSize,
0078                 const BaseIndexOffset &Other, int64_t OtherBitSize) const {
0079     int64_t BitOffset;
0080     return contains(DAG, BitSize, Other, OtherBitSize, BitOffset);
0081   }
0082 
0083   // Returns true `Op0` and `Op1` can be proven to alias/not alias, in
0084   // which case `IsAlias` is set to true/false.
0085   static bool computeAliasing(const SDNode *Op0, const LocationSize NumBytes0,
0086                               const SDNode *Op1, const LocationSize NumBytes1,
0087                               const SelectionDAG &DAG, bool &IsAlias);
0088 
0089   /// Parses tree in N for base, index, offset addresses.
0090   static BaseIndexOffset match(const SDNode *N, const SelectionDAG &DAG);
0091 
0092   void print(raw_ostream& OS) const;
0093   void dump() const;
0094 };
0095 
0096 } // end namespace llvm
0097 
0098 #endif // LLVM_CODEGEN_SELECTIONDAGADDRESSANALYSIS_H