MLIR-AIE
AIERegisterDatabase.h
Go to the documentation of this file.
1//===- AIERegisterDatabase.h ------------------------------------*- C++ -*-===//
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// Register and event database for AIE trace configuration
11//===----------------------------------------------------------------------===//
12
13#ifndef AIE_REGISTER_DATABASE_H
14#define AIE_REGISTER_DATABASE_H
15
16#include "llvm/ADT/StringMap.h"
17#include "llvm/ADT/StringRef.h"
18#include "llvm/Support/JSON.h"
19
20#include <memory>
21#include <optional>
22#include <string>
23#include <vector>
24
25namespace xilinx {
26namespace AIE {
27
28/// Bit field information for a register
30 std::string name;
31 uint32_t bit_start; // LSB position
32 uint32_t bit_end; // MSB position
33 std::string type;
34 std::string reset;
35 std::string description;
36
37 uint32_t getWidth() const { return bit_end - bit_start + 1; }
38};
39
40/// Register information
42 std::string name;
43 uint32_t offset;
44 std::string module;
45 uint32_t width;
46 std::string type;
47 std::string reset;
48 std::string description;
49 std::vector<BitFieldInfo> bit_fields;
50
51 const BitFieldInfo *getField(llvm::StringRef fieldName) const;
52};
53
54/// Event information
55struct EventInfo {
56 std::string name;
57 uint32_t number;
58 std::string module; // core, memory, pl, mem_tile
59};
60
61/// Register and event database for a specific architecture
63public:
64 /// Load database for AIE2 architecture
65 static std::unique_ptr<RegisterDatabase> loadAIE2();
66
67 /// Lookup register by name and module
68 const RegisterInfo *lookupRegister(llvm::StringRef name,
69 llvm::StringRef module) const;
70
71 /// Lookup event by name and module
72 std::optional<uint32_t> lookupEvent(llvm::StringRef name,
73 llvm::StringRef module) const;
74
75 /// Encode a value for a specific bitfield
76 uint32_t encodeFieldValue(const BitFieldInfo &field, uint32_t value) const;
77
78private:
79 RegisterDatabase() = default;
80
81 bool loadFromJSON(llvm::StringRef registerPath, llvm::StringRef eventPath);
82
83 llvm::StringMap<RegisterInfo> registers_;
84 llvm::StringMap<EventInfo> events_;
85};
86
87} // namespace AIE
88} // namespace xilinx
89
90#endif // AIE_REGISTER_DATABASE_H
Register and event database for a specific architecture.
uint32_t encodeFieldValue(const BitFieldInfo &field, uint32_t value) const
Encode a value for a specific bitfield.
static std::unique_ptr< RegisterDatabase > loadAIE2()
Load database for AIE2 architecture.
const RegisterInfo * lookupRegister(llvm::StringRef name, llvm::StringRef module) const
Lookup register by name and module.
std::optional< uint32_t > lookupEvent(llvm::StringRef name, llvm::StringRef module) const
Lookup event by name and module.
Bit field information for a register.
const BitFieldInfo * getField(llvm::StringRef fieldName) const
std::vector< BitFieldInfo > bit_fields