|
| 1 | +//===- AIETraceAttrs.td ------------------------------------*- tablegen -*-===// |
| 2 | +// |
| 3 | +// This file is licensed under the Apache License v2.0 with LLVM Exceptions. |
| 4 | +// See https://llvm.org/LICENSE.txt for license information. |
| 5 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | +// |
| 7 | +// Copyright (C) 2025, Advanced Micro Devices, Inc. |
| 8 | +// |
| 9 | +//===----------------------------------------------------------------------===// |
| 10 | +// Defines attributes for AIE trace operations |
| 11 | +//===----------------------------------------------------------------------===// |
| 12 | + |
| 13 | +#ifndef AIE_TRACE_ATTRS |
| 14 | +#define AIE_TRACE_ATTRS |
| 15 | + |
| 16 | +include "aie/Dialect/AIE/IR/AIE.td" |
| 17 | +include "mlir/IR/AttrTypeBase.td" |
| 18 | +include "mlir/IR/EnumAttr.td" |
| 19 | + |
| 20 | +//===----------------------------------------------------------------------===// |
| 21 | +// Trace Mode Enumeration |
| 22 | +//===----------------------------------------------------------------------===// |
| 23 | + |
| 24 | +def TraceModeEventTime : I32EnumAttrCase<"EventTime", 0, "Event-Time">; |
| 25 | +def TraceModeEventPC : I32EnumAttrCase<"EventPC", 1, "Event-PC">; |
| 26 | +def TraceModeExecution : I32EnumAttrCase<"Execution", 2, "Execution">; |
| 27 | + |
| 28 | +def TraceModeAttr : I32EnumAttr<"TraceMode", |
| 29 | + "Trace capture mode", |
| 30 | + [ |
| 31 | + TraceModeEventTime, |
| 32 | + TraceModeEventPC, |
| 33 | + TraceModeExecution |
| 34 | + ]> { |
| 35 | + let cppNamespace = "::xilinx::AIE"; |
| 36 | + let description = [{ |
| 37 | + Specifies the trace mode: |
| 38 | + - Event-Time (00): Captures event occurrence with timestamp |
| 39 | + - Event-PC (01): Captures program counter when event occurs |
| 40 | + - Execution (10): Instruction-level execution trace |
| 41 | + }]; |
| 42 | +} |
| 43 | + |
| 44 | +//===----------------------------------------------------------------------===// |
| 45 | +// Packet Type Enumeration |
| 46 | +//===----------------------------------------------------------------------===// |
| 47 | + |
| 48 | +def TracePacketTypeCore : I32EnumAttrCase<"Core", 0, "core">; |
| 49 | +def TracePacketTypeMem : I32EnumAttrCase<"Mem", 1, "mem">; |
| 50 | +def TracePacketTypeShimTile : I32EnumAttrCase<"ShimTile", 2, "shimtile">; |
| 51 | +def TracePacketTypeMemTile : I32EnumAttrCase<"MemTile", 3, "memtile">; |
| 52 | + |
| 53 | +def TracePacketTypeAttr : I32EnumAttr<"TracePacketType", |
| 54 | + "Packet type identifier for parsing", |
| 55 | + [ |
| 56 | + TracePacketTypeCore, |
| 57 | + TracePacketTypeMem, |
| 58 | + TracePacketTypeShimTile, |
| 59 | + TracePacketTypeMemTile |
| 60 | + ]> { |
| 61 | + let cppNamespace = "::xilinx::AIE"; |
| 62 | + let description = [{ |
| 63 | + Packet Type Convention: |
| 64 | + - 0: Core tile (CORE_MODULE) |
| 65 | + - 1: Core tile (MEMORY_MODULE) |
| 66 | + - 2: Shim tile |
| 67 | + - 3: Mem tile |
| 68 | + }]; |
| 69 | +} |
| 70 | + |
| 71 | +//===----------------------------------------------------------------------===// |
| 72 | +// Trace Event Attribute |
| 73 | +//===----------------------------------------------------------------------===// |
| 74 | + |
| 75 | +def TraceEventAttr : AttrDef<AIE_Dialect, "TraceEvent"> { |
| 76 | + let mnemonic = "trace_event"; |
| 77 | + let summary = "Reference to a trace event by name or enum"; |
| 78 | + |
| 79 | + let description = [{ |
| 80 | + References an event by name string or typed enum. Strings are used for |
| 81 | + generic references that are resolved during lowering. Enums provide |
| 82 | + compile-time type checking. |
| 83 | + |
| 84 | + Validated against: |
| 85 | + - Tile type (core events only valid for core tiles, etc.) |
| 86 | + - Architecture (AIE/AIE2/AIE2P/AIE4) |
| 87 | + |
| 88 | + Examples: |
| 89 | + "INSTR_EVENT_0" // String (resolved during lowering) |
| 90 | + CoreEventAIE2::INSTR_EVENT_0 // Enum |
| 91 | + }]; |
| 92 | + |
| 93 | + let parameters = (ins |
| 94 | + "Attribute":$value |
| 95 | + ); |
| 96 | + |
| 97 | + let assemblyFormat = "`<` custom<TraceEventValue>($value) `>`"; |
| 98 | + |
| 99 | + let extraClassDeclaration = [{ |
| 100 | + // Helper to get event name as string for lookups |
| 101 | + std::string getEventName() const; |
| 102 | + |
| 103 | + // Check if this is a string attribute (needs promotion) |
| 104 | + bool isStringAttr() const; |
| 105 | + |
| 106 | + // Get the underlying enum value if this is an enum |
| 107 | + std::optional<int64_t> getEnumValue() const; |
| 108 | + }]; |
| 109 | +} |
| 110 | + |
| 111 | +//===----------------------------------------------------------------------===// |
| 112 | +// Combo Event Logic Enumeration |
| 113 | +//===----------------------------------------------------------------------===// |
| 114 | + |
| 115 | +def ComboLogicAND : I32EnumAttrCase<"AND", 0, "AND">; |
| 116 | +def ComboLogicAND_NOT : I32EnumAttrCase<"AND_NOT", 1, "AND_NOT">; |
| 117 | +def ComboLogicOR : I32EnumAttrCase<"OR", 2, "OR">; |
| 118 | +def ComboLogicOR_NOT : I32EnumAttrCase<"OR_NOT", 3, "OR_NOT">; |
| 119 | + |
| 120 | +def ComboLogicAttr : I32EnumAttr<"ComboLogic", |
| 121 | + "Combo event logic function", |
| 122 | + [ |
| 123 | + ComboLogicAND, |
| 124 | + ComboLogicAND_NOT, |
| 125 | + ComboLogicOR, |
| 126 | + ComboLogicOR_NOT |
| 127 | + ]> { |
| 128 | + let cppNamespace = "::xilinx::AIE"; |
| 129 | + let description = [{ |
| 130 | + Logical operation for combining two events: |
| 131 | + - AND (00): eventA AND eventB |
| 132 | + - AND_NOT (01): eventA AND NOT eventB |
| 133 | + - OR (10): eventA OR eventB |
| 134 | + - OR_NOT (11): eventA OR NOT eventB |
| 135 | + }]; |
| 136 | +} |
| 137 | + |
| 138 | +//===----------------------------------------------------------------------===// |
| 139 | +// Edge Detection Trigger Mode Enumeration |
| 140 | +//===----------------------------------------------------------------------===// |
| 141 | + |
| 142 | +def EdgeTriggerRISING : I32EnumAttrCase<"RISING", 1, "RISING">; |
| 143 | +def EdgeTriggerFALLING : I32EnumAttrCase<"FALLING", 2, "FALLING">; |
| 144 | +def EdgeTriggerBOTH : I32EnumAttrCase<"BOTH", 3, "BOTH">; |
| 145 | + |
| 146 | +def EdgeTriggerAttr : I32EnumAttr<"EdgeTrigger", |
| 147 | + "Edge detection trigger mode", |
| 148 | + [ |
| 149 | + EdgeTriggerRISING, |
| 150 | + EdgeTriggerFALLING, |
| 151 | + EdgeTriggerBOTH |
| 152 | + ]> { |
| 153 | + let cppNamespace = "::xilinx::AIE"; |
| 154 | + let description = [{ |
| 155 | + Edge detection trigger mode: |
| 156 | + - RISING (01): Trigger on rising edge (0→1 transition) |
| 157 | + - FALLING (10): Trigger on falling edge (1→0 transition) |
| 158 | + - BOTH (11): Trigger on both edges |
| 159 | + }]; |
| 160 | +} |
| 161 | + |
| 162 | +#endif // AIE_TRACE_ATTRS |
0 commit comments