40 void apply(SetTheory &ST,
const DagInit *Expr, RecSet &Elts,
48 void apply(SetTheory &ST,
const DagInit *Expr, RecSet &Elts,
56 for (
const auto &
I :
Add)
64 void apply(SetTheory &ST,
const DagInit *Expr, RecSet &Elts,
72 for (
const auto &
I :
S1)
80 virtual void apply2(SetTheory &ST,
const DagInit *Expr, RecSet &Set,
83 void apply(SetTheory &ST,
const DagInit *Expr, RecSet &Elts,
94 apply2(ST, Expr, Set,
II->getValue(), Elts, Loc);
99struct ShlOp :
public SetIntBinOp {
100 void apply2(SetTheory &ST,
const DagInit *Expr, RecSet &Set, int64_t
N,
105 if (
unsigned(
N) <
Set.size())
106 Elts.insert(
Set.begin() +
N,
Set.end());
111struct TruncOp :
public SetIntBinOp {
112 void apply2(SetTheory &ST,
const DagInit *Expr, RecSet &Set, int64_t
N,
117 if (
unsigned(
N) >
Set.size())
119 Elts.insert(
Set.begin(),
Set.begin() +
N);
124struct RotOp :
public SetIntBinOp {
127 RotOp(
bool Rev) : Reverse(Rev) {}
129 void apply2(SetTheory &ST,
const DagInit *Expr, RecSet &Set, int64_t
N,
140 Elts.insert(
Set.begin() +
N,
Set.end());
141 Elts.insert(
Set.begin(),
Set.begin() +
N);
146struct DecimateOp :
public SetIntBinOp {
147 void apply2(SetTheory &ST,
const DagInit *Expr, RecSet &Set, int64_t
N,
152 for (
unsigned I = 0;
I <
Set.size();
I +=
N)
159 void apply(SetTheory &ST,
const DagInit *Expr, RecSet &Elts,
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]);
178 void apply(SetTheory &ST,
const DagInit *Expr, RecSet &Elts,
186 Step =
II->getValue();
200 From =
II->getValue();
203 if (From < 0 || From >= (1 << 30))
210 if (To < 0 || To >= (1 << 30))
216 Step *= From <= To ? 1 : -1;
218 if (Step > 0 && From > To)
220 else if (Step < 0 && From < To)
223 raw_string_ostream OS(Name);
225 const Record *Rec =
Records.getDef(Name);
230 if (
const RecVec *Result =
ST.expand(Rec))
231 Elts.insert_range(*Result);
244 FieldExpander(StringRef fn) : FieldName(fn) {}
246 void expand(SetTheory &ST,
const Record *Def, RecSet &Elts)
override {
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));
287 Elts.
insert(Def->getDef());
293 return evaluate(LI->begin(), LI->end(), Elts,
Loc);
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())
320 if (
I == Expanders.end())
323 RecVec &EltVec = Expansions[Set];
325 I->second->expand(*
this, Set, Elts);
326 EltVec.assign(Elts.
begin(), Elts.
end());
static Expected< BitVector > expand(StringRef S, StringRef Original)
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),...
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...
Operator - A callback representing a DAG operator.
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.
void insert_range(Range &&R)
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.
StringRef - Represent a constant reference to a string, i.e.
llvm::SmallVector< std::shared_ptr< RecordsSlice >, 4 > Records
void apply(Opt *O, const Mod &M, const Mods &... Ms)
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.
FunctionAddr VTableAddr Value
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
void PrintFatalError(const Twine &Msg)
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
@ Sub
Subtraction of integers.
DWARFExpression::Operation Op
ArrayRef(const T &OneElt) -> ArrayRef< T >
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.