-
Notifications
You must be signed in to change notification settings - Fork 10
/
sair_attributes.h
687 lines (528 loc) · 25.1 KB
/
sair_attributes.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef SAIR_SAIR_ATTRIBUTES_H_
#define SAIR_SAIR_ATTRIBUTES_H_
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/SmallBitVector.h"
#include "mlir/IR/AffineMap.h"
#include "mlir/IR/BuiltinAttributes.h"
#include "mlir/IR/Diagnostics.h"
#include "mlir/IR/Location.h"
#include "mlir/IR/MLIRContext.h"
#include "sair_types.h"
namespace sair {
namespace impl {
// Private implementation for sair::MappingDimExpr
class MappingDimExprStorage;
// Private implementation for sair::MappingStripeExpr
class MappingStripeExprStorage;
// Private implementation for sair::MappingUnStripeExpr
class MappingUnStripeExprStorage;
// Private implementation for sair::MappingAttr
class MappingAttrStorage;
// Private implementation for sair::NamedMappingAttr
class NamedMappingAttrStorage;
// Private implementation for sair::DomainShapeAttr
class DomainShapeAttrStorage;
} // namespace impl
class MappingExpr;
// MappingAttr describes how a Sair variable is accessed within an
// iteration domain. It indicates how dimensions of the current domain map to
// the dimensions of the variable domain. Dimensions are identified by their
// position in the domain definition.
//
// For example the mapping (0, 2) accesses a three-dimensional variable, with
// the first dimension of the domain iterating on the first dimension of the
// variable, and the third dimension of the domain on the second dimension of
// the variable.
class MappingAttr
: public mlir::Attribute::AttrBase<MappingAttr, mlir::Attribute,
impl::MappingAttrStorage> {
public:
using Base::Base;
static constexpr mlir::StringLiteral name = "sair.mapping";
// Constructs an instance of MappingAttr in the given context.
static MappingAttr get(mlir::MLIRContext *context, int domain_size,
llvm::ArrayRef<MappingExpr> mapping);
// Constructs an instance of MappingAttr and checks it is valid. Returns
// nullptr in case of failure.
static MappingAttr getChecked(mlir::MLIRContext *context, int domain_size,
llvm::ArrayRef<MappingExpr> mapping);
// Returns the mapping that accesses `num_dimensions` pointwise without
// transposing any of them, and has the given size of the use domain. If use
// domain size is `-1`, it is considered equal to `num_dimensions`.
static MappingAttr GetIdentity(mlir::MLIRContext *context, int num_dimensions,
int use_domain_size = -1);
// Returns the mapping that corresponds to the given affine map.
// Expects the map to be a permutation.
static MappingAttr FromAffineMap(mlir::AffineMap map);
// Returns the attribute itself. This is a hook for MLIR.
MappingAttr getValue() { return *this; }
// Returns the number of dimensiom in the calling context.
int UseDomainSize() const;
// Returns the dimensions along which the variable is accessed.
llvm::ArrayRef<MappingExpr> Dimensions() const;
// Returns the dimension at the given position.
const MappingExpr &Dimension(int position) const {
return Dimensions()[position];
}
// Indicates if the mapping contains no dimensions.
bool empty() const { return Dimensions().empty(); }
// Indicates the number of dimensions.
int size() const { return Dimensions().size(); }
// Returns the mapping resulting from applying `this` and then `other`
// to the current set of indices.
MappingAttr Compose(MappingAttr other) const;
// Converts the mapping into an affine map from the domain of the
// operation to the domain of the access value. The mapping must be
// fully specified.
mlir::AffineMap AsAffineMap() const;
// HasNoneExprs indicates if any sub-expression is `none`.
bool HasNoneExprs() const;
bool IsSurjective() const { return !HasNoneExprs(); }
// Replaces `none` expressions by new dimensions to make the mapping
// surjective.
MappingAttr MakeSurjective() const;
// HasUnknownExprs indicates if any sub-expression is `?`.
bool HasUnknownExprs() const;
bool IsFullySpecified() const { return !HasUnknownExprs(); }
// Replaces `?` expressions by `none` expressions.
MappingAttr MakeFullySpecified() const;
// Indicates whether the mapping is an identity, e.g. does not
// transpose or otherwise modify any dimension.
bool IsIdentity() const;
// A bit mask that indicates which dimensions of the domain the mapping
// depends on.
llvm::SmallBitVector DependencyMask() const;
// Minimal use domain size the mapping could have while remaining valid.
int MinDomainSize() const;
// Indicates if the mapping accesses a single element of the def
// domain per element of the use domain, when considering only the first
// `num_dimensions` of the use domain.
bool IsInjective(int num_dimensions) const;
// Returns this mapping with a different use domain size. Replaces
// expressions that are invalid in the new domain by `none`.
MappingAttr ResizeUseDomain(int new_size) const;
// Returns this mapping a different number of dimensions. If the new
// size is greater than the current one, appends `kNoDimensions` at the end of
// the mapping.
MappingAttr Resize(int new_size) const;
// Returns this mapping with dimensions shifted right by `offset`. If
// `start_from` is set, only starting from the given position will be shifted.
// Use domain size is also increased by `offset`.
// For example:
// (d0,d1,d2).ShiftRight(2) => (d2,d3,d4)
// (d0,d1,d2).ShiftRight(2,1) => (d0,d1,d4)
MappingAttr ShiftRight(int offset, int start_from = 0) const;
// Adds mapping expressions in front or at the end of the mapping.
MappingAttr AddPrefix(llvm::ArrayRef<MappingExpr> exprs) const;
MappingAttr AddSuffix(llvm::ArrayRef<MappingExpr> exprs) const;
// Drops expressions in front of the mapping.
MappingAttr DropFront(int num_drop) const;
// Take a slice of the expressions of the mapping.
MappingAttr Slice(int begin, int new_size) const;
// Inverse the mapping.
MappingAttr Inverse() const;
// Canonicalize dimension expressions.
MappingAttr Canonicalize() const;
// Unifies this mapping with `other` by substituting `none` and `?`
// expressions. In case `none` conflicts with a `?`, keeps the `none`
// expression. Returns `nullptr` if unification fails in one of the
// dimensions. Both expressions must have the same number of dimensions and
// domain size.
MappingAttr Unify(MappingAttr other) const;
// Unifies this mapping with `other` by substituting ``?` expressions. Returns
// `nullptr` if unification fails in one of the dimensions. Both expressions
// must have the same number of dimensions and domain size.
MappingAttr UnifyUnknownExprs(MappingAttr other) const;
using iterator = llvm::ArrayRef<MappingExpr>::iterator;
iterator begin() const { return Dimensions().begin(); }
iterator end() const { return Dimensions().end(); }
};
// Unifies two mapping expressions by substituting `none` and `?` expressions.
// In the case where `none` conflicts with `?`, keeps `none`. Returns nullptr
// in case of failure.
MappingExpr Unify(MappingExpr lhs, MappingExpr rhs);
// Fills `constraints` with expression such that
// `lhs.SubstituteDims(constraints).Unify(rhs)` succeeds. Expects `contraints`
// to be initially filled with `none`. Leaves `constraints[i]` untouched if
// dimension i generates no constraints. Returns a failure if expressions cannot
// be unified.
mlir::LogicalResult UnificationConstraints(
MappingAttr lhs, MappingAttr rhs,
llvm::MutableArrayRef<MappingExpr> constraints);
// A MappingAttr, with named dimensions in the use domain. Format is
// ```
// [d0:<name[0]>, ..., dn:<name[n]>] -> (<mapping>)
// ```
class NamedMappingAttr
: public mlir::Attribute::AttrBase<NamedMappingAttr, mlir::Attribute,
impl::NamedMappingAttrStorage> {
public:
using Base::Base;
static constexpr mlir::StringLiteral name = "sair.named_mapping";
// Constructs an instance of NamedMappingAttr.
static NamedMappingAttr get(llvm::ArrayRef<mlir::StringAttr> names,
MappingAttr mapping);
static NamedMappingAttr get(llvm::ArrayRef<mlir::StringAttr> names,
llvm::ArrayRef<MappingExpr> exprs,
mlir::MLIRContext *context);
// Constructs an instance of NamedMappingAttr with an identity mapping.
static NamedMappingAttr GetIdentity(mlir::MLIRContext *context,
llvm::ArrayRef<mlir::StringAttr> names);
llvm::ArrayRef<mlir::StringAttr> names() const;
MappingAttr mapping() const;
// Drop dimensions from the domain that are unused.
NamedMappingAttr DropUnusedDims() const;
// Returns the mapping resulting from applying `this` and then `other`.
NamedMappingAttr Compose(MappingAttr other) const;
};
// The shape of an iteration dimension of a Sair domain.
class DomainShapeDim {
public:
DomainShapeDim(DimensionType type, MappingAttr dependency_mapping);
// Expected type for the dimension.
const DimensionType &type() const { return type_; }
// Mapping for the dimension, with regard to previous dimensions in the
// domain.
MappingAttr dependency_mapping() const { return dependency_mapping_; }
// Composes the mapping with the shape dimension dependency mapping.
DomainShapeDim Apply(MappingAttr mapping) const;
// A mask that indicates which dimensions this dimension depends on. A
// dimension can only depend on dimensions that occure before this one.
llvm::SmallBitVector DependencyMask() const {
return dependency_mapping_.DependencyMask();
}
private:
DimensionType type_;
MappingAttr dependency_mapping_;
};
// Tests the equality of two domain shape dimensions.
bool operator==(const DomainShapeDim &lhs, const DomainShapeDim &rhs);
// Compute a hash for a domain shape dimension.
unsigned hash_value(const DomainShapeDim &shape_dim);
// DomainShapeAttr describes the shape of a Sair iteration domain. A Sair
// iteration domain is a product of iteration dimensions, with some dimensions
// depending on others. The shape of a domain specifies the type of each
// dimension and how they depend on each other.
//
// The general syntax for DomainShapeAttr is the following.
// ```
// <domain-shape> ::= () | <dim-shape> | <dim-shape> 'x' <domain-shape>
// <dim-shape> ::= <name> ':' 'range' ( '(' <int>,* ')' )?
// ```
// For example the following shape describes a two-dimensional domain where the
// second dimension depends on the first.
// ```mlir
// d0:range x d1:range(d0)
// ```
class DomainShapeAttr
: public mlir::Attribute::AttrBase<DomainShapeAttr, mlir::Attribute,
impl::DomainShapeAttrStorage> {
public:
using Base::Base;
static constexpr mlir::StringLiteral name = "sair.domain_shape";
// Constructs an instance of DomainShapeAttr in the given context. Defaults to
// the zero-dimensional shape when no dimenion shapes are given.
static DomainShapeAttr get(mlir::MLIRContext *context,
llvm::ArrayRef<DomainShapeDim> dims = {});
// Returns a prefix of this shape of the given size.
DomainShapeAttr Prefix(int size);
// Returns the attribute itself. This is a hook for TableGen.
DomainShapeAttr getValue() { return *this; }
// Returns the number of dimensions in the domain.
int NumDimensions() const;
// Indicates if the domain contains exactly one point.
bool Is0d() const;
// Returns the shape of the iteration dimension that compose the domain.
llvm::ArrayRef<DomainShapeDim> Dimensions() const;
// Returns the dimension at the given index.
const DomainShapeDim &Dimension(int index) const {
return Dimensions()[index];
}
// Returns the expected shape of the sair value the mapping refers to.
DomainShapeAttr AccessedShape(MappingAttr mapping) const;
};
// Location in a Sair attribute.
//
// The location is defined by an MLIR location, an attribute kind and an
// attribute name. The attribute name may be null.
class AttrLocation {
public:
AttrLocation(mlir::Location loc, llvm::StringRef kind,
mlir::StringAttr name = nullptr)
: loc_(loc), kind_(kind), name_(name) {}
// MLIR location.
mlir::Location location() const { return loc_; }
// Attribute name.
mlir::StringAttr name() const { return name_; }
// Context in which the attribute is defined.
mlir::MLIRContext *context() const { return name_.getContext(); }
// Emits an error at the attribute location. Error has format
// `error in <kind> <name>: <msg>`
mlir::InFlightDiagnostic EmitError() const;
private:
friend mlir::Diagnostic &operator<<(mlir::Diagnostic &diag,
const AttrLocation &loc);
mlir::Location loc_;
llvm::StringRef kind_;
mlir::StringAttr name_;
};
// Appends the attribute kind and name to the error message.
mlir::Diagnostic &operator<<(mlir::Diagnostic &diag, const AttrLocation &loc);
// Verifies that the mapping can be applied to a domain with the given shape.
// Does not emits errors.
mlir::LogicalResult VerifyMappingShape(const AttrLocation &loc,
MappingAttr mapping,
DomainShapeAttr shape);
#include "sair_attr_interfaces.h.inc"
// Mapping expression that maps to a dimension of the domain.
class MappingDimExpr
: public mlir::Attribute::AttrBase<MappingDimExpr, mlir::Attribute,
impl::MappingDimExprStorage,
MappingExpr::Trait> {
public:
using Base::Base;
static constexpr mlir::StringLiteral name = "sair.mapping_dim_expr";
// Creates an MappingDimExpr representing the given dimension.
static MappingDimExpr get(int dimension, mlir::MLIRContext *context);
// Returns the dimensions represented by the expression
int dimension() const;
MappingExpr Map(llvm::function_ref<MappingExpr(MappingExpr)> function) const;
void Walk(llvm::function_ref<void(MappingExpr)> function) const;
mlir::LogicalResult SetInverse(
MappingExpr context_inverse,
llvm::MutableArrayRef<MappingExpr> inverses) const;
MappingExpr Unify(MappingExpr other_expr,
llvm::function_ref<MappingExpr(MappingExpr, MappingExpr)>
on_mismatch) const;
MappingExpr FindInInverse(llvm::ArrayRef<MappingExpr> inverse) const {
return inverse[dimension()];
}
mlir::AffineExpr AsAffineExpr() const;
MappingExpr Canonicalize() const { return *this; }
};
// Mapping expression that maps to no dimensions.
class MappingNoneExpr
: public mlir::Attribute::AttrBase<MappingNoneExpr, mlir::Attribute,
mlir::AttributeStorage,
MappingExpr::Trait> {
public:
using Base::Base;
static constexpr mlir::StringLiteral name = "sair.mapping_none_expr";
static constexpr llvm::StringRef kAttrName = "none";
static MappingNoneExpr get(mlir::MLIRContext *context);
MappingExpr Map(llvm::function_ref<MappingExpr(MappingExpr)> function) const;
void Walk(llvm::function_ref<void(MappingExpr)> function) const;
mlir::LogicalResult SetInverse(
MappingExpr context_inverse,
llvm::MutableArrayRef<MappingExpr> inverses) const {
return mlir::success();
}
MappingExpr Unify(MappingExpr other_expr,
llvm::function_ref<MappingExpr(MappingExpr, MappingExpr)>
on_mismatch) const;
MappingExpr FindInInverse(llvm::ArrayRef<MappingExpr> inverse) const {
return *this;
}
mlir::AffineExpr AsAffineExpr() const {
llvm_unreachable("cannot call `AsAffineExpr` on none expressions");
}
MappingExpr Canonicalize() const { return *this; }
};
// To be specified mapping expression.
class MappingUnknownExpr
: public mlir::Attribute::AttrBase<MappingUnknownExpr, mlir::Attribute,
mlir::AttributeStorage,
MappingExpr::Trait> {
public:
using Base::Base;
static constexpr mlir::StringLiteral name = "sair.mapping_unknown_expr";
static constexpr llvm::StringRef kAttrName = "?";
static MappingUnknownExpr get(mlir::MLIRContext *context);
MappingExpr Map(llvm::function_ref<MappingExpr(MappingExpr)> function) const;
void Walk(llvm::function_ref<void(MappingExpr)> function) const;
mlir::LogicalResult SetInverse(
MappingExpr context_inverse,
llvm::MutableArrayRef<MappingExpr> inverses) const {
return mlir::success();
}
MappingExpr Unify(MappingExpr other_expr,
llvm::function_ref<MappingExpr(MappingExpr, MappingExpr)>
on_mismatch) const;
MappingExpr FindInInverse(llvm::ArrayRef<MappingExpr> inverse) const {
return *this;
}
mlir::AffineExpr AsAffineExpr() const {
llvm_unreachable("cannot call `AsAffineExpr` on unknown expressions");
}
MappingExpr Canonicalize() const { return *this; }
};
// Applies stripe-mining to an expression. Iterates on its operand with step
// `getStep()`, on a strip of size `size()`. If it iterates of the full
// expression, `size()` is none.
class MappingStripeExpr
: public mlir::Attribute::AttrBase<MappingStripeExpr, mlir::Attribute,
impl::MappingStripeExprStorage,
MappingExpr::Trait> {
public:
using Base::Base;
static constexpr mlir::StringLiteral name = "sair.mapping_stripe_expr";
static constexpr llvm::StringRef kAttrName = "stripe";
static MappingStripeExpr get(MappingExpr operand,
llvm::ArrayRef<int> factors);
// The striped expression.
MappingExpr operand() const;
// Successive stripe factors to apply to `operand` to obtain this dimension.
// Cannot be empty.
llvm::ArrayRef<int> factors() const;
MappingExpr Map(llvm::function_ref<MappingExpr(MappingExpr)> function) const;
void Walk(llvm::function_ref<void(MappingExpr)> function) const;
mlir::LogicalResult SetInverse(
MappingExpr context_inverse,
llvm::MutableArrayRef<MappingExpr> inverses) const;
MappingExpr Unify(MappingExpr other_expr,
llvm::function_ref<MappingExpr(MappingExpr, MappingExpr)>
on_mismatch) const;
MappingExpr FindInInverse(llvm::ArrayRef<MappingExpr> inverse) const;
mlir::AffineExpr AsAffineExpr() const;
MappingExpr Canonicalize() const;
};
// Stiches together stripe expressions to iterate on a full dimension. Specifies
// the step of stripe expression. The last step must be 1.
class MappingUnStripeExpr
: public mlir::Attribute::AttrBase<MappingUnStripeExpr, mlir::Attribute,
impl::MappingUnStripeExprStorage,
MappingExpr::Trait> {
public:
using Base::Base;
static constexpr mlir::StringLiteral name = "sair.mapping_un_stripe_expr";
static constexpr llvm::StringRef kAttrName = "unstripe";
// Constructs an unstripe mapping expression. `stripes` must not be empty.
static MappingUnStripeExpr get(llvm::ArrayRef<MappingExpr> stripes,
llvm::ArrayRef<int> factors);
// The stripe expressions that are combined to obtain the unstriped
// expression.
llvm::ArrayRef<MappingExpr> operands() const;
// Stripe expression sizes.
llvm::ArrayRef<int> factors() const;
MappingExpr Map(llvm::function_ref<MappingExpr(MappingExpr)> function) const;
void Walk(llvm::function_ref<void(MappingExpr)> function) const;
mlir::LogicalResult SetInverse(
MappingExpr context_inverse,
llvm::MutableArrayRef<MappingExpr> inverses) const;
MappingExpr Unify(MappingExpr other_expr,
llvm::function_ref<MappingExpr(MappingExpr, MappingExpr)>
on_mismatch) const;
MappingExpr FindInInverse(llvm::ArrayRef<MappingExpr> inverse) const;
mlir::AffineExpr AsAffineExpr() const;
MappingExpr Canonicalize() const;
};
// An attribute describing a loop to generate when lowering an operation.
class LoopAttr : public mlir::DictionaryAttr {
public:
using mlir::DictionaryAttr::DictionaryAttr;
static bool classof(mlir::Attribute attr);
static LoopAttr get(mlir::StringAttr name, MappingExpr iter,
mlir::IntegerAttr unroll, mlir::MLIRContext *context);
mlir::StringAttr name() const;
MappingExpr iter() const;
mlir::IntegerAttr unroll() const;
};
// An attribute that specifies how a value is stored in a buffer.
class BufferAttr : public mlir::DictionaryAttr {
public:
using mlir::DictionaryAttr::DictionaryAttr;
static bool classof(mlir::Attribute attr);
static BufferAttr get(mlir::StringAttr space, mlir::StringAttr name,
NamedMappingAttr layout, mlir::MLIRContext *context);
mlir::StringAttr space() const;
mlir::StringAttr name() const;
NamedMappingAttr layout() const;
};
// An attribute that specifies how to implement an operation.
class DecisionsAttr : public mlir::DictionaryAttr {
public:
using mlir::DictionaryAttr::DictionaryAttr;
static bool classof(mlir::Attribute attr);
static DecisionsAttr get(mlir::IntegerAttr sequence,
mlir::ArrayAttr loop_nest, mlir::ArrayAttr storage,
mlir::StringAttr expansion, mlir::Attribute copy_of,
mlir::ArrayAttr operands,
mlir::MLIRContext *context);
mlir::IntegerAttr sequence() const;
mlir::ArrayAttr loop_nest() const;
mlir::ArrayAttr storage() const;
mlir::StringAttr expansion() const;
mlir::Attribute copy_of() const;
mlir::ArrayAttr operands() const;
};
} // namespace sair
// Include the definition of struct attributes generated by MLIR. The using
// namespace is required by the generated code.
using namespace mlir; // NOLINT
#define GET_ATTRDEF_CLASSES
#include "sair_attributes.h.inc"
namespace mlir {
class OptionalParseResult;
}
namespace sair {
// Below are helper functions to manipulate DecisionsAttr. Each helper takes a
// function and returns a function that applies the first function to a field of
// a DecisionsAttr. Helpers return functions rather than directly applying the
// transformation so that it is easier to combine transformations.
// Takes a function that updates a loop nest and returns a function that updates
// the loop nest field of a DecisionsAttr.
std::function<DecisionsAttr(DecisionsAttr)> MapLoopNest(
std::function<mlir::ArrayAttr(mlir::ArrayAttr)> loop_nest_fn);
// Takes a function that updates a list of storages and returns a function that
// updates the storage field of a DecisionsAttr.
std::function<DecisionsAttr(DecisionsAttr)> MapStorage(
std::function<mlir::ArrayAttr(mlir::ArrayAttr)> storage_fn);
// Updates the sequence field of a DecisionsAttr and returns the new
// DecisionsAttr.
DecisionsAttr UpdateSequence(DecisionsAttr decisions, int new_sequence);
// Updates the operands field of a DecisionsAttr and returns the new
// DecisionsAttr.
DecisionsAttr UpdateOperands(DecisionsAttr decisions,
ArrayRef<mlir::Attribute> operands);
// Returns an array attribute containing `num_operands` InstanceAttr with
// position zero in the given context.
mlir::ArrayAttr GetInstanceZeroOperands(mlir::MLIRContext *context,
int num_operands);
// Returns an array attribute containing a single DecisionsAttr (one instance)
// that has its `operands` field set to contain `num_operands` InstanceAttrs
// with position zero and the remaining fields unset.
mlir::ArrayAttr GetInstanceZeroOperandsSingleInstance(
mlir::MLIRContext *context, int num_operands);
// Returns a copy of `decisions` with the given operand erased from the operands
// field.
DecisionsAttr EraseOperand(DecisionsAttr decisions, int operand);
// Returns a copy of `operands` without the `operand`-th element.
mlir::ArrayAttr EraseOperandFromArray(mlir::ArrayAttr operands, int operand);
// Returns a copy of array attribute containing DecisionsAttr with, for each
// element, the `operand`-th entry of the `operands` field erased.
mlir::ArrayAttr EraseOperandFromDecisions(mlir::ArrayAttr decisions,
int operand);
namespace detail {
mlir::OptionalParseResult ParseGeneratedAttribute(mlir::MLIRContext *context,
mlir::AsmParser &parser,
llvm::StringRef *mnemonic,
mlir::Type type,
mlir::Attribute &attribute);
mlir::LogicalResult PrintGeneratedAttribute(mlir::Attribute attribute,
mlir::AsmPrinter &printer);
} // namespace detail
} // namespace sair
#endif // SAIR_SAIR_ATTRIBUTES_H_