CIRCT 22.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 uint64_t epsilon) {
63 return wrap(
64 TimeAttr::get(unwrap(ctx), seconds, unwrap(timeUnit), delta, epsilon));
65}
66
67/// Get the time unit of a time attribute.
68MlirStringRef llhdTimeAttrGetTimeUnit(MlirAttribute attr) {
69 return wrap(cast<TimeAttr>(unwrap(attr)).getTimeUnit());
70}
71
72/// Get the seconds component of a time attribute.
73uint64_t llhdTimeAttrGetSeconds(MlirAttribute attr) {
74 return cast<TimeAttr>(unwrap(attr)).getTime();
75}
76
77/// Get the delta component of a time attribute.
78uint64_t llhdTimeAttrGetDelta(MlirAttribute attr) {
79 return cast<TimeAttr>(unwrap(attr)).getDelta();
80}
81
82/// Get the epsilon component of a time attribute.
83uint64_t llhdTimeAttrGetEpsilon(MlirAttribute attr) {
84 return cast<TimeAttr>(unwrap(attr)).getEpsilon();
85}
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:73
uint64_t llhdTimeAttrGetDelta(MlirAttribute attr)
Get the delta component of a time attribute.
Definition LLHD.cpp:78
MlirStringRef llhdTimeAttrGetTimeUnit(MlirAttribute attr)
Get the time unit of a time attribute.
Definition LLHD.cpp:68
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
bool llhdTypeIsATimeType(MlirType type)
Check if a type is a time type.
Definition LLHD.cpp:30
MlirType llhdRefTypeGet(MlirType element)
Create a reference type.
Definition LLHD.cpp:41
MlirAttribute llhdTimeAttrGet(MlirContext ctx, MlirStringRef timeUnit, uint64_t seconds, uint64_t delta, uint64_t epsilon)
Create a time attribute.
Definition LLHD.cpp:60
uint64_t llhdTimeAttrGetEpsilon(MlirAttribute attr)
Get the epsilon component of a time attribute.
Definition LLHD.cpp:83
bool llhdTypeIsARefType(MlirType type)
Check if a type is a reference type.
Definition LLHD.cpp:33
static EvaluatorValuePtr unwrap(OMEvaluatorValue c)
Definition OM.cpp:111
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.