File tree Expand file tree Collapse file tree 3 files changed +22
-2
lines changed
include/flang/Optimizer/Dialect Expand file tree Collapse file tree 3 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -2713,7 +2713,7 @@ def fir_AddrOfOp : fir_OneResultOp<"address_of", [NoMemoryEffect]> {
27132713 let assemblyFormat = "`(` $symbol `)` attr-dict `:` type($resTy)";
27142714}
27152715
2716- def fir_ConvertOp : fir_OneResultOp <"convert", [NoMemoryEffect]> {
2716+ def fir_ConvertOp : fir_SimpleOneResultOp <"convert", [NoMemoryEffect]> {
27172717 let summary = "encapsulates all Fortran entity type conversions";
27182718
27192719 let description = [{
@@ -2722,6 +2722,9 @@ def fir_ConvertOp : fir_OneResultOp<"convert", [NoMemoryEffect]> {
27222722 type, this instruction is a NOP and may be folded away. This also supports
27232723 integer to pointer conversion and pointer to integer conversion.
27242724
2725+ This operation also allows limited interaction between FIR and LLVM
2726+ dialects by allowing conversion between FIR pointer types and llvm.ptr type.
2727+
27252728 ```
27262729 %v = ... : i64
27272730 %w = fir.convert %v : (i64) -> i32
@@ -2731,6 +2734,7 @@ def fir_ConvertOp : fir_OneResultOp<"convert", [NoMemoryEffect]> {
27312734 }];
27322735
27332736 let arguments = (ins AnyType:$value);
2737+ let results = (outs AnyType:$res);
27342738
27352739 let assemblyFormat = [{
27362740 $value attr-dict `:` functional-type($value, results)
Original file line number Diff line number Diff line change @@ -1387,7 +1387,7 @@ bool fir::ConvertOp::isFloatCompatible(mlir::Type ty) {
13871387bool fir::ConvertOp::isPointerCompatible (mlir::Type ty) {
13881388 return mlir::isa<fir::ReferenceType, fir::PointerType, fir::HeapType,
13891389 fir::LLVMPointerType, mlir::MemRefType, mlir::FunctionType,
1390- fir::TypeDescType>(ty);
1390+ fir::TypeDescType, mlir::LLVM::LLVMPointerType >(ty);
13911391}
13921392
13931393static std::optional<mlir::Type> getVectorElementType (mlir::Type ty) {
Original file line number Diff line number Diff line change @@ -11,3 +11,19 @@ func.func @c(%x : !fir.complex<4>) -> !fir.complex<8> {
1111 %1 = fir.convert %x : (!fir.complex<4>) -> !fir.complex<8>
1212 return %1 : !fir.complex<8>
1313}
14+
15+ func.func @convert_to_llvm_pointer(%x : !fir.llvm_ptr<i32>) -> !llvm.ptr {
16+ %0 = fir.convert %x : (!fir.llvm_ptr<i32>) -> !llvm.ptr
17+ return %0 : !llvm.ptr
18+ }
19+ // CHECK-LABEL: convert_to_llvm_pointer(
20+ // CHECK-SAME: ptr %[[X:.*]])
21+ // CHECK-NEXT: ret ptr %[[X]]
22+
23+ func.func @convert_from_llvm_pointer(%x : !llvm.ptr) -> !fir.llvm_ptr<i32> {
24+ %0 = fir.convert %x : (!llvm.ptr) -> !fir.llvm_ptr<i32>
25+ return %0 : !fir.llvm_ptr<i32>
26+ }
27+ // CHECK-LABEL: convert_from_llvm_pointer(
28+ // CHECK-SAME: ptr %[[X:.*]])
29+ // CHECK-NEXT: ret ptr %[[X]]
You can’t perform that action at this time.
0 commit comments