-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[CIR] Upstream proper function alias lowering #150520
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -919,13 +919,46 @@ rewriteCallOrInvoke(mlir::Operation *op, mlir::ValueRange callOperands, | |||||||||||||
| memoryEffects, noUnwind, willReturn); | ||||||||||||||
|
|
||||||||||||||
| mlir::LLVM::LLVMFunctionType llvmFnTy; | ||||||||||||||
|
|
||||||||||||||
| // Temporary to handle the case where we need to prepend an operand if the | ||||||||||||||
| // callee is an alias. | ||||||||||||||
| SmallVector<mlir::Value> adjustedCallOperands; | ||||||||||||||
|
|
||||||||||||||
| if (calleeAttr) { // direct call | ||||||||||||||
| mlir::FunctionOpInterface fn = | ||||||||||||||
| mlir::SymbolTable::lookupNearestSymbolFrom<mlir::FunctionOpInterface>( | ||||||||||||||
| op, calleeAttr); | ||||||||||||||
| assert(fn && "Did not find function for call"); | ||||||||||||||
| llvmFnTy = cast<mlir::LLVM::LLVMFunctionType>( | ||||||||||||||
| converter->convertType(fn.getFunctionType())); | ||||||||||||||
| mlir::Operation *callee = | ||||||||||||||
| mlir::SymbolTable::lookupNearestSymbolFrom(op, calleeAttr); | ||||||||||||||
| if (auto fn = dyn_cast<mlir::FunctionOpInterface>(callee)) { | ||||||||||||||
| llvmFnTy = cast<mlir::LLVM::LLVMFunctionType>( | ||||||||||||||
| converter->convertType(fn.getFunctionType())); | ||||||||||||||
| } else if (auto alias = cast<mlir::LLVM::AliasOp>(callee)) { | ||||||||||||||
|
||||||||||||||
| } else if (auto alias = cast<mlir::LLVM::AliasOp>(callee)) { | |
| } else if (auto alias = mlir::cast<mlir::LLVM::AliasOp>(callee)) { |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wasan -> was an
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| auto symAttr = cast<mlir::FlatSymbolRefAttr>(calleeAttr); | |
| auto symAttr = mlir::cast<mlir::FlatSymbolRefAttr>(calleeAttr); |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| rewriter | |
| .create<mlir::LLVM::AddressOfOp>( | |
| mlir::LLVM::AddressOfOp::create(rewriter, |
- some formatting
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| llvmFnTy = cast<mlir::LLVM::LLVMFunctionType>(alias.getType()); | |
| llvmFnTy = mlir::cast<mlir::LLVM::LLVMFunctionType>(alias.getType()); |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| cir::FuncOp op, mlir::FlatSymbolRefAttr aliasee, mlir::Type ty, | |
| cir::FuncOp op, llvm::StringRef aliasee, mlir::Type ty, |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const { | |
| mlir::OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like OpAdaptor is an alias, so I can't use the mlir namespace qualifier here.
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| builder.create<mlir::LLVM::AddressOfOp>(loc, ptrTy, aliasee.getValue()); | |
| builder.create<mlir::LLVM::AddressOfOp>(loc, ptrTy, aliasee); |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| auto addrOp = | |
| builder.create<mlir::LLVM::AddressOfOp>(loc, ptrTy, aliasee.getValue()); | |
| builder.create<mlir::LLVM::ReturnOp>(loc, addrOp); | |
| auto addrOp = | |
| mlir::LLVM::AddressOfOp::create(builder, loc, ptrTy, aliasee.getValue()); | |
| mlir::LLVM::ReturnOp::(builder, loc, addrOp); |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| std::optional<mlir::FlatSymbolRefAttr> aliasee = op.getAliaseeAttr(); | |
| if (aliasee && *aliasee) | |
| return matchAndRewriteAlias(op, *aliasee, llvmFnTy, adaptor, rewriter); | |
| if (std::optional<llvm::StringRef> aliasee = op.getAliasee()) | |
| return matchAndRewriteAlias(op, *aliasee, llvmFnTy, adaptor, rewriter); |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -257,6 +257,11 @@ class CIRToLLVMFuncOpLowering : public mlir::OpConversionPattern<cir::FuncOp> { | |||||
| cir::FuncOp func, bool filterArgAndResAttrs, | ||||||
| mlir::SmallVectorImpl<mlir::NamedAttribute> &result) const; | ||||||
|
|
||||||
| mlir::LogicalResult | ||||||
| matchAndRewriteAlias(cir::FuncOp op, mlir::FlatSymbolRefAttr aliasee, | ||||||
|
||||||
| matchAndRewriteAlias(cir::FuncOp op, mlir::FlatSymbolRefAttr aliasee, | |
| matchAndRewriteAlias(cir::FuncOp op, llvm::StringRef aliasee, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.