-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[CIR] Upstream ComplexType builtin_complex #144225
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
Merged
AmrDeveloper
merged 4 commits into
llvm:main
from
AmrDeveloper:cir_upstream_builtin_complex_create
Jun 18, 2025
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
---|---|---|
|
@@ -15,11 +15,25 @@ class ComplexExprEmitter : public StmtVisitor<ComplexExprEmitter, mlir::Value> { | |
explicit ComplexExprEmitter(CIRGenFunction &cgf) | ||
: cgf(cgf), builder(cgf.getBuilder()) {} | ||
|
||
//===--------------------------------------------------------------------===// | ||
// Utilities | ||
//===--------------------------------------------------------------------===// | ||
|
||
/// Given an expression with complex type that represents a value l-value, | ||
/// this method emits the address of the l-value, then loads and returns the | ||
/// result. | ||
mlir::Value emitLoadOfLValue(const Expr *e) { | ||
return emitLoadOfLValue(cgf.emitLValue(e), e->getExprLoc()); | ||
} | ||
|
||
mlir::Value emitLoadOfLValue(LValue lv, SourceLocation loc); | ||
|
||
/// Store the specified real/imag parts into the | ||
/// specified value pointer. | ||
void emitStoreOfComplex(mlir::Location loc, mlir::Value val, LValue lv, | ||
bool isInit); | ||
|
||
mlir::Value VisitCallExpr(const CallExpr *e); | ||
mlir::Value VisitInitListExpr(InitListExpr *e); | ||
|
||
mlir::Value VisitImaginaryLiteral(const ImaginaryLiteral *il); | ||
|
@@ -34,18 +48,35 @@ static const ComplexType *getComplexType(QualType type) { | |
return cast<ComplexType>(cast<AtomicType>(type)->getValueType()); | ||
} | ||
|
||
mlir::Value ComplexExprEmitter::emitLoadOfLValue(LValue lv, | ||
SourceLocation loc) { | ||
assert(lv.isSimple() && "non-simple complex l-value?"); | ||
if (lv.getType()->isAtomicType()) | ||
cgf.cgm.errorNYI(loc, "emitLoadOfLValue with Atomic LV"); | ||
|
||
const Address srcAddr = lv.getAddress(); | ||
return builder.createLoad(cgf.getLoc(loc), srcAddr); | ||
} | ||
|
||
void ComplexExprEmitter::emitStoreOfComplex(mlir::Location loc, mlir::Value val, | ||
LValue lv, bool isInit) { | ||
if (lv.getType()->isAtomicType() || | ||
(!isInit && cgf.isLValueSuitableForInlineAtomic(lv))) { | ||
cgf.cgm.errorNYI("StoreOfComplex with Atomic LV"); | ||
cgf.cgm.errorNYI(loc, "StoreOfComplex with Atomic LV"); | ||
return; | ||
} | ||
|
||
const Address destAddr = lv.getAddress(); | ||
builder.createStore(loc, val, destAddr); | ||
} | ||
|
||
mlir::Value ComplexExprEmitter::VisitCallExpr(const CallExpr *e) { | ||
if (e->getCallReturnType(cgf.getContext())->isReferenceType()) | ||
return emitLoadOfLValue(e); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you know what sort of source construct gets us here? A test case for this would be useful. |
||
|
||
return cgf.emitCallExpr(e).getValue(); | ||
} | ||
|
||
mlir::Value ComplexExprEmitter::VisitInitListExpr(InitListExpr *e) { | ||
mlir::Location loc = cgf.getLoc(e->getExprLoc()); | ||
if (e->getNumInits() == 2) { | ||
|
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.