2017-09-14 18:56:21 +02:00
|
|
|
//===--- InfoByHwMode.cpp -------------------------------------------------===//
|
|
|
|
//
|
2019-01-19 09:50:56 +01:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2017-09-14 18:56:21 +02:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Classes that implement data parameterized by HW modes for instruction
|
|
|
|
// selection. Currently it is ValueTypeByHwMode (parameterized ValueType),
|
|
|
|
// and RegSizeInfoByHwMode (parameterized register/spill size and alignment
|
|
|
|
// data).
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "CodeGenTarget.h"
|
|
|
|
#include "InfoByHwMode.h"
|
|
|
|
#include "llvm/ADT/STLExtras.h"
|
|
|
|
#include "llvm/ADT/Twine.h"
|
|
|
|
#include "llvm/Support/Debug.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
|
|
|
|
#include <set>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
std::string llvm::getModeName(unsigned Mode) {
|
|
|
|
if (Mode == DefaultMode)
|
|
|
|
return "*";
|
|
|
|
return (Twine('m') + Twine(Mode)).str();
|
|
|
|
}
|
|
|
|
|
|
|
|
ValueTypeByHwMode::ValueTypeByHwMode(Record *R, const CodeGenHwModes &CGH) {
|
|
|
|
const HwModeSelect &MS = CGH.getHwModeSelect(R);
|
|
|
|
for (const HwModeSelect::PairType &P : MS.Items) {
|
|
|
|
auto I = Map.insert({P.first, MVT(llvm::getValueType(P.second))});
|
|
|
|
assert(I.second && "Duplicate entry?");
|
|
|
|
(void)I;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Add support for pointer types in patterns
Summary:
This adds support for defining patterns for global isel using pointer
types, for example:
def : Pat<(load GPR32:$src),
(p1 (LOAD GPR32:$src))>;
DAGISelEmitter will ignore the pointer information and treat these
types as integers with the same bit-width as the pointer type.
Reviewers: dsanders, rtereshin, arsenm
Reviewed By: arsenm
Subscribers: Petar.Avramovic, wdng, rovka, kristof.beyls, jfb, volkan, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D57065
llvm-svn: 354510
2019-02-20 20:43:47 +01:00
|
|
|
ValueTypeByHwMode::ValueTypeByHwMode(Record *R, MVT T) : ValueTypeByHwMode(T) {
|
|
|
|
if (R->isSubClassOf("PtrValueType"))
|
|
|
|
PtrAddrSpace = R->getValueAsInt("AddrSpace");
|
|
|
|
}
|
|
|
|
|
2017-09-14 18:56:21 +02:00
|
|
|
bool ValueTypeByHwMode::operator== (const ValueTypeByHwMode &T) const {
|
|
|
|
assert(isValid() && T.isValid() && "Invalid type in assignment");
|
|
|
|
bool Simple = isSimple();
|
|
|
|
if (Simple != T.isSimple())
|
|
|
|
return false;
|
|
|
|
if (Simple)
|
|
|
|
return getSimple() == T.getSimple();
|
|
|
|
|
|
|
|
return Map == T.Map;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ValueTypeByHwMode::operator< (const ValueTypeByHwMode &T) const {
|
|
|
|
assert(isValid() && T.isValid() && "Invalid type in comparison");
|
|
|
|
// Default order for maps.
|
|
|
|
return Map < T.Map;
|
|
|
|
}
|
|
|
|
|
|
|
|
MVT &ValueTypeByHwMode::getOrCreateTypeForMode(unsigned Mode, MVT Type) {
|
|
|
|
auto F = Map.find(Mode);
|
|
|
|
if (F != Map.end())
|
|
|
|
return F->second;
|
|
|
|
// If Mode is not in the map, look up the default mode. If it exists,
|
|
|
|
// make a copy of it for Mode and return it.
|
|
|
|
auto D = Map.find(DefaultMode);
|
|
|
|
if (D != Map.end())
|
|
|
|
return Map.insert(std::make_pair(Mode, D->second)).first->second;
|
|
|
|
// If default mode is not present either, use provided Type.
|
|
|
|
return Map.insert(std::make_pair(Mode, Type)).first->second;
|
|
|
|
}
|
|
|
|
|
2017-09-22 15:32:26 +02:00
|
|
|
StringRef ValueTypeByHwMode::getMVTName(MVT T) {
|
|
|
|
StringRef N = llvm::getEnumName(T.SimpleTy);
|
|
|
|
N.consume_front("MVT::");
|
2017-09-14 18:56:21 +02:00
|
|
|
return N;
|
|
|
|
}
|
|
|
|
|
2017-09-22 20:29:37 +02:00
|
|
|
void ValueTypeByHwMode::writeToStream(raw_ostream &OS) const {
|
|
|
|
if (isSimple()) {
|
|
|
|
OS << getMVTName(getSimple());
|
|
|
|
return;
|
|
|
|
}
|
2017-09-14 18:56:21 +02:00
|
|
|
|
|
|
|
std::vector<const PairType*> Pairs;
|
|
|
|
for (const auto &P : Map)
|
|
|
|
Pairs.push_back(&P);
|
llvm::sort(C.begin(), C.end(), ...) -> llvm::sort(C, ...)
Summary: The convenience wrapper in STLExtras is available since rL342102.
Reviewers: dblaikie, javed.absar, JDevlieghere, andreadb
Subscribers: MatzeB, sanjoy, arsenm, dschuff, mehdi_amini, sdardis, nemanjai, jvesely, nhaehnle, sbc100, jgravelle-google, eraman, aheejin, kbarton, JDevlieghere, javed.absar, gbedwell, jrtc27, mgrang, atanasyan, steven_wu, george.burgess.iv, dexonsmith, kristina, jsji, llvm-commits
Differential Revision: https://reviews.llvm.org/D52573
llvm-svn: 343163
2018-09-27 04:13:45 +02:00
|
|
|
llvm::sort(Pairs, deref<std::less<PairType>>());
|
2017-09-14 18:56:21 +02:00
|
|
|
|
2017-09-22 20:29:37 +02:00
|
|
|
OS << '{';
|
2021-02-10 07:14:26 +01:00
|
|
|
ListSeparator LS(",");
|
|
|
|
for (const PairType *P : Pairs)
|
|
|
|
OS << LS << '(' << getModeName(P->first) << ':'
|
|
|
|
<< getMVTName(P->second).str() << ')';
|
2017-09-22 20:29:37 +02:00
|
|
|
OS << '}';
|
2017-09-14 18:56:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
LLVM_DUMP_METHOD
|
|
|
|
void ValueTypeByHwMode::dump() const {
|
2017-09-22 20:29:37 +02:00
|
|
|
dbgs() << *this << '\n';
|
2017-09-14 18:56:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ValueTypeByHwMode llvm::getValueTypeByHwMode(Record *Rec,
|
|
|
|
const CodeGenHwModes &CGH) {
|
|
|
|
#ifndef NDEBUG
|
|
|
|
if (!Rec->isSubClassOf("ValueType"))
|
|
|
|
Rec->dump();
|
|
|
|
#endif
|
|
|
|
assert(Rec->isSubClassOf("ValueType") &&
|
|
|
|
"Record must be derived from ValueType");
|
|
|
|
if (Rec->isSubClassOf("HwModeSelect"))
|
|
|
|
return ValueTypeByHwMode(Rec, CGH);
|
Add support for pointer types in patterns
Summary:
This adds support for defining patterns for global isel using pointer
types, for example:
def : Pat<(load GPR32:$src),
(p1 (LOAD GPR32:$src))>;
DAGISelEmitter will ignore the pointer information and treat these
types as integers with the same bit-width as the pointer type.
Reviewers: dsanders, rtereshin, arsenm
Reviewed By: arsenm
Subscribers: Petar.Avramovic, wdng, rovka, kristof.beyls, jfb, volkan, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D57065
llvm-svn: 354510
2019-02-20 20:43:47 +01:00
|
|
|
return ValueTypeByHwMode(Rec, llvm::getValueType(Rec));
|
2017-09-14 18:56:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
RegSizeInfo::RegSizeInfo(Record *R, const CodeGenHwModes &CGH) {
|
|
|
|
RegSize = R->getValueAsInt("RegSize");
|
|
|
|
SpillSize = R->getValueAsInt("SpillSize");
|
|
|
|
SpillAlignment = R->getValueAsInt("SpillAlignment");
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RegSizeInfo::operator< (const RegSizeInfo &I) const {
|
|
|
|
return std::tie(RegSize, SpillSize, SpillAlignment) <
|
|
|
|
std::tie(I.RegSize, I.SpillSize, I.SpillAlignment);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RegSizeInfo::isSubClassOf(const RegSizeInfo &I) const {
|
|
|
|
return RegSize <= I.RegSize &&
|
|
|
|
SpillAlignment && I.SpillAlignment % SpillAlignment == 0 &&
|
|
|
|
SpillSize <= I.SpillSize;
|
|
|
|
}
|
|
|
|
|
2017-09-22 20:29:37 +02:00
|
|
|
void RegSizeInfo::writeToStream(raw_ostream &OS) const {
|
|
|
|
OS << "[R=" << RegSize << ",S=" << SpillSize
|
|
|
|
<< ",A=" << SpillAlignment << ']';
|
2017-09-14 18:56:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
RegSizeInfoByHwMode::RegSizeInfoByHwMode(Record *R,
|
|
|
|
const CodeGenHwModes &CGH) {
|
|
|
|
const HwModeSelect &MS = CGH.getHwModeSelect(R);
|
|
|
|
for (const HwModeSelect::PairType &P : MS.Items) {
|
|
|
|
auto I = Map.insert({P.first, RegSizeInfo(P.second, CGH)});
|
|
|
|
assert(I.second && "Duplicate entry?");
|
|
|
|
(void)I;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RegSizeInfoByHwMode::operator< (const RegSizeInfoByHwMode &I) const {
|
|
|
|
unsigned M0 = Map.begin()->first;
|
|
|
|
return get(M0) < I.get(M0);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RegSizeInfoByHwMode::operator== (const RegSizeInfoByHwMode &I) const {
|
|
|
|
unsigned M0 = Map.begin()->first;
|
|
|
|
return get(M0) == I.get(M0);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RegSizeInfoByHwMode::isSubClassOf(const RegSizeInfoByHwMode &I) const {
|
|
|
|
unsigned M0 = Map.begin()->first;
|
|
|
|
return get(M0).isSubClassOf(I.get(M0));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RegSizeInfoByHwMode::hasStricterSpillThan(const RegSizeInfoByHwMode &I)
|
|
|
|
const {
|
|
|
|
unsigned M0 = Map.begin()->first;
|
|
|
|
const RegSizeInfo &A0 = get(M0);
|
|
|
|
const RegSizeInfo &B0 = I.get(M0);
|
|
|
|
return std::tie(A0.SpillSize, A0.SpillAlignment) >
|
|
|
|
std::tie(B0.SpillSize, B0.SpillAlignment);
|
|
|
|
}
|
|
|
|
|
2017-09-22 20:29:37 +02:00
|
|
|
void RegSizeInfoByHwMode::writeToStream(raw_ostream &OS) const {
|
2017-09-14 18:56:21 +02:00
|
|
|
typedef typename decltype(Map)::value_type PairType;
|
|
|
|
std::vector<const PairType*> Pairs;
|
|
|
|
for (const auto &P : Map)
|
|
|
|
Pairs.push_back(&P);
|
llvm::sort(C.begin(), C.end(), ...) -> llvm::sort(C, ...)
Summary: The convenience wrapper in STLExtras is available since rL342102.
Reviewers: dblaikie, javed.absar, JDevlieghere, andreadb
Subscribers: MatzeB, sanjoy, arsenm, dschuff, mehdi_amini, sdardis, nemanjai, jvesely, nhaehnle, sbc100, jgravelle-google, eraman, aheejin, kbarton, JDevlieghere, javed.absar, gbedwell, jrtc27, mgrang, atanasyan, steven_wu, george.burgess.iv, dexonsmith, kristina, jsji, llvm-commits
Differential Revision: https://reviews.llvm.org/D52573
llvm-svn: 343163
2018-09-27 04:13:45 +02:00
|
|
|
llvm::sort(Pairs, deref<std::less<PairType>>());
|
2017-09-14 18:56:21 +02:00
|
|
|
|
2017-09-22 20:29:37 +02:00
|
|
|
OS << '{';
|
2021-02-10 07:14:26 +01:00
|
|
|
ListSeparator LS(",");
|
|
|
|
for (const PairType *P : Pairs)
|
|
|
|
OS << LS << '(' << getModeName(P->first) << ':' << P->second << ')';
|
2017-09-22 20:29:37 +02:00
|
|
|
OS << '}';
|
|
|
|
}
|
|
|
|
|
2019-09-19 15:39:54 +02:00
|
|
|
EncodingInfoByHwMode::EncodingInfoByHwMode(Record *R, const CodeGenHwModes &CGH) {
|
|
|
|
const HwModeSelect &MS = CGH.getHwModeSelect(R);
|
|
|
|
for (const HwModeSelect::PairType &P : MS.Items) {
|
|
|
|
assert(P.second && P.second->isSubClassOf("InstructionEncoding") &&
|
|
|
|
"Encoding must subclass InstructionEncoding");
|
|
|
|
auto I = Map.insert({P.first, P.second});
|
|
|
|
assert(I.second && "Duplicate entry?");
|
|
|
|
(void)I;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-22 20:29:37 +02:00
|
|
|
namespace llvm {
|
|
|
|
raw_ostream &operator<<(raw_ostream &OS, const ValueTypeByHwMode &T) {
|
|
|
|
T.writeToStream(OS);
|
|
|
|
return OS;
|
|
|
|
}
|
|
|
|
|
|
|
|
raw_ostream &operator<<(raw_ostream &OS, const RegSizeInfo &T) {
|
|
|
|
T.writeToStream(OS);
|
|
|
|
return OS;
|
|
|
|
}
|
|
|
|
|
|
|
|
raw_ostream &operator<<(raw_ostream &OS, const RegSizeInfoByHwMode &T) {
|
|
|
|
T.writeToStream(OS);
|
|
|
|
return OS;
|
2017-09-14 18:56:21 +02:00
|
|
|
}
|
|
|
|
}
|