Skip to content

Commit 5656cbc

Browse files
authored
[MLIR][CAPI] export LLVMFunctionType param getter and setters (#121888)
1 parent 5aef8ab commit 5656cbc

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

mlir/include/mlir-c/Dialect/LLVM.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ MLIR_CAPI_EXPORTED MlirType
4545
mlirLLVMFunctionTypeGet(MlirType resultType, intptr_t nArgumentTypes,
4646
MlirType const *argumentTypes, bool isVarArg);
4747

48+
/// Returns the number of input types.
49+
MLIR_CAPI_EXPORTED intptr_t mlirLLVMFunctionTypeGetNumInputs(MlirType type);
50+
51+
/// Returns the pos-th input type.
52+
MLIR_CAPI_EXPORTED MlirType mlirLLVMFunctionTypeGetInput(MlirType type,
53+
intptr_t pos);
54+
4855
/// Returns `true` if the type is an LLVM dialect struct type.
4956
MLIR_CAPI_EXPORTED bool mlirTypeIsALLVMStructType(MlirType type);
5057

mlir/lib/CAPI/Dialect/LLVM.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@ MlirType mlirLLVMFunctionTypeGet(MlirType resultType, intptr_t nArgumentTypes,
5555
unwrapList(nArgumentTypes, argumentTypes, argumentStorage), isVarArg));
5656
}
5757

58+
intptr_t mlirLLVMFunctionTypeGetNumInputs(MlirType type) {
59+
return llvm::cast<LLVM::LLVMFunctionType>(unwrap(type)).getNumParams();
60+
}
61+
62+
MlirType mlirLLVMFunctionTypeGetInput(MlirType type, intptr_t pos) {
63+
assert(pos >= 0 && "pos in array must be positive");
64+
return wrap(llvm::cast<LLVM::LLVMFunctionType>(unwrap(type))
65+
.getParamType(static_cast<unsigned>(pos)));
66+
}
67+
5868
bool mlirTypeIsALLVMStructType(MlirType type) {
5969
return isa<LLVM::LLVMStructType>(unwrap(type));
6070
}

0 commit comments

Comments
 (0)