Skip to content

Commit 822684e

Browse files
committed
Revert "[CIR] Add dedicated CIR op for setjmp (#1853)"
This reverts commit 4e092b2.
1 parent 7f95114 commit 822684e

File tree

7 files changed

+14
-161
lines changed

7 files changed

+14
-161
lines changed

clang/include/clang/CIR/Dialect/IR/CIROps.td

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4703,36 +4703,6 @@ def CIR_EhTypeIdOp : CIR_Op<"eh.typeid",
47034703
}];
47044704
}
47054705

4706-
def CIR_EhSetjmp : CIR_Op<"eh.setjmp"> {
4707-
let summary = "CIR setjmp operation";
4708-
let description = [{
4709-
Saves call-site information (e.g., stack pointer, instruction
4710-
pointer, signal mask, and other registers) in memory at `env` for use by longjmp(). In this case,
4711-
setjmp() returns 0. Following a successful longjmp(), execution proceeds
4712-
from cir.eh.setjmp with the operation yielding a non-zero value.
4713-
4714-
The presence of the `builtin` attribute refers to the setjmp() function; the lack of the attribute refers
4715-
to the _setjmp() function.
4716-
4717-
Examples:
4718-
```mlir
4719-
// Specify setjmp is builtin.
4720-
%0 = cir.eh.setjmp builtin %arg0 : (!cir.ptr<!cir.void>) -> !s32i
4721-
4722-
// Specify setjmp is not builtin.
4723-
%0 = cir.eh.setjmp %arg0 : (!cir.ptr<!cir.void>) -> !s32i
4724-
```
4725-
}];
4726-
let arguments = (ins CIR_PointerType:$env, UnitAttr:$is_builtin);
4727-
4728-
let results = (outs CIR_SInt32:$res);
4729-
4730-
let assemblyFormat = [{
4731-
(`builtin` $is_builtin^)?
4732-
$env `:` functional-type($env, results) attr-dict
4733-
}];
4734-
}
4735-
47364706
//===----------------------------------------------------------------------===//
47374707
// CopyOp
47384708
//===----------------------------------------------------------------------===//

clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1927,9 +1927,12 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
19271927
cir::PtrStrideOp stackSaveSlot = cir::PtrStrideOp::create(
19281928
builder, loc, ppTy, castBuf, builder.getSInt32(2, loc));
19291929
cir::StoreOp::create(builder, loc, stacksave, stackSaveSlot);
1930-
cir::EhSetjmp op =
1931-
cir::EhSetjmp::create(builder, loc, castBuf, /*is_builtin=*/true);
1932-
return RValue::get(op);
1930+
mlir::Value setjmpCall =
1931+
cir::LLVMIntrinsicCallOp::create(
1932+
builder, loc, builder.getStringAttr("eh.sjlj.setjmp"),
1933+
builder.getSInt32Ty(), mlir::ValueRange{castBuf})
1934+
.getResult();
1935+
return RValue::get(setjmpCall);
19331936
}
19341937
case Builtin::BI__builtin_longjmp:
19351938
llvm_unreachable("BI__builtin_longjmp NYI");
@@ -2431,13 +2434,7 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
24312434
llvm_unreachable("NYI setjmp on aarch64");
24322435
llvm_unreachable("NYI setjmp on generic MSVCRT");
24332436
}
2434-
Address buf = emitPointerWithAlignment(E->getArg(0));
2435-
mlir::Location loc = getLoc(E->getExprLoc());
2436-
cir::PointerType ppTy = builder.getPointerTo(builder.getVoidPtrTy());
2437-
mlir::Value castBuf = builder.createBitcast(buf.getPointer(), ppTy);
2438-
cir::EhSetjmp op =
2439-
cir::EhSetjmp::create(builder, loc, castBuf, /*builtin = */ false);
2440-
return RValue::get(op);
2437+
break;
24412438
}
24422439

24432440
// C++ std:: builtins.

clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4287,28 +4287,6 @@ mlir::LogicalResult CIRToLLVMEhTypeIdOpLowering::matchAndRewrite(
42874287
return mlir::success();
42884288
}
42894289

4290-
mlir::LogicalResult CIRToLLVMEhSetjmpOpLowering::matchAndRewrite(
4291-
cir::EhSetjmp op, OpAdaptor adaptor,
4292-
mlir::ConversionPatternRewriter &rewriter) const {
4293-
mlir::Type returnType = typeConverter->convertType(op.getType());
4294-
if (op.getIsBuiltin()) {
4295-
mlir::LLVM::CallIntrinsicOp newOp =
4296-
createCallLLVMIntrinsicOp(rewriter, op.getLoc(), "llvm.eh.sjlj.setjmp",
4297-
returnType, adaptor.getEnv());
4298-
rewriter.replaceOp(op, newOp);
4299-
return mlir::success();
4300-
}
4301-
4302-
StringRef fnName = "_setjmp";
4303-
auto llvmPtrTy = mlir::LLVM::LLVMPointerType::get(rewriter.getContext());
4304-
auto fnType = mlir::LLVM::LLVMFunctionType::get(returnType, llvmPtrTy,
4305-
/*isVarArg=*/false);
4306-
getOrCreateLLVMFuncOp(rewriter, op, fnName, fnType);
4307-
rewriter.replaceOpWithNewOp<mlir::LLVM::CallOp>(op, returnType, fnName,
4308-
adaptor.getEnv());
4309-
return mlir::success();
4310-
}
4311-
43124290
mlir::LogicalResult CIRToLLVMCatchParamOpLowering::matchAndRewrite(
43134291
cir::CatchParamOp op, OpAdaptor adaptor,
43144292
mlir::ConversionPatternRewriter &rewriter) const {
@@ -4552,7 +4530,6 @@ void populateCIRToLLVMConversionPatterns(
45524530
CIRToLLVMDerivedClassAddrOpLowering,
45534531
CIRToLLVMEhInflightOpLowering,
45544532
CIRToLLVMEhTypeIdOpLowering,
4555-
CIRToLLVMEhSetjmpOpLowering,
45564533
CIRToLLVMExpectOpLowering,
45574534
CIRToLLVMExtractMemberOpLowering,
45584535
CIRToLLVMFrameAddrOpLowering,

clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,16 +1220,6 @@ class CIRToLLVMEhTypeIdOpLowering
12201220
mlir::ConversionPatternRewriter &) const override;
12211221
};
12221222

1223-
class CIRToLLVMEhSetjmpOpLowering
1224-
: public mlir::OpConversionPattern<cir::EhSetjmp> {
1225-
public:
1226-
using mlir::OpConversionPattern<cir::EhSetjmp>::OpConversionPattern;
1227-
1228-
mlir::LogicalResult
1229-
matchAndRewrite(cir::EhSetjmp op, OpAdaptor,
1230-
mlir::ConversionPatternRewriter &) const override;
1231-
};
1232-
12331223
class CIRToLLVMCatchParamOpLowering
12341224
: public mlir::OpConversionPattern<cir::CatchParamOp> {
12351225
public:

clang/test/CIR/CodeGen/builtin-setjmp-longjmp.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// RUN: %clang_cc1 -triple x86_64-unknown-linux -O2 -emit-llvm %s -o %t.ll
66
// RUN: FileCheck --input-file=%t.ll %s -check-prefix=OGCG
77
void test_setjmp(void *env) {
8+
89
// CIR-LABEL: test_setjmp
910
// CIR-SAME: [[ENV:%.*]]:
1011
// CIR-NEXT: [[ENV_ALLOCA:%[0-9]+]] = cir.alloca !cir.ptr<!void>, !cir.ptr<!cir.ptr<!void>>,
@@ -18,7 +19,7 @@ void test_setjmp(void *env) {
1819
// CIR-NEXT: [[TWO:%[0-9]+]] = cir.const #cir.int<2>
1920
// CIR-NEXT: [[GEP:%[0-9]+]] = cir.ptr_stride [[CAST]], [[TWO]] : (!cir.ptr<!cir.ptr<!void>>, !s32i) -> !cir.ptr<!cir.ptr<!void>>
2021
// CIR-NEXT: cir.store [[SS]], [[GEP]] : !cir.ptr<!void>, !cir.ptr<!cir.ptr<!void>>
21-
// CIR-NEXT: [[SJ:%[0-9]+]] = cir.eh.setjmp builtin [[CAST]] : (!cir.ptr<!cir.ptr<!void>>) -> !s32i
22+
// CIR-NEXT: [[SJ:%[0-9]+]] = cir.llvm.intrinsic "eh.sjlj.setjmp" [[CAST]]
2223

2324

2425
// LLVM-LABEL: test_setjmp
@@ -43,14 +44,14 @@ void test_setjmp(void *env) {
4344

4445
extern int _setjmp(void *env);
4546
void test_setjmp2(void *env) {
47+
4648
// CIR-LABEL: test_setjmp2
47-
// CIR-SAME: [[ENV:%.*]]:
48-
// CIR-NEXT: [[ENV_ALLOCA]] = cir.alloca
49+
// CIR-SAME: [[ENV:%.*]]: !cir.ptr<!void>
50+
// CIR-NEXT: [[ENV_ALLOCA:%.*]] = cir.alloca
4951
// CIR-NEXT: cir.store [[ENV]], [[ENV_ALLOCA]]
52+
// CIR-NEXT: [[DEAD_GET_GLOBAL:%.*]] = cir.get_global @_setjmp
5053
// CIR-NEXT: [[ENV_LOAD:%.*]] = cir.load align(8) [[ENV_ALLOCA]]
51-
// CIR-NEXT: [[CAST:%.*]] = cir.cast(bitcast, [[ENV_LOAD]]
52-
// CIR-NEXT: cir.eh.setjmp [[CAST]] : (!cir.ptr<!cir.ptr<!void>>) -> !s32i
53-
54+
// CIR-NEXT: cir.call @_setjmp([[ENV_LOAD]])
5455

5556
// LLVM-LABEL: test_setjmp2
5657
// LLVM-SAME: (ptr{{.*}}[[ENV:%.*]])

clang/test/CIR/Lowering/setjmp-longjmp.cir

Lines changed: 0 additions & 28 deletions
This file was deleted.

clang/test/CIR/Transforms/setjmp-longjmp-lower.c

Lines changed: 0 additions & 54 deletions
This file was deleted.

0 commit comments

Comments
 (0)