CIRCT 24.0.0git
Loading...
Searching...
No Matches
LLHD.cpp
Go to the documentation of this file.
1//===- LLHD.cpp - C interface for the LLHD dialect ------------------------===//
2//
3// Part of the LLVM Project, 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//===----------------------------------------------------------------------===//
8
12#include "mlir/CAPI/IR.h"
13#include "mlir/CAPI/Registration.h"
14#include "mlir/CAPI/Support.h"
15
16using namespace circt;
17using namespace circt::llhd;
18
19//===----------------------------------------------------------------------===//
20// Dialect
21//===----------------------------------------------------------------------===//
22
23MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(LLHD, llhd, circt::llhd::LLHDDialect)
24
25//===----------------------------------------------------------------------===//
26// Types
27//===----------------------------------------------------------------------===//
28
29/// Check if a type is a time type.
30bool llhdTypeIsATimeType(MlirType type) { return isa<TimeType>(unwrap(type)); }
31
32/// Check if a type is a reference type.
33bool llhdTypeIsARefType(MlirType type) { return isa<RefType>(unwrap(type)); }
34
35/// Create a time type.
36MlirType llhdTimeTypeGet(MlirContext ctx) {
37 return wrap(TimeType::get(unwrap(ctx)));
38}
39
40/// Create a reference type.
41MlirType llhdRefTypeGet(MlirType element) {
42 return wrap(RefType::get(unwrap(element)));
43}
44
45/// Get the inner type of a reference.
46MlirType llhdRefTypeGetNestedType(MlirType type) {
47 return wrap(cast<RefType>(unwrap(type)).getNestedType());
48}
49
50//===----------------------------------------------------------------------===//
51// Attributes
52//===----------------------------------------------------------------------===//
53
54/// Check if an attribute is a time attribute.
55bool llhdAttrIsATimeAttr(MlirAttribute attr) {
56 return isa<TimeAttr>(unwrap(attr));
57}
58
59/// Create a time attribute.
60MlirAttribute llhdTimeAttrGet(MlirContext ctx, MlirStringRef timeUnit,
61 uint64_t seconds, uint64_t delta) {
62 return wrap(TimeAttr::get(unwrap(ctx), seconds, unwrap(timeUnit), delta));
63}
64
65/// Get the time unit of a time attribute.
66MlirStringRef llhdTimeAttrGetTimeUnit(MlirAttribute attr) {
67 return wrap(cast<TimeAttr>(unwrap(attr)).getTimeUnit());
68}
69
70/// Get the seconds component of a time attribute.
71uint64_t llhdTimeAttrGetSeconds(MlirAttribute attr) {
72 return cast<TimeAttr>(unwrap(attr)).getTime();
73}
74
75/// Get the delta component of a time attribute.
76uint64_t llhdTimeAttrGetDelta(MlirAttribute attr) {
77 return cast<TimeAttr>(unwrap(attr)).getDelta();
78}
return wrap(CMemoryType::get(unwrap(ctx), baseType, numElements))
MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(CHIRRTL, chirrtl, circt::chirrtl::CHIRRTLDialect) MlirType chirrtlTypeGetCMemory(MlirContext ctx
MlirType llhdTimeTypeGet(MlirContext ctx)
Create a time type.
Definition LLHD.cpp:36
uint64_t llhdTimeAttrGetSeconds(MlirAttribute attr)
Get the seconds component of a time attribute.
Definition LLHD.cpp:71
uint64_t llhdTimeAttrGetDelta(MlirAttribute attr)
Get the delta component of a time attribute.
Definition LLHD.cpp:76
MlirAttribute llhdTimeAttrGet(MlirContext ctx, MlirStringRef timeUnit, uint64_t seconds, uint64_t delta)
Create a time attribute.
Definition LLHD.cpp:60
MlirStringRef llhdTimeAttrGetTimeUnit(MlirAttribute attr)
Get the time unit of a time attribute.
Definition LLHD.cpp:66
MlirType llhdRefTypeGetNestedType(MlirType type)
Get the inner type of a reference.
Definition LLHD.cpp:46
bool llhdAttrIsATimeAttr(MlirAttribute attr)
Check if an attribute is a time attribute.
Definition LLHD.cpp:55
MlirType llhdRefTypeGet(MlirType element)
Create a reference type.
Definition LLHD.cpp:41
bool llhdTypeIsARefType(MlirType type)
Check if a type is a reference type.
Definition LLHD.cpp:33
MLIR_CAPI_EXPORTED bool llhdTypeIsATimeType(MlirType)
Check if a type is a time type.
Definition LLHD.cpp:30
static EvaluatorValuePtr unwrap(OMEvaluatorValue c)
Definition OM.cpp:111
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.