MLIR-AIE 1.4.6.dev
AIETraceOps.cpp
Go to the documentation of this file.
1//===- AIETraceOps.cpp ------------------------------------------*- C++ -*-===//
2//
3// Copyright (C) 2025 Advanced Micro Devices, Inc.
4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5//
6//===----------------------------------------------------------------------===//
7// Implementation of AIE trace operations
8//===----------------------------------------------------------------------===//
9
11
12#include "mlir/IR/OpImplementation.h"
13#include "mlir/IR/SymbolTable.h"
14#include "llvm/ADT/SmallVector.h"
15#include "llvm/ADT/StringRef.h"
16
17using namespace mlir;
18using namespace xilinx;
19using namespace xilinx::AIE;
20
21//===----------------------------------------------------------------------===//
22// TraceEventAttr Helper Methods
23//===----------------------------------------------------------------------===//
24
25std::string TraceEventAttr::getEventName() const {
26 if (auto strAttr = llvm::dyn_cast<StringAttr>(getValue())) {
27 // If the string is fully qualified (contains '::'), extract just the name
28 StringRef strValue = strAttr.getValue();
29 size_t pos = strValue.find("::");
30 if (pos != StringRef::npos) {
31 return strValue.substr(pos + 2).str();
32 }
33 return strAttr.getValue().str();
34 }
35
36 // Fallback: unexpected attribute kind.
37 return "";
38}
39
40bool TraceEventAttr::isStringAttr() const {
41 return llvm::isa<StringAttr>(getValue());
42}
43
44std::optional<int64_t> TraceEventAttr::getEnumValue() const {
45 if (auto intAttr = llvm::dyn_cast<IntegerAttr>(getValue())) {
46 return intAttr.getInt();
47 }
48 // String values don't have enum values - they're event names
49 return std::nullopt;
50}
51
52//===----------------------------------------------------------------------===//
53// Tile Type Validation Helper
54//===----------------------------------------------------------------------===//
55
56static bool isValidEventForTile(TileLike tile, Attribute eventAttr,
57 const AIETargetModel &targetModel) {
58 // Determine tile type from TileLike interface
59 bool isShimTile = tile.isShimTile();
60 bool isMemTile = tile.isMemTile();
61 bool isCoreTile = tile.isCoreTile();
62 AIEArch arch = targetModel.getTargetArch();
63
64 // If eventAttr is a TraceEventAttr, extract the inner attribute
65 Attribute innerAttr = eventAttr;
66 if (auto traceEvent = llvm::dyn_cast<TraceEventAttr>(eventAttr)) {
67 innerAttr = traceEvent.getValue();
68 }
69
70 // Enum-qualified strings (e.g. "CoreEventAIE2P::INSTR_EVENT_0") encode both
71 // architecture and tile type in the prefix. We validate the prefix against
72 // the device arch and tile kind here. Plain strings (no "::") are deferred
73 // to lowering where the event database is available.
74 //
75 // NOTE: The parser stores enum events as strings rather than typed
76 // I32EnumAttrs because AIE2 and AIE2P enums share identical integer values,
77 // making isa<> checks ambiguous across architectures.
78 if (auto strAttr = llvm::dyn_cast<StringAttr>(innerAttr)) {
79 StringRef val = strAttr.getValue();
80 size_t sep = val.find("::");
81 if (sep == StringRef::npos)
82 return true; // plain string — validated during lowering
83
84 StringRef prefix = val.substr(0, sep);
85
86 // Map (arch, tileKind) → set of allowed prefixes.
87 if (isCoreTile) {
88 switch (arch) {
89 case AIEArch::AIE1:
90 return prefix == "CoreEventAIE" || prefix == "MemEventAIE";
91 case AIEArch::AIE2:
92 return prefix == "CoreEventAIE2" || prefix == "MemEventAIE2";
93 case AIEArch::AIE2p:
94 return prefix == "CoreEventAIE2P" || prefix == "MemEventAIE2P";
95 case AIEArch::AIE4:
96 return prefix == "CoreEventAIE4" || prefix == "MemEventAIE4";
97 default:
98 return false;
99 }
100 }
101 if (isMemTile) {
102 switch (arch) {
103 case AIEArch::AIE2:
104 return prefix == "MemTileEventAIE2";
105 case AIEArch::AIE2p:
106 return prefix == "MemTileEventAIE2P";
107 case AIEArch::AIE4:
108 return prefix == "MemTileEventAIE4";
109 default:
110 return false;
111 }
112 }
113 if (isShimTile) {
114 switch (arch) {
115 case AIEArch::AIE1:
116 return prefix == "ShimTileEventAIE";
117 case AIEArch::AIE2:
118 return prefix == "ShimTileEventAIE2";
119 case AIEArch::AIE2p:
120 return prefix == "ShimTileEventAIE2P";
121 case AIEArch::AIE4:
122 return prefix == "ShimTileEventAIE4";
123 default:
124 return false;
125 }
126 }
127 return false;
128 }
129
130 return false;
131}
132
133//===----------------------------------------------------------------------===//
134// TraceOp
135//===----------------------------------------------------------------------===//
136
137void TraceOp::getAsmResultNames(
138 function_ref<void(Value, StringRef)> setNameFn) {
139 // No results for this operation
140}
141
142LogicalResult TraceOp::verify() {
143 // Count trace events
144 int eventCount = 0;
145 for (auto &op : getBody().getOps()) {
146 if (isa<TraceEventOp>(op)) {
147 eventCount++;
148 }
149 }
150
151 // Check max 8 events
152 if (eventCount > 8) {
153 return emitOpError("trace unit supports maximum 8 events, got ")
154 << eventCount;
155 }
156
157 // Verify tile operand is a TileOp or LogicalTileOp
158 if (!llvm::dyn_cast_or_null<TileLike>(getTile().getDefiningOp())) {
159 return emitOpError("tile operand must be a TileOp or LogicalTileOp");
160 }
161
162 // Track combo/edge slot usage within this trace
163 llvm::DenseSet<uint32_t> comboSlots;
164 llvm::DenseSet<uint32_t> edgeSlots;
165
166 for (auto &op : getBody().getOps()) {
167 if (auto comboOp = dyn_cast<TraceComboEventOp>(op)) {
168 uint32_t slot = comboOp.getSlot();
169 if (!comboSlots.insert(slot).second) {
170 return comboOp.emitOpError("combo event slot ")
171 << slot << " already in use in this trace";
172 }
173 } else if (auto edgeOp = dyn_cast<TraceEdgeEventOp>(op)) {
174 uint32_t slot = edgeOp.getSlot();
175 if (!edgeSlots.insert(slot).second) {
176 return edgeOp.emitOpError("edge detection slot ")
177 << slot << " already in use in this trace";
178 }
179 }
180 }
181
182 return success();
183}
184
185//===----------------------------------------------------------------------===//
186// Helper function for parsing event values (string or typed enum)
187// Made available in xilinx::AIE namespace for reuse in AIEDialect.cpp
188//===----------------------------------------------------------------------===//
189
190ParseResult xilinx::AIE::parseTraceEvent(AsmParser &parser, Attribute &result) {
191 MLIRContext *ctx = parser.getContext();
192
193 // Try to parse as string first
194 std::string strValue;
195 if (succeeded(parser.parseOptionalString(&strValue))) {
196 result = StringAttr::get(ctx, strValue);
197 return success();
198 }
199
200 // Try to parse as enum (EnumType::VALUE)
201 StringRef enumTypeName;
202 llvm::SMLoc loc = parser.getCurrentLocation();
203
204 if (failed(parser.parseKeyword(&enumTypeName))) {
205 return parser.emitError(loc, "expected string or enum event");
206 }
207
208 if (failed(parser.parseColon()) || failed(parser.parseColon())) {
209 return parser.emitError(loc, "expected '::' after enum type name");
210 }
211
212 StringRef caseName;
213 if (failed(parser.parseKeyword(&caseName))) {
214 return parser.emitError(parser.getCurrentLocation(),
215 "expected enum case name");
216 }
217 // Store as a qualified string ("EnumType::CaseName") rather than a typed
218 // I32EnumAttr because different architecture enums share identical integer
219 // values, making isa<> checks ambiguous. The enum prefix is validated
220 // against the device architecture in isValidEventForTile().
221
222 // Define a helper struct for enum validation
223 struct EnumValidator {
224 StringRef name;
225 std::function<bool(StringRef)> symbolizer;
226 };
227
228 // Table of supported enum types and their symbolizer functions
229 static const EnumValidator validators[] = {
230 // AIE2 event enums
231 {"CoreEventAIE2",
232 [](StringRef s) { return symbolizeCoreEventAIE2(s).has_value(); }},
233 {"MemEventAIE2",
234 [](StringRef s) {
235 auto result = symbolizeMemEventAIE2(s);
236 return result.has_value();
237 }},
238 {"MemTileEventAIE2",
239 [](StringRef s) {
240 auto result = symbolizeMemTileEventAIE2(s);
241 return result.has_value();
242 }},
243 {"ShimTileEventAIE2",
244 [](StringRef s) {
245 auto result = symbolizeShimTileEventAIE2(s);
246 return result.has_value();
247 }},
248 // AIE event enums
249 {"CoreEventAIE",
250 [](StringRef s) {
251 auto result = symbolizeCoreEventAIE(s);
252 return result.has_value();
253 }},
254 {"MemEventAIE",
255 [](StringRef s) {
256 auto result = symbolizeMemEventAIE(s);
257 return result.has_value();
258 }},
259 {"ShimTileEventAIE",
260 [](StringRef s) {
261 auto result = symbolizeShimTileEventAIE(s);
262 return result.has_value();
263 }},
264 // AIE2P event enums
265 {"CoreEventAIE2P",
266 [](StringRef s) {
267 auto result = symbolizeCoreEventAIE2P(s);
268 return result.has_value();
269 }},
270 {"MemEventAIE2P",
271 [](StringRef s) {
272 auto result = symbolizeMemEventAIE2P(s);
273 return result.has_value();
274 }},
275 {"MemTileEventAIE2P",
276 [](StringRef s) {
277 auto result = symbolizeMemTileEventAIE2P(s);
278 return result.has_value();
279 }},
280 {"ShimTileEventAIE2P",
281 [](StringRef s) {
282 auto result = symbolizeShimTileEventAIE2P(s);
283 return result.has_value();
284 }},
285 // AIE4 event enums
286 {"CoreEventAIE4",
287 [](StringRef s) { return symbolizeCoreEventAIE4(s).has_value(); }},
288 {"MemEventAIE4",
289 [](StringRef s) { return symbolizeMemEventAIE4(s).has_value(); }},
290 {"MemTileEventAIE4",
291 [](StringRef s) { return symbolizeMemTileEventAIE4(s).has_value(); }},
292 {"ShimTileEventAIE4",
293 [](StringRef s) { return symbolizeShimTileEventAIE4(s).has_value(); }},
294 };
295
296 // Look up and validate the enum type
297 for (const auto &validator : validators) {
298 if (enumTypeName != validator.name)
299 continue;
300 if (!validator.symbolizer(caseName))
301 return parser.emitError(loc, "unknown ")
302 << enumTypeName << " value: " << caseName;
303 result = StringAttr::get(ctx, enumTypeName + "::" + caseName);
304 return success();
305 }
306
307 return parser.emitError(loc, "unknown event enum type: ") << enumTypeName;
308}
309
310void xilinx::AIE::printTraceEventEnum(AsmPrinter &printer, Attribute attr) {
311 if (auto traceAttr = llvm::dyn_cast<TraceEventAttr>(attr)) {
312 printTraceEventEnum(printer, traceAttr.getValue());
313 return;
314 }
315 if (auto strAttr = llvm::dyn_cast<StringAttr>(attr)) {
316 // If string contains "::" (enum format), print without quotes
317 if (strAttr.getValue().contains("::")) {
318 printer << strAttr.getValue();
319 return;
320 }
321 printer << "\"" << strAttr.getValue() << "\"";
322 }
323 if (auto intAttr = llvm::dyn_cast<IntegerAttr>(attr)) {
324 printer << intAttr.getInt();
325 return;
326 }
327}
328
329//===----------------------------------------------------------------------===//
330// TraceEventOp
331//===----------------------------------------------------------------------===//
332
333LogicalResult TraceEventOp::verify() {
334 // Get event name/value
335 auto eventAttr = getEvent();
336
337 // Basic validation - event should not be empty
338 std::string eventName = eventAttr.getEventName();
339 if (eventName.empty()) {
340 return emitOpError("event name cannot be empty");
341 }
342
343 // Validate event type matches tile type
344 auto trace = (*this)->getParentOfType<TraceOp>();
345 if (!trace) {
346 return emitOpError("must be nested in aie.trace");
347 }
348
349 auto tileLike = dyn_cast<TileLike>(trace.getTile().getDefiningOp());
350 if (!tileLike) {
351 return emitOpError("trace tile must be a TileOp or LogicalTileOp");
352 }
353
354 auto device = trace->getParentOfType<DeviceOp>();
355 const auto &targetModel = device.getTargetModel();
356
357 if (!isValidEventForTile(tileLike, eventAttr.getValue(), targetModel)) {
358 std::string tileTypeStr;
359 if (tileLike.isCoreTile())
360 tileTypeStr = "core tile";
361 else if (tileLike.isMemTile())
362 tileTypeStr = "mem tile";
363 else
364 tileTypeStr = "shim tile";
365
366 // Use the full string value (including enum prefix) for clarity.
367 std::string fullEventName;
368 if (auto strAttr = llvm::dyn_cast<StringAttr>(eventAttr.getValue()))
369 fullEventName = strAttr.getValue().str();
370 else
371 fullEventName = eventName;
372
373 auto col = tileLike.tryGetCol();
374 auto row = tileLike.tryGetRow();
375 auto fmtCoord = [](std::optional<int> v) -> std::string {
376 return v ? std::to_string(*v) : "?";
377 };
378 return emitOpError("event '")
379 << fullEventName << "' is not valid for " << tileTypeStr << " ("
380 << stringifyAIEArch(targetModel.getTargetArch()) << ") at ("
381 << fmtCoord(col) << ", " << fmtCoord(row) << ")";
382 }
383
384 return success();
385}
386
387//===----------------------------------------------------------------------===//
388// TracePacketOp
389//===----------------------------------------------------------------------===//
390
391LogicalResult TracePacketOp::verify() {
392 // Range is enforced by the Confined constraint in TableGen when id is
393 // present; when absent, -aie-insert-trace-flows assigns one in valid
394 // range from the (col, row) order over active trace tiles.
395 if (auto id = getId()) {
396 if (*id < 1 || *id > 31)
397 return emitOpError("packet ID must be in range [1, 31], got ") << *id;
398 }
399 return success();
400}
401
402//===----------------------------------------------------------------------===//
403// TracePortOp
404//===----------------------------------------------------------------------===//
405
406LogicalResult TracePortOp::verify() {
407 // Get parent trace and tile
408 auto trace = (*this)->getParentOfType<TraceOp>();
409 if (!trace) {
410 return emitOpError("must be nested in aie.trace");
411 }
412
413 auto tileLike = dyn_cast<TileLike>(trace.getTile().getDefiningOp());
414 if (!tileLike) {
415 return emitOpError("trace tile must be a TileOp or LogicalTileOp");
416 }
417
418 // Get target model
419 auto device = trace->getParentOfType<DeviceOp>();
420 const auto &targetModel = device.getTargetModel();
421
422 // The direction selects the port's side, not a DMA engine: S2MM=master,
423 // MM2S=slave.
424 if (getDMAChannelBundle(getDirection()) != WireBundle::DMA)
425 return emitOpError("direction must be S2MM (master) or MM2S (slave)");
426 bool isMaster = (getDirection() == DMAChannelDir::S2MM);
427
428 // Verify port is valid for this tile (only when placed with known col/row)
429 auto col = tileLike.tryGetCol();
430 auto row = tileLike.tryGetRow();
431 if (col && row) {
432 if (!targetModel
433 .getStreamSwitchPortIndex(*col, *row, getPort(), getChannel(),
434 isMaster)
435 .has_value()) {
436 return emitOpError("invalid stream switch port configuration for tile (")
437 << *col << ", " << *row << ")";
438 }
439 }
440
441 // Check for duplicate slots within same trace
442 for (auto &op : trace.getBody().getOps()) {
443 if (auto otherPort = dyn_cast<TracePortOp>(op)) {
444 if (otherPort != *this && otherPort.getSlot() == getSlot()) {
445 return emitOpError("duplicate port slot ")
446 << getSlot() << " in trace " << trace.getSymName();
447 }
448 }
449 }
450
451 return success();
452}
453
454//===----------------------------------------------------------------------===//
455// TraceStartEventOp
456//===----------------------------------------------------------------------===//
457
458LogicalResult TraceStartEventOp::verify() {
459 // Must have either broadcast or event, but not both
460 bool hasBroadcast = getBroadcast().has_value();
461 bool hasEvent = getEvent().has_value();
462
463 if (!hasBroadcast && !hasEvent) {
464 return emitOpError("must specify either broadcast or event");
465 }
466
467 if (hasBroadcast && hasEvent) {
468 return emitOpError("cannot specify both broadcast and event");
469 }
470
471 return success();
472}
473
474//===----------------------------------------------------------------------===//
475// TraceStopEventOp
476//===----------------------------------------------------------------------===//
477
478LogicalResult TraceStopEventOp::verify() {
479 // Must have either broadcast or event, but not both
480 bool hasBroadcast = getBroadcast().has_value();
481 bool hasEvent = getEvent().has_value();
482
483 if (!hasBroadcast && !hasEvent) {
484 return emitOpError("must specify either broadcast or event");
485 }
486
487 if (hasBroadcast && hasEvent) {
488 return emitOpError("cannot specify both broadcast and event");
489 }
490
491 return success();
492}
493
494//===----------------------------------------------------------------------===//
495// TraceStartEventOp and TraceStopEventOp
496//===----------------------------------------------------------------------===//
497
498void TraceStartEventOp::print(OpAsmPrinter &p) {
499 if (auto broadcast = getBroadcast()) {
500 p << " broadcast = " << broadcast.value();
501 }
502 if (auto event = getEvent()) {
503 p << " event = <";
504 printTraceEventEnum(p, event->getValue());
505 p << ">";
506 }
507 p.printOptionalAttrDict((*this)->getAttrs(),
508 /*elidedAttrs=*/{"broadcast", "event"});
509}
510
511ParseResult TraceStartEventOp::parse(OpAsmParser &parser,
512 OperationState &result) {
513 // Parse optional broadcast
514 if (succeeded(parser.parseOptionalKeyword("broadcast"))) {
515 IntegerAttr broadcast;
516 if (parser.parseEqual() ||
517 parser.parseAttribute(broadcast, parser.getBuilder().getI32Type(),
518 "broadcast", result.attributes))
519 return failure();
520 }
521
522 // Parse optional event
523 if (succeeded(parser.parseOptionalKeyword("event"))) {
524 if (parser.parseEqual() || parser.parseLess())
525 return failure();
526
527 Attribute innerValue;
528 if (failed(parseTraceEvent(parser, innerValue)))
529 return failure();
530
531 auto traceEvent = TraceEventAttr::get(parser.getContext(), innerValue);
532 result.attributes.set("event", traceEvent);
533
534 if (parser.parseGreater())
535 return failure();
536 }
537
538 if (parser.parseOptionalAttrDict(result.attributes))
539 return failure();
540
541 return success();
542}
543
544void TraceStopEventOp::print(OpAsmPrinter &p) {
545 if (auto broadcast = getBroadcast()) {
546 p << " broadcast = " << broadcast.value();
547 }
548 if (auto event = getEvent()) {
549 p << " event = <";
550 printTraceEventEnum(p, event->getValue());
551 p << ">";
552 }
553 p.printOptionalAttrDict((*this)->getAttrs(),
554 /*elidedAttrs=*/{"broadcast", "event"});
555}
556
557ParseResult TraceStopEventOp::parse(OpAsmParser &parser,
558 OperationState &result) {
559 // Parse optional broadcast
560 if (succeeded(parser.parseOptionalKeyword("broadcast"))) {
561 IntegerAttr broadcast;
562 if (parser.parseEqual() ||
563 parser.parseAttribute(broadcast, parser.getBuilder().getI32Type(),
564 "broadcast", result.attributes))
565 return failure();
566 }
567
568 // Parse optional event
569 if (succeeded(parser.parseOptionalKeyword("event"))) {
570 if (parser.parseEqual() || parser.parseLess())
571 return failure();
572
573 Attribute innerValue;
574 if (failed(parseTraceEvent(parser, innerValue)))
575 return failure();
576
577 auto traceEvent = TraceEventAttr::get(parser.getContext(), innerValue);
578 result.attributes.set("event", traceEvent);
579
580 if (parser.parseGreater())
581 return failure();
582 }
583
584 if (parser.parseOptionalAttrDict(result.attributes))
585 return failure();
586
587 return success();
588}
589
590//===----------------------------------------------------------------------===//
591// TraceComboEventOp
592//===----------------------------------------------------------------------===//
593
594LogicalResult TraceComboEventOp::verify() {
595 uint32_t slot = getSlot();
596
597 // Check slot is valid (0, 1, or 2)
598 if (slot > 2) {
599 return emitOpError("combo event slot must be 0, 1, or 2, got ") << slot;
600 }
601
602 // Get parent trace and tile for validation
603 auto trace = (*this)->getParentOfType<TraceOp>();
604 if (!trace) {
605 return emitOpError("must be nested in aie.trace");
606 }
607
608 auto tileLike = dyn_cast<TileLike>(trace.getTile().getDefiningOp());
609 if (!tileLike) {
610 return emitOpError("trace tile must be a TileOp or LogicalTileOp");
611 }
612
613 // Validate event types match tile
614 auto device = trace->getParentOfType<DeviceOp>();
615 const auto &targetModel = device.getTargetModel();
616
617 if (!isValidEventForTile(tileLike, getEventA().getValue(), targetModel)) {
618 return emitOpError("eventA is not valid for this tile type");
619 }
620 if (!isValidEventForTile(tileLike, getEventB().getValue(), targetModel)) {
621 return emitOpError("eventB is not valid for this tile type");
622 }
623
624 // Validate event selection based on slot
625 std::string eventAName = getEventA().getEventName();
626 std::string eventBName = getEventB().getEventName();
627
628 if (slot == 0) {
629 // Combo 0: should not use eventC/D or combo results
630 if (eventAName.find("COMBO_EVENT") != std::string::npos ||
631 eventBName.find("COMBO_EVENT") != std::string::npos) {
632 return emitOpError("combo slot 0 should use regular events, not "
633 "COMBO_EVENT_* (uses eventA/B)");
634 }
635 } else if (slot == 1) {
636 // Combo 1: should not use combo results
637 if (eventAName.find("COMBO_EVENT") != std::string::npos ||
638 eventBName.find("COMBO_EVENT") != std::string::npos) {
639 return emitOpError("combo slot 1 should use regular events, not "
640 "COMBO_EVENT_* (uses eventC/D)");
641 }
642 } else if (slot == 2) {
643 // Combo 2 is hierarchical - must use COMBO_EVENT_0 and COMBO_EVENT_1
644 if (eventAName != "COMBO_EVENT_0") {
645 return emitOpError("combo slot 2 first event must be COMBO_EVENT_0 "
646 "(hierarchical), got ")
647 << eventAName;
648 }
649 if (eventBName != "COMBO_EVENT_1") {
650 return emitOpError("combo slot 2 second event must be COMBO_EVENT_1 "
651 "(hierarchical), got ")
652 << eventBName;
653 }
654 }
655
656 return success();
657}
658
659//===----------------------------------------------------------------------===//
660// TraceEdgeEventOp
661//===----------------------------------------------------------------------===//
662
663LogicalResult TraceEdgeEventOp::verify() {
664 uint32_t slot = getSlot();
665
666 // Check slot is valid (0 or 1)
667 if (slot > 1) {
668 return emitOpError("edge detection slot must be 0 or 1, got ") << slot;
669 }
670
671 // Get parent trace and tile for validation
672 auto trace = (*this)->getParentOfType<TraceOp>();
673 if (!trace) {
674 return emitOpError("must be nested in aie.trace");
675 }
676
677 auto tileLike = dyn_cast<TileLike>(trace.getTile().getDefiningOp());
678 if (!tileLike) {
679 return emitOpError("trace tile must be a TileOp or LogicalTileOp");
680 }
681
682 // Validate event type matches tile
683 auto device = trace->getParentOfType<DeviceOp>();
684 const auto &targetModel = device.getTargetModel();
685
686 if (!isValidEventForTile(tileLike, getEvent().getValue(), targetModel)) {
687 return emitOpError("event is not valid for this tile type");
688 }
689
690 // Edge events should not be other edge/combo events
691 std::string eventName = getEvent().getEventName();
692 if (eventName.find("EDGE_DETECTION_EVENT") != std::string::npos) {
693 return emitOpError("edge detection source should be a regular event, not "
694 "another EDGE_DETECTION_EVENT");
695 }
696 if (eventName.find("COMBO_EVENT") != std::string::npos) {
697 return emitOpError("edge detection source should be a regular event, not "
698 "a COMBO_EVENT (combo events can be used but may have "
699 "unexpected behavior)");
700 }
701
702 return success();
703}
704
705void TraceEdgeEventOp::print(OpAsmPrinter &p) {
706 p << "<" << getSlot() << "> event = <";
707 printTraceEventEnum(p, getEvent().getValue());
708 p << "> trigger = " << getTrigger();
709 p.printOptionalAttrDict((*this)->getAttrs(),
710 /*elidedAttrs=*/{"slot", "event", "trigger"});
711}
712
713ParseResult TraceEdgeEventOp::parse(OpAsmParser &parser,
714 OperationState &result) {
715 IntegerAttr slot;
716 Attribute eventValue;
717 EdgeTriggerAttr trigger;
718
719 if (parser.parseLess() ||
720 parser.parseAttribute(slot, parser.getBuilder().getI32Type(), "slot",
721 result.attributes) ||
722 parser.parseGreater() || parser.parseKeyword("event") ||
723 parser.parseEqual() || parser.parseLess())
724 return failure();
725
726 // Parse event value (string or enum)
727 if (failed(parseTraceEvent(parser, eventValue)))
728 return failure();
729
730 auto event = TraceEventAttr::get(parser.getContext(), eventValue);
731 result.attributes.set("event", event);
732
733 if (parser.parseGreater() || parser.parseKeyword("trigger") ||
734 parser.parseEqual())
735 return failure();
736
737 // Parse trigger as keyword (RISING, FALLING, BOTH)
738 StringRef triggerStr;
739 if (failed(parser.parseKeyword(&triggerStr)))
740 return failure();
741
742 auto triggerEnum = symbolizeEdgeTrigger(triggerStr);
743 if (!triggerEnum) {
744 return parser.emitError(parser.getCurrentLocation(),
745 "unknown edge trigger: ")
746 << triggerStr;
747 }
748 trigger = EdgeTriggerAttr::get(parser.getContext(), *triggerEnum);
749 result.attributes.set("trigger", trigger);
750
751 if (parser.parseOptionalAttrDict(result.attributes))
752 return failure();
753
754 return success();
755}
756
757//===----------------------------------------------------------------------===//
758// TraceHostConfigOp
759//===----------------------------------------------------------------------===//
760
761LogicalResult TraceHostConfigOp::verify() {
762 // Reusing the last output buffer for trace data only works with a single
763 // shim destination (the trace bytes are appended to one buffer).
764 if (getReuseOutputBuffer()) {
765 if (getRouting() != TraceShimRouting::Single) {
766 return emitOpError("reuse_output_buffer (append trace after last tensor) "
767 "only works with single shim destination strategy "
768 "(routing=single)");
769 }
770 }
771
772 // Validate buffer_size is positive
773 if (getBufferSize() <= 0) {
774 return emitOpError("buffer_size must be positive");
775 }
776
777 // Validate Shim col id
778 if (getEgressShimCol() < 0) {
779 return emitOpError("egress_shim_col must be >= 0");
780 }
781
782 return success();
783}
784
785//===----------------------------------------------------------------------===//
786// TraceStartConfigOp
787//===----------------------------------------------------------------------===//
788
789LogicalResult TraceStartConfigOp::verify() {
790 // Verify that the referenced symbol exists
791 // This will be checked more thoroughly during lowering
792 auto symbolName = getTraceConfig();
793 if (symbolName.empty()) {
794 return emitOpError("trace config symbol name cannot be empty");
795 }
796
797 return success();
798}
virtual AIEArch getTargetArch() const =0
Return the target architecture.
mlir::ParseResult parseTraceEvent(mlir::AsmParser &parser, mlir::Attribute &result)
void printTraceEventEnum(mlir::AsmPrinter &printer, mlir::Attribute attr)
WireBundle getDMAChannelBundle(DMAChannelDir dir)
The stream-switch bundle the channels of dir use.
Definition AIEEnums.h:29