-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[CIR] Implement __builtin_return_address and __builtin_frame_address #153698
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 all commits
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 |
---|---|---|
|
@@ -267,6 +267,26 @@ void convertSideEffectForCall(mlir::Operation *callOp, bool isNothrow, | |
} | ||
} | ||
|
||
static mlir::LLVM::CallIntrinsicOp | ||
createCallLLVMIntrinsicOp(mlir::ConversionPatternRewriter &rewriter, | ||
mlir::Location loc, const llvm::Twine &intrinsicName, | ||
mlir::Type resultTy, mlir::ValueRange operands) { | ||
auto intrinsicNameAttr = | ||
mlir::StringAttr::get(rewriter.getContext(), intrinsicName); | ||
return mlir::LLVM::CallIntrinsicOp::create(rewriter, loc, resultTy, | ||
intrinsicNameAttr, operands); | ||
} | ||
|
||
static mlir::LLVM::CallIntrinsicOp replaceOpWithCallLLVMIntrinsicOp( | ||
mlir::ConversionPatternRewriter &rewriter, mlir::Operation *op, | ||
const llvm::Twine &intrinsicName, mlir::Type resultTy, | ||
mlir::ValueRange operands) { | ||
mlir::LLVM::CallIntrinsicOp callIntrinOp = createCallLLVMIntrinsicOp( | ||
rewriter, op->getLoc(), intrinsicName, resultTy, operands); | ||
rewriter.replaceOp(op, callIntrinOp.getOperation()); | ||
return callIntrinOp; | ||
} | ||
|
||
/// IntAttr visitor. | ||
mlir::Value CIRAttrToValue::visitCirAttr(cir::IntAttr intAttr) { | ||
mlir::Location loc = parentOp->getLoc(); | ||
|
@@ -1097,6 +1117,24 @@ mlir::LogicalResult CIRToLLVMCallOpLowering::matchAndRewrite( | |
getTypeConverter(), op.getCalleeAttr()); | ||
} | ||
|
||
mlir::LogicalResult CIRToLLVMReturnAddrOpLowering::matchAndRewrite( | ||
cir::ReturnAddrOp op, OpAdaptor adaptor, | ||
mlir::ConversionPatternRewriter &rewriter) const { | ||
auto llvmPtrTy = mlir::LLVM::LLVMPointerType::get(rewriter.getContext()); | ||
replaceOpWithCallLLVMIntrinsicOp(rewriter, op, "llvm.returnaddress", | ||
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. Given that we're lowering these to an LLVM intrinsic call anyway, I wonder if we should just use @bcardosolopes Were these useful for some kind of analysis? 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. The information coming from these builtins are likely useful in order to mark some function as unsafe for certain optimizations (e.g. where the return address or stack addressed in general might escape), they feel very different IMO than random shift vectors for ARM SVE. That said, you are right we don't use them right now, but I'd argue for keeping them because their behavior could be more intrusive than regular intrinsics. |
||
llvmPtrTy, adaptor.getOperands()); | ||
return mlir::success(); | ||
} | ||
|
||
mlir::LogicalResult CIRToLLVMFrameAddrOpLowering::matchAndRewrite( | ||
cir::FrameAddrOp op, OpAdaptor adaptor, | ||
mlir::ConversionPatternRewriter &rewriter) const { | ||
auto llvmPtrTy = mlir::LLVM::LLVMPointerType::get(rewriter.getContext()); | ||
replaceOpWithCallLLVMIntrinsicOp(rewriter, op, "llvm.frameaddress", llvmPtrTy, | ||
adaptor.getOperands()); | ||
return mlir::success(); | ||
} | ||
|
||
mlir::LogicalResult CIRToLLVMLoadOpLowering::matchAndRewrite( | ||
cir::LoadOp op, OpAdaptor adaptor, | ||
mlir::ConversionPatternRewriter &rewriter) const { | ||
|
@@ -2307,10 +2345,12 @@ void ConvertCIRToLLVMPass::runOnOperation() { | |
CIRToLLVMConstantOpLowering, | ||
CIRToLLVMExpectOpLowering, | ||
CIRToLLVMFAbsOpLowering, | ||
CIRToLLVMFrameAddrOpLowering, | ||
CIRToLLVMFuncOpLowering, | ||
CIRToLLVMGetBitfieldOpLowering, | ||
CIRToLLVMGetGlobalOpLowering, | ||
CIRToLLVMGetMemberOpLowering, | ||
CIRToLLVMReturnAddrOpLowering, | ||
CIRToLLVMRotateOpLowering, | ||
CIRToLLVMSelectOpLowering, | ||
CIRToLLVMSetBitfieldOpLowering, | ||
|
Uh oh!
There was an error while loading. Please reload this page.