Skip to content

Commit

Permalink
[NFC][ESI][MSFT] Move AppIDs over to ESI (#6177)
Browse files Browse the repository at this point in the history
Since AppIDs serve as system identifiers, they classify as a system
construction feature. So they should be in the ESI dialect, which will
be using them shortly.
  • Loading branch information
teqdruid authored Sep 22, 2023
1 parent ca5affe commit 1b901c3
Show file tree
Hide file tree
Showing 25 changed files with 490 additions and 656 deletions.
8 changes: 4 additions & 4 deletions frontends/PyCDE/src/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from __future__ import annotations

from .circt.dialects import msft
from .circt.dialects import esi
from .circt import ir

from .types import Type, Channel, ChannelSignaling, ClockType, Bits
Expand Down Expand Up @@ -71,15 +71,15 @@ def __init__(self,


class AppID:
AttributeName = "msft.appid"
AttributeName = "esi.appid"

@singledispatchmethod
def __init__(self, name: str, idx: int):
self._appid = msft.AppIDAttr.get(name, idx)
self._appid = esi.AppIDAttr.get(name, idx)

@__init__.register(ir.Attribute)
def __init__mlir_attr(self, attr: ir.Attribute):
self._appid = msft.AppIDAttr(attr)
self._appid = esi.AppIDAttr(attr)

@property
def name(self) -> str:
Expand Down
6 changes: 3 additions & 3 deletions frontends/PyCDE/src/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from .devicedb import LocationVector
from .module import AppID

from .circt.dialects import hw, msft, seq
from .circt.dialects import esi, hw, msft, seq
from .circt import ir

from typing import Dict, Iterator, List, Optional, Tuple, Union
Expand Down Expand Up @@ -128,7 +128,7 @@ def _add_appids(self):
child_appids = ir.ArrayAttr(
self.root.system._appid_index.get_child_appids_of(circt_mod))
child_appid_names = {}
for id in [msft.AppIDAttr(id) for id in child_appids]:
for id in [esi.AppIDAttr(id) for id in child_appids]:
if id.name not in child_appid_names:
child_appid_names[id.name] = {}
child_appid_names[id.name][id.index] = id
Expand Down Expand Up @@ -225,7 +225,7 @@ class _AppIDInstance:
__slots__ = ["owner_instance", "appid_name", "appids", "circt_mod"]

def __init__(self, owner_instance: ModuleInstance, circt_mod, appid_name: str,
appids: Dict[int, msft.AppIDAttr]):
appids: Dict[int, esi.AppIDAttr]):
self.owner_instance = owner_instance
self.circt_mod = circt_mod
self.appid_name = appid_name
Expand Down
4 changes: 2 additions & 2 deletions frontends/PyCDE/src/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def __init__(self,
self._instance_roots: dict[(Module, str), InstanceHierarchyRoot] = {}

self._placedb: PlacementDB = None
self._appid_index: msft.AppIDIndex = None
self._appid_index: esi.AppIDIndex = None

# The set of all files generated by PyCDE.
self.files: Set[os.PathLike] = set()
Expand Down Expand Up @@ -226,7 +226,7 @@ def generate(self, generator_names=[], iters=None):
m.generate()
i += 1

self._appid_index = msft.AppIDIndex(self.mod.operation)
self._appid_index = esi.AppIDIndex(self.mod.operation)

def get_instance(self,
mod_cls: object,
Expand Down
43 changes: 43 additions & 0 deletions include/circt-c/Dialect/ESI.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,49 @@ typedef MlirLogicalResult (*CirctESIServiceGeneratorFunc)(
MLIR_CAPI_EXPORTED void circtESIRegisterGlobalServiceGenerator(
MlirStringRef impl_type, CirctESIServiceGeneratorFunc, void *userData);

//===----------------------------------------------------------------------===//
// AppID
//===----------------------------------------------------------------------===//

MLIR_CAPI_EXPORTED bool circtESIAttributeIsAnAppIDAttr(MlirAttribute);
MLIR_CAPI_EXPORTED
MlirAttribute circtESIAppIDAttrGet(MlirContext, MlirStringRef name,
uint64_t index);
MLIR_CAPI_EXPORTED MlirStringRef circtESIAppIDAttrGetName(MlirAttribute attr);
MLIR_CAPI_EXPORTED uint64_t circtESIAppIDAttrGetIndex(MlirAttribute attr);

MLIR_CAPI_EXPORTED bool circtESIAttributeIsAnAppIDPathAttr(MlirAttribute);
MLIR_CAPI_EXPORTED
MlirAttribute circtESIAppIDAttrPathGet(MlirContext, MlirAttribute root,
intptr_t numElements,
MlirAttribute const *elements);
MLIR_CAPI_EXPORTED MlirAttribute
circtESIAppIDAttrPathGetRoot(MlirAttribute attr);
MLIR_CAPI_EXPORTED uint64_t
circtESIAppIDAttrPathGetNumComponents(MlirAttribute attr);
MLIR_CAPI_EXPORTED MlirAttribute
circtESIAppIDAttrPathGetComponent(MlirAttribute attr, uint64_t index);

// NOLINTNEXTLINE(modernize-use-using)
typedef struct {
void *ptr;
} CirctESIAppIDIndex;

/// Create an index of appids through which to do appid lookups efficiently.
MLIR_CAPI_EXPORTED CirctESIAppIDIndex circtESIAppIDIndexGet(MlirOperation root);

/// Free an AppIDIndex.
MLIR_CAPI_EXPORTED void circtESIAppIDIndexFree(CirctESIAppIDIndex);

MLIR_CAPI_EXPORTED MlirAttribute
circtESIAppIDIndexGetChildAppIDsOf(CirctESIAppIDIndex, MlirOperation);

MLIR_CAPI_EXPORTED
MlirAttribute circtESIAppIDIndexGetAppIDPath(CirctESIAppIDIndex,
MlirOperation fromMod,
MlirAttribute appid,
MlirLocation loc);

#ifdef __cplusplus
}
#endif
Expand Down
48 changes: 0 additions & 48 deletions include/circt-c/Dialect/MSFT.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,25 +63,6 @@ intptr_t circtMSFTLocationVectorAttrGetNumElements(MlirAttribute);
MLIR_CAPI_EXPORTED MlirAttribute
circtMSFTLocationVectorAttrGetElement(MlirAttribute attr, intptr_t pos);

MLIR_CAPI_EXPORTED bool circtMSFTAttributeIsAnAppIDAttr(MlirAttribute);
MLIR_CAPI_EXPORTED
MlirAttribute circtMSFTAppIDAttrGet(MlirContext, MlirStringRef name,
uint64_t index);
MLIR_CAPI_EXPORTED MlirStringRef circtMSFTAppIDAttrGetName(MlirAttribute attr);
MLIR_CAPI_EXPORTED uint64_t circtMSFTAppIDAttrGetIndex(MlirAttribute attr);

MLIR_CAPI_EXPORTED bool circtMSFTAttributeIsAnAppIDPathAttr(MlirAttribute);
MLIR_CAPI_EXPORTED
MlirAttribute circtMSFTAppIDAttrPathGet(MlirContext, MlirAttribute root,
intptr_t numElements,
MlirAttribute const *elements);
MLIR_CAPI_EXPORTED MlirAttribute
circtMSFTAppIDAttrPathGetRoot(MlirAttribute attr);
MLIR_CAPI_EXPORTED uint64_t
circtMSFTAppIDAttrPathGetNumComponents(MlirAttribute attr);
MLIR_CAPI_EXPORTED MlirAttribute
circtMSFTAppIDAttrPathGetComponent(MlirAttribute attr, uint64_t index);

//===----------------------------------------------------------------------===//
// PrimitiveDB.
//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -115,7 +96,6 @@ typedef struct {
MLIR_CAPI_EXPORTED CirctMSFTPlacementDB
circtMSFTCreatePlacementDB(MlirModule top, CirctMSFTPrimitiveDB seed);
MLIR_CAPI_EXPORTED void circtMSFTDeletePlacementDB(CirctMSFTPlacementDB self);
MLIR_CAPI_EXPORTED
MLIR_CAPI_EXPORTED MlirOperation circtMSFTPlacementDBPlace(
CirctMSFTPlacementDB, MlirOperation inst, MlirAttribute loc,
MlirStringRef subpath, MlirLocation srcLoc);
Expand All @@ -138,34 +118,6 @@ MLIR_CAPI_EXPORTED void circtMSFTPlacementDBWalkPlacements(
CirctMSFTPrimitiveType primTypeFilter, CirctMSFTWalkOrder walkOrder,
void *userData);

//===----------------------------------------------------------------------===//
// AppID
//===----------------------------------------------------------------------===//

// NOLINTNEXTLINE(modernize-use-using)
typedef struct {
void *ptr;
} CirctMSFTAppIDIndex;

/// Create an index of appids through which to do appid lookups efficiently.
MLIR_CAPI_EXPORTED CirctMSFTAppIDIndex
circtMSFTAppIDIndexGet(MlirOperation root);

/// Free an AppIDIndex.
MLIR_CAPI_EXPORTED void circtMSFTAppIDIndexFree(CirctMSFTAppIDIndex);

/// Lookup a DynamicInstanceOp from an appid path.
MLIR_CAPI_EXPORTED MlirOperation circtMSFTAppIDIndexGetInstance(
CirctMSFTAppIDIndex, MlirAttribute appIDPath, MlirLocation querySite);

MLIR_CAPI_EXPORTED MlirAttribute
circtMSFTAppIDIndexGetChildAppIDsOf(CirctMSFTAppIDIndex, MlirOperation);

MLIR_CAPI_EXPORTED
MlirAttribute circtMSFTAppIDIndexGetAppIDPath(CirctMSFTAppIDIndex,
MlirOperation fromMod,
MlirAttribute appid,
MlirLocation loc);
#ifdef __cplusplus
}
#endif
Expand Down
66 changes: 66 additions & 0 deletions include/circt/Dialect/ESI/AppID.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
//===- AppID.h - AppID related code -----------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// Application IDs are paths through the instance hierarchy with some
// application-specific meaning. They allow designers and users to avoid some of
// the design's implementation details.
//
//===----------------------------------------------------------------------===//

#ifndef CIRCT_DIALECT_ESI_APPID_H
#define CIRCT_DIALECT_ESI_APPID_H

#include "circt/Dialect/ESI/ESIAttributes.h"
#include "circt/Dialect/HW/HWSymCache.h"

#include "mlir/IR/Operation.h"
#include "llvm/ADT/DenseMap.h"

namespace circt {
namespace esi {

/// An index for resolving AppIDPaths to dynamic instances.
class AppIDIndex {
public:
AppIDIndex(Operation *mlirTop);
~AppIDIndex();

// If invalid, construction failed for some reason (which was emitted via an
// error). Since we want to be able to call this class as an analysis, all of
// the index construction occurs in the constructor, which doesn't allow for
// a LogicalResult return. (This is where exceptions would be useful.)
bool isValid() const { return valid; }

// Return an array of AppIDAttrs which are contained in the module.
ArrayAttr getChildAppIDsOf(hw::HWModuleLike) const;

/// Return an array of InnerNameRefAttrs representing the relative path to
/// 'appid' from 'fromMod'.
FailureOr<ArrayAttr> getAppIDPathAttr(hw::HWModuleLike fromMod,
AppIDAttr appid, Location loc) const;

private:
//===--------------------------------------------------------------------===//
// Index construction and storage.
//===--------------------------------------------------------------------===//
class ModuleAppIDs;

/// Construct the index for a module.
FailureOr<const ModuleAppIDs *> buildIndexFor(hw::HWModuleLike modToProcess);

// Map modules to their cached child app ID indexes.
DenseMap<hw::HWModuleLike, ModuleAppIDs *> containerAppIDs;

bool valid;
hw::HWSymbolCache symCache;
};

} // namespace esi
} // namespace circt

#endif // CIRCT_DIALECT_ESI_APPID_H
7 changes: 7 additions & 0 deletions include/circt/Dialect/ESI/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,20 @@ set(LLVM_TARGET_DEFINITIONS ESI.td)
mlir_tablegen(ESIEnums.h.inc -gen-enum-decls)
mlir_tablegen(ESIEnums.cpp.inc -gen-enum-defs)
add_public_tablegen_target(MLIRESIEnumsIncGen)
add_dependencies(circt-headers MLIRESIEnumsIncGen)

mlir_tablegen(ESIAttributes.h.inc -gen-attrdef-decls -attrdefs-dialect=esi)
mlir_tablegen(ESIAttributes.cpp.inc -gen-attrdef-defs -attrdefs-dialect=esi)
add_public_tablegen_target(MLIRESIAttrsIncGen)
add_dependencies(circt-headers MLIRESIAttrsIncGen)

set(LLVM_TARGET_DEFINITIONS ESIInterfaces.td)
mlir_tablegen(ESIInterfaces.h.inc -gen-op-interface-decls)
mlir_tablegen(ESIInterfaces.cpp.inc -gen-op-interface-defs)
add_public_tablegen_target(MLIRESIInterfacesIncGen)
add_dependencies(circt-headers MLIRESIInterfacesIncGen)

add_circt_doc(ESIChannels Dialects/ESIAppID -gen-attrdef-doc)
add_circt_doc(ESIChannels Dialects/ESIChannels -gen-op-doc)
add_circt_doc(ESIChannels Dialects/ESIChannelTypes -gen-typedef-doc)
add_circt_doc(ESIServices Dialects/ESIServices -gen-op-doc)
Expand Down
1 change: 1 addition & 0 deletions include/circt/Dialect/ESI/ESI.td
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ include "mlir/IR/OpBase.td"

include "circt/Dialect/ESI/ESIDialect.td"

include "circt/Dialect/ESI/ESIAppID.td"
include "circt/Dialect/ESI/ESIInterfaces.td"
include "circt/Dialect/ESI/ESITypes.td"
include "circt/Dialect/ESI/ESIChannels.td"
Expand Down
51 changes: 51 additions & 0 deletions include/circt/Dialect/ESI/ESIAppID.td
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//===- ESIChannels.td - All ESI ops related to app channels -- tablegen -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This is where any operations for the ESI dialect live.
//
//===----------------------------------------------------------------------===//

#ifndef CIRCT_DIALECT_ESI_APPID_TD
#define CIRCT_DIALECT_ESI_APPID_TD

include "mlir/IR/AttrTypeBase.td"

def AppIDAttr : ESI_Attr<"AppID"> {
let summary = "An application relevant instance identifier";
let description = [{
Identifies an instance which is visible through multiple hierarchy levels.
Indended to make locating an instance easier in the instance hierarchy.
}];

let parameters = (ins "StringAttr":$name, "uint64_t":$index);
let mnemonic = "appid";
let assemblyFormat = [{
`<` $name `[` $index `]` `>`
}];

let extraClassDeclaration = [{
static constexpr StringRef AppIDAttrName = "esi.appid";
}];
}

def AppIDPathAttr : ESI_Attr<"AppIDPath"> {
let summary = "An application-specific hierarchical path through a design";
let description = [{
A list of AppID components which specifies a specific dynamic instance
in the design.
}];

let parameters = (ins "FlatSymbolRefAttr":$root,
ArrayRefParameter<"AppIDAttr">:$path);
let mnemonic = "appid_path";
let assemblyFormat = [{
`<` $root `[` $path `]` `>`
}];
}

#endif // CIRCT_DIALECT_ESI_APPID_TD
23 changes: 23 additions & 0 deletions include/circt/Dialect/ESI/ESIAttributes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//===- ESIAttributes.h - attributes for the ESI dialect ---------*- C++ -*-===//
//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef CIRCT_DIALECT_ESI_ESIATTRIBUTES_H
#define CIRCT_DIALECT_ESI_ESIATTRIBUTES_H

#include "circt/Dialect/HW/HWTypes.h"
#include "circt/Support/LLVM.h"
#include "mlir/IR/Dialect.h"
#include "mlir/IR/Operation.h"

#include "ESIDialect.h"

#define GET_ATTRDEF_CLASSES
#include "circt/Dialect/ESI/ESIAttributes.h.inc"

#endif
9 changes: 9 additions & 0 deletions include/circt/Dialect/ESI/ESIDialect.td
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@ def ESI_Dialect : Dialect {

let hasConstantMaterializer = 1;
let useDefaultTypePrinterParser = 1;
let useDefaultAttributePrinterParser = 1;

// Opt-out of properties for now, must migrate by LLVM 19. #5273.
let usePropertiesForAttributes = 0;

let extraClassDeclaration = [{
/// Register all ESI attributes.
void registerAttributes();
/// Register all ESI types.
void registerTypes();
}];
Expand All @@ -50,4 +53,10 @@ class ESI_Physical_Op<string mnemonic, list<Trait> traits = []> :

class ESI_Type<string name> : TypeDef<ESI_Dialect, name> { }

class ESI_Attr<string name, list<Trait> traits = [],
string baseCppClass = "::mlir::Attribute">
: AttrDef<ESI_Dialect, name, traits, baseCppClass> {
let mnemonic = ?;
}

#endif // CIRCT_DIALECT_ESI_DIALECT_TD
Loading

0 comments on commit 1b901c3

Please sign in to comment.