2017-09-13 23:15:20 +02:00
|
|
|
//===- SelectionDAGAddressAnalysis.h - DAG Address Analysis -----*- C++ -*-===//
|
2017-06-21 17:40:43 +02:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_CODEGEN_SELECTIONDAGADDRESSANALYSIS_H
|
|
|
|
#define LLVM_CODEGEN_SELECTIONDAGADDRESSANALYSIS_H
|
|
|
|
|
|
|
|
#include "llvm/CodeGen/SelectionDAGNodes.h"
|
2017-09-13 23:15:20 +02:00
|
|
|
#include <cstdint>
|
2017-06-21 17:40:43 +02:00
|
|
|
|
|
|
|
namespace llvm {
|
2017-09-13 23:15:20 +02:00
|
|
|
|
|
|
|
class SelectionDAG;
|
|
|
|
|
2017-06-21 17:40:43 +02:00
|
|
|
/// Helper struct to parse and store a memory address as base + index + offset.
|
|
|
|
/// We ignore sign extensions when it is safe to do so.
|
|
|
|
/// The following two expressions are not equivalent. To differentiate we need
|
|
|
|
/// to store whether there was a sign extension involved in the index
|
|
|
|
/// computation.
|
|
|
|
/// (load (i64 add (i64 copyfromreg %c)
|
|
|
|
/// (i64 signextend (add (i8 load %index)
|
|
|
|
/// (i8 1))))
|
|
|
|
/// vs
|
|
|
|
///
|
|
|
|
/// (load (i64 add (i64 copyfromreg %c)
|
|
|
|
/// (i64 signextend (i32 add (i32 signextend (i8 load %index))
|
|
|
|
/// (i32 1)))))
|
|
|
|
class BaseIndexOffset {
|
|
|
|
private:
|
|
|
|
SDValue Base;
|
|
|
|
SDValue Index;
|
2017-09-13 23:15:20 +02:00
|
|
|
int64_t Offset = 0;
|
|
|
|
bool IsIndexSignExt = false;
|
2017-06-21 17:40:43 +02:00
|
|
|
|
|
|
|
public:
|
2017-09-13 23:15:20 +02:00
|
|
|
BaseIndexOffset() = default;
|
2017-06-21 17:40:43 +02:00
|
|
|
BaseIndexOffset(SDValue Base, SDValue Index, int64_t Offset,
|
|
|
|
bool IsIndexSignExt)
|
|
|
|
: Base(Base), Index(Index), Offset(Offset),
|
|
|
|
IsIndexSignExt(IsIndexSignExt) {}
|
|
|
|
|
|
|
|
SDValue getBase() { return Base; }
|
2018-10-30 19:26:43 +01:00
|
|
|
SDValue getBase() const { return Base; }
|
2017-06-21 17:40:43 +02:00
|
|
|
SDValue getIndex() { return Index; }
|
2018-10-30 19:26:43 +01:00
|
|
|
SDValue getIndex() const { return Index; }
|
2017-06-21 17:40:43 +02:00
|
|
|
|
2018-10-30 19:26:43 +01:00
|
|
|
bool equalBaseIndex(const BaseIndexOffset &Other,
|
|
|
|
const SelectionDAG &DAG) const {
|
2017-06-21 17:40:43 +02:00
|
|
|
int64_t Off;
|
|
|
|
return equalBaseIndex(Other, DAG, Off);
|
|
|
|
}
|
|
|
|
|
2018-10-30 19:26:43 +01:00
|
|
|
bool equalBaseIndex(const BaseIndexOffset &Other, const SelectionDAG &DAG,
|
|
|
|
int64_t &Off) const;
|
2017-06-21 17:40:43 +02:00
|
|
|
|
|
|
|
/// Parses tree in Ptr for base, index, offset addresses.
|
2018-10-30 19:26:43 +01:00
|
|
|
static BaseIndexOffset match(const LSBaseSDNode *N, const SelectionDAG &DAG);
|
2017-06-21 17:40:43 +02:00
|
|
|
};
|
|
|
|
|
2017-09-13 23:15:20 +02:00
|
|
|
} // end namespace llvm
|
|
|
|
|
|
|
|
#endif // LLVM_CODEGEN_SELECTIONDAGADDRESSANALYSIS_H
|