File tree Expand file tree Collapse file tree 4 files changed +30
-1
lines changed
lib/CIR/Lowering/ThroughMLIR Expand file tree Collapse file tree 4 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -544,6 +544,12 @@ class CIRFuncOpLowering : public mlir::OpConversionPattern<cir::FuncOp> {
544544 signatureConversion.addInputs (argType.index (), convertedType);
545545 }
546546
547+ SmallVector<mlir::NamedAttribute, 2 > passThroughAttrs;
548+
549+ if (auto symVisibilityAttr = op.getSymVisibilityAttr ())
550+ passThroughAttrs.push_back (
551+ rewriter.getNamedAttr (" sym_visibility" , symVisibilityAttr));
552+
547553 SmallVector<mlir::Type> resultTypes;
548554 // Only convert return type if the function is not void
549555 if (!mlir::isa<cir::VoidType>(fnType.getReturnType ())) {
@@ -556,7 +562,8 @@ class CIRFuncOpLowering : public mlir::OpConversionPattern<cir::FuncOp> {
556562 auto fn = rewriter.create <mlir::func::FuncOp>(
557563 op.getLoc (), op.getName (),
558564 rewriter.getFunctionType (signatureConversion.getConvertedTypes (),
559- resultTypes));
565+ resultTypes),
566+ passThroughAttrs);
560567
561568 if (failed (rewriter.convertRegionTypes (&op.getBody (), *getTypeConverter (),
562569 &signatureConversion)))
Original file line number Diff line number Diff line change 2424#include " mlir/Pass/PassManager.h"
2525#include " mlir/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.h"
2626#include " mlir/Transforms/DialectConversion.h"
27+ #include " clang/CIR/Dialect/IR/CIRDialect.h"
2728#include " clang/CIR/Passes.h"
2829
2930using namespace cir ;
@@ -62,6 +63,17 @@ void ConvertMLIRToLLVMPass::runOnOperation() {
6263 populateFuncToLLVMConversionPatterns (typeConverter, patterns);
6364
6465 auto module = getOperation ();
66+
67+ // Lower the module attributes to LLVM equivalents.
68+ if (auto tripleAttr = module ->getAttr (cir::CIRDialect::getTripleAttrName ()))
69+ module ->setAttr (mlir::LLVM::LLVMDialect::getTargetTripleAttrName (),
70+ tripleAttr);
71+
72+ // Strip the CIR attributes.
73+ module ->removeAttr (cir::CIRDialect::getSOBAttrName ());
74+ module ->removeAttr (cir::CIRDialect::getLangAttrName ());
75+ module ->removeAttr (cir::CIRDialect::getTripleAttrName ());
76+
6577 if (failed (applyFullConversion (module , target, std::move (patterns))))
6678 signalPassFailure ();
6779}
Original file line number Diff line number Diff line change 1+ // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -fno-clangir-direct-lowering -emit-mlir=core %s -o %t.mlir
2+ // RUN: FileCheck --input-file=%t.mlir %s
3+
4+ // CHECK: func.func private @declaration(i32) -> i32
5+
6+ int declaration (int x );
7+ int declaration_test () {
8+ return declaration (15 );
9+ }
Original file line number Diff line number Diff line change 2525// RUN: FileCheck --input-file=%t.cir %s -check-prefix=CIR_MACOS
2626// RUN: %clang -target arm64-apple-macosx12.0.0 -fclangir -S -emit-llvm %s -o %t3.ll
2727// RUN: FileCheck --input-file=%t3.ll %s -check-prefix=LLVM_MACOS
28+ // RUN: %clang -target x86_64-unknown-linux-gnu -fclangir -fno-clangir-direct-lowering -c %s -o %t.o
2829
2930void foo (void ) {}
3031
You can’t perform that action at this time.
0 commit comments