2008-01-06 02:10:31 +01:00
|
|
|
//===- CodeGenDAGPatterns.h - Read DAG patterns from .td file ---*- C++ -*-===//
|
2008-01-05 23:25:12 +01:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2008-01-06 02:10:31 +01:00
|
|
|
// This file declares the CodeGenDAGPatterns class, which is used to read and
|
2008-01-05 23:25:12 +01:00
|
|
|
// represent the patterns present in a .td file for instructions.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-08-13 18:26:38 +02:00
|
|
|
#ifndef LLVM_UTILS_TABLEGEN_CODEGENDAGPATTERNS_H
|
|
|
|
#define LLVM_UTILS_TABLEGEN_CODEGENDAGPATTERNS_H
|
2008-01-05 23:25:12 +01:00
|
|
|
|
2017-09-14 18:56:21 +02:00
|
|
|
#include "CodeGenHwModes.h"
|
2008-01-05 23:25:12 +01:00
|
|
|
#include "CodeGenIntrinsics.h"
|
2012-12-04 11:37:14 +01:00
|
|
|
#include "CodeGenTarget.h"
|
2017-12-20 20:36:28 +01:00
|
|
|
#include "SDNodeProperties.h"
|
2010-03-15 07:00:16 +01:00
|
|
|
#include "llvm/ADT/SmallVector.h"
|
|
|
|
#include "llvm/ADT/StringMap.h"
|
2017-09-20 20:01:40 +02:00
|
|
|
#include "llvm/ADT/StringSet.h"
|
2012-02-05 08:21:30 +01:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2017-09-19 20:42:34 +02:00
|
|
|
#include "llvm/Support/MathExtras.h"
|
2010-03-19 02:07:44 +01:00
|
|
|
#include <algorithm>
|
2017-09-19 20:42:34 +02:00
|
|
|
#include <array>
|
2017-11-11 04:23:44 +01:00
|
|
|
#include <functional>
|
2010-03-19 02:07:44 +01:00
|
|
|
#include <map>
|
2012-12-04 11:37:14 +01:00
|
|
|
#include <set>
|
|
|
|
#include <vector>
|
2008-01-05 23:25:12 +01:00
|
|
|
|
|
|
|
namespace llvm {
|
2017-09-19 20:42:34 +02:00
|
|
|
|
|
|
|
class Record;
|
|
|
|
class Init;
|
|
|
|
class ListInit;
|
|
|
|
class DagInit;
|
|
|
|
class SDNodeInfo;
|
|
|
|
class TreePattern;
|
|
|
|
class TreePatternNode;
|
|
|
|
class CodeGenDAGPatterns;
|
|
|
|
class ComplexPattern;
|
|
|
|
|
|
|
|
/// This represents a set of MVTs. Since the underlying type for the MVT
|
|
|
|
/// is uint8_t, there are at most 256 values. To reduce the number of memory
|
|
|
|
/// allocations and deallocations, represent the set as a sequence of bits.
|
|
|
|
/// To reduce the allocations even further, make MachineValueTypeSet own
|
|
|
|
/// the storage and use std::array as the bit container.
|
|
|
|
struct MachineValueTypeSet {
|
|
|
|
static_assert(std::is_same<std::underlying_type<MVT::SimpleValueType>::type,
|
|
|
|
uint8_t>::value,
|
|
|
|
"Change uint8_t here to the SimpleValueType's type");
|
|
|
|
static unsigned constexpr Capacity = std::numeric_limits<uint8_t>::max()+1;
|
|
|
|
using WordType = uint64_t;
|
2017-09-21 06:55:04 +02:00
|
|
|
static unsigned constexpr WordWidth = CHAR_BIT*sizeof(WordType);
|
2017-09-19 20:42:34 +02:00
|
|
|
static unsigned constexpr NumWords = Capacity/WordWidth;
|
|
|
|
static_assert(NumWords*WordWidth == Capacity,
|
|
|
|
"Capacity should be a multiple of WordWidth");
|
|
|
|
|
|
|
|
LLVM_ATTRIBUTE_ALWAYS_INLINE
|
|
|
|
MachineValueTypeSet() {
|
|
|
|
clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
LLVM_ATTRIBUTE_ALWAYS_INLINE
|
|
|
|
unsigned size() const {
|
|
|
|
unsigned Count = 0;
|
|
|
|
for (WordType W : Words)
|
|
|
|
Count += countPopulation(W);
|
|
|
|
return Count;
|
|
|
|
}
|
|
|
|
LLVM_ATTRIBUTE_ALWAYS_INLINE
|
|
|
|
void clear() {
|
|
|
|
std::memset(Words.data(), 0, NumWords*sizeof(WordType));
|
|
|
|
}
|
|
|
|
LLVM_ATTRIBUTE_ALWAYS_INLINE
|
|
|
|
bool empty() const {
|
|
|
|
for (WordType W : Words)
|
|
|
|
if (W != 0)
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
LLVM_ATTRIBUTE_ALWAYS_INLINE
|
|
|
|
unsigned count(MVT T) const {
|
|
|
|
return (Words[T.SimpleTy / WordWidth] >> (T.SimpleTy % WordWidth)) & 1;
|
|
|
|
}
|
|
|
|
std::pair<MachineValueTypeSet&,bool> insert(MVT T) {
|
|
|
|
bool V = count(T.SimpleTy);
|
|
|
|
Words[T.SimpleTy / WordWidth] |= WordType(1) << (T.SimpleTy % WordWidth);
|
|
|
|
return {*this, V};
|
|
|
|
}
|
|
|
|
MachineValueTypeSet &insert(const MachineValueTypeSet &S) {
|
|
|
|
for (unsigned i = 0; i != NumWords; ++i)
|
|
|
|
Words[i] |= S.Words[i];
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
LLVM_ATTRIBUTE_ALWAYS_INLINE
|
|
|
|
void erase(MVT T) {
|
|
|
|
Words[T.SimpleTy / WordWidth] &= ~(WordType(1) << (T.SimpleTy % WordWidth));
|
|
|
|
}
|
|
|
|
|
|
|
|
struct const_iterator {
|
|
|
|
// Some implementations of the C++ library require these traits to be
|
|
|
|
// defined.
|
|
|
|
using iterator_category = std::forward_iterator_tag;
|
|
|
|
using value_type = MVT;
|
|
|
|
using difference_type = ptrdiff_t;
|
|
|
|
using pointer = const MVT*;
|
|
|
|
using reference = const MVT&;
|
|
|
|
|
|
|
|
LLVM_ATTRIBUTE_ALWAYS_INLINE
|
|
|
|
MVT operator*() const {
|
|
|
|
assert(Pos != Capacity);
|
|
|
|
return MVT::SimpleValueType(Pos);
|
|
|
|
}
|
|
|
|
LLVM_ATTRIBUTE_ALWAYS_INLINE
|
|
|
|
const_iterator(const MachineValueTypeSet *S, bool End) : Set(S) {
|
|
|
|
Pos = End ? Capacity : find_from_pos(0);
|
|
|
|
}
|
|
|
|
LLVM_ATTRIBUTE_ALWAYS_INLINE
|
|
|
|
const_iterator &operator++() {
|
|
|
|
assert(Pos != Capacity);
|
|
|
|
Pos = find_from_pos(Pos+1);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
LLVM_ATTRIBUTE_ALWAYS_INLINE
|
|
|
|
bool operator==(const const_iterator &It) const {
|
|
|
|
return Set == It.Set && Pos == It.Pos;
|
|
|
|
}
|
|
|
|
LLVM_ATTRIBUTE_ALWAYS_INLINE
|
|
|
|
bool operator!=(const const_iterator &It) const {
|
|
|
|
return !operator==(It);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
unsigned find_from_pos(unsigned P) const {
|
|
|
|
unsigned SkipWords = P / WordWidth;
|
|
|
|
unsigned SkipBits = P % WordWidth;
|
|
|
|
unsigned Count = SkipWords * WordWidth;
|
|
|
|
|
|
|
|
// If P is in the middle of a word, process it manually here, because
|
|
|
|
// the trailing bits need to be masked off to use findFirstSet.
|
|
|
|
if (SkipBits != 0) {
|
|
|
|
WordType W = Set->Words[SkipWords];
|
|
|
|
W &= maskLeadingOnes<WordType>(WordWidth-SkipBits);
|
|
|
|
if (W != 0)
|
|
|
|
return Count + findFirstSet(W);
|
|
|
|
Count += WordWidth;
|
|
|
|
SkipWords++;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (unsigned i = SkipWords; i != NumWords; ++i) {
|
|
|
|
WordType W = Set->Words[i];
|
|
|
|
if (W != 0)
|
|
|
|
return Count + findFirstSet(W);
|
|
|
|
Count += WordWidth;
|
|
|
|
}
|
|
|
|
return Capacity;
|
|
|
|
}
|
|
|
|
|
|
|
|
const MachineValueTypeSet *Set;
|
|
|
|
unsigned Pos;
|
|
|
|
};
|
|
|
|
|
|
|
|
LLVM_ATTRIBUTE_ALWAYS_INLINE
|
|
|
|
const_iterator begin() const { return const_iterator(this, false); }
|
|
|
|
LLVM_ATTRIBUTE_ALWAYS_INLINE
|
|
|
|
const_iterator end() const { return const_iterator(this, true); }
|
|
|
|
|
|
|
|
LLVM_ATTRIBUTE_ALWAYS_INLINE
|
|
|
|
bool operator==(const MachineValueTypeSet &S) const {
|
|
|
|
return Words == S.Words;
|
|
|
|
}
|
|
|
|
LLVM_ATTRIBUTE_ALWAYS_INLINE
|
|
|
|
bool operator!=(const MachineValueTypeSet &S) const {
|
|
|
|
return !operator==(S);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
friend struct const_iterator;
|
|
|
|
std::array<WordType,NumWords> Words;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct TypeSetByHwMode : public InfoByHwMode<MachineValueTypeSet> {
|
|
|
|
using SetType = MachineValueTypeSet;
|
2017-09-14 18:56:21 +02:00
|
|
|
|
|
|
|
TypeSetByHwMode() = default;
|
|
|
|
TypeSetByHwMode(const TypeSetByHwMode &VTS) = default;
|
|
|
|
TypeSetByHwMode(MVT::SimpleValueType VT)
|
|
|
|
: TypeSetByHwMode(ValueTypeByHwMode(VT)) {}
|
|
|
|
TypeSetByHwMode(ValueTypeByHwMode VT)
|
|
|
|
: TypeSetByHwMode(ArrayRef<ValueTypeByHwMode>(&VT, 1)) {}
|
|
|
|
TypeSetByHwMode(ArrayRef<ValueTypeByHwMode> VTList);
|
|
|
|
|
|
|
|
SetType &getOrCreate(unsigned Mode) {
|
|
|
|
if (hasMode(Mode))
|
|
|
|
return get(Mode);
|
|
|
|
return Map.insert({Mode,SetType()}).first->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isValueTypeByHwMode(bool AllowEmpty) const;
|
|
|
|
ValueTypeByHwMode getValueTypeByHwMode() const;
|
2017-09-19 20:42:34 +02:00
|
|
|
|
|
|
|
LLVM_ATTRIBUTE_ALWAYS_INLINE
|
2017-09-14 18:56:21 +02:00
|
|
|
bool isMachineValueType() const {
|
|
|
|
return isDefaultOnly() && Map.begin()->second.size() == 1;
|
|
|
|
}
|
|
|
|
|
2017-09-19 20:42:34 +02:00
|
|
|
LLVM_ATTRIBUTE_ALWAYS_INLINE
|
2017-09-14 18:56:21 +02:00
|
|
|
MVT getMachineValueType() const {
|
|
|
|
assert(isMachineValueType());
|
|
|
|
return *Map.begin()->second.begin();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isPossible() const;
|
2017-09-19 20:42:34 +02:00
|
|
|
|
|
|
|
LLVM_ATTRIBUTE_ALWAYS_INLINE
|
2017-09-14 18:56:21 +02:00
|
|
|
bool isDefaultOnly() const {
|
2017-09-19 20:42:34 +02:00
|
|
|
return Map.size() == 1 && Map.begin()->first == DefaultMode;
|
2017-09-14 18:56:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool insert(const ValueTypeByHwMode &VVT);
|
|
|
|
bool constrain(const TypeSetByHwMode &VTS);
|
|
|
|
template <typename Predicate> bool constrain(Predicate P);
|
2017-09-20 20:01:40 +02:00
|
|
|
template <typename Predicate>
|
|
|
|
bool assign_if(const TypeSetByHwMode &VTS, Predicate P);
|
2017-09-14 18:56:21 +02:00
|
|
|
|
2017-09-20 20:01:40 +02:00
|
|
|
void writeToStream(raw_ostream &OS) const;
|
|
|
|
static void writeToStream(const SetType &S, raw_ostream &OS);
|
2017-09-14 18:56:21 +02:00
|
|
|
|
|
|
|
bool operator==(const TypeSetByHwMode &VTS) const;
|
|
|
|
bool operator!=(const TypeSetByHwMode &VTS) const { return !(*this == VTS); }
|
|
|
|
|
|
|
|
void dump() const;
|
2017-12-21 18:12:43 +01:00
|
|
|
bool validate() const;
|
2017-09-14 18:56:21 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
/// Intersect two sets. Return true if anything has changed.
|
|
|
|
bool intersect(SetType &Out, const SetType &In);
|
|
|
|
};
|
|
|
|
|
2017-09-22 20:29:37 +02:00
|
|
|
raw_ostream &operator<<(raw_ostream &OS, const TypeSetByHwMode &T);
|
|
|
|
|
2017-09-14 18:56:21 +02:00
|
|
|
struct TypeInfer {
|
|
|
|
TypeInfer(TreePattern &T) : TP(T), ForceMode(0) {}
|
|
|
|
|
|
|
|
bool isConcrete(const TypeSetByHwMode &VTS, bool AllowEmpty) const {
|
|
|
|
return VTS.isValueTypeByHwMode(AllowEmpty);
|
|
|
|
}
|
|
|
|
ValueTypeByHwMode getConcrete(const TypeSetByHwMode &VTS,
|
|
|
|
bool AllowEmpty) const {
|
|
|
|
assert(VTS.isValueTypeByHwMode(AllowEmpty));
|
|
|
|
return VTS.getValueTypeByHwMode();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// The protocol in the following functions (Merge*, force*, Enforce*,
|
|
|
|
/// expand*) is to return "true" if a change has been made, "false"
|
|
|
|
/// otherwise.
|
|
|
|
|
|
|
|
bool MergeInTypeInfo(TypeSetByHwMode &Out, const TypeSetByHwMode &In);
|
|
|
|
bool MergeInTypeInfo(TypeSetByHwMode &Out, MVT::SimpleValueType InVT) {
|
|
|
|
return MergeInTypeInfo(Out, TypeSetByHwMode(InVT));
|
|
|
|
}
|
|
|
|
bool MergeInTypeInfo(TypeSetByHwMode &Out, ValueTypeByHwMode InVT) {
|
|
|
|
return MergeInTypeInfo(Out, TypeSetByHwMode(InVT));
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Reduce the set \p Out to have at most one element for each mode.
|
|
|
|
bool forceArbitrary(TypeSetByHwMode &Out);
|
|
|
|
|
|
|
|
/// The following four functions ensure that upon return the set \p Out
|
|
|
|
/// will only contain types of the specified kind: integer, floating-point,
|
|
|
|
/// scalar, or vector.
|
|
|
|
/// If \p Out is empty, all legal types of the specified kind will be added
|
|
|
|
/// to it. Otherwise, all types that are not of the specified kind will be
|
|
|
|
/// removed from \p Out.
|
|
|
|
bool EnforceInteger(TypeSetByHwMode &Out);
|
|
|
|
bool EnforceFloatingPoint(TypeSetByHwMode &Out);
|
|
|
|
bool EnforceScalar(TypeSetByHwMode &Out);
|
|
|
|
bool EnforceVector(TypeSetByHwMode &Out);
|
|
|
|
|
|
|
|
/// If \p Out is empty, fill it with all legal types. Otherwise, leave it
|
|
|
|
/// unchanged.
|
|
|
|
bool EnforceAny(TypeSetByHwMode &Out);
|
|
|
|
/// Make sure that for each type in \p Small, there exists a larger type
|
|
|
|
/// in \p Big.
|
|
|
|
bool EnforceSmallerThan(TypeSetByHwMode &Small, TypeSetByHwMode &Big);
|
|
|
|
/// 1. Ensure that for each type T in \p Vec, T is a vector type, and that
|
|
|
|
/// for each type U in \p Elem, U is a scalar type.
|
|
|
|
/// 2. Ensure that for each (scalar) type U in \p Elem, there exists a
|
|
|
|
/// (vector) type T in \p Vec, such that U is the element type of T.
|
|
|
|
bool EnforceVectorEltTypeIs(TypeSetByHwMode &Vec, TypeSetByHwMode &Elem);
|
|
|
|
bool EnforceVectorEltTypeIs(TypeSetByHwMode &Vec,
|
|
|
|
const ValueTypeByHwMode &VVT);
|
|
|
|
/// Ensure that for each type T in \p Sub, T is a vector type, and there
|
|
|
|
/// exists a type U in \p Vec such that U is a vector type with the same
|
|
|
|
/// element type as T and at least as many elements as T.
|
|
|
|
bool EnforceVectorSubVectorTypeIs(TypeSetByHwMode &Vec,
|
|
|
|
TypeSetByHwMode &Sub);
|
|
|
|
/// 1. Ensure that \p V has a scalar type iff \p W has a scalar type.
|
|
|
|
/// 2. Ensure that for each vector type T in \p V, there exists a vector
|
|
|
|
/// type U in \p W, such that T and U have the same number of elements.
|
|
|
|
/// 3. Ensure that for each vector type U in \p W, there exists a vector
|
|
|
|
/// type T in \p V, such that T and U have the same number of elements
|
|
|
|
/// (reverse of 2).
|
|
|
|
bool EnforceSameNumElts(TypeSetByHwMode &V, TypeSetByHwMode &W);
|
|
|
|
/// 1. Ensure that for each type T in \p A, there exists a type U in \p B,
|
|
|
|
/// such that T and U have equal size in bits.
|
|
|
|
/// 2. Ensure that for each type U in \p B, there exists a type T in \p A
|
|
|
|
/// such that T and U have equal size in bits (reverse of 1).
|
|
|
|
bool EnforceSameSize(TypeSetByHwMode &A, TypeSetByHwMode &B);
|
|
|
|
|
|
|
|
/// For each overloaded type (i.e. of form *Any), replace it with the
|
|
|
|
/// corresponding subset of legal, specific types.
|
|
|
|
void expandOverloads(TypeSetByHwMode &VTS);
|
|
|
|
void expandOverloads(TypeSetByHwMode::SetType &Out,
|
|
|
|
const TypeSetByHwMode::SetType &Legal);
|
|
|
|
|
|
|
|
struct ValidateOnExit {
|
2017-12-21 18:12:43 +01:00
|
|
|
ValidateOnExit(TypeSetByHwMode &T, TypeInfer &TI) : Infer(TI), VTS(T) {}
|
|
|
|
#ifndef NDEBUG
|
|
|
|
~ValidateOnExit();
|
|
|
|
#else
|
|
|
|
~ValidateOnExit() {} // Empty destructor with NDEBUG.
|
|
|
|
#endif
|
|
|
|
TypeInfer &Infer;
|
2017-09-14 18:56:21 +02:00
|
|
|
TypeSetByHwMode &VTS;
|
2010-03-15 07:00:16 +01:00
|
|
|
};
|
2017-09-14 18:56:21 +02:00
|
|
|
|
|
|
|
TreePattern &TP;
|
|
|
|
unsigned ForceMode; // Mode to use when set.
|
|
|
|
bool CodeGen = false; // Set during generation of matcher code.
|
|
|
|
|
|
|
|
private:
|
|
|
|
TypeSetByHwMode getLegalTypes();
|
2017-09-19 20:42:34 +02:00
|
|
|
|
|
|
|
/// Cached legal types.
|
|
|
|
bool LegalTypesCached = false;
|
|
|
|
TypeSetByHwMode::SetType LegalCache = {};
|
2017-09-14 18:56:21 +02:00
|
|
|
};
|
2008-01-05 23:25:12 +01:00
|
|
|
|
2008-03-05 18:49:05 +01:00
|
|
|
/// Set type used to track multiply used variables in patterns
|
2017-09-20 20:01:40 +02:00
|
|
|
typedef StringSet<> MultipleUseVarSet;
|
2008-03-05 18:49:05 +01:00
|
|
|
|
2008-01-05 23:25:12 +01:00
|
|
|
/// SDTypeConstraint - This is a discriminated union of constraints,
|
|
|
|
/// corresponding to the SDTypeConstraint tablegen class in Target.td.
|
|
|
|
struct SDTypeConstraint {
|
2017-09-14 18:56:21 +02:00
|
|
|
SDTypeConstraint(Record *R, const CodeGenHwModes &CGH);
|
2010-12-24 06:06:32 +01:00
|
|
|
|
2008-01-05 23:25:12 +01:00
|
|
|
unsigned OperandNo; // The operand # this constraint applies to.
|
2010-12-24 06:06:32 +01:00
|
|
|
enum {
|
|
|
|
SDTCisVT, SDTCisPtrTy, SDTCisInt, SDTCisFP, SDTCisVec, SDTCisSameAs,
|
2011-01-24 21:53:18 +01:00
|
|
|
SDTCisVTSmallerThanOp, SDTCisOpSmallerThanOp, SDTCisEltOfVec,
|
2015-11-26 08:02:18 +01:00
|
|
|
SDTCisSubVecOfVec, SDTCVecEltisVT, SDTCisSameNumEltsAs, SDTCisSameSizeAs
|
2008-01-05 23:25:12 +01:00
|
|
|
} ConstraintType;
|
2010-12-24 06:06:32 +01:00
|
|
|
|
2008-01-05 23:25:12 +01:00
|
|
|
union { // The discriminated union.
|
|
|
|
struct {
|
|
|
|
unsigned OtherOperandNum;
|
|
|
|
} SDTCisSameAs_Info;
|
|
|
|
struct {
|
|
|
|
unsigned OtherOperandNum;
|
|
|
|
} SDTCisVTSmallerThanOp_Info;
|
|
|
|
struct {
|
|
|
|
unsigned BigOperandNum;
|
|
|
|
} SDTCisOpSmallerThanOp_Info;
|
2008-02-09 02:37:05 +01:00
|
|
|
struct {
|
|
|
|
unsigned OtherOperandNum;
|
|
|
|
} SDTCisEltOfVec_Info;
|
2011-01-24 21:53:18 +01:00
|
|
|
struct {
|
|
|
|
unsigned OtherOperandNum;
|
|
|
|
} SDTCisSubVecOfVec_Info;
|
2015-03-05 08:11:34 +01:00
|
|
|
struct {
|
|
|
|
unsigned OtherOperandNum;
|
|
|
|
} SDTCisSameNumEltsAs_Info;
|
2015-11-26 08:02:18 +01:00
|
|
|
struct {
|
|
|
|
unsigned OtherOperandNum;
|
|
|
|
} SDTCisSameSizeAs_Info;
|
2008-01-05 23:25:12 +01:00
|
|
|
} x;
|
|
|
|
|
2017-09-14 18:56:21 +02:00
|
|
|
// The VT for SDTCisVT and SDTCVecEltisVT.
|
|
|
|
// Must not be in the union because it has a non-trivial destructor.
|
|
|
|
ValueTypeByHwMode VVT;
|
|
|
|
|
2008-01-05 23:25:12 +01:00
|
|
|
/// ApplyTypeConstraint - Given a node in a pattern, apply this type
|
|
|
|
/// constraint to the nodes operands. This returns true if it makes a
|
2012-10-25 22:33:17 +02:00
|
|
|
/// change, false otherwise. If a type contradiction is found, an error
|
|
|
|
/// is flagged.
|
2008-01-05 23:25:12 +01:00
|
|
|
bool ApplyTypeConstraint(TreePatternNode *N, const SDNodeInfo &NodeInfo,
|
|
|
|
TreePattern &TP) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// SDNodeInfo - One of these records is created for each SDNode instance in
|
|
|
|
/// the target .td file. This represents the various dag nodes we will be
|
|
|
|
/// processing.
|
|
|
|
class SDNodeInfo {
|
|
|
|
Record *Def;
|
2017-05-31 23:12:46 +02:00
|
|
|
StringRef EnumName;
|
|
|
|
StringRef SDClassName;
|
2008-01-05 23:25:12 +01:00
|
|
|
unsigned Properties;
|
|
|
|
unsigned NumResults;
|
|
|
|
int NumOperands;
|
|
|
|
std::vector<SDTypeConstraint> TypeConstraints;
|
|
|
|
public:
|
2017-09-14 18:56:21 +02:00
|
|
|
// Parse the specified record.
|
|
|
|
SDNodeInfo(Record *R, const CodeGenHwModes &CGH);
|
2010-12-24 06:06:32 +01:00
|
|
|
|
2008-01-05 23:25:12 +01:00
|
|
|
unsigned getNumResults() const { return NumResults; }
|
2010-12-24 06:06:32 +01:00
|
|
|
|
2010-03-28 10:48:47 +02:00
|
|
|
/// getNumOperands - This is the number of operands required or -1 if
|
|
|
|
/// variadic.
|
2008-01-05 23:25:12 +01:00
|
|
|
int getNumOperands() const { return NumOperands; }
|
|
|
|
Record *getRecord() const { return Def; }
|
2017-05-31 23:12:46 +02:00
|
|
|
StringRef getEnumName() const { return EnumName; }
|
|
|
|
StringRef getSDClassName() const { return SDClassName; }
|
2010-12-24 06:06:32 +01:00
|
|
|
|
2008-01-05 23:25:12 +01:00
|
|
|
const std::vector<SDTypeConstraint> &getTypeConstraints() const {
|
|
|
|
return TypeConstraints;
|
|
|
|
}
|
2010-12-24 06:06:32 +01:00
|
|
|
|
2010-02-28 01:22:30 +01:00
|
|
|
/// getKnownType - If the type constraints on this node imply a fixed type
|
|
|
|
/// (e.g. all stores return void, etc), then return it as an
|
2010-03-19 02:14:27 +01:00
|
|
|
/// MVT::SimpleValueType. Otherwise, return MVT::Other.
|
2010-03-24 01:41:19 +01:00
|
|
|
MVT::SimpleValueType getKnownType(unsigned ResNo) const;
|
2010-12-24 06:06:32 +01:00
|
|
|
|
2008-01-05 23:25:12 +01:00
|
|
|
/// hasProperty - Return true if this node has the specified property.
|
|
|
|
///
|
|
|
|
bool hasProperty(enum SDNP Prop) const { return Properties & (1 << Prop); }
|
|
|
|
|
|
|
|
/// ApplyTypeConstraints - Given a node in a pattern, apply the type
|
|
|
|
/// constraints for this node to the operands of the node. This returns
|
|
|
|
/// true if it makes a change, false otherwise. If a type contradiction is
|
2012-10-25 22:33:17 +02:00
|
|
|
/// found, an error is flagged.
|
2017-09-14 18:56:21 +02:00
|
|
|
bool ApplyTypeConstraints(TreePatternNode *N, TreePattern &TP) const;
|
2008-01-05 23:25:12 +01:00
|
|
|
};
|
2017-09-22 18:57:28 +02:00
|
|
|
|
2011-04-17 23:38:24 +02:00
|
|
|
/// TreePredicateFn - This is an abstraction that represents the predicates on
|
|
|
|
/// a PatFrag node. This is a simple one-word wrapper around a pointer to
|
|
|
|
/// provide nice accessors.
|
|
|
|
class TreePredicateFn {
|
|
|
|
/// PatFragRec - This is the TreePattern for the PatFrag that we
|
|
|
|
/// originally came from.
|
|
|
|
TreePattern *PatFragRec;
|
|
|
|
public:
|
|
|
|
/// TreePredicateFn constructor. Here 'N' is a subclass of PatFrag.
|
2011-04-18 00:05:17 +02:00
|
|
|
TreePredicateFn(TreePattern *N);
|
2011-04-17 23:38:24 +02:00
|
|
|
|
2017-09-22 18:57:28 +02:00
|
|
|
|
2011-04-17 23:38:24 +02:00
|
|
|
TreePattern *getOrigPatFragRecord() const { return PatFragRec; }
|
2017-09-22 18:57:28 +02:00
|
|
|
|
2011-04-17 23:38:24 +02:00
|
|
|
/// isAlwaysTrue - Return true if this is a noop predicate.
|
|
|
|
bool isAlwaysTrue() const;
|
2017-09-22 18:57:28 +02:00
|
|
|
|
2017-10-15 21:01:32 +02:00
|
|
|
bool isImmediatePattern() const { return hasImmCode(); }
|
2017-09-22 18:57:28 +02:00
|
|
|
|
2011-04-18 08:22:33 +02:00
|
|
|
/// getImmediatePredicateCode - Return the code that evaluates this pattern if
|
|
|
|
/// this is an immediate predicate. It is an error to call this on a
|
|
|
|
/// non-immediate pattern.
|
2017-10-15 04:06:44 +02:00
|
|
|
std::string getImmediatePredicateCode() const {
|
|
|
|
std::string Result = getImmCode();
|
2011-04-18 08:22:33 +02:00
|
|
|
assert(!Result.empty() && "Isn't an immediate pattern!");
|
|
|
|
return Result;
|
|
|
|
}
|
2017-09-22 18:57:28 +02:00
|
|
|
|
2011-04-17 23:38:24 +02:00
|
|
|
bool operator==(const TreePredicateFn &RHS) const {
|
|
|
|
return PatFragRec == RHS.PatFragRec;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator!=(const TreePredicateFn &RHS) const { return !(*this == RHS); }
|
|
|
|
|
|
|
|
/// Return the name to use in the generated code to reference this, this is
|
|
|
|
/// "Predicate_foo" if from a pattern fragment "foo".
|
|
|
|
std::string getFnName() const;
|
2017-09-22 18:57:28 +02:00
|
|
|
|
2011-04-17 23:38:24 +02:00
|
|
|
/// getCodeToRunOnSDNode - Return the code for the function body that
|
|
|
|
/// evaluates this predicate. The argument is expected to be in "Node",
|
|
|
|
/// not N. This handles casting and conversion to a concrete node type as
|
|
|
|
/// appropriate.
|
|
|
|
std::string getCodeToRunOnSDNode() const;
|
2017-09-22 18:57:28 +02:00
|
|
|
|
[aarch64] Support APInt and APFloat in ImmLeaf subclasses and make AArch64 use them.
Summary:
The purpose of this patch is to expose more information about ImmLeaf-like
PatLeaf's so that GlobalISel can learn to import them. Previously, ImmLeaf
could only be used to test int64_t's produced by sign-extending an APInt.
Other tests on immediates had to use the generic PatLeaf and extract the
constant using C++.
With this patch, tablegen will know how to generate predicates for APInt,
and APFloat. This will allow it to 'do the right thing' for both SelectionDAG
and GlobalISel which require different methods of extracting the immediate
from the IR.
This is NFC for SelectionDAG since the new code is equivalent to the
previous code. It's also NFC for FastISel because FastIselShouldIgnore is 1
for the ImmLeaf subclasses. Enabling FastIselShouldIgnore == 0 for these new
subclasses will require a significant re-factor of FastISel.
For GlobalISel, it's currently NFC because the relevant code to import the
affected rules is not yet present. This will be added in a later patch.
Depends on D36086
Reviewers: ab, t.p.northover, qcolombet, rovka, aditya_nandakumar
Reviewed By: qcolombet
Subscribers: bjope, aemerson, rengolin, javed.absar, igorb, llvm-commits, kristof.beyls
Differential Revision: https://reviews.llvm.org/D36534
llvm-svn: 315747
2017-10-13 22:42:18 +02:00
|
|
|
/// Get the data type of the argument to getImmediatePredicateCode().
|
2017-10-14 23:27:53 +02:00
|
|
|
StringRef getImmType() const;
|
[aarch64] Support APInt and APFloat in ImmLeaf subclasses and make AArch64 use them.
Summary:
The purpose of this patch is to expose more information about ImmLeaf-like
PatLeaf's so that GlobalISel can learn to import them. Previously, ImmLeaf
could only be used to test int64_t's produced by sign-extending an APInt.
Other tests on immediates had to use the generic PatLeaf and extract the
constant using C++.
With this patch, tablegen will know how to generate predicates for APInt,
and APFloat. This will allow it to 'do the right thing' for both SelectionDAG
and GlobalISel which require different methods of extracting the immediate
from the IR.
This is NFC for SelectionDAG since the new code is equivalent to the
previous code. It's also NFC for FastISel because FastIselShouldIgnore is 1
for the ImmLeaf subclasses. Enabling FastIselShouldIgnore == 0 for these new
subclasses will require a significant re-factor of FastISel.
For GlobalISel, it's currently NFC because the relevant code to import the
affected rules is not yet present. This will be added in a later patch.
Depends on D36086
Reviewers: ab, t.p.northover, qcolombet, rovka, aditya_nandakumar
Reviewed By: qcolombet
Subscribers: bjope, aemerson, rengolin, javed.absar, igorb, llvm-commits, kristof.beyls
Differential Revision: https://reviews.llvm.org/D36534
llvm-svn: 315747
2017-10-13 22:42:18 +02:00
|
|
|
|
[globalisel][tablegen] Add support for fpimm and import of APInt/APFloat based ImmLeaf.
Summary:
There's only a tablegen testcase for IntImmLeaf and not a CodeGen one
because the relevant rules are rejected for other reasons at the moment.
On AArch64, it's because there's an SDNodeXForm attached to the operand.
On X86, it's because the rule either emits multiple instructions or has
another predicate using PatFrag which cannot easily be supported at the
same time.
Reviewers: ab, t.p.northover, qcolombet, rovka, aditya_nandakumar
Reviewed By: qcolombet
Subscribers: aemerson, javed.absar, igorb, llvm-commits, kristof.beyls
Differential Revision: https://reviews.llvm.org/D36569
llvm-svn: 315761
2017-10-13 23:28:03 +02:00
|
|
|
/// Get a string that describes the type returned by getImmType() but is
|
|
|
|
/// usable as part of an identifier.
|
2017-10-14 23:27:53 +02:00
|
|
|
StringRef getImmTypeIdentifier() const;
|
[globalisel][tablegen] Add support for fpimm and import of APInt/APFloat based ImmLeaf.
Summary:
There's only a tablegen testcase for IntImmLeaf and not a CodeGen one
because the relevant rules are rejected for other reasons at the moment.
On AArch64, it's because there's an SDNodeXForm attached to the operand.
On X86, it's because the rule either emits multiple instructions or has
another predicate using PatFrag which cannot easily be supported at the
same time.
Reviewers: ab, t.p.northover, qcolombet, rovka, aditya_nandakumar
Reviewed By: qcolombet
Subscribers: aemerson, javed.absar, igorb, llvm-commits, kristof.beyls
Differential Revision: https://reviews.llvm.org/D36569
llvm-svn: 315761
2017-10-13 23:28:03 +02:00
|
|
|
|
2017-10-15 04:06:44 +02:00
|
|
|
// Is the desired predefined predicate for a load?
|
|
|
|
bool isLoad() const;
|
|
|
|
// Is the desired predefined predicate for a store?
|
|
|
|
bool isStore() const;
|
2017-11-13 23:26:13 +01:00
|
|
|
// Is the desired predefined predicate for an atomic?
|
|
|
|
bool isAtomic() const;
|
2017-10-15 04:06:44 +02:00
|
|
|
|
|
|
|
/// Is this predicate the predefined unindexed load predicate?
|
|
|
|
/// Is this predicate the predefined unindexed store predicate?
|
|
|
|
bool isUnindexed() const;
|
|
|
|
/// Is this predicate the predefined non-extending load predicate?
|
|
|
|
bool isNonExtLoad() const;
|
|
|
|
/// Is this predicate the predefined any-extend load predicate?
|
|
|
|
bool isAnyExtLoad() const;
|
|
|
|
/// Is this predicate the predefined sign-extend load predicate?
|
|
|
|
bool isSignExtLoad() const;
|
|
|
|
/// Is this predicate the predefined zero-extend load predicate?
|
|
|
|
bool isZeroExtLoad() const;
|
|
|
|
/// Is this predicate the predefined non-truncating store predicate?
|
|
|
|
bool isNonTruncStore() const;
|
|
|
|
/// Is this predicate the predefined truncating store predicate?
|
|
|
|
bool isTruncStore() const;
|
|
|
|
|
2017-11-14 00:03:47 +01:00
|
|
|
/// Is this predicate the predefined monotonic atomic predicate?
|
|
|
|
bool isAtomicOrderingMonotonic() const;
|
|
|
|
/// Is this predicate the predefined acquire atomic predicate?
|
|
|
|
bool isAtomicOrderingAcquire() const;
|
|
|
|
/// Is this predicate the predefined release atomic predicate?
|
|
|
|
bool isAtomicOrderingRelease() const;
|
|
|
|
/// Is this predicate the predefined acquire-release atomic predicate?
|
|
|
|
bool isAtomicOrderingAcquireRelease() const;
|
|
|
|
/// Is this predicate the predefined sequentially consistent atomic predicate?
|
|
|
|
bool isAtomicOrderingSequentiallyConsistent() const;
|
|
|
|
|
2017-11-30 22:05:59 +01:00
|
|
|
/// Is this predicate the predefined acquire-or-stronger atomic predicate?
|
|
|
|
bool isAtomicOrderingAcquireOrStronger() const;
|
|
|
|
/// Is this predicate the predefined weaker-than-acquire atomic predicate?
|
|
|
|
bool isAtomicOrderingWeakerThanAcquire() const;
|
|
|
|
|
|
|
|
/// Is this predicate the predefined release-or-stronger atomic predicate?
|
|
|
|
bool isAtomicOrderingReleaseOrStronger() const;
|
|
|
|
/// Is this predicate the predefined weaker-than-release atomic predicate?
|
|
|
|
bool isAtomicOrderingWeakerThanRelease() const;
|
|
|
|
|
2017-10-15 04:06:44 +02:00
|
|
|
/// If non-null, indicates that this predicate is a predefined memory VT
|
|
|
|
/// predicate for a load/store and returns the ValueType record for the memory VT.
|
|
|
|
Record *getMemoryVT() const;
|
|
|
|
/// If non-null, indicates that this predicate is a predefined memory VT
|
|
|
|
/// predicate (checking only the scalar type) for load/store and returns the
|
|
|
|
/// ValueType record for the memory VT.
|
|
|
|
Record *getScalarMemoryVT() const;
|
|
|
|
|
2011-04-17 23:38:24 +02:00
|
|
|
private:
|
2017-10-15 21:01:32 +02:00
|
|
|
bool hasPredCode() const;
|
|
|
|
bool hasImmCode() const;
|
2017-10-15 04:06:44 +02:00
|
|
|
std::string getPredCode() const;
|
|
|
|
std::string getImmCode() const;
|
[aarch64] Support APInt and APFloat in ImmLeaf subclasses and make AArch64 use them.
Summary:
The purpose of this patch is to expose more information about ImmLeaf-like
PatLeaf's so that GlobalISel can learn to import them. Previously, ImmLeaf
could only be used to test int64_t's produced by sign-extending an APInt.
Other tests on immediates had to use the generic PatLeaf and extract the
constant using C++.
With this patch, tablegen will know how to generate predicates for APInt,
and APFloat. This will allow it to 'do the right thing' for both SelectionDAG
and GlobalISel which require different methods of extracting the immediate
from the IR.
This is NFC for SelectionDAG since the new code is equivalent to the
previous code. It's also NFC for FastISel because FastIselShouldIgnore is 1
for the ImmLeaf subclasses. Enabling FastIselShouldIgnore == 0 for these new
subclasses will require a significant re-factor of FastISel.
For GlobalISel, it's currently NFC because the relevant code to import the
affected rules is not yet present. This will be added in a later patch.
Depends on D36086
Reviewers: ab, t.p.northover, qcolombet, rovka, aditya_nandakumar
Reviewed By: qcolombet
Subscribers: bjope, aemerson, rengolin, javed.absar, igorb, llvm-commits, kristof.beyls
Differential Revision: https://reviews.llvm.org/D36534
llvm-svn: 315747
2017-10-13 22:42:18 +02:00
|
|
|
bool immCodeUsesAPInt() const;
|
|
|
|
bool immCodeUsesAPFloat() const;
|
2017-10-15 04:06:44 +02:00
|
|
|
|
|
|
|
bool isPredefinedPredicateEqualTo(StringRef Field, bool Value) const;
|
2011-04-17 23:38:24 +02:00
|
|
|
};
|
2017-09-22 18:57:28 +02:00
|
|
|
|
2008-01-05 23:25:12 +01:00
|
|
|
|
|
|
|
/// FIXME: TreePatternNode's can be shared in some cases (due to dag-shaped
|
|
|
|
/// patterns), and as such should be ref counted. We currently just leak all
|
|
|
|
/// TreePatternNode objects!
|
|
|
|
class TreePatternNode {
|
2010-03-19 22:37:09 +01:00
|
|
|
/// The type of each node result. Before and during type inference, each
|
|
|
|
/// result may be a set of possible types. After (successful) type inference,
|
|
|
|
/// each is a single concrete type.
|
2017-09-14 18:56:21 +02:00
|
|
|
std::vector<TypeSetByHwMode> Types;
|
2010-12-24 06:06:32 +01:00
|
|
|
|
2008-01-05 23:25:12 +01:00
|
|
|
/// Operator - The Record for the operator if this is an interior node (not
|
|
|
|
/// a leaf).
|
|
|
|
Record *Operator;
|
2010-12-24 06:06:32 +01:00
|
|
|
|
2008-01-05 23:25:12 +01:00
|
|
|
/// Val - The init value (e.g. the "GPRC" record, or "7") for a leaf.
|
|
|
|
///
|
2011-07-30 00:43:06 +02:00
|
|
|
Init *Val;
|
2010-12-24 06:06:32 +01:00
|
|
|
|
2008-01-05 23:25:12 +01:00
|
|
|
/// Name - The name given to this node with the :$foo notation.
|
|
|
|
///
|
|
|
|
std::string Name;
|
2010-12-24 06:06:32 +01:00
|
|
|
|
2008-10-15 08:17:21 +02:00
|
|
|
/// PredicateFns - The predicate functions to execute on this node to check
|
|
|
|
/// for a match. If this list is empty, no predicate is involved.
|
2011-04-17 23:38:24 +02:00
|
|
|
std::vector<TreePredicateFn> PredicateFns;
|
2010-12-24 06:06:32 +01:00
|
|
|
|
2008-01-05 23:25:12 +01:00
|
|
|
/// TransformFn - The transformation function to execute on this node before
|
|
|
|
/// it can be substituted into the resulting instruction on a pattern match.
|
|
|
|
Record *TransformFn;
|
2010-12-24 06:06:32 +01:00
|
|
|
|
2008-01-05 23:25:12 +01:00
|
|
|
std::vector<TreePatternNode*> Children;
|
|
|
|
public:
|
2010-03-19 22:37:09 +01:00
|
|
|
TreePatternNode(Record *Op, const std::vector<TreePatternNode*> &Ch,
|
2010-12-24 06:06:32 +01:00
|
|
|
unsigned NumResults)
|
2014-04-16 06:21:27 +02:00
|
|
|
: Operator(Op), Val(nullptr), TransformFn(nullptr), Children(Ch) {
|
2010-03-19 22:37:09 +01:00
|
|
|
Types.resize(NumResults);
|
|
|
|
}
|
2011-07-30 00:43:06 +02:00
|
|
|
TreePatternNode(Init *val, unsigned NumResults) // leaf ctor
|
2014-04-16 06:21:27 +02:00
|
|
|
: Operator(nullptr), Val(val), TransformFn(nullptr) {
|
2010-03-19 22:37:09 +01:00
|
|
|
Types.resize(NumResults);
|
2008-01-05 23:25:12 +01:00
|
|
|
}
|
|
|
|
~TreePatternNode();
|
2010-12-24 06:06:32 +01:00
|
|
|
|
2013-03-23 19:08:44 +01:00
|
|
|
bool hasName() const { return !Name.empty(); }
|
2008-01-05 23:25:12 +01:00
|
|
|
const std::string &getName() const { return Name; }
|
2010-03-28 08:50:34 +02:00
|
|
|
void setName(StringRef N) { Name.assign(N.begin(), N.end()); }
|
2010-12-24 06:06:32 +01:00
|
|
|
|
2014-04-16 06:21:27 +02:00
|
|
|
bool isLeaf() const { return Val != nullptr; }
|
2010-12-24 06:06:32 +01:00
|
|
|
|
2010-03-15 07:00:16 +01:00
|
|
|
// Type accessors.
|
2010-03-19 22:37:09 +01:00
|
|
|
unsigned getNumTypes() const { return Types.size(); }
|
2017-09-14 18:56:21 +02:00
|
|
|
ValueTypeByHwMode getType(unsigned ResNo) const {
|
|
|
|
return Types[ResNo].getValueTypeByHwMode();
|
2010-03-19 22:37:09 +01:00
|
|
|
}
|
2017-09-14 18:56:21 +02:00
|
|
|
const std::vector<TypeSetByHwMode> &getExtTypes() const { return Types; }
|
|
|
|
const TypeSetByHwMode &getExtType(unsigned ResNo) const {
|
|
|
|
return Types[ResNo];
|
2010-03-19 22:37:09 +01:00
|
|
|
}
|
2017-09-14 18:56:21 +02:00
|
|
|
TypeSetByHwMode &getExtType(unsigned ResNo) { return Types[ResNo]; }
|
|
|
|
void setType(unsigned ResNo, const TypeSetByHwMode &T) { Types[ResNo] = T; }
|
|
|
|
MVT::SimpleValueType getSimpleType(unsigned ResNo) const {
|
|
|
|
return Types[ResNo].getMachineValueType().SimpleTy;
|
2010-03-19 22:37:09 +01:00
|
|
|
}
|
2017-09-14 18:56:21 +02:00
|
|
|
|
|
|
|
bool hasConcreteType(unsigned ResNo) const {
|
|
|
|
return Types[ResNo].isValueTypeByHwMode(false);
|
|
|
|
}
|
|
|
|
bool isTypeCompletelyUnknown(unsigned ResNo, TreePattern &TP) const {
|
|
|
|
return Types[ResNo].empty();
|
2010-03-19 22:37:09 +01:00
|
|
|
}
|
2010-12-24 06:06:32 +01:00
|
|
|
|
2011-07-30 00:43:06 +02:00
|
|
|
Init *getLeafValue() const { assert(isLeaf()); return Val; }
|
2008-01-05 23:25:12 +01:00
|
|
|
Record *getOperator() const { assert(!isLeaf()); return Operator; }
|
2010-12-24 06:06:32 +01:00
|
|
|
|
2008-01-05 23:25:12 +01:00
|
|
|
unsigned getNumChildren() const { return Children.size(); }
|
|
|
|
TreePatternNode *getChild(unsigned N) const { return Children[N]; }
|
|
|
|
void setChild(unsigned i, TreePatternNode *N) {
|
|
|
|
Children[i] = N;
|
|
|
|
}
|
2010-12-24 06:06:32 +01:00
|
|
|
|
2010-02-16 07:10:58 +01:00
|
|
|
/// hasChild - Return true if N is any of our children.
|
|
|
|
bool hasChild(const TreePatternNode *N) const {
|
|
|
|
for (unsigned i = 0, e = Children.size(); i != e; ++i)
|
|
|
|
if (Children[i] == N) return true;
|
|
|
|
return false;
|
|
|
|
}
|
2008-01-06 06:36:50 +01:00
|
|
|
|
2017-09-14 18:56:21 +02:00
|
|
|
bool hasProperTypeByHwMode() const;
|
|
|
|
bool hasPossibleType() const;
|
|
|
|
bool setDefaultMode(unsigned Mode);
|
|
|
|
|
2011-04-17 23:38:24 +02:00
|
|
|
bool hasAnyPredicate() const { return !PredicateFns.empty(); }
|
2017-09-22 18:57:28 +02:00
|
|
|
|
2011-04-17 23:38:24 +02:00
|
|
|
const std::vector<TreePredicateFn> &getPredicateFns() const {
|
|
|
|
return PredicateFns;
|
|
|
|
}
|
2008-10-15 08:17:21 +02:00
|
|
|
void clearPredicateFns() { PredicateFns.clear(); }
|
2011-04-17 23:38:24 +02:00
|
|
|
void setPredicateFns(const std::vector<TreePredicateFn> &Fns) {
|
2008-10-15 08:17:21 +02:00
|
|
|
assert(PredicateFns.empty() && "Overwriting non-empty predicate list!");
|
|
|
|
PredicateFns = Fns;
|
|
|
|
}
|
2011-04-17 23:38:24 +02:00
|
|
|
void addPredicateFn(const TreePredicateFn &Fn) {
|
|
|
|
assert(!Fn.isAlwaysTrue() && "Empty predicate string!");
|
2016-08-12 00:21:41 +02:00
|
|
|
if (!is_contained(PredicateFns, Fn))
|
2008-10-15 08:17:21 +02:00
|
|
|
PredicateFns.push_back(Fn);
|
|
|
|
}
|
2008-01-05 23:25:12 +01:00
|
|
|
|
|
|
|
Record *getTransformFn() const { return TransformFn; }
|
|
|
|
void setTransformFn(Record *Fn) { TransformFn = Fn; }
|
2010-12-24 06:06:32 +01:00
|
|
|
|
2008-01-06 06:36:50 +01:00
|
|
|
/// getIntrinsicInfo - If this node corresponds to an intrinsic, return the
|
|
|
|
/// CodeGenIntrinsic information for it, otherwise return a null pointer.
|
|
|
|
const CodeGenIntrinsic *getIntrinsicInfo(const CodeGenDAGPatterns &CDP) const;
|
2008-06-16 22:29:38 +02:00
|
|
|
|
2010-02-14 23:22:58 +01:00
|
|
|
/// getComplexPatternInfo - If this node corresponds to a ComplexPattern,
|
|
|
|
/// return the ComplexPattern information, otherwise return null.
|
|
|
|
const ComplexPattern *
|
|
|
|
getComplexPatternInfo(const CodeGenDAGPatterns &CGP) const;
|
|
|
|
|
2014-05-20 13:52:46 +02:00
|
|
|
/// Returns the number of MachineInstr operands that would be produced by this
|
|
|
|
/// node if it mapped directly to an output Instruction's
|
|
|
|
/// operand. ComplexPattern specifies this explicitly; MIOperandInfo gives it
|
|
|
|
/// for Operands; otherwise 1.
|
|
|
|
unsigned getNumMIResults(const CodeGenDAGPatterns &CGP) const;
|
|
|
|
|
2010-02-14 23:22:58 +01:00
|
|
|
/// NodeHasProperty - Return true if this node has the specified property.
|
2010-02-14 23:33:49 +01:00
|
|
|
bool NodeHasProperty(SDNP Property, const CodeGenDAGPatterns &CGP) const;
|
2010-12-24 06:06:32 +01:00
|
|
|
|
2010-02-14 23:22:58 +01:00
|
|
|
/// TreeHasProperty - Return true if any node in this tree has the specified
|
|
|
|
/// property.
|
2010-02-14 23:33:49 +01:00
|
|
|
bool TreeHasProperty(SDNP Property, const CodeGenDAGPatterns &CGP) const;
|
2010-12-24 06:06:32 +01:00
|
|
|
|
2008-06-16 22:29:38 +02:00
|
|
|
/// isCommutativeIntrinsic - Return true if the node is an intrinsic which is
|
|
|
|
/// marked isCommutative.
|
|
|
|
bool isCommutativeIntrinsic(const CodeGenDAGPatterns &CDP) const;
|
2010-12-24 06:06:32 +01:00
|
|
|
|
2009-07-03 02:10:29 +02:00
|
|
|
void print(raw_ostream &OS) const;
|
2008-01-05 23:25:12 +01:00
|
|
|
void dump() const;
|
2010-12-24 06:06:32 +01:00
|
|
|
|
2008-01-05 23:25:12 +01:00
|
|
|
public: // Higher level manipulation routines.
|
|
|
|
|
|
|
|
/// clone - Return a new copy of this tree.
|
|
|
|
///
|
|
|
|
TreePatternNode *clone() const;
|
2010-02-14 23:22:58 +01:00
|
|
|
|
|
|
|
/// RemoveAllTypes - Recursively strip all the types of this tree.
|
|
|
|
void RemoveAllTypes();
|
2010-12-24 06:06:32 +01:00
|
|
|
|
2008-01-05 23:25:12 +01:00
|
|
|
/// isIsomorphicTo - Return true if this node is recursively isomorphic to
|
|
|
|
/// the specified node. For this comparison, all of the state of the node
|
|
|
|
/// is considered, except for the assigned name. Nodes with differing names
|
|
|
|
/// that are otherwise identical are considered isomorphic.
|
2008-03-05 18:49:05 +01:00
|
|
|
bool isIsomorphicTo(const TreePatternNode *N,
|
|
|
|
const MultipleUseVarSet &DepVars) const;
|
2010-12-24 06:06:32 +01:00
|
|
|
|
2008-01-05 23:25:12 +01:00
|
|
|
/// SubstituteFormalArguments - Replace the formal arguments in this tree
|
|
|
|
/// with actual values specified by ArgMap.
|
|
|
|
void SubstituteFormalArguments(std::map<std::string,
|
|
|
|
TreePatternNode*> &ArgMap);
|
|
|
|
|
|
|
|
/// InlinePatternFragments - If this pattern refers to any pattern
|
|
|
|
/// fragments, inline them into place, giving us a pattern without any
|
|
|
|
/// PatFrag references.
|
|
|
|
TreePatternNode *InlinePatternFragments(TreePattern &TP);
|
2010-12-24 06:06:32 +01:00
|
|
|
|
2009-01-05 18:23:09 +01:00
|
|
|
/// ApplyTypeConstraints - Apply all of the type constraints relevant to
|
2008-01-05 23:25:12 +01:00
|
|
|
/// this node and its children in the tree. This returns true if it makes a
|
2012-10-25 22:33:17 +02:00
|
|
|
/// change, false otherwise. If a type contradiction is found, flag an error.
|
2008-01-05 23:25:12 +01:00
|
|
|
bool ApplyTypeConstraints(TreePattern &TP, bool NotRegisters);
|
2010-12-24 06:06:32 +01:00
|
|
|
|
2008-01-05 23:25:12 +01:00
|
|
|
/// UpdateNodeType - Set the node type of N to VT if VT contains
|
2012-10-25 22:33:17 +02:00
|
|
|
/// information. If N already contains a conflicting type, then flag an
|
|
|
|
/// error. This returns true if any information was updated.
|
2008-01-05 23:25:12 +01:00
|
|
|
///
|
2017-09-14 18:56:21 +02:00
|
|
|
bool UpdateNodeType(unsigned ResNo, const TypeSetByHwMode &InTy,
|
|
|
|
TreePattern &TP);
|
2010-03-19 22:37:09 +01:00
|
|
|
bool UpdateNodeType(unsigned ResNo, MVT::SimpleValueType InTy,
|
2017-09-14 18:56:21 +02:00
|
|
|
TreePattern &TP);
|
|
|
|
bool UpdateNodeType(unsigned ResNo, ValueTypeByHwMode InTy,
|
|
|
|
TreePattern &TP);
|
2010-12-24 06:06:32 +01:00
|
|
|
|
2013-03-18 05:08:07 +01:00
|
|
|
// Update node type with types inferred from an instruction operand or result
|
|
|
|
// def from the ins/outs lists.
|
|
|
|
// Return true if the type changed.
|
|
|
|
bool UpdateNodeTypeFromInst(unsigned ResNo, Record *Operand, TreePattern &TP);
|
|
|
|
|
2008-01-05 23:25:12 +01:00
|
|
|
/// ContainsUnresolvedType - Return true if this tree contains any
|
|
|
|
/// unresolved types.
|
2017-09-14 18:56:21 +02:00
|
|
|
bool ContainsUnresolvedType(TreePattern &TP) const;
|
2010-12-24 06:06:32 +01:00
|
|
|
|
2008-01-05 23:25:12 +01:00
|
|
|
/// canPatternMatch - If it is impossible for this pattern to match on this
|
|
|
|
/// target, fill in Reason and return false. Otherwise, return true.
|
2008-04-03 02:02:49 +02:00
|
|
|
bool canPatternMatch(std::string &Reason, const CodeGenDAGPatterns &CDP);
|
2008-01-05 23:25:12 +01:00
|
|
|
};
|
|
|
|
|
2010-02-14 22:10:33 +01:00
|
|
|
inline raw_ostream &operator<<(raw_ostream &OS, const TreePatternNode &TPN) {
|
|
|
|
TPN.print(OS);
|
|
|
|
return OS;
|
|
|
|
}
|
2010-12-24 06:06:32 +01:00
|
|
|
|
2008-01-05 23:25:12 +01:00
|
|
|
|
|
|
|
/// TreePattern - Represent a pattern, used for instructions, pattern
|
|
|
|
/// fragments, etc.
|
|
|
|
///
|
|
|
|
class TreePattern {
|
|
|
|
/// Trees - The list of pattern trees which corresponds to this pattern.
|
|
|
|
/// Note that PatFrag's only have a single tree.
|
|
|
|
///
|
2014-11-17 23:55:41 +01:00
|
|
|
std::vector<TreePatternNode*> Trees;
|
2010-12-24 06:06:32 +01:00
|
|
|
|
2010-03-15 07:00:16 +01:00
|
|
|
/// NamedNodes - This is all of the nodes that have names in the trees in this
|
|
|
|
/// pattern.
|
|
|
|
StringMap<SmallVector<TreePatternNode*,1> > NamedNodes;
|
2010-12-24 06:06:32 +01:00
|
|
|
|
2008-01-05 23:25:12 +01:00
|
|
|
/// TheRecord - The actual TableGen record corresponding to this pattern.
|
|
|
|
///
|
|
|
|
Record *TheRecord;
|
2010-12-24 06:06:32 +01:00
|
|
|
|
2008-01-05 23:25:12 +01:00
|
|
|
/// Args - This is a list of all of the arguments to this pattern (for
|
|
|
|
/// PatFrag patterns), which are the 'node' markers in this pattern.
|
|
|
|
std::vector<std::string> Args;
|
2010-12-24 06:06:32 +01:00
|
|
|
|
2008-01-05 23:25:12 +01:00
|
|
|
/// CDP - the top-level object coordinating this madness.
|
|
|
|
///
|
2008-01-06 02:10:31 +01:00
|
|
|
CodeGenDAGPatterns &CDP;
|
2008-01-05 23:25:12 +01:00
|
|
|
|
|
|
|
/// isInputPattern - True if this is an input pattern, something to match.
|
|
|
|
/// False if this is an output pattern, something to emit.
|
|
|
|
bool isInputPattern;
|
2012-10-25 22:33:17 +02:00
|
|
|
|
|
|
|
/// hasError - True if the currently processed nodes have unresolvable types
|
|
|
|
/// or other non-fatal errors
|
|
|
|
bool HasError;
|
2014-05-20 13:52:46 +02:00
|
|
|
|
|
|
|
/// It's important that the usage of operands in ComplexPatterns is
|
|
|
|
/// consistent: each named operand can be defined by at most one
|
|
|
|
/// ComplexPattern. This records the ComplexPattern instance and the operand
|
|
|
|
/// number for each operand encountered in a ComplexPattern to aid in that
|
|
|
|
/// check.
|
|
|
|
StringMap<std::pair<Record *, unsigned>> ComplexPatternOperands;
|
2017-09-14 18:56:21 +02:00
|
|
|
|
|
|
|
TypeInfer Infer;
|
|
|
|
|
2008-01-05 23:25:12 +01:00
|
|
|
public:
|
2010-12-24 06:06:32 +01:00
|
|
|
|
2008-01-05 23:25:12 +01:00
|
|
|
/// TreePattern constructor - Parse the specified DagInits into the
|
|
|
|
/// current record.
|
2011-07-30 00:43:06 +02:00
|
|
|
TreePattern(Record *TheRec, ListInit *RawPat, bool isInput,
|
2008-01-06 02:10:31 +01:00
|
|
|
CodeGenDAGPatterns &ise);
|
2011-07-30 00:43:06 +02:00
|
|
|
TreePattern(Record *TheRec, DagInit *Pat, bool isInput,
|
2008-01-06 02:10:31 +01:00
|
|
|
CodeGenDAGPatterns &ise);
|
2014-11-17 23:55:41 +01:00
|
|
|
TreePattern(Record *TheRec, TreePatternNode *Pat, bool isInput,
|
|
|
|
CodeGenDAGPatterns &ise);
|
2010-12-24 06:06:32 +01:00
|
|
|
|
2008-01-05 23:25:12 +01:00
|
|
|
/// getTrees - Return the tree patterns which corresponds to this pattern.
|
|
|
|
///
|
2014-11-17 23:55:41 +01:00
|
|
|
const std::vector<TreePatternNode*> &getTrees() const { return Trees; }
|
2008-01-05 23:25:12 +01:00
|
|
|
unsigned getNumTrees() const { return Trees.size(); }
|
2014-11-17 23:55:41 +01:00
|
|
|
TreePatternNode *getTree(unsigned i) const { return Trees[i]; }
|
2017-11-11 04:23:44 +01:00
|
|
|
void setTree(unsigned i, TreePatternNode *Tree) { Trees[i] = Tree; }
|
2014-11-17 23:55:41 +01:00
|
|
|
TreePatternNode *getOnlyTree() const {
|
2008-01-05 23:25:12 +01:00
|
|
|
assert(Trees.size() == 1 && "Doesn't have exactly one pattern!");
|
|
|
|
return Trees[0];
|
|
|
|
}
|
2010-12-24 06:06:32 +01:00
|
|
|
|
2010-03-15 07:00:16 +01:00
|
|
|
const StringMap<SmallVector<TreePatternNode*,1> > &getNamedNodesMap() {
|
|
|
|
if (NamedNodes.empty())
|
|
|
|
ComputeNamedNodes();
|
|
|
|
return NamedNodes;
|
|
|
|
}
|
2010-12-24 06:06:32 +01:00
|
|
|
|
2008-01-05 23:25:12 +01:00
|
|
|
/// getRecord - Return the actual TableGen record corresponding to this
|
|
|
|
/// pattern.
|
|
|
|
///
|
|
|
|
Record *getRecord() const { return TheRecord; }
|
2010-12-24 06:06:32 +01:00
|
|
|
|
2008-01-05 23:25:12 +01:00
|
|
|
unsigned getNumArgs() const { return Args.size(); }
|
|
|
|
const std::string &getArgName(unsigned i) const {
|
|
|
|
assert(i < Args.size() && "Argument reference out of range!");
|
|
|
|
return Args[i];
|
|
|
|
}
|
|
|
|
std::vector<std::string> &getArgList() { return Args; }
|
2010-12-24 06:06:32 +01:00
|
|
|
|
2008-01-06 02:10:31 +01:00
|
|
|
CodeGenDAGPatterns &getDAGPatterns() const { return CDP; }
|
2008-01-05 23:25:12 +01:00
|
|
|
|
|
|
|
/// InlinePatternFragments - If this pattern refers to any pattern
|
|
|
|
/// fragments, inline them into place, giving us a pattern without any
|
|
|
|
/// PatFrag references.
|
|
|
|
void InlinePatternFragments() {
|
|
|
|
for (unsigned i = 0, e = Trees.size(); i != e; ++i)
|
2014-11-17 23:55:41 +01:00
|
|
|
Trees[i] = Trees[i]->InlinePatternFragments(*this);
|
2008-01-05 23:25:12 +01:00
|
|
|
}
|
2010-12-24 06:06:32 +01:00
|
|
|
|
2008-01-05 23:25:12 +01:00
|
|
|
/// InferAllTypes - Infer/propagate as many types throughout the expression
|
2009-03-26 17:17:51 +01:00
|
|
|
/// patterns as possible. Return true if all types are inferred, false
|
2012-10-25 22:33:17 +02:00
|
|
|
/// otherwise. Bail out if a type contradiction is found.
|
2010-03-15 07:00:16 +01:00
|
|
|
bool InferAllTypes(const StringMap<SmallVector<TreePatternNode*,1> >
|
2014-04-16 06:21:27 +02:00
|
|
|
*NamedTypes=nullptr);
|
2010-12-24 06:06:32 +01:00
|
|
|
|
2012-10-25 22:33:17 +02:00
|
|
|
/// error - If this is the first error in the current resolution step,
|
|
|
|
/// print it and set the error flag. Otherwise, continue silently.
|
2014-11-12 00:48:11 +01:00
|
|
|
void error(const Twine &Msg);
|
2012-10-25 22:33:17 +02:00
|
|
|
bool hasError() const {
|
|
|
|
return HasError;
|
|
|
|
}
|
|
|
|
void resetError() {
|
|
|
|
HasError = false;
|
|
|
|
}
|
2010-12-24 06:06:32 +01:00
|
|
|
|
2017-09-14 18:56:21 +02:00
|
|
|
TypeInfer &getInfer() { return Infer; }
|
|
|
|
|
2009-07-03 02:10:29 +02:00
|
|
|
void print(raw_ostream &OS) const;
|
2008-01-05 23:25:12 +01:00
|
|
|
void dump() const;
|
2010-12-24 06:06:32 +01:00
|
|
|
|
2008-01-05 23:25:12 +01:00
|
|
|
private:
|
2014-11-17 23:55:41 +01:00
|
|
|
TreePatternNode *ParseTreePattern(Init *DI, StringRef OpName);
|
2010-03-15 07:00:16 +01:00
|
|
|
void ComputeNamedNodes();
|
|
|
|
void ComputeNamedNodes(TreePatternNode *N);
|
2008-01-05 23:25:12 +01:00
|
|
|
};
|
|
|
|
|
2017-09-14 18:56:21 +02:00
|
|
|
|
|
|
|
inline bool TreePatternNode::UpdateNodeType(unsigned ResNo,
|
|
|
|
const TypeSetByHwMode &InTy,
|
|
|
|
TreePattern &TP) {
|
|
|
|
TypeSetByHwMode VTS(InTy);
|
|
|
|
TP.getInfer().expandOverloads(VTS);
|
|
|
|
return TP.getInfer().MergeInTypeInfo(Types[ResNo], VTS);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool TreePatternNode::UpdateNodeType(unsigned ResNo,
|
|
|
|
MVT::SimpleValueType InTy,
|
|
|
|
TreePattern &TP) {
|
|
|
|
TypeSetByHwMode VTS(InTy);
|
|
|
|
TP.getInfer().expandOverloads(VTS);
|
|
|
|
return TP.getInfer().MergeInTypeInfo(Types[ResNo], VTS);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool TreePatternNode::UpdateNodeType(unsigned ResNo,
|
|
|
|
ValueTypeByHwMode InTy,
|
|
|
|
TreePattern &TP) {
|
|
|
|
TypeSetByHwMode VTS(InTy);
|
|
|
|
TP.getInfer().expandOverloads(VTS);
|
|
|
|
return TP.getInfer().MergeInTypeInfo(Types[ResNo], VTS);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-09-06 16:15:52 +02:00
|
|
|
/// DAGDefaultOperand - One of these is created for each OperandWithDefaultOps
|
|
|
|
/// that has a set ExecuteAlways / DefaultOps field.
|
2008-01-05 23:25:12 +01:00
|
|
|
struct DAGDefaultOperand {
|
|
|
|
std::vector<TreePatternNode*> DefaultOps;
|
|
|
|
};
|
|
|
|
|
|
|
|
class DAGInstruction {
|
|
|
|
TreePattern *Pattern;
|
|
|
|
std::vector<Record*> Results;
|
|
|
|
std::vector<Record*> Operands;
|
|
|
|
std::vector<Record*> ImpResults;
|
2014-11-17 23:55:41 +01:00
|
|
|
TreePatternNode *ResultPattern;
|
2008-01-05 23:25:12 +01:00
|
|
|
public:
|
|
|
|
DAGInstruction(TreePattern *TP,
|
|
|
|
const std::vector<Record*> &results,
|
|
|
|
const std::vector<Record*> &operands,
|
2010-04-20 08:28:43 +02:00
|
|
|
const std::vector<Record*> &impresults)
|
2010-12-24 06:06:32 +01:00
|
|
|
: Pattern(TP), Results(results), Operands(operands),
|
2014-11-17 23:55:41 +01:00
|
|
|
ImpResults(impresults), ResultPattern(nullptr) {}
|
2008-01-05 23:25:12 +01:00
|
|
|
|
2012-10-25 22:33:17 +02:00
|
|
|
TreePattern *getPattern() const { return Pattern; }
|
2008-01-05 23:25:12 +01:00
|
|
|
unsigned getNumResults() const { return Results.size(); }
|
|
|
|
unsigned getNumOperands() const { return Operands.size(); }
|
|
|
|
unsigned getNumImpResults() const { return ImpResults.size(); }
|
|
|
|
const std::vector<Record*>& getImpResults() const { return ImpResults; }
|
2010-12-24 06:06:32 +01:00
|
|
|
|
2014-11-17 23:55:41 +01:00
|
|
|
void setResultPattern(TreePatternNode *R) { ResultPattern = R; }
|
2010-12-24 06:06:32 +01:00
|
|
|
|
2008-01-05 23:25:12 +01:00
|
|
|
Record *getResult(unsigned RN) const {
|
|
|
|
assert(RN < Results.size());
|
|
|
|
return Results[RN];
|
|
|
|
}
|
2010-12-24 06:06:32 +01:00
|
|
|
|
2008-01-05 23:25:12 +01:00
|
|
|
Record *getOperand(unsigned ON) const {
|
|
|
|
assert(ON < Operands.size());
|
|
|
|
return Operands[ON];
|
|
|
|
}
|
|
|
|
|
|
|
|
Record *getImpResult(unsigned RN) const {
|
|
|
|
assert(RN < ImpResults.size());
|
|
|
|
return ImpResults[RN];
|
|
|
|
}
|
2010-12-24 06:06:32 +01:00
|
|
|
|
2014-11-17 23:55:41 +01:00
|
|
|
TreePatternNode *getResultPattern() const { return ResultPattern; }
|
2008-01-05 23:25:12 +01:00
|
|
|
};
|
2010-12-24 06:06:32 +01:00
|
|
|
|
2017-09-14 18:56:21 +02:00
|
|
|
/// This class represents a condition that has to be satisfied for a pattern
|
|
|
|
/// to be tried. It is a generalization of a class "Pattern" from Target.td:
|
|
|
|
/// in addition to the Target.td's predicates, this class can also represent
|
|
|
|
/// conditions associated with HW modes. Both types will eventually become
|
|
|
|
/// strings containing C++ code to be executed, the difference is in how
|
|
|
|
/// these strings are generated.
|
|
|
|
class Predicate {
|
|
|
|
public:
|
|
|
|
Predicate(Record *R, bool C = true) : Def(R), IfCond(C), IsHwMode(false) {
|
|
|
|
assert(R->isSubClassOf("Predicate") &&
|
|
|
|
"Predicate objects should only be created for records derived"
|
|
|
|
"from Predicate class");
|
|
|
|
}
|
|
|
|
Predicate(StringRef FS, bool C = true) : Def(nullptr), Features(FS.str()),
|
|
|
|
IfCond(C), IsHwMode(true) {}
|
|
|
|
|
|
|
|
/// Return a string which contains the C++ condition code that will serve
|
|
|
|
/// as a predicate during instruction selection.
|
|
|
|
std::string getCondString() const {
|
|
|
|
// The string will excute in a subclass of SelectionDAGISel.
|
|
|
|
// Cast to std::string explicitly to avoid ambiguity with StringRef.
|
|
|
|
std::string C = IsHwMode
|
|
|
|
? std::string("MF->getSubtarget().checkFeatures(\"" + Features + "\")")
|
|
|
|
: std::string(Def->getValueAsString("CondString"));
|
|
|
|
return IfCond ? C : "!("+C+')';
|
|
|
|
}
|
|
|
|
bool operator==(const Predicate &P) const {
|
|
|
|
return IfCond == P.IfCond && IsHwMode == P.IsHwMode && Def == P.Def;
|
|
|
|
}
|
|
|
|
bool operator<(const Predicate &P) const {
|
|
|
|
if (IsHwMode != P.IsHwMode)
|
|
|
|
return IsHwMode < P.IsHwMode;
|
|
|
|
assert(!Def == !P.Def && "Inconsistency between Def and IsHwMode");
|
|
|
|
if (IfCond != P.IfCond)
|
|
|
|
return IfCond < P.IfCond;
|
|
|
|
if (Def)
|
|
|
|
return LessRecord()(Def, P.Def);
|
|
|
|
return Features < P.Features;
|
|
|
|
}
|
|
|
|
Record *Def; ///< Predicate definition from .td file, null for
|
|
|
|
///< HW modes.
|
|
|
|
std::string Features; ///< Feature string for HW mode.
|
|
|
|
bool IfCond; ///< The boolean value that the condition has to
|
|
|
|
///< evaluate to for this predicate to be true.
|
|
|
|
bool IsHwMode; ///< Does this predicate correspond to a HW mode?
|
|
|
|
};
|
|
|
|
|
2008-01-06 02:10:31 +01:00
|
|
|
/// PatternToMatch - Used by CodeGenDAGPatterns to keep tab of patterns
|
2008-01-05 23:25:12 +01:00
|
|
|
/// processed to produce isel.
|
2010-02-18 07:47:49 +01:00
|
|
|
class PatternToMatch {
|
|
|
|
public:
|
2017-09-14 18:56:21 +02:00
|
|
|
PatternToMatch(Record *srcrecord, const std::vector<Predicate> &preds,
|
|
|
|
TreePatternNode *src, TreePatternNode *dst,
|
|
|
|
const std::vector<Record*> &dstregs,
|
|
|
|
int complexity, unsigned uid, unsigned setmode = 0)
|
|
|
|
: SrcRecord(srcrecord), SrcPattern(src), DstPattern(dst),
|
|
|
|
Predicates(preds), Dstregs(std::move(dstregs)),
|
|
|
|
AddedComplexity(complexity), ID(uid), ForceMode(setmode) {}
|
|
|
|
|
|
|
|
PatternToMatch(Record *srcrecord, std::vector<Predicate> &&preds,
|
|
|
|
TreePatternNode *src, TreePatternNode *dst,
|
|
|
|
std::vector<Record*> &&dstregs,
|
|
|
|
int complexity, unsigned uid, unsigned setmode = 0)
|
|
|
|
: SrcRecord(srcrecord), SrcPattern(src), DstPattern(dst),
|
|
|
|
Predicates(preds), Dstregs(std::move(dstregs)),
|
|
|
|
AddedComplexity(complexity), ID(uid), ForceMode(setmode) {}
|
2008-01-05 23:25:12 +01:00
|
|
|
|
2010-12-08 00:05:49 +01:00
|
|
|
Record *SrcRecord; // Originating Record for the pattern.
|
2008-01-05 23:25:12 +01:00
|
|
|
TreePatternNode *SrcPattern; // Source pattern to match.
|
|
|
|
TreePatternNode *DstPattern; // Resulting pattern.
|
2017-09-14 18:56:21 +02:00
|
|
|
std::vector<Predicate> Predicates; // Top level predicate conditions
|
|
|
|
// to match.
|
2008-01-05 23:25:12 +01:00
|
|
|
std::vector<Record*> Dstregs; // Physical register defs being matched.
|
2014-08-01 02:32:36 +02:00
|
|
|
int AddedComplexity; // Add to matching pattern complexity.
|
2010-03-01 23:09:11 +01:00
|
|
|
unsigned ID; // Unique ID for the record.
|
2017-09-14 18:56:21 +02:00
|
|
|
unsigned ForceMode; // Force this mode in type inference when set.
|
2008-01-05 23:25:12 +01:00
|
|
|
|
2010-12-08 00:05:49 +01:00
|
|
|
Record *getSrcRecord() const { return SrcRecord; }
|
2008-01-05 23:25:12 +01:00
|
|
|
TreePatternNode *getSrcPattern() const { return SrcPattern; }
|
|
|
|
TreePatternNode *getDstPattern() const { return DstPattern; }
|
|
|
|
const std::vector<Record*> &getDstRegs() const { return Dstregs; }
|
2014-08-01 02:32:36 +02:00
|
|
|
int getAddedComplexity() const { return AddedComplexity; }
|
2017-09-14 18:56:21 +02:00
|
|
|
const std::vector<Predicate> &getPredicates() const { return Predicates; }
|
2008-08-22 02:20:26 +02:00
|
|
|
|
|
|
|
std::string getPredicateCheck() const;
|
2010-12-24 06:06:32 +01:00
|
|
|
|
2010-03-29 03:40:38 +02:00
|
|
|
/// Compute the complexity metric for the input pattern. This roughly
|
|
|
|
/// corresponds to the number of nodes that are covered.
|
2014-08-01 02:32:36 +02:00
|
|
|
int getPatternComplexity(const CodeGenDAGPatterns &CGP) const;
|
2008-01-05 23:25:12 +01:00
|
|
|
};
|
|
|
|
|
2008-01-06 02:10:31 +01:00
|
|
|
class CodeGenDAGPatterns {
|
2008-01-05 23:25:12 +01:00
|
|
|
RecordKeeper &Records;
|
|
|
|
CodeGenTarget Target;
|
2016-07-15 18:31:37 +02:00
|
|
|
CodeGenIntrinsicTable Intrinsics;
|
|
|
|
CodeGenIntrinsicTable TgtIntrinsics;
|
2010-12-24 06:06:32 +01:00
|
|
|
|
2012-09-19 03:47:00 +02:00
|
|
|
std::map<Record*, SDNodeInfo, LessRecordByID> SDNodes;
|
2017-09-12 17:31:26 +02:00
|
|
|
std::map<Record*, std::pair<Record*, std::string>, LessRecordByID>
|
|
|
|
SDNodeXForms;
|
2012-09-19 03:47:00 +02:00
|
|
|
std::map<Record*, ComplexPattern, LessRecordByID> ComplexPatterns;
|
2014-11-13 22:40:02 +01:00
|
|
|
std::map<Record *, std::unique_ptr<TreePattern>, LessRecordByID>
|
|
|
|
PatternFragments;
|
2012-09-19 03:47:00 +02:00
|
|
|
std::map<Record*, DAGDefaultOperand, LessRecordByID> DefaultOperands;
|
|
|
|
std::map<Record*, DAGInstruction, LessRecordByID> Instructions;
|
2010-12-24 06:06:32 +01:00
|
|
|
|
2008-01-05 23:25:12 +01:00
|
|
|
// Specific SDNode definitions:
|
|
|
|
Record *intrinsic_void_sdnode;
|
|
|
|
Record *intrinsic_w_chain_sdnode, *intrinsic_wo_chain_sdnode;
|
2010-12-24 06:06:32 +01:00
|
|
|
|
2008-01-05 23:25:12 +01:00
|
|
|
/// PatternsToMatch - All of the things we are matching on the DAG. The first
|
|
|
|
/// value is the pattern to match, the second pattern is the result to
|
|
|
|
/// emit.
|
|
|
|
std::vector<PatternToMatch> PatternsToMatch;
|
2017-09-14 18:56:21 +02:00
|
|
|
|
|
|
|
TypeSetByHwMode LegalVTS;
|
|
|
|
|
2017-11-11 04:23:44 +01:00
|
|
|
using PatternRewriterFn = std::function<void (TreePattern *)>;
|
|
|
|
PatternRewriterFn PatternRewriter;
|
|
|
|
|
2008-01-05 23:25:12 +01:00
|
|
|
public:
|
2017-11-11 04:23:44 +01:00
|
|
|
CodeGenDAGPatterns(RecordKeeper &R,
|
|
|
|
PatternRewriterFn PatternRewriter = nullptr);
|
2010-12-24 06:06:32 +01:00
|
|
|
|
2008-04-03 02:02:49 +02:00
|
|
|
CodeGenTarget &getTargetInfo() { return Target; }
|
2008-01-05 23:25:12 +01:00
|
|
|
const CodeGenTarget &getTargetInfo() const { return Target; }
|
2017-09-14 18:56:21 +02:00
|
|
|
const TypeSetByHwMode &getLegalTypes() const { return LegalVTS; }
|
2010-12-24 06:06:32 +01:00
|
|
|
|
2017-10-13 21:00:01 +02:00
|
|
|
Record *getSDNodeNamed(const std::string &Name) const;
|
2010-12-24 06:06:32 +01:00
|
|
|
|
2008-01-05 23:25:12 +01:00
|
|
|
const SDNodeInfo &getSDNodeInfo(Record *R) const {
|
2017-10-07 16:34:24 +02:00
|
|
|
auto F = SDNodes.find(R);
|
|
|
|
assert(F != SDNodes.end() && "Unknown node!");
|
|
|
|
return F->second;
|
2008-01-05 23:25:12 +01:00
|
|
|
}
|
2010-12-24 06:06:32 +01:00
|
|
|
|
2008-01-05 23:54:53 +01:00
|
|
|
// Node transformation lookups.
|
|
|
|
typedef std::pair<Record*, std::string> NodeXForm;
|
|
|
|
const NodeXForm &getSDNodeTransform(Record *R) const {
|
2017-10-07 16:34:24 +02:00
|
|
|
auto F = SDNodeXForms.find(R);
|
|
|
|
assert(F != SDNodeXForms.end() && "Invalid transform!");
|
|
|
|
return F->second;
|
2008-01-05 23:25:12 +01:00
|
|
|
}
|
2010-12-24 06:06:32 +01:00
|
|
|
|
2012-09-19 03:47:00 +02:00
|
|
|
typedef std::map<Record*, NodeXForm, LessRecordByID>::const_iterator
|
2009-08-23 12:39:21 +02:00
|
|
|
nx_iterator;
|
2008-01-05 23:54:53 +01:00
|
|
|
nx_iterator nx_begin() const { return SDNodeXForms.begin(); }
|
|
|
|
nx_iterator nx_end() const { return SDNodeXForms.end(); }
|
|
|
|
|
2010-12-24 06:06:32 +01:00
|
|
|
|
2008-01-05 23:25:12 +01:00
|
|
|
const ComplexPattern &getComplexPattern(Record *R) const {
|
2017-10-07 16:34:24 +02:00
|
|
|
auto F = ComplexPatterns.find(R);
|
|
|
|
assert(F != ComplexPatterns.end() && "Unknown addressing mode!");
|
|
|
|
return F->second;
|
2008-01-05 23:25:12 +01:00
|
|
|
}
|
2010-12-24 06:06:32 +01:00
|
|
|
|
2008-01-05 23:25:12 +01:00
|
|
|
const CodeGenIntrinsic &getIntrinsic(Record *R) const {
|
|
|
|
for (unsigned i = 0, e = Intrinsics.size(); i != e; ++i)
|
|
|
|
if (Intrinsics[i].TheDef == R) return Intrinsics[i];
|
2009-02-05 02:49:45 +01:00
|
|
|
for (unsigned i = 0, e = TgtIntrinsics.size(); i != e; ++i)
|
|
|
|
if (TgtIntrinsics[i].TheDef == R) return TgtIntrinsics[i];
|
2012-02-05 08:21:30 +01:00
|
|
|
llvm_unreachable("Unknown intrinsic!");
|
2008-01-05 23:25:12 +01:00
|
|
|
}
|
2010-12-24 06:06:32 +01:00
|
|
|
|
2008-01-05 23:25:12 +01:00
|
|
|
const CodeGenIntrinsic &getIntrinsicInfo(unsigned IID) const {
|
2009-02-05 02:49:45 +01:00
|
|
|
if (IID-1 < Intrinsics.size())
|
|
|
|
return Intrinsics[IID-1];
|
|
|
|
if (IID-Intrinsics.size()-1 < TgtIntrinsics.size())
|
|
|
|
return TgtIntrinsics[IID-Intrinsics.size()-1];
|
2012-02-05 08:21:30 +01:00
|
|
|
llvm_unreachable("Bad intrinsic ID!");
|
2008-01-05 23:25:12 +01:00
|
|
|
}
|
2010-12-24 06:06:32 +01:00
|
|
|
|
2008-01-05 23:25:12 +01:00
|
|
|
unsigned getIntrinsicID(Record *R) const {
|
|
|
|
for (unsigned i = 0, e = Intrinsics.size(); i != e; ++i)
|
|
|
|
if (Intrinsics[i].TheDef == R) return i;
|
2009-02-05 02:49:45 +01:00
|
|
|
for (unsigned i = 0, e = TgtIntrinsics.size(); i != e; ++i)
|
|
|
|
if (TgtIntrinsics[i].TheDef == R) return i + Intrinsics.size();
|
2012-02-05 08:21:30 +01:00
|
|
|
llvm_unreachable("Unknown intrinsic!");
|
2008-01-05 23:25:12 +01:00
|
|
|
}
|
2010-12-24 06:06:32 +01:00
|
|
|
|
2010-02-18 07:47:49 +01:00
|
|
|
const DAGDefaultOperand &getDefaultOperand(Record *R) const {
|
2017-10-07 16:34:24 +02:00
|
|
|
auto F = DefaultOperands.find(R);
|
|
|
|
assert(F != DefaultOperands.end() &&"Isn't an analyzed default operand!");
|
|
|
|
return F->second;
|
2008-01-05 23:25:12 +01:00
|
|
|
}
|
2010-12-24 06:06:32 +01:00
|
|
|
|
2008-01-05 23:25:12 +01:00
|
|
|
// Pattern Fragment information.
|
|
|
|
TreePattern *getPatternFragment(Record *R) const {
|
2017-10-07 16:34:24 +02:00
|
|
|
auto F = PatternFragments.find(R);
|
|
|
|
assert(F != PatternFragments.end() && "Invalid pattern fragment request!");
|
|
|
|
return F->second.get();
|
2008-01-05 23:25:12 +01:00
|
|
|
}
|
2010-03-19 22:37:09 +01:00
|
|
|
TreePattern *getPatternFragmentIfRead(Record *R) const {
|
2017-10-07 16:34:24 +02:00
|
|
|
auto F = PatternFragments.find(R);
|
|
|
|
if (F == PatternFragments.end())
|
2014-11-13 22:40:02 +01:00
|
|
|
return nullptr;
|
2017-10-07 16:34:24 +02:00
|
|
|
return F->second.get();
|
2010-03-19 22:37:09 +01:00
|
|
|
}
|
2010-12-24 06:06:32 +01:00
|
|
|
|
2014-11-13 22:56:57 +01:00
|
|
|
typedef std::map<Record *, std::unique_ptr<TreePattern>,
|
|
|
|
LessRecordByID>::const_iterator pf_iterator;
|
2008-01-05 23:25:12 +01:00
|
|
|
pf_iterator pf_begin() const { return PatternFragments.begin(); }
|
|
|
|
pf_iterator pf_end() const { return PatternFragments.end(); }
|
2016-12-22 00:26:20 +01:00
|
|
|
iterator_range<pf_iterator> ptfs() const { return PatternFragments; }
|
2008-01-05 23:25:12 +01:00
|
|
|
|
|
|
|
// Patterns to match information.
|
2008-01-05 23:30:17 +01:00
|
|
|
typedef std::vector<PatternToMatch>::const_iterator ptm_iterator;
|
|
|
|
ptm_iterator ptm_begin() const { return PatternsToMatch.begin(); }
|
|
|
|
ptm_iterator ptm_end() const { return PatternsToMatch.end(); }
|
2016-12-22 00:26:20 +01:00
|
|
|
iterator_range<ptm_iterator> ptms() const { return PatternsToMatch; }
|
2010-12-24 06:06:32 +01:00
|
|
|
|
2013-10-28 19:07:21 +01:00
|
|
|
/// Parse the Pattern for an instruction, and insert the result in DAGInsts.
|
|
|
|
typedef std::map<Record*, DAGInstruction, LessRecordByID> DAGInstMap;
|
|
|
|
const DAGInstruction &parseInstructionPattern(
|
|
|
|
CodeGenInstruction &CGI, ListInit *Pattern,
|
|
|
|
DAGInstMap &DAGInsts);
|
2010-12-24 06:06:32 +01:00
|
|
|
|
2008-01-05 23:25:12 +01:00
|
|
|
const DAGInstruction &getInstruction(Record *R) const {
|
2017-10-07 16:34:24 +02:00
|
|
|
auto F = Instructions.find(R);
|
|
|
|
assert(F != Instructions.end() && "Unknown instruction!");
|
|
|
|
return F->second;
|
2008-01-05 23:25:12 +01:00
|
|
|
}
|
2010-12-24 06:06:32 +01:00
|
|
|
|
2008-01-05 23:25:12 +01:00
|
|
|
Record *get_intrinsic_void_sdnode() const {
|
|
|
|
return intrinsic_void_sdnode;
|
|
|
|
}
|
|
|
|
Record *get_intrinsic_w_chain_sdnode() const {
|
|
|
|
return intrinsic_w_chain_sdnode;
|
|
|
|
}
|
|
|
|
Record *get_intrinsic_wo_chain_sdnode() const {
|
|
|
|
return intrinsic_wo_chain_sdnode;
|
|
|
|
}
|
2010-12-24 06:06:32 +01:00
|
|
|
|
2009-10-15 20:50:03 +02:00
|
|
|
bool hasTargetIntrinsics() { return !TgtIntrinsics.empty(); }
|
|
|
|
|
2008-01-05 23:25:12 +01:00
|
|
|
private:
|
|
|
|
void ParseNodeInfo();
|
2008-01-05 23:54:53 +01:00
|
|
|
void ParseNodeTransforms();
|
2008-01-05 23:25:12 +01:00
|
|
|
void ParseComplexPatterns();
|
2014-02-28 01:26:56 +01:00
|
|
|
void ParsePatternFragments(bool OutFrags = false);
|
2008-01-05 23:25:12 +01:00
|
|
|
void ParseDefaultOperands();
|
|
|
|
void ParseInstructions();
|
|
|
|
void ParsePatterns();
|
2017-09-14 18:56:21 +02:00
|
|
|
void ExpandHwModeBasedTypes();
|
2008-04-03 02:02:49 +02:00
|
|
|
void InferInstructionFlags();
|
2008-01-05 23:25:12 +01:00
|
|
|
void GenerateVariants();
|
2012-08-28 05:26:49 +02:00
|
|
|
void VerifyInstructionFlags();
|
2010-12-24 06:06:32 +01:00
|
|
|
|
2017-09-14 18:56:21 +02:00
|
|
|
std::vector<Predicate> makePredList(ListInit *L);
|
|
|
|
|
2017-06-25 19:33:49 +02:00
|
|
|
void AddPatternToMatch(TreePattern *Pattern, PatternToMatch &&PTM);
|
2008-01-05 23:25:12 +01:00
|
|
|
void FindPatternInputsAndOutputs(TreePattern *I, TreePatternNode *Pat,
|
|
|
|
std::map<std::string,
|
|
|
|
TreePatternNode*> &InstInputs,
|
|
|
|
std::map<std::string,
|
|
|
|
TreePatternNode*> &InstResults,
|
|
|
|
std::vector<Record*> &InstImpResults);
|
|
|
|
};
|
2017-09-14 18:56:21 +02:00
|
|
|
|
|
|
|
|
|
|
|
inline bool SDNodeInfo::ApplyTypeConstraints(TreePatternNode *N,
|
|
|
|
TreePattern &TP) const {
|
|
|
|
bool MadeChange = false;
|
|
|
|
for (unsigned i = 0, e = TypeConstraints.size(); i != e; ++i)
|
|
|
|
MadeChange |= TypeConstraints[i].ApplyTypeConstraint(N, *this, TP);
|
|
|
|
return MadeChange;
|
|
|
|
}
|
2017-12-20 20:36:28 +01:00
|
|
|
|
2008-01-05 23:25:12 +01:00
|
|
|
} // end namespace llvm
|
|
|
|
|
|
|
|
#endif
|