Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CIR][Lowering] Support lowering of cir.const with GlobalViewAttr (gh-352) #363

Merged
merged 2 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1040,6 +1040,12 @@ class CIRConstantLowering
return mlir::success();
}
}
// Lower GlobalViewAttr to llvm.mlir.addressof
if (auto gv = op.getValue().dyn_cast<mlir::cir::GlobalViewAttr>()) {
auto newOp = lowerCirAttrAsValue(op, gv, rewriter, getTypeConverter());
rewriter.replaceOp(op, newOp);
return mlir::success();
}
attr = op.getValue();
}
// TODO(cir): constant arrays are currently just pushed into the stack using
Expand Down
11 changes: 11 additions & 0 deletions clang/test/CIR/Lowering/globals.cir
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,15 @@ module {
//MLIR: %[[RES8:.*]] = llvm.getelementptr %[[RES7]][0, 0] : (!llvm.ptr) -> !llvm.ptr, !llvm.struct<"struct.anon.1", (ptr)>
//MLIR: %[[RES9:.*]] = llvm.load %[[RES8]] : !llvm.ptr -> !llvm.ptr
//MLIR: llvm.call %[[RES9]]({{.*}}) : !llvm.ptr, (i32) -> ()

cir.global external @zero_array = #cir.zero : !cir.array<!s32i x 16>
cir.func @use_zero_array() {
%0 = cir.const(#cir.global_view<@zero_array> : !cir.ptr<!s32i>) : !cir.ptr<!s32i>
%1 = cir.const(#cir.int<0> : !s32i) : !s32i
%2 = cir.ptr_stride(%0 : !cir.ptr<!s32i>, %1 : !s32i), !cir.ptr<!s32i>
%3 = cir.load %2 : cir.ptr <!s32i>, !s32i
cir.return
}
// MLIR: %0 = llvm.mlir.addressof @zero_array

}