56 for (
const auto &
I :
Add)
72 for (
const auto &
I :
S1)
90 const auto *
II = dyn_cast<IntInit>(Expr->
arg_begin()[1]);
94 apply2(ST, Expr, Set,
II->getValue(), Elts, Loc);
99struct ShlOp :
public SetIntBinOp {
105 if (
unsigned(
N) <
Set.size())
106 Elts.insert(
Set.begin() +
N,
Set.end());
111struct TruncOp :
public SetIntBinOp {
117 if (
unsigned(
N) >
Set.size())
119 Elts.insert(
Set.begin(),
Set.begin() +
N);
124struct RotOp :
public SetIntBinOp {
127 RotOp(
bool Rev) :
Reverse(Rev) {}
140 Elts.insert(
Set.begin() +
N,
Set.end());
141 Elts.insert(
Set.begin(),
Set.begin() +
N);
146struct DecimateOp :
public SetIntBinOp {
152 for (
unsigned I = 0;
I <
Set.size();
I +=
N)
163 unsigned MaxSize = 0;
166 MaxSize = std::max(MaxSize,
unsigned(
Value.size()));
169 for (
unsigned n = 0; n != MaxSize; ++n)
170 for (
const RecSet &
Value : Values)
171 if (n <
Value.size())
172 Elts.insert(
Value[n]);
185 if (
const auto *
II = dyn_cast<IntInit>(Expr->
arg_begin()[3]))
186 Step =
II->getValue();
193 if (
const auto *SI = dyn_cast<StringInit>(Expr->
arg_begin()[0]))
194 Format = std::string(
SI->getValue());
199 if (
const auto *
II = dyn_cast<IntInit>(Expr->
arg_begin()[1]))
203 if (From < 0 || From >= (1 << 30))
206 if (
const auto *
II = dyn_cast<IntInit>(Expr->
arg_begin()[2]))
210 if (To < 0 || To >= (1 << 30))
214 cast<DefInit>(Expr->
getOperator())->getDef()->getRecords();
216 Step *=
From <= To ? 1 : -1;
218 if (Step > 0 &&
From > To)
220 else if (Step < 0 &&
From < To)
230 if (
const RecVec *Result =
ST.expand(Rec))
244 FieldExpander(
StringRef fn) : FieldName(fn) {}
247 ST.evaluate(
Def->getValueInit(FieldName), Elts,
Def->getLoc());
254void SetTheory::Operator::anchor() {}
255void SetTheory::Expander::anchor() {}
263 addOperator(
"rotl", std::make_unique<RotOp>(
false));
264 addOperator(
"rotr", std::make_unique<RotOp>(
true));
265 addOperator(
"decimate", std::make_unique<DecimateOp>());
266 addOperator(
"interleave", std::make_unique<InterleaveOp>());
267 addOperator(
"sequence", std::make_unique<SequenceOp>());
271 Operators[
Name] = std::move(
Op);
275 Expanders[ClassName] = std::move(E);
279 addExpander(ClassName, std::make_unique<FieldExpander>(FieldName));
284 if (
const auto *Def = dyn_cast<DefInit>(Expr)) {
286 return Elts.
insert(Result->begin(), Result->end());
287 Elts.
insert(Def->getDef());
292 if (
const auto *LI = dyn_cast<ListInit>(Expr))
293 return evaluate(LI->begin(), LI->end(), Elts, Loc);
296 const auto *DagExpr = dyn_cast<DagInit>(Expr);
299 const auto *
OpInit = dyn_cast<DefInit>(DagExpr->getOperator());
302 auto I = Operators.find(
OpInit->getDef()->getName());
303 if (
I == Operators.end())
305 I->second->apply(*
this, DagExpr, Elts, Loc);
310 ExpandMap::iterator
I = Expansions.find(Set);
311 if (
I != Expansions.end())
315 for (
const auto &[
SuperClass, Loc] : Set->getSuperClasses()) {
317 if (!isa<StringInit>(
SuperClass->getNameInit()))
320 if (
I == Expanders.end())
323 RecVec &EltVec = Expansions[Set];
325 I->second->expand(*
this, Set, Elts);
326 EltVec.assign(Elts.
begin(), Elts.
end());
BlockVerifier::State From
uint64_t IntrinsicInst * II
This file defines the SmallVector class.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
This class represents an Operation in the Expression.
(v a, b) - Represent a DAG tree value.
unsigned getNumArgs() const
const_arg_iterator arg_begin() const
const_arg_iterator arg_end() const
const Init * getOperator() const
ArrayRef< const Init * > getArgs() const
std::string getAsString() const override
Convert this value to a literal form.
virtual std::string getAsString() const =0
Convert this value to a literal form.
Base class for operators.
Expander - A callback function that can transform a Record representing a set into a fully expanded l...
virtual void expand(SetTheory &, const Record *, RecSet &Elts)=0
Operator - A callback representing a DAG operator.
virtual void apply(SetTheory &, const DagInit *Expr, RecSet &Elts, ArrayRef< SMLoc > Loc)=0
apply - Apply this operator to Expr's arguments and insert the result in Elts.
void addOperator(StringRef Name, std::unique_ptr< Operator >)
addOperator - Add a DAG operator.
SetTheory()
Create a SetTheory instance with only the standard operators.
const RecVec * expand(const Record *Set)
expand - Expand a record into a set of elements if possible.
SmallSetVector< const Record *, 16 > RecSet
void evaluate(const Init *Expr, RecSet &Elts, ArrayRef< SMLoc > Loc)
evaluate - Evaluate Expr and append the resulting set to Elts.
std::vector< const Record * > RecVec
void addFieldExpander(StringRef ClassName, StringRef FieldName)
addFieldExpander - Add an expander for ClassName that simply evaluates FieldName in the Record to get...
void addExpander(StringRef ClassName, std::unique_ptr< Expander >)
addExpander - Add an expander for Records with the named super class.
iterator end()
Get an iterator to the end of the SetVector.
iterator begin()
Get an iterator to the beginning of the SetVector.
bool insert(const value_type &X)
Insert a new element into the SetVector.
A SetVector that performs no allocations if smaller than a certain size.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
LLVM Value Representation.
A raw_ostream that writes to an std::string.
llvm::SmallVector< std::shared_ptr< RecordsSlice >, 4 > Records
NodeAddr< DefNode * > Def
This is an optimization pass for GlobalISel generic memory operations.
detail::zippy< detail::zip_shortest, T, U, Args... > zip(T &&t, U &&u, Args &&...args)
zip iterator for two or more iteratable types.
void PrintFatalError(const Twine &Msg)
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.