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> {
544
544
signatureConversion.addInputs (argType.index (), convertedType);
545
545
}
546
546
547
+ SmallVector<mlir::NamedAttribute, 2 > passThroughAttrs;
548
+
549
+ if (auto symVisibilityAttr = op.getSymVisibilityAttr ())
550
+ passThroughAttrs.push_back (
551
+ rewriter.getNamedAttr (" sym_visibility" , symVisibilityAttr));
552
+
547
553
SmallVector<mlir::Type> resultTypes;
548
554
// Only convert return type if the function is not void
549
555
if (!mlir::isa<cir::VoidType>(fnType.getReturnType ())) {
@@ -556,7 +562,8 @@ class CIRFuncOpLowering : public mlir::OpConversionPattern<cir::FuncOp> {
556
562
auto fn = rewriter.create <mlir::func::FuncOp>(
557
563
op.getLoc (), op.getName (),
558
564
rewriter.getFunctionType (signatureConversion.getConvertedTypes (),
559
- resultTypes));
565
+ resultTypes),
566
+ passThroughAttrs);
560
567
561
568
if (failed (rewriter.convertRegionTypes (&op.getBody (), *getTypeConverter (),
562
569
&signatureConversion)))
Original file line number Diff line number Diff line change 24
24
#include " mlir/Pass/PassManager.h"
25
25
#include " mlir/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.h"
26
26
#include " mlir/Transforms/DialectConversion.h"
27
+ #include " clang/CIR/Dialect/IR/CIRDialect.h"
27
28
#include " clang/CIR/Passes.h"
28
29
29
30
using namespace cir ;
@@ -62,6 +63,17 @@ void ConvertMLIRToLLVMPass::runOnOperation() {
62
63
populateFuncToLLVMConversionPatterns (typeConverter, patterns);
63
64
64
65
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
+
65
77
if (failed (applyFullConversion (module , target, std::move (patterns))))
66
78
signalPassFailure ();
67
79
}
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 25
25
// RUN: FileCheck --input-file=%t.cir %s -check-prefix=CIR_MACOS
26
26
// RUN: %clang -target arm64-apple-macosx12.0.0 -fclangir -S -emit-llvm %s -o %t3.ll
27
27
// 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
28
29
29
30
void foo (void ) {}
30
31
You can’t perform that action at this time.
0 commit comments