-
Notifications
You must be signed in to change notification settings - Fork 175
Closed
Description
In the CIRtoMLIR lowering, when lowering a cir.func operation with
clangir/clang/lib/CIR/Lowering/ThroughMLIR/LowerCIRToMLIR.cpp
Lines 524 to 559 in 5df5009
class CIRFuncOpLowering : public mlir::OpConversionPattern<cir::FuncOp> { | |
public: | |
using OpConversionPattern<cir::FuncOp>::OpConversionPattern; | |
mlir::LogicalResult | |
matchAndRewrite(cir::FuncOp op, OpAdaptor adaptor, | |
mlir::ConversionPatternRewriter &rewriter) const override { | |
auto fnType = op.getFunctionType(); | |
mlir::TypeConverter::SignatureConversion signatureConversion( | |
fnType.getNumInputs()); | |
for (const auto &argType : enumerate(fnType.getInputs())) { | |
auto convertedType = typeConverter->convertType(argType.value()); | |
if (!convertedType) | |
return mlir::failure(); | |
signatureConversion.addInputs(argType.index(), convertedType); | |
} | |
mlir::Type resultType = | |
getTypeConverter()->convertType(fnType.getReturnType()); | |
auto fn = rewriter.create<mlir::func::FuncOp>( | |
op.getLoc(), op.getName(), | |
rewriter.getFunctionType(signatureConversion.getConvertedTypes(), | |
resultType ? mlir::TypeRange(resultType) | |
: mlir::TypeRange())); | |
if (failed(rewriter.convertRegionTypes(&op.getBody(), *typeConverter, | |
&signatureConversion))) | |
return mlir::failure(); | |
rewriter.inlineRegionBefore(op.getBody(), fn.getBody(), fn.end()); | |
rewriter.eraseOp(op); | |
return mlir::LogicalResult::success(); | |
} | |
}; |
error: 'func.func' op symbol declaration cannot have public visibility
I would suggest fixing this by passing the sym_visibility and maybe also the arg_attrs, res_attrs attributes of the cir.func to the created func.func (arg_attrs, res_attrs don't fix this particular issue and I'm not sure if they are currently used for anything, maybe someone else can explain what the purpose of the attributes is)
Here's a minimal example that triggers the issue:
test.c
#include "example.h"
int main(int argc, char *argv[]) {
// Variables
int number = 15;
number = add10(number);
return 0;
}
example.h
#ifndef ADD10_H
#define ADD10_H
int add10(int x);
#endif
example.c
#include "example.h"
int add10(int x) {
return x + 10;
}
trying to lower throughmlir here leads to the describe error:
clang -fclangir -S -Xclang -emit-mlir=core -fno-clangir-direct-lowering test.c
loc(fused["./example.h":4:1, "./example.h":4:16]): error: 'func.func' op symbol declaration cannot have public visibility
fatal error: error in backend: The pass manager failed to lower CIR to MLIR standard dialects!
bcardosolopes
Metadata
Metadata
Assignees
Labels
No labels