31#include "llvm/ADT/ArrayRef.h"
32#include "llvm/ADT/DenseMap.h"
33#include "llvm/ADT/MapVector.h"
34#include "llvm/ADT/PostOrderIterator.h"
35#include "llvm/ADT/STLExtras.h"
36#include "llvm/ADT/Sequence.h"
37#include "llvm/ADT/SetVector.h"
38#include "llvm/ADT/SmallSet.h"
39#include "llvm/ADT/SmallVector.h"
40#include "llvm/ADT/TypeSwitch.h"
41#include "llvm/Support/Casting.h"
42#include "llvm/Support/Debug.h"
43#include "llvm/Support/LogicalResult.h"
44#include "llvm/Support/MathExtras.h"
45#include "llvm/Support/raw_ostream.h"
49#define GEN_PASS_DEF_XEGPUPROPAGATELAYOUT
50#include "mlir/Dialect/XeGPU/Transforms/Passes.h.inc"
54#define DEBUG_TYPE "xegpu-propagate-layout"
55#define DBGS() (llvm::dbgs() << "[" DEBUG_TYPE "]: ")
122 : scopeRoot(scopeRoot), layoutKind(layoutKind) {}
129 xegpu::DistributeLayoutAttr getRequestedLayout(
Value val)
const {
130 return requestedLayouts.lookup(val);
134 void print(llvm::raw_ostream &os);
137 void commitDecisions();
150 using AnchorLayouts =
169 void setOperandDecision(
OpOperand &operand,
170 xegpu::DistributeLayoutAttr layout) {
172 operandDecisions[&operand] = layout;
174 void setValueDecision(
Value value, xegpu::DistributeLayoutAttr layout) {
176 valueDecisions[value] = layout;
178 void setAnchorDecision(
Operation *op, AnchorLayouts layouts) {
179 if (!layouts.empty())
180 anchorDecisions[op] = std::move(layouts);
182 xegpu::DistributeLayoutAttr getOperandDecision(
OpOperand &operand)
const {
183 return operandDecisions.lookup(&operand);
187 struct PendingDiagnostic {
194 LogicalResult emitPendingDiagnostics();
201 void recordRequestedLayout(
Value val, xegpu::DistributeLayoutAttr layout) {
203 requestedLayouts[val] = layout;
205 void visitRegularOp(
Operation *op)
override;
206 void visitTerminator(RegionBranchTerminatorOpInterface terminator)
override;
207 void visitRegionOp(RegionBranchOpInterface regionOp)
override;
208 bool shouldRevisitRegions(RegionBranchOpInterface regionOp)
override;
214 void visitOperation(
Operation *op, LayoutsMutRef operands,
215 LayoutsMutRef results, AnchorLayouts &anchorLayouts);
217 void visitDpasOp(xegpu::DpasOp dpas, LayoutsMutRef operands,
218 LayoutsRef results, AnchorLayouts &anchorLayouts);
219 void visitDpasMxOp(xegpu::DpasMxOp dpasMx, LayoutsMutRef operands,
220 LayoutsRef results, AnchorLayouts &anchorLayouts);
221 void visitStoreNdOp(xegpu::StoreNdOp store, LayoutsMutRef operands,
222 LayoutsRef results, AnchorLayouts &anchorLayouts);
223 void visitStoreScatterOp(xegpu::StoreScatterOp storeScatter,
224 LayoutsMutRef operands, LayoutsRef results,
225 AnchorLayouts &anchorLayouts);
226 void visitLoadNdOp(xegpu::LoadNdOp
load, LayoutsMutRef operands,
227 LayoutsRef results, AnchorLayouts &anchorLayouts);
228 void visitLoadGatherOp(xegpu::LoadGatherOp
load, LayoutsMutRef operands,
229 LayoutsRef results, AnchorLayouts &anchorLayouts);
230 void visitPrefetchNdOp(xegpu::PrefetchNdOp prefetch, LayoutsMutRef operands,
231 LayoutsRef results, AnchorLayouts &anchorLayouts);
232 void visitLoadMatrixOp(xegpu::LoadMatrixOp
load, LayoutsMutRef operands,
233 LayoutsRef results, AnchorLayouts &anchorLayouts);
234 void visitStoreMatrixOp(xegpu::StoreMatrixOp store, LayoutsMutRef operands,
235 LayoutsRef results, AnchorLayouts &anchorLayouts);
236 void visitConvertLayoutOp(xegpu::ConvertLayoutOp convertLayout,
237 LayoutsMutRef operands, LayoutsMutRef results);
238 void visitTransposeOp(vector::TransposeOp transpose, LayoutsMutRef operands,
239 LayoutsMutRef results);
240 void visitVectorBitcastOp(vector::BitCastOp bitcast, LayoutsMutRef operands,
241 LayoutsMutRef results);
242 void visitVectorInterleaveOp(vector::InterleaveOp interleave,
243 LayoutsMutRef operands, LayoutsMutRef results);
244 void visitVectorDeinterleaveOp(vector::DeinterleaveOp deinterleave,
245 LayoutsMutRef operands, LayoutsMutRef results);
246 void visitVectorMultiReductionOp(vector::MultiDimReductionOp reduction,
247 LayoutsMutRef operands,
248 LayoutsMutRef results);
249 void visitVectorReductionOp(vector::ReductionOp reduction,
250 LayoutsMutRef operands, LayoutsMutRef results);
251 void visitVectorBroadCastOp(vector::BroadcastOp
broadcast,
252 LayoutsMutRef operands, LayoutsMutRef results);
253 void visitShapeCastOp(vector::ShapeCastOp shapeCast, LayoutsMutRef operands,
254 LayoutsMutRef results);
256 visitInsertStridedSliceOp(vector::InsertStridedSliceOp insertStridedSlice,
257 LayoutsMutRef operands, LayoutsMutRef results);
259 bool hasParamsOfLayoutKind(xegpu::DistributeLayoutAttr anchorLayout);
262 FailureOr<int64_t> getNumSgOrFail(
Operation *op,
int sgSize,
263 xegpu::DistributeLayoutAttr consumerLayout);
266 void markFailure(
Operation *op,
const llvm::Twine &message) {
267 pendingDiagnostics[op].push_back(
271 void markWarning(
Operation *op,
const llvm::Twine &message) {
272 pendingDiagnostics[op].push_back(
278void LayoutPropagation::visitOperation(
Operation *op, LayoutsMutRef operands,
279 LayoutsMutRef results,
280 AnchorLayouts &anchorLayouts) {
282 .Case([&](xegpu::DpasOp op) {
283 visitDpasOp(op, operands, results, anchorLayouts);
285 .Case([&](xegpu::DpasMxOp op) {
286 visitDpasMxOp(op, operands, results, anchorLayouts);
288 .Case([&](xegpu::StoreNdOp op) {
289 visitStoreNdOp(op, operands, results, anchorLayouts);
291 .Case([&](xegpu::StoreScatterOp op) {
292 visitStoreScatterOp(op, operands, results, anchorLayouts);
294 .Case([&](xegpu::LoadNdOp op) {
295 visitLoadNdOp(op, operands, results, anchorLayouts);
297 .Case([&](xegpu::LoadGatherOp op) {
298 visitLoadGatherOp(op, operands, results, anchorLayouts);
300 .Case([&](xegpu::PrefetchNdOp op) {
301 visitPrefetchNdOp(op, operands, results, anchorLayouts);
303 .Case([&](vector::TransposeOp op) {
304 visitTransposeOp(op, operands, results);
306 .Case([&](vector::BitCastOp op) {
307 visitVectorBitcastOp(op, operands, results);
309 .Case([&](vector::InterleaveOp op) {
310 visitVectorInterleaveOp(op, operands, results);
312 .Case([&](vector::DeinterleaveOp op) {
313 visitVectorDeinterleaveOp(op, operands, results);
315 .Case([&](vector::MultiDimReductionOp op) {
316 visitVectorMultiReductionOp(op, operands, results);
318 .Case([&](vector::ReductionOp op) {
319 visitVectorReductionOp(op, operands, results);
321 .Case([&](vector::BroadcastOp op) {
322 visitVectorBroadCastOp(op, operands, results);
324 .Case([&](vector::ShapeCastOp op) {
325 visitShapeCastOp(op, operands, results);
327 .Case([&](vector::InsertStridedSliceOp op) {
328 visitInsertStridedSliceOp(op, operands, results);
330 .Case([&](xegpu::LoadMatrixOp op) {
331 visitLoadMatrixOp(op, operands, results, anchorLayouts);
333 .Case([&](xegpu::StoreMatrixOp op) {
334 visitStoreMatrixOp(op, operands, results, anchorLayouts);
336 .Case([&](xegpu::ConvertLayoutOp op) {
337 visitConvertLayoutOp(op, operands, results);
341 .Default([&](Operation *op) {
342 auto it = llvm::find_if(
343 results, [](
auto layout) {
return static_cast<bool>(layout); });
344 if (it == results.end())
346 for (
auto [operandLayout, operand] :
353bool LayoutPropagation::hasParamsOfLayoutKind(
354 xegpu::DistributeLayoutAttr anchorLayout) {
355 if (anchorLayout ==
nullptr) {
358 if (layoutKind == xegpu::LayoutKind::InstData) {
359 return !(anchorLayout.getEffectiveInstDataAsInt().empty());
361 if (layoutKind == xegpu::LayoutKind::Lane) {
362 return !(anchorLayout.getEffectiveLaneLayoutAsInt().empty() ||
363 anchorLayout.getEffectiveLaneDataAsInt().empty());
365 if (layoutKind == xegpu::LayoutKind::Subgroup) {
366 return !(anchorLayout.getEffectiveSgLayoutAsInt().empty() ||
367 anchorLayout.getEffectiveSgDataAsInt().empty());
373LayoutPropagation::getNumSgOrFail(Operation *op,
int sgSize,
374 xegpu::DistributeLayoutAttr consumerLayout) {
376 if (consumerLayout) {
377 auto sgLayout = consumerLayout.getEffectiveSgLayoutAsInt();
378 if (!sgLayout.empty())
379 return llvm::product_of(sgLayout);
382 if (FailureOr<int64_t> numSg =
387 if (layoutKind == xegpu::LayoutKind::Subgroup) {
388 markFailure(op,
"Unable to determine the number of subgroups for the "
389 "operation. Please check @known_block_size is properly "
390 "attached as kernel attributes, with power-of-two "
391 "dimensions covering at least one subgroup.");
397void LayoutPropagation::visitPrefetchNdOp(xegpu::PrefetchNdOp prefetch,
398 LayoutsMutRef operands,
400 AnchorLayouts &anchorLayouts) {
402 xegpu::DistributeLayoutAttr prefetchLayout;
406 xegpu::DistributeLayoutAttr anchorLayout = prefetch.getLayoutAttr();
407 if (hasParamsOfLayoutKind(anchorLayout)) {
408 prefetchLayout = anchorLayout;
409 if (layoutKind == xegpu::LayoutKind::InstData) {
410 const auto *uArchInstruction =
411 dyn_cast<xegpu::uArch::Subgroup2DBlockPrefetchInstruction>(
412 uArch->getInstruction(
413 xegpu::uArch::InstructionKind::Subgroup2DBlockPrefetch));
414 if (!uArchInstruction)
417 anchorLayout, prefetch.getTensorDescType().getElementType(),
418 uArchInstruction, uArch->getSubgroupSize());
422 "Failed to identify lane layouts for the specified inst_data.");
425 anchorLayouts.emplace_back(prefetch.getLayoutAttrName(), *completed);
426 prefetchLayout = *completed;
429 auto tdescTy = prefetch.getTensorDescType();
431 getNumSgOrFail(prefetch, uArch->getSubgroupSize(),
nullptr);
436 layoutKind, tdescTy, numSgOrErr.value_or(0), uArch);
438 markWarning(prefetch,
439 "Failed to determine required layout for prefetch_nd.");
442 prefetchLayout = layoutAttr;
443 anchorLayouts.emplace_back(prefetch.getLayoutAttrName(), layoutAttr);
446 operands[0] = prefetchLayout;
449void LayoutPropagation::visitVectorMultiReductionOp(
450 vector::MultiDimReductionOp reduction, LayoutsMutRef operands,
451 LayoutsMutRef results) {
452 Type resultTy = reduction.getDestType();
455 xegpu::DistributeLayoutAttr consumerLayoutAttr;
457 consumerLayoutAttr = results[0];
458 if (!consumerLayoutAttr)
462 VectorType sourceTy = reduction.getSourceVectorType();
463 SmallVector<int64_t> reductionDims(reduction.getReductionDims());
471 getNumSgOrFail(reduction, uArch->getSubgroupSize(), consumerLayoutAttr);
477 layoutKind, sourceTy, consumerLayoutAttr, reductionDims,
478 numSgOrErr.value_or(0), uArch);
480 results[0] = requiredResLayoutAttr;
484 requiredResLayoutAttr, reductionDims);
486 operands[0] = srcLayoutAttr;
488 operands[1] = requiredResLayoutAttr;
491void LayoutPropagation::visitVectorReductionOp(vector::ReductionOp reduction,
492 LayoutsMutRef operands,
493 LayoutsMutRef results) {
495 VectorType sourceTy = reduction.getSourceVectorType();
501 auto requiredResLayoutAttr =
503 results[0] = requiredResLayoutAttr;
506 operands[0] = srcLayoutAttr;
507 if (reduction.getAcc())
508 operands[1] = requiredResLayoutAttr;
511void LayoutPropagation::visitVectorBroadCastOp(vector::BroadcastOp
broadcast,
512 LayoutsMutRef operands,
513 LayoutsMutRef results) {
515 xegpu::DistributeLayoutAttr resultLayoutAttr = results[0];
516 if (!resultLayoutAttr)
520 VectorType resultTy =
broadcast.getResultVectorType();
521 VectorType sourceTy = dyn_cast<VectorType>(
broadcast.getSourceType());
526 auto srcShape = sourceTy.getShape();
527 auto resShape = resultTy.getShape();
529 xegpu::DistributeLayoutAttr srcLayoutAttr =
532 operands[0] = srcLayoutAttr;
535void LayoutPropagation::visitShapeCastOp(vector::ShapeCastOp shapeCast,
536 LayoutsMutRef operands,
537 LayoutsMutRef results) {
539 xegpu::DistributeLayoutAttr resultLayoutAttr = results[0];
540 if (!resultLayoutAttr)
542 ArrayRef<int64_t> resShape = shapeCast.getResultVectorType().getShape();
543 ArrayRef<int64_t> srcShape = shapeCast.getSourceVectorType().getShape();
546 layoutKind, shapeCast.getSourceVectorType(),
547 shapeCast.getResultVectorType(), resultLayoutAttr);
552 if (!requiredResLayoutAttr) {
553 markWarning(shapeCast,
"Failed to infer source layout for shape_cast; the "
554 "result layout required by its consumers cannot be "
555 "collapsed onto the source shape.");
558 results[0] = requiredResLayoutAttr;
561 requiredResLayoutAttr, resShape, srcShape);
564 if (!srcLayoutAttr) {
565 markWarning(shapeCast,
"Failed to infer source layout for shape_cast; "
566 "unsupported shape-cast pattern.");
570 operands[0] = srcLayoutAttr;
574void LayoutPropagation::visitDpasOp(xegpu::DpasOp dpas, LayoutsMutRef operands,
576 AnchorLayouts &anchorLayouts) {
577 xegpu::DistributeLayoutAttr dpasALayout;
578 xegpu::DistributeLayoutAttr dpasBLayout;
579 xegpu::DistributeLayoutAttr dpasCDLayout;
584 VectorType aTy = dpas.getLhsType();
585 VectorType bTy = dpas.getRhsType();
586 VectorType cdTy = dpas.getResultType();
588 xegpu::DistributeLayoutAttr anchorLayoutCD = dpas.getLayoutCdAttr();
589 if (hasParamsOfLayoutKind(anchorLayoutCD)) {
590 xegpu::DistributeLayoutAttr anchorLayoutA = dpas.getLayoutAAttr();
591 xegpu::DistributeLayoutAttr anchorLayoutB = dpas.getLayoutBAttr();
592 assert(hasParamsOfLayoutKind(anchorLayoutA) &&
593 "Expected anchor layout for DPAS A operand.");
594 assert(hasParamsOfLayoutKind(anchorLayoutB) &&
595 "Expected anchor layout for DPAS B operand.");
596 dpasALayout = anchorLayoutA;
597 dpasBLayout = anchorLayoutB;
598 dpasCDLayout = anchorLayoutCD;
599 if (layoutKind == xegpu::LayoutKind::InstData) {
601 anchorLayoutA, anchorLayoutB, anchorLayoutCD, aTy, bTy, cdTy, uArch);
605 "Failed to identify lane layouts for the specified inst_data.");
608 auto [completedA, completedB, completedCD] = *completed;
609 anchorLayouts.emplace_back(dpas.getLayoutAAttrName(), completedA);
610 anchorLayouts.emplace_back(dpas.getLayoutBAttrName(), completedB);
611 anchorLayouts.emplace_back(dpas.getLayoutCdAttrName(), completedCD);
612 dpasALayout = completedA;
613 dpasBLayout = completedB;
614 dpasCDLayout = completedCD;
617 xegpu::DistributeLayoutAttr requiredCDLayoutAttr, requiredALayout,
620 xegpu::DistributeLayoutAttr consumerLayoutAttr = results[0];
621 if (!consumerLayoutAttr)
625 getNumSgOrFail(dpas, uArch->getSubgroupSize(), consumerLayoutAttr);
631 numSgOrErr.value_or(0), uArch);
632 if (!layouts.has_value()) {
634 "Failed to determine required layouts for DPAS operands.");
638 std::tie(requiredALayout, requiredBLayout, requiredCDLayoutAttr) = *layouts;
640 anchorLayouts.emplace_back(dpas.getLayoutAAttrName(), requiredALayout);
641 anchorLayouts.emplace_back(dpas.getLayoutBAttrName(), requiredBLayout);
642 anchorLayouts.emplace_back(dpas.getLayoutCdAttrName(),
643 requiredCDLayoutAttr);
644 dpasALayout = requiredALayout;
645 dpasBLayout = requiredBLayout;
646 dpasCDLayout = requiredCDLayoutAttr;
648 operands[0] = dpasALayout;
649 operands[1] = dpasBLayout;
650 if (operands.size() > 2)
651 operands[2] = dpasCDLayout;
657void LayoutPropagation::visitDpasMxOp(xegpu::DpasMxOp dpasMx,
658 LayoutsMutRef operands,
660 AnchorLayouts &anchorLayouts) {
663 xegpu::DistributeLayoutAttr dpasMxALayout, dpasMxBLayout, dpasMxCDLayout;
664 xegpu::DistributeLayoutAttr dpasMxAScaleLayout, dpasMxBScaleLayout;
667 xegpu::DistributeLayoutAttr anchorLayoutA = dpasMx.getLayoutAAttr();
668 xegpu::DistributeLayoutAttr anchorLayoutB = dpasMx.getLayoutBAttr();
669 xegpu::DistributeLayoutAttr anchorLayoutCD = dpasMx.getLayoutCdAttr();
675 VectorType aTy = dpasMx.getAType();
676 VectorType bTy = dpasMx.getBType();
677 VectorType cdTy = dpasMx.getResultType();
682 Value scaleA = dpasMx.getScaleA();
683 Value scaleB = dpasMx.getScaleB();
685 aScaleTy = dyn_cast<VectorType>(scaleA.
getType());
687 bScaleTy = dyn_cast<VectorType>(scaleB.
getType());
690 if (anchorLayoutA && anchorLayoutB && anchorLayoutCD &&
691 hasParamsOfLayoutKind(anchorLayoutA) &&
692 hasParamsOfLayoutKind(anchorLayoutB) &&
693 hasParamsOfLayoutKind(anchorLayoutCD)) {
694 dpasMxALayout = anchorLayoutA;
695 dpasMxBLayout = anchorLayoutB;
696 dpasMxCDLayout = anchorLayoutCD;
699 xegpu::DistributeLayoutAttr anchorLayoutAScale =
700 dpasMx.getLayoutAScaleAttr();
701 xegpu::DistributeLayoutAttr anchorLayoutBScale =
702 dpasMx.getLayoutBScaleAttr();
703 if (anchorLayoutAScale)
704 dpasMxAScaleLayout = anchorLayoutAScale;
705 if (anchorLayoutBScale)
706 dpasMxBScaleLayout = anchorLayoutBScale;
708 if (layoutKind == xegpu::LayoutKind::InstData) {
710 anchorLayoutA, anchorLayoutB, anchorLayoutCD, aTy, bTy, cdTy,
711 aScaleTy, bScaleTy, uArch);
715 "Failed to identify lane layouts for the specified inst_data.");
718 auto [completedA, completedB, completedCD, completedAScale,
719 completedBScale] = *completed;
720 anchorLayouts.emplace_back(dpasMx.getLayoutAAttrName(), completedA);
721 anchorLayouts.emplace_back(dpasMx.getLayoutBAttrName(), completedB);
722 anchorLayouts.emplace_back(dpasMx.getLayoutCdAttrName(), completedCD);
723 dpasMxALayout = completedA;
724 dpasMxBLayout = completedB;
725 dpasMxCDLayout = completedCD;
726 if (completedAScale) {
727 anchorLayouts.emplace_back(dpasMx.getLayoutAScaleAttrName(),
729 dpasMxAScaleLayout = completedAScale;
731 if (completedBScale) {
732 anchorLayouts.emplace_back(dpasMx.getLayoutBScaleAttrName(),
734 dpasMxBScaleLayout = completedBScale;
738 xegpu::DistributeLayoutAttr requiredCDLayoutAttr, requiredALayout,
739 requiredBLayout, requiredAScaleLayout, requiredBScaleLayout;
741 xegpu::DistributeLayoutAttr consumerLayoutAttr = results[0];
742 if (!consumerLayoutAttr)
746 getNumSgOrFail(dpasMx, uArch->getSubgroupSize(), consumerLayoutAttr);
751 layoutKind, aTy, bTy, cdTy, aScaleTy, bScaleTy, consumerLayoutAttr,
752 numSgOrErr.value_or(0), uArch);
753 if (!layouts.has_value()) {
755 "Failed to determine required layouts for DPAS_MX operands.");
759 std::tie(requiredALayout, requiredBLayout, requiredCDLayoutAttr,
760 requiredAScaleLayout, requiredBScaleLayout) = *layouts;
762 anchorLayouts.emplace_back(dpasMx.getLayoutAAttrName(), requiredALayout);
763 anchorLayouts.emplace_back(dpasMx.getLayoutBAttrName(), requiredBLayout);
764 anchorLayouts.emplace_back(dpasMx.getLayoutCdAttrName(),
765 requiredCDLayoutAttr);
766 if (requiredAScaleLayout)
767 anchorLayouts.emplace_back(dpasMx.getLayoutAScaleAttrName(),
768 requiredAScaleLayout);
769 if (requiredBScaleLayout)
770 anchorLayouts.emplace_back(dpasMx.getLayoutBScaleAttrName(),
771 requiredBScaleLayout);
773 dpasMxALayout = requiredALayout;
774 dpasMxBLayout = requiredBLayout;
775 dpasMxCDLayout = requiredCDLayoutAttr;
776 if (requiredAScaleLayout)
777 dpasMxAScaleLayout = requiredAScaleLayout;
778 if (requiredBScaleLayout)
779 dpasMxBScaleLayout = requiredBScaleLayout;
786 operands[0] = dpasMxALayout;
787 operands[1] = dpasMxBLayout;
789 if (dpasMx.getAcc()) {
790 operands[idx] = dpasMxCDLayout;
793 if (dpasMx.getScaleA()) {
794 if (dpasMxAScaleLayout)
795 operands[idx] = dpasMxAScaleLayout;
798 if (dpasMx.getScaleB()) {
799 if (dpasMxBScaleLayout)
800 operands[idx] = dpasMxBScaleLayout;
806void LayoutPropagation::visitStoreNdOp(xegpu::StoreNdOp store,
807 LayoutsMutRef operands,
809 AnchorLayouts &anchorLayouts) {
810 xegpu::DistributeLayoutAttr storeLayout;
814 xegpu::DistributeLayoutAttr anchorLayout = store.getLayoutAttr();
815 if (hasParamsOfLayoutKind(anchorLayout)) {
816 storeLayout = anchorLayout;
817 if (layoutKind == xegpu::LayoutKind::InstData) {
819 const auto *uArchInstruction =
820 dyn_cast<xegpu::uArch::Subgroup2DBlockStoreInstruction>(
821 uArch->getInstruction(
822 xegpu::uArch::InstructionKind::Subgroup2DBlockStore));
823 if (!uArchInstruction)
826 anchorLayout, store.getValueType().getElementType(), uArchInstruction,
827 uArch->getSubgroupSize());
831 "Failed to identify lane layouts for the specified inst_data.");
834 anchorLayouts.emplace_back(store.getLayoutAttrName(), *completed);
835 storeLayout = *completed;
838 auto numSgOrErr = getNumSgOrFail(store, uArch->getSubgroupSize(),
nullptr);
843 layoutKind, store.getValueType(), numSgOrErr.value_or(0), uArch);
845 markFailure(store,
"Failed to determine required layout for store_nd.");
848 storeLayout = layoutAttr;
849 anchorLayouts.emplace_back(store.getLayoutAttrName(), layoutAttr);
853 for (xegpu::DistributeLayoutAttr &operand : operands)
854 operand = storeLayout;
859void LayoutPropagation::visitLoadNdOp(xegpu::LoadNdOp
load,
860 LayoutsMutRef operands,
862 AnchorLayouts &anchorLayouts) {
863 xegpu::DistributeLayoutAttr loadLayout;
868 xegpu::DistributeLayoutAttr consumerLayoutAttr = results[0];
869 xegpu::DistributeLayoutAttr anchorLayout =
load.getLayoutAttr();
870 if (hasParamsOfLayoutKind(anchorLayout)) {
871 loadLayout = anchorLayout;
872 if (layoutKind == xegpu::LayoutKind::InstData && consumerLayoutAttr &&
873 !consumerLayoutAttr.getEffectiveLaneLayoutAsInt().empty()) {
874 const auto *uArchInstruction =
875 dyn_cast<xegpu::uArch::Subgroup2DBlockLoadInstruction>(
876 uArch->getInstruction(
877 xegpu::uArch::InstructionKind::Subgroup2DBlockLoad));
878 if (!uArchInstruction)
881 anchorLayout, consumerLayoutAttr,
load.getType().getElementType(),
882 uArchInstruction, uArch->getSubgroupSize());
886 "Failed to identify lane layouts for the specified inst_data.");
889 anchorLayouts.emplace_back(
load.getLayoutAttrName(), *completed);
890 loadLayout = *completed;
894 getNumSgOrFail(
load, uArch->getSubgroupSize(), consumerLayoutAttr);
898 layoutKind,
load.getType(), consumerLayoutAttr, numSgOrErr.value_or(0),
901 markWarning(
load,
"Failed to determine required layout for load_nd.");
904 loadLayout = layoutAttr;
905 anchorLayouts.emplace_back(
load.getLayoutAttrName(), layoutAttr);
908 operands[0] = loadLayout;
913void LayoutPropagation::visitConvertLayoutOp(xegpu::ConvertLayoutOp convert,
914 LayoutsMutRef operands,
915 LayoutsMutRef results) {
918 auto targetLayoutAttr =
919 dyn_cast<xegpu::LayoutAttr>(convert.getTargetLayoutAttr());
921 auto inputLayoutAttr =
922 dyn_cast_if_present<xegpu::LayoutAttr>(convert.getInputLayoutAttr());
928 auto resultLayoutAttr = dyn_cast_if_present<xegpu::LayoutAttr>(results[0]);
929 if (resultLayoutAttr && targetLayoutAttr) {
930 if (layoutKind == xegpu::LayoutKind::InstData &&
931 !targetLayoutAttr.getLaneLayout()) {
932 targetLayoutAttr = xegpu::LayoutAttr::get(
933 convert.getContext(), targetLayoutAttr.getSgLayout(),
934 targetLayoutAttr.getSgData(), targetLayoutAttr.getInstData(),
935 resultLayoutAttr.getLaneLayout(), resultLayoutAttr.getLaneData(),
936 resultLayoutAttr.getOrder());
937 convert.setTargetLayoutAttr(targetLayoutAttr);
944 if (inputLayoutAttr && targetLayoutAttr) {
945 if (layoutKind == xegpu::LayoutKind::InstData &&
946 !inputLayoutAttr.getLaneLayout()) {
947 auto merged = xegpu::LayoutAttr::get(
948 convert.getContext(), inputLayoutAttr.getSgLayout(),
949 inputLayoutAttr.getSgData(), inputLayoutAttr.getInstData(),
950 targetLayoutAttr.getLaneLayout(), targetLayoutAttr.getLaneData(),
951 targetLayoutAttr.getOrder());
952 convert.setInputLayoutAttr(merged);
957 operands[0] = convert.getEffectiveInputLayout();
962void LayoutPropagation::visitTransposeOp(vector::TransposeOp transpose,
963 LayoutsMutRef operands,
964 LayoutsMutRef results) {
966 xegpu::DistributeLayoutAttr consumerLayoutAttr = results[0];
967 if (!consumerLayoutAttr)
970 consumerLayoutAttr, transpose.getPermutation());
973 operands[0] = srcLayoutAttr;
978void LayoutPropagation::visitVectorBitcastOp(vector::BitCastOp bitcast,
979 LayoutsMutRef operands,
980 LayoutsMutRef results) {
982 xegpu::DistributeLayoutAttr consumerLayoutAttr = results[0];
983 if (!consumerLayoutAttr)
986 auto srcVecType = bitcast.getSourceVectorType();
987 auto resVecType = bitcast.getResultVectorType();
993 layoutKind, srcVecType, resVecType, consumerLayoutAttr, uArch);
995 results[0] = requiredResLayoutAttr;
997 int inElemTyBitWidth = srcVecType.getElementType().getIntOrFloatBitWidth();
998 int outElemTyBitWidth = resVecType.getElementType().getIntOrFloatBitWidth();
1002 requiredResLayoutAttr, outElemTyBitWidth, inElemTyBitWidth);
1004 operands[0] = srcLayoutAttr;
1010void LayoutPropagation::visitVectorInterleaveOp(vector::InterleaveOp interleave,
1011 LayoutsMutRef operands,
1012 LayoutsMutRef results) {
1014 xegpu::DistributeLayoutAttr consumerLayoutAttr = results[0];
1015 if (!consumerLayoutAttr)
1018 auto srcVecType = interleave.getSourceVectorType();
1019 auto resVecType = interleave.getResultVectorType();
1027 layoutKind, srcVecType, resVecType, consumerLayoutAttr, uArch);
1029 results[0] = requiredResLayoutAttr;
1032 auto srcLayoutAttr =
1036 operands[0] = srcLayoutAttr;
1037 operands[1] = srcLayoutAttr;
1043void LayoutPropagation::visitVectorDeinterleaveOp(
1044 vector::DeinterleaveOp deinterleave, LayoutsMutRef operands,
1045 LayoutsMutRef results) {
1048 xegpu::DistributeLayoutAttr consumerLayoutAttr = results[0];
1049 if (!consumerLayoutAttr)
1056 operands[0] = srcLayoutAttr;
1059void LayoutPropagation::visitInsertStridedSliceOp(
1060 vector::InsertStridedSliceOp insertStridedSlice, LayoutsMutRef operands,
1061 LayoutsMutRef results) {
1063 xegpu::DistributeLayoutAttr consumerLayoutAttr = results[0];
1064 if (!consumerLayoutAttr)
1067 auto srcVecType = insertStridedSlice.getSourceVectorType();
1068 auto resVecType = insertStridedSlice.getDestVectorType();
1075 layoutKind, srcVecType, resVecType, consumerLayoutAttr, uArch);
1076 results[0] = requiredResLayoutAttr;
1079 requiredResLayoutAttr, resVecType.getShape(), srcVecType.getShape());
1080 operands[0] = srcLayoutAttr;
1081 operands[1] = requiredResLayoutAttr;
1086void LayoutPropagation::visitLoadGatherOp(xegpu::LoadGatherOp
load,
1087 LayoutsMutRef operands,
1089 AnchorLayouts &anchorLayouts) {
1090 xegpu::DistributeLayoutAttr requiredAnchorLayoutAttr;
1091 xegpu::DistributeLayoutAttr anchorLayoutAttr =
load.getLayoutAttr();
1095 VectorType resVecTy =
load.getValueType();
1098 int contigChunkSize =
load.getContiguity().value_or(1);
1100 xegpu::DistributeLayoutAttr consumerLayoutAttr = results[0];
1101 if (hasParamsOfLayoutKind(anchorLayoutAttr)) {
1102 requiredAnchorLayoutAttr = anchorLayoutAttr;
1103 if (layoutKind == xegpu::LayoutKind::InstData && consumerLayoutAttr &&
1104 !consumerLayoutAttr.getEffectiveLaneLayoutAsInt().empty()) {
1105 const auto uArchInstruction =
1106 dyn_cast<xegpu::uArch::LoadGatherInstruction>(
1107 uArch->getInstruction(xegpu::uArch::InstructionKind::LoadGather));
1108 if (!uArchInstruction)
1111 anchorLayoutAttr, consumerLayoutAttr, resVecTy.getElementType(),
1112 uArchInstruction, uArch->getSubgroupSize());
1116 "Failed to identify lane layouts for the specified inst_data.");
1119 requiredAnchorLayoutAttr = *completed;
1120 anchorLayouts.emplace_back(
load.getLayoutAttrName(),
1121 requiredAnchorLayoutAttr);
1123 }
else if (!resVecTy) {
1124 markWarning(
load,
"Not propagating, non-vector payload supplied.");
1128 getNumSgOrFail(
load, uArch->getSubgroupSize(), consumerLayoutAttr);
1132 layoutKind, resVecTy, contigChunkSize, consumerLayoutAttr,
1133 numSgOrErr.value_or(0), uArch);
1134 if (!requiredAnchorLayoutAttr) {
1135 markWarning(
load,
"Failed to determine required layout for load_gather.");
1138 anchorLayouts.emplace_back(
load.getLayoutAttrName(),
1139 requiredAnchorLayoutAttr);
1143 if (isa<xegpu::TensorDescType>(
load.getSourceType()))
1144 operands[0] = requiredAnchorLayoutAttr;
1146 operands[1] = requiredAnchorLayoutAttr;
1147 operands[2] = requiredAnchorLayoutAttr;
1152void LayoutPropagation::visitStoreScatterOp(xegpu::StoreScatterOp storeScatter,
1153 LayoutsMutRef operands,
1155 AnchorLayouts &anchorLayouts) {
1157 xegpu::DistributeLayoutAttr requiredAnchorLayoutAttr;
1158 xegpu::DistributeLayoutAttr anchorLayoutAttr = storeScatter.getLayoutAttr();
1163 VectorType srcVecTy = storeScatter.getValueType();
1166 int contigChunkSize = storeScatter.getContiguity().value_or(1);
1168 if (hasParamsOfLayoutKind(anchorLayoutAttr)) {
1169 requiredAnchorLayoutAttr = anchorLayoutAttr;
1170 if (layoutKind == xegpu::LayoutKind::InstData) {
1171 const auto uArchInstruction =
1172 dyn_cast<xegpu::uArch::StoreScatterInstruction>(uArch->getInstruction(
1173 xegpu::uArch::InstructionKind::StoreScatter));
1174 if (!uArchInstruction)
1177 anchorLayoutAttr, srcVecTy.getElementType(), uArchInstruction,
1178 uArch->getSubgroupSize());
1182 "Failed to identify lane layouts for the specified inst_data.");
1185 requiredAnchorLayoutAttr = *completed;
1186 anchorLayouts.emplace_back(storeScatter.getLayoutAttrName(),
1187 requiredAnchorLayoutAttr);
1191 markWarning(storeScatter,
1192 "Not propagating, non-vector payload supplied.");
1196 getNumSgOrFail(storeScatter, uArch->getSubgroupSize(),
nullptr);
1200 layoutKind, srcVecTy, contigChunkSize, numSgOrErr.value_or(0), uArch);
1201 if (!requiredAnchorLayoutAttr) {
1202 markFailure(storeScatter,
1203 "Failed to determine required layout for store scatter.");
1206 anchorLayouts.emplace_back(storeScatter.getLayoutAttrName(),
1207 requiredAnchorLayoutAttr);
1211 operands[0] = requiredAnchorLayoutAttr;
1213 if (isa<xegpu::TensorDescType>(storeScatter.getDestType()))
1214 operands[1] = requiredAnchorLayoutAttr;
1216 operands[2] = requiredAnchorLayoutAttr;
1217 operands[3] = requiredAnchorLayoutAttr;
1220void LayoutPropagation::visitLoadMatrixOp(xegpu::LoadMatrixOp loadMatrixOp,
1221 LayoutsMutRef operands,
1223 AnchorLayouts &anchorLayouts) {
1225 xegpu::DistributeLayoutAttr consumerLayoutAttr = results[0];
1226 xegpu::DistributeLayoutAttr anchorLayout = loadMatrixOp.getLayoutAttr();
1230 if (!hasParamsOfLayoutKind(anchorLayout)) {
1231 VectorType resVecTy =
1232 llvm::cast<VectorType>(loadMatrixOp.getRes().getType());
1239 auto numSgOrErr = getNumSgOrFail(loadMatrixOp, uArch->getSubgroupSize(),
1240 consumerLayoutAttr);
1244 layoutKind, resVecTy, chunkSize, consumerLayoutAttr,
1245 numSgOrErr.value_or(0), uArch);
1246 if (!requiredAnchorLayoutAttr) {
1247 markWarning(loadMatrixOp,
1248 "Failed to determine required layout for load_matrix.");
1251 anchorLayouts.emplace_back(loadMatrixOp.getLayoutAttrName(),
1252 requiredAnchorLayoutAttr);
1256void LayoutPropagation::visitStoreMatrixOp(xegpu::StoreMatrixOp storeMatrix,
1257 LayoutsMutRef operands,
1259 AnchorLayouts &anchorLayouts) {
1260 xegpu::DistributeLayoutAttr requiredAnchorLayoutAttr;
1261 xegpu::DistributeLayoutAttr anchorLayoutAttr = storeMatrix.getLayoutAttr();
1262 VectorType srcVecTy = llvm::cast<VectorType>(storeMatrix.getData().getType());
1267 if (hasParamsOfLayoutKind(anchorLayoutAttr)) {
1268 requiredAnchorLayoutAttr = anchorLayoutAttr;
1269 if (layoutKind == xegpu::LayoutKind::InstData) {
1270 const auto uArchInstruction =
1271 dyn_cast<xegpu::uArch::StoreScatterInstruction>(uArch->getInstruction(
1272 xegpu::uArch::InstructionKind::StoreScatter));
1273 if (!uArchInstruction)
1276 anchorLayoutAttr, srcVecTy.getElementType(), uArchInstruction,
1277 uArch->getSubgroupSize());
1281 "Failed to identify lane layouts for the specified inst_data.");
1284 requiredAnchorLayoutAttr = *completed;
1285 anchorLayouts.emplace_back(storeMatrix.getLayoutAttrName(),
1286 requiredAnchorLayoutAttr);
1292 getNumSgOrFail(storeMatrix, uArch->getSubgroupSize(),
nullptr);
1296 layoutKind, srcVecTy, chunkSize, numSgOrErr.value_or(0), uArch);
1297 if (!requiredAnchorLayoutAttr) {
1298 markFailure(storeMatrix,
1299 "Failed to determine required layout for store matrix.");
1302 anchorLayouts.emplace_back(storeMatrix.getLayoutAttrName(),
1303 requiredAnchorLayoutAttr);
1305 operands[0] = requiredAnchorLayoutAttr;
1318void LayoutPropagation::commitDecisions() {
1319 for (
auto &[op, layouts] : anchorDecisions) {
1320 for (
auto [name, layout] : layouts) {
1327 for (
auto [operand, layout] : operandDecisions)
1329 for (
auto [value, layout] : valueDecisions) {
1330 if (isa<xegpu::TensorDescType>(value.getType()))
1332 else if (
auto result = dyn_cast<OpResult>(value))
1337LogicalResult LayoutPropagation::emitPendingDiagnostics() {
1339 for (
auto &[op, diagnostics] : pendingDiagnostics) {
1340 for (
const PendingDiagnostic &diag : diagnostics) {
1341 if (diag.severity == DiagnosticSeverity::Error) {
1349 return failure(failed);
1352LogicalResult LayoutPropagation::run() {
1354 return emitPendingDiagnostics();
1357void LayoutPropagation::visitRegularOp(Operation *op) {
1358 pendingDiagnostics.erase(op);
1359 SmallVector<xegpu::DistributeLayoutAttr> resultLayouts =
1361 return getRequestedLayout(result);
1363 SmallVector<xegpu::DistributeLayoutAttr> operandLayouts(op->
getNumOperands());
1364 AnchorLayouts anchorLayouts;
1365 visitOperation(op, operandLayouts, resultLayouts, anchorLayouts);
1367 for (
auto [operand, layout] :
1368 llvm::zip_equal(op->
getOperands(), operandLayouts))
1369 recordRequestedLayout(operand, layout);
1371 if (isa<xegpu::AnchorLayoutInterface>(op)) {
1372 setAnchorDecision(op, std::move(anchorLayouts));
1377 for (
auto [
result, layout] :
1378 llvm::zip_equal(op->
getResults(), resultLayouts)) {
1379 if (isa<xegpu::TensorDescType, VectorType>(
result.getType()) ||
1380 isa<vector::MultiDimReductionOp, vector::ReductionOp>(op))
1381 setValueDecision(
result, layout);
1385void LayoutPropagation::visitTerminator(
1386 RegionBranchTerminatorOpInterface terminator) {
1387 pendingDiagnostics.erase(terminator);
1388 auto regionOp = cast<RegionBranchOpInterface>(terminator->getParentOp());
1390 regionOp.getSuccessorOperandInputMapping(mapping,
1391 RegionBranchPoint(terminator));
1396 terminator, [&](Value val) {
return getRequestedLayout(val); },
1397 [&](OpOperand &operand, xegpu::DistributeLayoutAttr layout) {
1398 setOperandDecision(operand, layout);
1400 for (OpOperand &operand : llvm::reverse(terminator->getOpOperands()))
1401 recordRequestedLayout(operand.
get(), getOperandDecision(operand));
1403 for (
const auto &[successorOperand, successorInputs] : mapping) {
1406 auto loop = dyn_cast<LoopLikeOpInterface>(regionOp.getOperation());
1407 for (
auto arg : llvm::make_isa_range<BlockArgument>(successorInputs)) {
1408 if (isa<VectorType>(arg.getType()) &&
1409 !(loop && loop.getTiedLoopInit(arg)) &&
1410 !isa<BlockArgument>(successorOperand->get())) {
1411 markFailure(terminator,
1412 "unsupported region structure: the successor argument it "
1413 "feeds is not tied to an init operand, so its value must "
1414 "be passed through from predecessor region argument.");
1425bool LayoutPropagation::shouldRevisitRegions(RegionBranchOpInterface regionOp) {
1426 for (Region ®ion : regionOp->getRegions()) {
1427 for (
Block &block : region) {
1429 dyn_cast<RegionBranchTerminatorOpInterface>(block.getTerminator());
1433 regionOp.getSuccessorOperandInputMapping(mapping,
1434 RegionBranchPoint(terminator));
1436 for (
const auto &[operand, inputs] : mapping) {
1440 for (
auto arg : llvm::make_isa_range<BlockArgument>(inputs)) {
1441 if (arg.getOwner()->getParentOp() != regionOp.getOperation())
1443 xegpu::DistributeLayoutAttr requested = getRequestedLayout(arg);
1444 xegpu::DistributeLayoutAttr given = getOperandDecision(*operand);
1445 if (requested && (!given || !given.isEqualTo(requested)))
1454void LayoutPropagation::visitRegionOp(RegionBranchOpInterface regionOp) {
1458 regionOp, [&](Value val) {
return getRequestedLayout(val); },
1459 [&](OpOperand &operand, xegpu::DistributeLayoutAttr layout) {
1460 setOperandDecision(operand, layout);
1462 [&](BlockArgument arg, xegpu::DistributeLayoutAttr layout) {
1463 setValueDecision(arg, layout);
1465 for (OpOperand &operand : llvm::reverse(regionOp->getOpOperands()))
1466 recordRequestedLayout(operand.
get(), getOperandDecision(operand));
1469void LayoutPropagation::print(llvm::raw_ostream &os) {
1470 auto printLayout = [&](Value val) {
1471 if (xegpu::DistributeLayoutAttr layout = getRequestedLayout(val))
1474 os <<
"Not assigned.";
1477 auto printFunctionResult = [&](FunctionOpInterface funcOp) {
1478 os <<
"function: " << funcOp.getName() <<
":\n";
1479 for (BlockArgument arg : funcOp.getArguments()) {
1480 os <<
"argument: " << arg <<
"\n";
1484 funcOp.walk([&](Operation *op) {
1489 if (isa<BranchOpInterface, RegionBranchOpInterface>(op))
1494 for (
auto [i, r] : llvm::enumerate(op->
getResults())) {
1495 os <<
"layout for result #" << i <<
": ";
1501 auto modOp = dyn_cast<ModuleOp>(scopeRoot);
1504 for (
auto funcOp : modOp.getOps<FunctionOpInterface>())
1505 printFunctionResult(funcOp);
1506 for (
auto gpuModOp : modOp.getOps<gpu::GPUModuleOp>())
1507 for (
auto gpuFuncOp : gpuModOp.getOps<FunctionOpInterface>())
1508 printFunctionResult(gpuFuncOp);
1519static xegpu::CreateNdDescOp getDefiningCreateNdDescOp(Value tdescValue) {
1521 auto definingOp = tdescValue.
getDefiningOp<xegpu::CreateNdDescOp>();
1526 if (
auto arg = dyn_cast<BlockArgument>(tdescValue)) {
1528 if (
auto loop = dyn_cast<LoopLikeOpInterface>(parentOp)) {
1529 OpOperand *tiedInit = loop.getTiedLoopInit(arg);
1531 return getDefiningCreateNdDescOp(tiedInit->
get());
1538struct ResolveLayoutConflicts {
1539 ResolveLayoutConflicts(Operation *parentOp)
1540 : parentOp(parentOp), builder(parentOp->
getContext()) {}
1541 LogicalResult run();
1544 Operation *parentOp;
1546 LogicalResult resolveTensorDescConsumer(OpOperand &operand);
1547 LogicalResult resolveVectorConsumer(OpOperand &operand);
1548 LogicalResult assignResultLayout(OpResult &
result);
1552LogicalResult ResolveLayoutConflicts::run() {
1555 auto r = parentOp->
walk([&](Operation *op) -> WalkResult {
1560 if (
result.getType().isIntOrFloat() &&
1561 (isa<vector::MultiDimReductionOp>(op) ||
1562 isa<vector::ReductionOp>(op))) {
1563 auto res = assignResultLayout(
result);
1565 DBGS() <<
"Failed to assign layout for scalar consumer of reduction "
1573 if (isa<VectorType>(
result.getType()) &&
result.use_empty() &&
1574 isa<RegionBranchOpInterface>(op)) {
1575 auto res = assignResultLayout(
result);
1577 DBGS() <<
"Failed to assign layout for vector consumer of region op "
1586 if (isa<xegpu::AnchorLayoutInterface>(op) &&
1587 isa<xegpu::TensorDescType>(operandType)) {
1588 auto res = resolveTensorDescConsumer(operand);
1590 DBGS() <<
"Failed to resolve tensor descriptor consumer: " << *op
1596 if (isa<VectorType>(operandType)) {
1597 auto res = resolveVectorConsumer(operand);
1599 DBGS() <<
"Failed to resolve vector consumer: " << *op <<
"\n";
1607 if (r.wasInterrupted())
1611 DBGS() <<
"IR after resolving layout conflicts:\n";
1618LogicalResult ResolveLayoutConflicts::assignResultLayout(OpResult &
result) {
1619 Operation *producerOp =
result.getDefiningOp();
1623 auto convertOp = xegpu::ConvertLayoutOp::create(
1626 result.replaceAllUsesExcept(convertOp.getResult(), convertOp);
1631ResolveLayoutConflicts::resolveVectorConsumer(OpOperand &operand) {
1632 Value vectorValue = operand.
get();
1633 Operation *consumerOp = operand.
getOwner();
1636 if (!producerLayout) {
1637 if (
auto vectorTy = dyn_cast<VectorType>(vectorValue.
getType());
1638 vectorTy && vectorTy.getRank() > 1)
1639 consumerOp->
emitWarning(
"Expected layout for non-1D vectors.");
1647 if (!consumerLayout) {
1648 if (isa<func::ReturnOp>(consumerOp) || isa<gpu::ReturnOp>(consumerOp))
1651 "No consumer layout found for vector operand.");
1655 if (consumerLayout.isEqualTo(producerLayout))
1661 if (
auto consumerConvert = dyn_cast<xegpu::ConvertLayoutOp>(consumerOp)) {
1662 consumerConvert.setInputLayoutAttr(producerLayout);
1668 if (
auto producerConvert =
1670 producerConvert && vectorValue.
hasOneUse()) {
1673 producerConvert.setInputLayoutAttr(
1674 producerConvert.getEffectiveInputLayout());
1675 producerConvert.setTargetLayoutAttr(consumerLayout);
1681 auto convertOp = xegpu::ConvertLayoutOp::create(
1682 builder, consumerOp->
getLoc(), vectorValue.
getType(), vectorValue,
1683 producerLayout, consumerLayout);
1686 operand.
set(convertOp.getResult());
1691ResolveLayoutConflicts::resolveTensorDescConsumer(OpOperand &operand) {
1692 Operation *consumerOp = operand.
getOwner();
1693 Value tdescValue = operand.
get();
1694 auto anchorOp = dyn_cast<xegpu::AnchorLayoutInterface>(consumerOp);
1695 auto currTDescType = dyn_cast<xegpu::TensorDescType>(tdescValue.
getType());
1696 assert(anchorOp && currTDescType &&
1697 "Expected anchor layout op and tensor descriptor consumer.");
1698 Attribute currLayout = currTDescType.getLayout();
1699 Attribute expectedLayout = anchorOp.getAnchorLayout();
1702 if (expectedLayout && currLayout && expectedLayout != currLayout) {
1704 auto conflictingCreateNdOp = getDefiningCreateNdDescOp(tdescValue);
1705 if (!conflictingCreateNdOp) {
1706 DBGS() <<
"Unable to find defining CreateNdDescOp for tensor descriptor: "
1707 << tdescValue <<
"\n";
1712 auto newTensorDescType = xegpu::TensorDescType::get(
1713 conflictingCreateNdOp.getContext(), currTDescType.getShape(),
1714 currTDescType.getElementType(), currTDescType.getEncoding(),
1716 auto newOp = xegpu::CreateNdDescOp::create(
1718 conflictingCreateNdOp->getOperands(),
1719 conflictingCreateNdOp.getProperties(),
1720 conflictingCreateNdOp->getDiscardableAttrDictionary().getValue());
1745 xegpu::DistributeLayoutAttr layout = getLayoutOfValue(
result);
1750 bool anyAssigned =
false;
1753 srcLayouts.push_back(srclayout);
1754 anyAssigned |= (srclayout !=
nullptr);
1761 if (!layout &&
result.getNumUses() > 0) {
1762 op->
emitWarning(
"op has users but no layout assigned for its result");
1766 if (isa<xegpu::TensorDescType>(resultType)) {
1803 [&](xegpu::ConvertLayoutOp convert) { conversions.push_back(convert); });
1804 for (xegpu::ConvertLayoutOp convert : conversions) {
1808 convert.getResult().replaceAllUsesWith(
clone);
1830 llvm::SmallSetVector<xegpu::ConvertLayoutOp, 8> deadConverts;
1835 if (!isa<VectorType>(
result.getType()))
1837 xegpu::DistributeLayoutAttr resultLayout =
1844 xegpu::DistributeLayoutAttr uniformConvSrcLayout;
1846 Value operandValue = operand.
get();
1847 if (!isa<VectorType>(operandValue.
getType()))
1849 auto operandConversionOp =
1853 if (!operandConversionOp) {
1859 xegpu::DistributeLayoutAttr input =
1860 operandConversionOp.getEffectiveInputLayout();
1863 if (!uniformConvSrcLayout)
1864 uniformConvSrcLayout = input;
1865 else if (!uniformConvSrcLayout.isEqualTo(input))
1867 conversions.emplace_back(&operand, operandConversionOp);
1870 if (!uniformConvSrcLayout)
1877 resultLayout.getEffectiveInstDataAsInt();
1879 uniformConvSrcLayout.getEffectiveInstDataAsInt();
1880 if (resultLayoutInstData.empty() || sourceInstData.empty() ||
1886 llvm::SmallDenseSet<unsigned> rewiredOpIdxs;
1887 for (
auto [operand, convert] : conversions) {
1888 operand->
set(convert.getSource());
1892 Value operandValue = operand.
get();
1893 if (!isa<VectorType>(operandValue.
getType()))
1899 "operand should have been rejected above");
1904 clone->getResult(cast<OpResult>(operandValue).getResultNumber());
1907 operand.
set(cloneResult);
1913 auto newConvOp = xegpu::ConvertLayoutOp::create(
1916 result.replaceAllUsesExcept(newConvOp.getResult(), newConvOp);
1920 for (
auto [operand, convert] : conversions)
1921 if (convert.getResult().use_empty())
1922 deadConverts.insert(convert);
1926 for (xegpu::ConvertLayoutOp convert : deadConverts)
1931struct XeGPUPropagateLayoutPass final
1932 :
public xegpu::impl::XeGPUPropagateLayoutBase<XeGPUPropagateLayoutPass> {
1933 XeGPUPropagateLayoutPass() =
default;
1934 XeGPUPropagateLayoutPass(
const XeGPUPropagateLayoutPass &other) =
default;
1935 XeGPUPropagateLayoutPass(xegpu::XeGPUPropagateLayoutOptions
options)
1936 : XeGPUPropagateLayoutBase(std::move(
options)) {}
1937 void runOnOperation()
override;
1945 auto loop = dyn_cast<LoopLikeOpInterface>(regionOp.getOperation());
1948 for (
OpOperand &init : loop.getInitsMutable()) {
1949 if (!isa<VectorType>(init.get().getType()) ||
1952 if (xegpu::DistributeLayoutAttr layout = getLayoutOfValue(init.get()))
1960 RegionBranchTerminatorOpInterface terminator,
1963 auto branchOp = dyn_cast<RegionBranchOpInterface>(terminator->getParentOp());
1968 branchOp.getSuccessorOperandInputMapping(mapping,
1970 for (
const auto &[successorOperand, successorInputs] : mapping) {
1971 for (
Value successorInput : successorInputs) {
1973 if (!isa<VectorType>(successorInput.getType()))
1975 xegpu::DistributeLayoutAttr successorOperandLayout =
1979 if (!successorOperandLayout)
1980 successorOperandLayout = getLayoutOfValue(successorOperand->get());
1982 if (!successorOperandLayout)
1985 if (
auto result = dyn_cast<OpResult>(successorInput))
1993 mlir::FunctionOpInterface funcOp,
1999 if (!isa<FunctionType>(funcOp.getFunctionType()))
2005 newArgTypes.push_back(argType);
2008 xegpu::DistributeLayoutAttr layout = getLayoutOfValue(arg);
2010 LLVM_DEBUG(
DBGS() <<
"Expecting layout for function argument: " << arg
2011 <<
" but got none.\n");
2014 if (isa<xegpu::TensorDescType>(argType)) {
2016 newArgTypes.back() = arg.
getType();
2021 funcOp.setType(FunctionType::get(funcOp.getContext(), newArgTypes,
2022 funcOp.getResultTypes()));
2041 .Case([&](RegionBranchTerminatorOpInterface terminator) {
2045 .Case([&](FunctionOpInterface funcOp) {
2048 .Case([&](RegionBranchOpInterface regionOp) {
2055 op->
emitError(
"Failed to update operation with the layout.");
2067 LayoutPropagation propagation(
target, layoutKind);
2068 LogicalResult
result = propagation.run();
2071 if (printOnly || failed(
result)) {
2073 propagation.print(llvm::outs());
2077 propagation.commitDecisions();
2081 builder,
target, [&](
Value val) -> xegpu::DistributeLayoutAttr {
2082 if (xegpu::DistributeLayoutAttr layout =
2085 return propagation.getRequestedLayout(val);
2090 ResolveLayoutConflicts resolver(
target);
2091 return resolver.run();
2094void XeGPUPropagateLayoutPass::runOnOperation() {
2099 if (this->layoutKind ==
"lane") {
2101 }
else if (this->layoutKind ==
"inst") {
2103 }
else if (this->layoutKind ==
"subgroup") {
2104 layoutKind = xegpu::LayoutKind::Subgroup;
2106 getOperation()->emitError(
"Unsupported layout kind option: " +
2108 signalPassFailure();
2113 this->indexBitWidth, this->printOnly))) {
2114 signalPassFailure();
2119 signalPassFailure();
2123 if (layoutKind == xegpu::LayoutKind::InstData)
static llvm::ManagedStatic< PassManagerOptions > options
static void print(spirv::VerCapExtAttr triple, DialectAsmPrinter &printer)
static Value broadcast(Location loc, Value toBroadcast, unsigned numElements, const TypeConverter &typeConverter, ConversionPatternRewriter &rewriter)
Broadcasts the value to vector with numElements number of elements.
static LogicalResult forwardFillUnassignedLayouts(OpBuilder &builder, Operation *target, GetLayoutFnTy getLayoutOfValue)
Fill the layouts the backward scan leaves to the forward pass, in program order: the results of an op...
static LogicalResult forwardYieldOperandsToRegionResults(RegionBranchTerminatorOpInterface terminator, GetLayoutFnTy getLayoutOfValue)
Assign each region result the layout of the terminator operand forwarded to it.
function_ref< xegpu::DistributeLayoutAttr(Value)> GetLayoutFnTy
static void forwardInitsToRegionArgs(RegionBranchOpInterface regionOp, GetLayoutFnTy getLayoutOfValue)
Give each init operand of a loop without a layout decided for it the layout of its init value: the re...
static LogicalResult forwardFillRegularOp(mlir::OpBuilder &builder, mlir::Operation *op, GetLayoutFnTy getLayoutOfValue)
Update an operation with the layout of its results.
static LogicalResult updateFunctionOpInterface(mlir::OpBuilder &builder, mlir::FunctionOpInterface funcOp, GetLayoutFnTy getLayoutOfValue)
This class represents an argument of a Block.
Block * getOwner() const
Returns the block that owns this argument.
Operation * getParentOp()
Returns the closest surrounding operation that contains this block.
IRValueT get() const
Return the current value being used by this operand.
void set(IRValueT newValue)
Set the current value being used by this operand.
This class helps build Operations.
Operation * clone(Operation &op, IRMapping &mapper)
Creates a deep copy of the specified operation, remapping any operands that use values outside of the...
void setInsertionPointAfterValue(Value val)
Sets the insertion point to the node after the specified value.
void setInsertionPointAfter(Operation *op)
Sets the insertion point to the node after the specified operation, which will cause subsequent inser...
This class represents an operand of an operation.
unsigned getOperandNumber() const
Return which operand this is in the OpOperand list of the Operation.
This is a value defined by a result of an operation.
Operation is the basic unit of execution within MLIR.
void replaceUsesOfWith(Value from, Value to)
Replace any uses of 'from' with 'to' within this operation.
InFlightDiagnostic emitWarning(const Twine &message={})
Emit a warning about this operation, reporting up to any diagnostic handlers that may be listening.
OpResult getResult(unsigned idx)
Get the 'idx'th result of this operation.
Location getLoc()
The source location the operation was defined or derived from.
LLVM_DUMP_METHOD void dump()
MutableArrayRef< OpOperand > getOpOperands()
unsigned getNumOperands()
InFlightDiagnostic emitError(const Twine &message={})
Emit an error about fatal conditions with this operation, reporting up to any diagnostic handlers tha...
void setAttr(StringAttr name, Attribute value)
If the an attribute exists with the specified name, change it to the new value.
OperationName getName()
The name of an operation is the key identifier for it.
void print(raw_ostream &os, const OpPrintingFlags &flags={})
operand_range getOperands()
Returns an iterator on the underlying Value's.
std::enable_if_t< llvm::function_traits< std::decay_t< FnT > >::num_args==1, RetT > walk(FnT &&callback)
Walk the operation by calling the callback for each nested operation (including this one),...
result_range getResults()
Attribute removeAttr(StringAttr name)
Remove the attribute with the specified name if it exists.
unsigned getNumResults()
Return the number of results held by this operation.
This class represents a point being branched from in the methods of the RegionBranchOpInterface.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
bool isIntOrFloat() const
Return true if this is an integer (of any signedness) or a float type.
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Type getType() const
Return the type of this value.
bool hasOneUse() const
Returns true if this value has exactly one use.
Operation * getDefiningOp() const
If this value is the result of an operation, return the operation that defines it.
A utility result that is used to signal how to proceed with an ongoing walk:
static WalkResult advance()
bool wasInterrupted() const
Returns true if the walk was interrupted.
static WalkResult interrupt()
Operation * getOwner() const
Return the owner of this operand.
Callbacks for walkBackward.
bool hasElementwiseMappableTraits(Operation *op)
Together, Elementwise, Scalarizable, Vectorizable, and Tensorizable provide an easy way for scalar op...
const uArch * getUArch(llvm::StringRef archName)
DistributeLayoutAttr inferShapeCastSourceLayout(DistributeLayoutAttr resLayout, ArrayRef< int64_t > resShape, ArrayRef< int64_t > srcShape)
Infers the source layout attribute for a shape cast operation given the result layout attribute,...
void sinkElementwiseConversions(OpBuilder &builder, Operation *target)
Sink xegpu.convert_layout ops past the elementwise operations they feed, so that an elementwise op ru...
DistributeLayoutAttr setupLoadNdAnchorLayout(LayoutKind layoutKind, VectorType vectorTy, DistributeLayoutAttr consumerLayout, int numSg, const uArch::uArch *uArch)
Sets up the anchor layout for a load_nd operation.
DistributeLayoutAttr inferResultLayoutFromSourceForNonAnchorOp(Operation *op, ArrayRef< DistributeLayoutAttr > operandLayouts)
Infers the result layout attribute for a non-anchor operation from the layouts of its source operands...
DistributeLayoutAttr setupInterleaveResultLayout(LayoutKind layoutKind, VectorType srcVectorTy, VectorType resVectorTy, DistributeLayoutAttr consumerLayout, const uArch::uArch *uArch)
Sets up the result layout for an interleave operation to ensure the source layout can be safely deriv...
DistributeLayoutAttr inferTransposeSourceLayout(DistributeLayoutAttr resLayout, ArrayRef< int64_t > permutation)
Infers the source layout attribute for a transpose operation given the result layout attribute and pe...
std::optional< std::tuple< DistributeLayoutAttr, DistributeLayoutAttr, DistributeLayoutAttr, DistributeLayoutAttr, DistributeLayoutAttr > > completeDpasMxLaneLayoutFromInstData(DistributeLayoutAttr aLayout, DistributeLayoutAttr bLayout, DistributeLayoutAttr cdLayout, VectorType aTy, VectorType bTy, VectorType cdTy, VectorType aScaleTy, VectorType bScaleTy, const uArch::uArch *uArch)
Like completeDpasLaneLayoutFromInstData, but for dpas_mx: additionally re-derives the A_scale / B_sca...
DistributeLayoutAttr inferInsertStridedSliceSourceLayout(DistributeLayoutAttr resLayout, ArrayRef< int64_t > resShape, ArrayRef< int64_t > srcShape)
Infers the source layout attribute for an insert strided slice operation given the result layout attr...
DistributeLayoutAttr setupStoreMatrixAnchorLayout(LayoutKind layoutKind, VectorType vectorTy, int contigChunkSize, int numSg, const uArch::uArch *uArch)
Sets up the anchor layout for a store matrix operation.
void removeTemporaryLayoutAttrs(Operation *op)
Removes the temporary layout attributes for each OpOperand and OpResult of the given operation.
std::optional< std::tuple< DistributeLayoutAttr, DistributeLayoutAttr, DistributeLayoutAttr > > completeDpasLaneLayoutFromInstData(DistributeLayoutAttr aLayout, DistributeLayoutAttr bLayout, DistributeLayoutAttr cdLayout, VectorType aTy, VectorType bTy, VectorType cdTy, const uArch::uArch *uArch)
Completes user-provided DPAS A/B/C-D anchors that carry only inst_data by filling in lane_layout / la...
void setTemporaryLayout(const T &operandOrResult, const DistributeLayoutAttr layout)
LogicalResult propagateRegionArgsToInits(RegionBranchOpInterface regionOp, GetLayoutFnTy getLayoutOfValue, SetOperandLayoutFnTy setOperandLayout, SetTDescArgLayoutFnTy setTDescArgLayout)
Propagate layouts from a region branch op's region entry block arguments back to its init operands.
LayoutKind
Specifies the level of a layout hierarchy for comparison or propagation.
void setDistributeLayoutAttr(const OpResult &Result, const DistributeLayoutAttr layout)
[to-be-deprecated] Sets the DistributeLayoutAttr for a given OpResult user should use setAnchorLayout...
DistributeLayoutAttr inferInterleaveSourceLayout(DistributeLayoutAttr resLayout)
Infers the source layout attribute for an interleave operation given the result layout attribute.
DistributeLayoutAttr setupLoadGatherAnchorLayout(LayoutKind layoutKind, VectorType vectorTy, int contigChunkSize, DistributeLayoutAttr consumerLayout, int numSg, const uArch::uArch *uArch)
Sets up the anchor layout for a load gather operation.
FailureOr< int64_t > getNumSubgroupsFromBlockSize(Operation *op, int64_t subgroupSize)
Returns the number of subgroups the kernel enclosing op runs, derived from the known_block_size of it...
DistributeLayoutAttr inferBroadcastSourceLayout(DistributeLayoutAttr resLayout, ArrayRef< int64_t > resShape, ArrayRef< int64_t > srcShape)
Infers the source layout attribute for a broadcast operation given the result layout attribute,...
std::optional< std::tuple< DistributeLayoutAttr, DistributeLayoutAttr, DistributeLayoutAttr, DistributeLayoutAttr, DistributeLayoutAttr > > setupDpasMxLayout(LayoutKind layoutKind, VectorType aTy, VectorType bTy, VectorType cdTy, VectorType aScaleTy, VectorType bScaleTy, DistributeLayoutAttr consumerLayout, int numSg, const uArch::uArch *uArch)
Sets up the anchor layouts for dpas_mx operands (A, B, C/D, A_scale, and B_scale).
void walkBackward(Operation *root, BackwardLayoutVisitor &visitor)
Walk function bodies under root in CFG post-order, visiting ops within each block back to front and n...
SliceAttr setupMultiReductionResultLayout(LayoutKind layoutKind, VectorType srcVectorTy, DistributeLayoutAttr consumerLayout, SmallVector< int64_t > reductionDims, int numSg, const uArch::uArch *uArch)
Note on the consumerLayout argument used by the consumer-driven setup* / complete* helpers below:
std::optional< DistributeLayoutAttr > completeScatterLoadLaneLayoutFromInstData(DistributeLayoutAttr userSpecifiedLayout, DistributeLayoutAttr consumerLayout, Type elemTy, const xegpu::uArch::LoadGatherInstruction *uArchInstruction, const int subgroupSize)
If the consumer layout has only inst_data (no lane_layout/lane_data), completes it by running the cor...
DistributeLayoutAttr setupLoadMatrixAnchorLayout(LayoutKind layoutKind, VectorType vectorTy, int contigChunkSize, DistributeLayoutAttr consumerLayout, int numSg, const uArch::uArch *uArch)
Sets up the anchor layout for load matrix operation.
DistributeLayoutAttr setupStoreScatterAnchorLayout(LayoutKind layoutKind, VectorType vectorTy, int contigChunkSize, int numSg, const uArch::uArch *uArch)
Sets up the anchor layout for a store scatter operation.
DistributeLayoutAttr setupBitCastResultLayout(LayoutKind layoutKind, VectorType srcVectorTy, VectorType resVectorTy, DistributeLayoutAttr consumerLayout, const uArch::uArch *uArch)
Setup the result layout attribute for a bitcast operation based on element type bitwidths.
void propagateRegionResultsToYieldOperands(RegionBranchTerminatorOpInterface terminator, GetLayoutFnTy getLayoutOfValue, SetOperandLayoutFnTy setOperandLayout)
Propagate layouts to the operands of a region branch terminator: each operand gets,...
void removeLayoutAttr(const T &operandOrResult)
Removes the LayoutAttr for a given OpOperand or OpResult if it exists.
bool isLayoutCarrierType(Type type)
Returns true if values of type can carry a DistributeLayoutAttr, i.e.
DistributeLayoutAttr getDistributeLayoutAttr(const Value value)
Retrieves the DistributeLayoutAttr associated with a given Value, or nullptr if none is found.
DistributeLayoutAttr setupPrefetchNdAnchorLayout(LayoutKind layoutKind, TensorDescType tdescTy, int numSg, const uArch::uArch *uArch)
Sets up the anchor layout for a prefetch_nd operation.
LogicalResult resolveLayoutConflicts(Operation *target)
DistributeLayoutAttr inferBitCastSourceLayout(DistributeLayoutAttr resLayout, int resElemTyBitWidth, int srcElemTyBitWidth)
Infers the source layout attribute for a bitcast operation given the result layout attribute,...
DistributeLayoutAttr setupInsertStridedSliceResultLayout(LayoutKind layoutKind, VectorType srcVectorTy, VectorType resVectorTy, DistributeLayoutAttr consumerLayout, const uArch::uArch *uArch)
Sets up the result layout for an insert strided slice operation.
DistributeLayoutAttr setupShapeCastResultLayout(LayoutKind layoutKind, VectorType srcVectorTy, VectorType resVectorTy, DistributeLayoutAttr consumerLayout)
Sets up the result layout for a shape cast that splits one source dim into several consecutive result...
std::optional< std::string > getChipStr(Operation *op)
Retrieves the chip string from the XeVM target attribute of the parent GPU module operation.
DistributeLayoutAttr inferReductionSourceLayout(DistributeLayoutAttr resLayout)
Infers the source layout attribute for a reduction operation given the result layout attribute and re...
std::optional< DistributeLayoutAttr > completeScatterStoreLaneLayoutFromInstData(DistributeLayoutAttr specifiedLayout, Type elemTy, const xegpu::uArch::StoreScatterInstruction *uArchInstruction, const int subgroupSize)
Like completeScatterLoadLaneLayoutFromInstData, but for scatter stores (store_scatter / store_matrix)...
DistributeLayoutAttr getTemporaryLayout(const T &operandOrResult)
get and set distribute layout attribute for non-anchor operations (and offsets/masks of load/store op...
std::optional< DistributeLayoutAttr > completeBlockStoreLaneLayoutFromInstData(DistributeLayoutAttr specifiedLayout, Type elemTy, const xegpu::uArch::BlockIOInstructionInterface *uArchInstruction, const int subgroupSize)
Completes a user-provided 2D-block store_nd / prefetch_nd anchor that has only inst_data.
DistributeLayoutAttr inferDeinterleaveSourceLayout(DistributeLayoutAttr resLayout)
Infers the source layout attribute for a deinterleave operation given the result layout attribute.
DistributeLayoutAttr getConsumerLayoutAt(OpOperand &operand)
Gets the expected layout for a given consumer operand.
DistributeLayoutAttr inferMultiReductionSourceLayout(DistributeLayoutAttr resLayout, SmallVector< int64_t > reduceDims)
Infers the source layout attribute for a reduction operation given the result layout attribute and re...
bool isTriviallyRematerializable(Operation *op)
Returns true if the vector produced by op is cheap to recompute in any layout, i.e.
LogicalResult propagateLayouts(OpBuilder &builder, Operation *target, LayoutKind layoutKind, unsigned indexBitWidth, bool printOnly=false)
Value rematerialize(OpBuilder &builder, Value value)
Clone a bounded chain of pure vector generators and layout-preserving elementwise ops without layout ...
DistributeLayoutAttr setupStoreNdAnchorLayout(LayoutKind layoutKind, VectorType vectorTy, int numSg, const uArch::uArch *uArch)
Sets up the anchor layout for a store_nd operation.
std::optional< DistributeLayoutAttr > completeBlockLoadLaneLayoutFromInstData(DistributeLayoutAttr specifiedLayout, DistributeLayoutAttr consumerLayout, Type elemTy, const xegpu::uArch::BlockIOInstructionInterface *uArchInstruction, const int subgroupSize)
Like completeBlockStoreLaneLayoutFromInstData, but for load_nd.
void setTensorDescLayout(Value value, DistributeLayoutAttr layout)
Sets layout on the type of the tensor_desc value value, replacing any layout the type already has.
std::optional< std::tuple< DistributeLayoutAttr, DistributeLayoutAttr, DistributeLayoutAttr > > setupDpasLayout(LayoutKind layoutKind, VectorType aTy, VectorType bTy, VectorType cdTy, DistributeLayoutAttr consumerLayout, int numSg, const uArch::uArch *uArch)
Sets up the anchor layouts for a dpas operands (A, B, and C/D).
void rematerializeConversionSources(OpBuilder &builder, Operation *target)
Replace layout conversions of cheap producer chains by recomputation.
SliceAttr setupReductionResultLayout(LayoutKind layoutKind, VectorType srcVectorTy, const uArch::uArch *uArch)
Sets up layout for Reduction operations by creating a SliceAttr for the result.
Include the generated interface declarations.
DenseMap< OpOperand *, SmallVector< Value > > RegionBranchSuccessorMapping
A mapping from successor operands to successor inputs.
DiagnosticSeverity
Defines the different supported severity of a diagnostic.
int64_t computeProduct(ArrayRef< int64_t > basis)
Self-explicit.
llvm::TypeSwitch< T, ResultT > TypeSwitch
Operation * clone(OpBuilder &b, Operation *op, TypeRange newResultTypes, ValueRange newOperands)
llvm::DenseMap< KeyT, ValueT, KeyInfoT, BucketT > DenseMap
llvm::function_ref< Fn > function_ref