Skip to content

Commit e2e9c5f

Browse files
fifieldCopilot
andauthored
Add event trace configuration to aie dialect (#2705)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent b544e78 commit e2e9c5f

50 files changed

Lines changed: 5595 additions & 12 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

include/aie/Dialect/AIE/IR/AIEAttrs.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#define AIE_ATTRS
1313

1414
include "aie/Dialect/AIE/IR/AIE.td"
15+
include "aie/Dialect/AIE/IR/AIETraceAttrs.td"
1516

1617
include "mlir/IR/AttrTypeBase.td"
1718
include "mlir/IR/EnumAttr.td"
@@ -221,7 +222,7 @@ def InitValuesArrayAttr
221222
// Generated AIE event enumerations
222223
//===----------------------------------------------------------------------===//
223224

224-
include "AIEEvents.td.inc"
225+
include "AIEEventsAIE.td.inc"
225226
include "AIEEventsAIE2.td.inc"
226227
include "AIEEventsAIE2P.td.inc"
227228

include/aie/Dialect/AIE/IR/AIEDialect.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,11 @@ void printObjectFifoConsumerTiles(mlir::OpAsmPrinter &printer,
201201

202202
int32_t getBufferBaseAddress(mlir::Operation *bufOp);
203203

204+
// Trace Event Value Parsing/Printing (handles both string and typed enums)
205+
mlir::ParseResult parseTraceEvent(mlir::AsmParser &parser,
206+
mlir::Attribute &result);
207+
void printTraceEventEnum(mlir::AsmPrinter &printer, mlir::Attribute attr);
208+
204209
} // namespace xilinx::AIE
205210

206211
// include TableGen generated Op definitions

include/aie/Dialect/AIE/IR/AIEOps.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ include "mlir/Interfaces/SideEffectInterfaces.td"
2727
class AIE_Op<string mnemonic, list<Trait> traits = []> :
2828
Op<AIE_Dialect, mnemonic, traits>;
2929

30+
include "aie/Dialect/AIE/IR/AIETraceOps.td"
31+
3032

3133
def AIE_DeviceOp: AIE_Op<"device", [
3234
Symbol,

include/aie/Dialect/AIE/IR/AIETargetModel.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,13 @@ class AIETargetModel {
279279
/// Return the number of buffer descriptors for a given tile type.
280280
virtual uint32_t getNumBDs(AIETileType tileType) const = 0;
281281

282+
/// Get stream switch port index for a given port specification
283+
/// Return port index for Stream_Switch_Event_Port_Selection register, or
284+
/// nullopt if invalid
285+
virtual std::optional<uint32_t>
286+
getStreamSwitchPortIndex(int col, int row, WireBundle bundle,
287+
uint32_t channel, bool master) const = 0;
288+
282289
/// Return the number of buffer descriptors supported by the DMA in the given
283290
/// tile.
284291
uint32_t getNumBDs(int col, int row) const {
@@ -383,6 +390,15 @@ class AIETargetModel {
383390
/// Encode a field value with proper bit shifting.
384391
/// Return Value shifted to correct bit position
385392
uint32_t encodeFieldValue(const BitFieldInfo &field, uint32_t value) const;
393+
394+
/// Compute a 32-bit mask for a register field.
395+
/// Return nullopt if the field does not fit in a 32-bit register.
396+
std::optional<uint32_t> getFieldMask(const BitFieldInfo &field) const;
397+
398+
/// Resolve stream switch port specification to port index.
399+
/// Return Port index for stream switch register, or nullopt if invalid
400+
std::optional<uint32_t> resolvePortValue(llvm::StringRef value, TileID tile,
401+
bool master) const;
386402
};
387403

388404
class AIE1TargetModel : public AIETargetModel {
@@ -463,6 +479,11 @@ class AIE1TargetModel : public AIETargetModel {
463479
int srcChan, WireBundle dstBundle,
464480
int dstChan) const override;
465481

482+
std::optional<uint32_t> getStreamSwitchPortIndex(int col, int row,
483+
WireBundle bundle,
484+
uint32_t channel,
485+
bool master) const override;
486+
466487
uint32_t getColumnShift() const override { return 23; }
467488
uint32_t getRowShift() const override { return 18; }
468489

@@ -573,6 +594,11 @@ class AIE2TargetModel : public AIETargetModel {
573594
int srcChan, WireBundle dstBundle,
574595
int dstChan) const override;
575596

597+
std::optional<uint32_t> getStreamSwitchPortIndex(int col, int row,
598+
WireBundle bundle,
599+
uint32_t channel,
600+
bool master) const override;
601+
576602
uint32_t getColumnShift() const override { return 25; }
577603
uint32_t getRowShift() const override { return 20; }
578604

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
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

Comments
 (0)