@@ -185,6 +185,9 @@ def DistributeLayoutAttr: AttrInterface<"DistributeLayoutAttr"> {
185185 InterfaceMethod<"Check the availability of workgroup level layouts",
186186 "bool",
187187 "isForWorkgroup">,
188+ InterfaceMethod<"Check the availability of subgroup level layouts",
189+ "bool",
190+ "isForSubgroup">,
188191 InterfaceMethod<"Get the rank of attribute",
189192 "int64_t",
190193 "getRank">,
@@ -197,14 +200,26 @@ def DistributeLayoutAttr: AttrInterface<"DistributeLayoutAttr"> {
197200 return 0;
198201 }], [{}]>,
199202 InterfaceMethod<"Get the SgLayout field of the attribute as integer array",
200- "std::optional< SmallVector<int64_t> >",
203+ "SmallVector<int64_t>",
201204 "getSgLayoutAsInt">,
202205 InterfaceMethod<"Get the SgData field of the attribute as integer array",
203- "std::optional< SmallVector<int64_t> >",
206+ "SmallVector<int64_t>",
204207 "getSgDataAsInt">,
208+ InterfaceMethod<"Get the InstData field of the attribute as integer array",
209+ "SmallVector<int64_t>",
210+ "getInstDataAsInt">,
211+ InterfaceMethod<"Get the LaneLayout field of the attribute as integer array",
212+ "SmallVector<int64_t>",
213+ "getLaneLayoutAsInt">,
214+ InterfaceMethod<"Get the LaneData field of the attribute as integer array",
215+ "SmallVector<int64_t>",
216+ "getLaneDataAsInt">,
205217 InterfaceMethod<"Derive a new layout by dropping sgLayout and sgData",
206218 "xegpu::DistributeLayoutAttr",
207219 "dropSgLayoutAndData">,
220+ InterfaceMethod<"Derive a new layout by dropping InstData",
221+ "xegpu::DistributeLayoutAttr",
222+ "dropInstData">,
208223 InterfaceMethod<[{Delinearizes a linear subgroup ID into its multidimensional
209224 indices based on the effective subgroup layout.}],
210225 "FailureOr<SmallVector<Value>>",
@@ -376,16 +391,34 @@ def XeGPU_LayoutAttr : XeGPUAttr<"Layout", "layout", [DistributeLayoutAttr]> {
376391 getLaneLayout(), getLaneData(), getOrder());
377392 }
378393
379- std::optional< SmallVector<int64_t> > getSgLayoutAsInt() const {
394+ SmallVector<int64_t> getSgLayoutAsInt() const {
380395 if (DenseI32ArrayAttr layout = getSgLayout())
381396 return llvm::to_vector_of<int64_t>(layout.asArrayRef());
382- return std::nullopt ;
397+ return {} ;
383398 }
384399
385- std::optional< SmallVector<int64_t> > getSgDataAsInt() const {
400+ SmallVector<int64_t> getSgDataAsInt() const {
386401 if (DenseI32ArrayAttr data = getSgData())
387402 return llvm::to_vector_of<int64_t>(data.asArrayRef());
388- return std::nullopt;
403+ return {};
404+ }
405+
406+ SmallVector<int64_t> getInstDataAsInt() const {
407+ if (DenseI32ArrayAttr inst = getInstData())
408+ return llvm::to_vector_of<int64_t>(inst.asArrayRef());
409+ return {};
410+ }
411+
412+ SmallVector<int64_t> getLaneLayoutAsInt() const {
413+ if (DenseI32ArrayAttr layout = getLaneLayout())
414+ return llvm::to_vector_of<int64_t>(layout.asArrayRef());
415+ return {};
416+ }
417+
418+ SmallVector<int64_t> getLaneDataAsInt() const {
419+ if (DenseI32ArrayAttr data = getLaneData())
420+ return llvm::to_vector_of<int64_t>(data.asArrayRef());
421+ return {};
389422 }
390423
391424 /// Delinearizes a linear subgroup ID into its multidimensional indices
@@ -466,26 +499,67 @@ def XeGPU_SliceAttr : XeGPUAttr<"Slice", "slice", [DistributeLayoutAttr]> {
466499
467500 /// Returns the SgLayout of the attribute, computed by applying
468501 /// the slice dimensions to the underlying LayoutAttr.
469- std::optional< SmallVector<int64_t> > getSgLayoutAsInt() const {
502+ SmallVector<int64_t> getSgLayoutAsInt() const {
470503 SliceAttr attr = flatten();
471504 auto parent = dyn_cast<LayoutAttr>(attr.getParent());
472- if (auto layout = parent.getSgLayoutAsInt()) {
505+ auto layout = parent.getSgLayoutAsInt();
506+ if (layout.size()) {
473507 ArrayRef<int64_t> dims = attr.getDims().asArrayRef();
474- return XeGPUDialect::slice(llvm:: ArrayRef<int64_t>(* layout), dims);
508+ return XeGPUDialect::slice(ArrayRef<int64_t>(layout), dims);
475509 }
476- return std::nullopt ;
510+ return {} ;
477511 }
478512
479513 /// Returns the SgData of the attribute, computed by applying
480514 /// the slice dimensions to the underlying LayoutAttr.
481- std::optional<SmallVector<int64_t>> getSgDataAsInt() const {
515+ SmallVector<int64_t> getSgDataAsInt() const {
516+ SliceAttr attr = flatten();
517+ auto parent = dyn_cast<LayoutAttr>(attr.getParent());
518+ auto data = parent.getSgDataAsInt();
519+ if (data.size()) {
520+ ArrayRef<int64_t> dims = attr.getDims().asArrayRef();
521+ return XeGPUDialect::slice(ArrayRef<int64_t>(data), dims);
522+ }
523+ return {};
524+ }
525+
526+ /// Returns the InstData of the attribute, computed by applying
527+ /// the slice dimensions to the underlying LayoutAttr.
528+ SmallVector<int64_t> getInstDataAsInt() const {
529+ SliceAttr attr = flatten();
530+ auto parent = dyn_cast<LayoutAttr>(attr.getParent());
531+ auto inst = parent.getInstDataAsInt();
532+ if (inst.size()) {
533+ ArrayRef<int64_t> dims = attr.getDims().asArrayRef();
534+ return XeGPUDialect::slice(llvm::ArrayRef<int64_t>(inst), dims);
535+ }
536+ return {};
537+ }
538+
539+ /// Returns the LaneLayout of the attribute, computed by applying
540+ /// the slice dimensions to the underlying LayoutAttr.
541+ SmallVector<int64_t> getLaneLayoutAsInt() const {
542+ SliceAttr attr = flatten();
543+ auto parent = dyn_cast<LayoutAttr>(attr.getParent());
544+ auto layout = parent.getLaneLayoutAsInt();
545+ if (layout.size()) {
546+ ArrayRef<int64_t> dims = attr.getDims().asArrayRef();
547+ return XeGPUDialect::slice(llvm::ArrayRef<int64_t>(layout), dims);
548+ }
549+ return {};
550+ }
551+
552+ /// Returns the LaneData of the attribute, computed by applying
553+ /// the slice dimensions to the underlying LayoutAttr.
554+ SmallVector<int64_t> getLaneDataAsInt() const {
482555 SliceAttr attr = flatten();
483556 auto parent = dyn_cast<LayoutAttr>(attr.getParent());
484- if (auto data = parent.getSgDataAsInt()) {
557+ auto data = parent.getLaneDataAsInt();
558+ if (data.size()) {
485559 ArrayRef<int64_t> dims = attr.getDims().asArrayRef();
486- return XeGPUDialect::slice(llvm::ArrayRef<int64_t>(* data), dims);
560+ return XeGPUDialect::slice(llvm::ArrayRef<int64_t>(data), dims);
487561 }
488- return std::nullopt ;
562+ return {} ;
489563 }
490564
491565 SliceAttr dropSgLayoutAndData() {
0 commit comments