Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[flang] add hlfir.null to implement NULL()
In HLFIR, the address of a Fortran entity in lowering must be defined by an operation that has the FortranVariableOpInterface (it is a sanity requirement to ensure that the mlir::Value propagated in certain places of lowering can be reasoned about). fir.zero_bits does not have this interface and it makes little sense to add it since it can "zero initialize" more types than just addresses. Creating an hlfir.declare for null addresses is a bit too much (what would be the name), and it would be noisy in the IR. Instead add a small hlfir.null operation whose codegen is simply a replacement by fir.zero_bits. It may also later help dealing with the NULL(MOLD) cases in a nicer way (the current lowering of this uses special handling it). Differential Revision: https://reviews.llvm.org/D141040
- Loading branch information
1 parent
543db09
commit 241cb29
Showing
5 changed files
with
68 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Test hlfir.null code generation to FIR | ||
|
||
// RUN: fir-opt %s -convert-hlfir-to-fir | FileCheck %s | ||
|
||
func.func @test() { | ||
// CHECK: fir.zero_bits !fir.ref<none> | ||
%0 = hlfir.null !fir.ref<none> | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Test hlfir.null operation parse, verify (no errors), and unparse. | ||
|
||
// RUN: fir-opt %s | fir-opt | FileCheck %s | ||
|
||
func.func @test() { | ||
// CHECK: hlfir.null !fir.ref<none> | ||
%0 = hlfir.null !fir.ref<none> | ||
return | ||
} |