Skip to content

Commit f55c26f

Browse files
committed
rebase
Created using spr 1.3.6
2 parents 14034c2 + 5ef787d commit f55c26f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+601
-345
lines changed

clang/docs/ClangOffloadPackager.rst

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

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

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3277,9 +3277,9 @@ def CIR_ComplexCreateOp : CIR_Op<"complex.create", [Pure, SameTypeOperands]> {
32773277
def CIR_ComplexRealOp : CIR_Op<"complex.real", [Pure]> {
32783278
let summary = "Extract the real part of a complex value";
32793279
let description = [{
3280-
`cir.complex.real` operation takes an operand of `!cir.complex`, `!cir.int`
3281-
or `!cir.float`. If the operand is `!cir.complex`, the real part of it will
3282-
be returned, otherwise the value returned unmodified.
3280+
`cir.complex.real` operation takes an operand of `!cir.complex`, `cir.int`,
3281+
`!cir.bool` or `!cir.float`. If the operand is `!cir.complex`, the real
3282+
part of it will be returned, otherwise the value returned unmodified.
32833283

32843284
Example:
32853285

@@ -3289,8 +3289,8 @@ def CIR_ComplexRealOp : CIR_Op<"complex.real", [Pure]> {
32893289
```
32903290
}];
32913291

3292-
let results = (outs CIR_AnyIntOrFloatType:$result);
3293-
let arguments = (ins CIR_AnyComplexOrIntOrFloatType:$operand);
3292+
let results = (outs CIR_AnyIntOrBoolOrFloatType:$result);
3293+
let arguments = (ins CIR_AnyComplexOrIntOrBoolOrFloatType:$operand);
32943294

32953295
let assemblyFormat = [{
32963296
$operand `:` qualified(type($operand)) `->` qualified(type($result))
@@ -3309,8 +3309,8 @@ def CIR_ComplexImagOp : CIR_Op<"complex.imag", [Pure]> {
33093309
let summary = "Extract the imaginary part of a complex value";
33103310
let description = [{
33113311
`cir.complex.imag` operation takes an operand of `!cir.complex`, `!cir.int`
3312-
or `!cir.float`. If the operand is `!cir.complex`, the imag part of it will
3313-
be returned, otherwise a zero value will be returned.
3312+
`!cir.bool` or `!cir.float`. If the operand is `!cir.complex`, the imag
3313+
part of it will be returned, otherwise a zero value will be returned.
33143314

33153315
Example:
33163316

@@ -3320,8 +3320,8 @@ def CIR_ComplexImagOp : CIR_Op<"complex.imag", [Pure]> {
33203320
```
33213321
}];
33223322

3323-
let results = (outs CIR_AnyIntOrFloatType:$result);
3324-
let arguments = (ins CIR_AnyComplexOrIntOrFloatType:$operand);
3323+
let results = (outs CIR_AnyIntOrBoolOrFloatType:$result);
3324+
let arguments = (ins CIR_AnyComplexOrIntOrBoolOrFloatType:$operand);
33253325

33263326
let assemblyFormat = [{
33273327
$operand `:` qualified(type($operand)) `->` qualified(type($result))
@@ -4168,6 +4168,40 @@ def CIR_ThrowOp : CIR_Op<"throw"> {
41684168
let hasVerifier = 1;
41694169
}
41704170

4171+
//===----------------------------------------------------------------------===//
4172+
// AllocExceptionOp
4173+
//===----------------------------------------------------------------------===//
4174+
4175+
def CIR_AllocExceptionOp : CIR_Op<"alloc.exception"> {
4176+
let summary = "Allocates an exception according to Itanium ABI";
4177+
let description = [{
4178+
Implements a slightly higher level __cxa_allocate_exception:
4179+
4180+
`void *__cxa_allocate_exception(size_t thrown_size);`
4181+
4182+
If the operation fails, the program terminates rather than throw.
4183+
4184+
Example:
4185+
4186+
```mlir
4187+
// if (b == 0) {
4188+
// ...
4189+
// throw "...";
4190+
cir.if %10 {
4191+
%11 = cir.alloc_exception 8 -> !cir.ptr<!void>
4192+
... // store exception content into %11
4193+
cir.throw %11 : !cir.ptr<!cir.ptr<!u8i>>, ...
4194+
```
4195+
}];
4196+
4197+
let arguments = (ins I64Attr:$size);
4198+
let results = (outs Res<CIR_PointerType, "", [MemAlloc<DefaultResource>]>:$addr);
4199+
4200+
let assemblyFormat = [{
4201+
$size `->` qualified(type($addr)) attr-dict
4202+
}];
4203+
}
4204+
41714205
//===----------------------------------------------------------------------===//
41724206
// Atomic operations
41734207
//===----------------------------------------------------------------------===//

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,16 +159,22 @@ def CIR_AnyIntOrFloatType : AnyTypeOf<[CIR_AnyFloatType, CIR_AnyIntType],
159159
let cppFunctionName = "isAnyIntegerOrFloatingPointType";
160160
}
161161

162+
def CIR_AnyIntOrBoolOrFloatType
163+
: AnyTypeOf<[CIR_AnyBoolType, CIR_AnyFloatType, CIR_AnyIntType],
164+
"integer, boolean or floating point type"> {
165+
let cppFunctionName = "isAnyIntegerOrBooleanOrFloatingPointType";
166+
}
167+
162168
//===----------------------------------------------------------------------===//
163169
// Complex Type predicates
164170
//===----------------------------------------------------------------------===//
165171

166172
def CIR_AnyComplexType : CIR_TypeBase<"::cir::ComplexType", "complex type">;
167173

168-
def CIR_AnyComplexOrIntOrFloatType : AnyTypeOf<[
169-
CIR_AnyComplexType, CIR_AnyFloatType, CIR_AnyIntType
170-
], "complex, integer or floating point type"> {
171-
let cppFunctionName = "isComplexOrIntegerOrFloatingPointType";
174+
def CIR_AnyComplexOrIntOrBoolOrFloatType
175+
: AnyTypeOf<[CIR_AnyComplexType, CIR_AnyIntOrBoolOrFloatType],
176+
"complex, integer or floating point type"> {
177+
let cppFunctionName = "isComplexOrIntegerOrBoolOrFloatingPointType";
172178
}
173179

174180
//===----------------------------------------------------------------------===//

clang/lib/CIR/CodeGen/CIRGenCXXABI.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ class CIRGenCXXABI {
113113
CIRGenFunction &cgf) = 0;
114114

115115
virtual void emitRethrow(CIRGenFunction &cgf, bool isNoReturn) = 0;
116+
virtual void emitThrow(CIRGenFunction &cgf, const CXXThrowExpr *e) = 0;
116117

117118
virtual mlir::Attribute getAddrOfRTTIDescriptor(mlir::Location loc,
118119
QualType ty) = 0;

clang/lib/CIR/CodeGen/CIRGenCleanup.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ class alignas(EHScopeStack::ScopeStackAlignment) EHCleanupScope
104104
bool isNormalCleanup() const { return cleanupBits.isNormalCleanup; }
105105

106106
bool isActive() const { return cleanupBits.isActive; }
107+
void setActive(bool isActive) { cleanupBits.isActive = isActive; }
107108

108109
size_t getCleanupSize() const { return cleanupBits.cleanupSize; }
109110
void *getCleanupBuffer() { return this + 1; }
@@ -138,5 +139,13 @@ inline EHScopeStack::iterator EHScopeStack::begin() const {
138139
return iterator(startOfData);
139140
}
140141

142+
inline EHScopeStack::iterator
143+
EHScopeStack::find(stable_iterator savePoint) const {
144+
assert(savePoint.isValid() && "finding invalid savepoint");
145+
assert(savePoint.size <= stable_begin().size &&
146+
"finding savepoint after pop");
147+
return iterator(endOfBuffer - savePoint.size);
148+
}
149+
141150
} // namespace clang::CIRGen
142151
#endif // CLANG_LIB_CIR_CODEGEN_CIRGENCLEANUP_H

clang/lib/CIR/CodeGen/CIRGenException.cpp

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,36 @@ void CIRGenFunction::emitCXXThrowExpr(const CXXThrowExpr *e) {
3131
if (throwType->isObjCObjectPointerType()) {
3232
cgm.errorNYI("emitCXXThrowExpr ObjCObjectPointerType");
3333
return;
34-
} else {
35-
cgm.errorNYI("emitCXXThrowExpr with subExpr");
36-
return;
3734
}
38-
} else {
39-
cgm.getCXXABI().emitRethrow(*this, /*isNoReturn=*/true);
35+
36+
cgm.getCXXABI().emitThrow(*this, e);
37+
return;
4038
}
39+
40+
cgm.getCXXABI().emitRethrow(*this, /*isNoReturn=*/true);
41+
}
42+
43+
void CIRGenFunction::emitAnyExprToExn(const Expr *e, Address addr) {
44+
// Make sure the exception object is cleaned up if there's an
45+
// exception during initialization.
46+
assert(!cir::MissingFeatures::ehCleanupScope());
47+
48+
// __cxa_allocate_exception returns a void*; we need to cast this
49+
// to the appropriate type for the object.
50+
mlir::Type ty = convertTypeForMem(e->getType());
51+
Address typedAddr = addr.withElementType(builder, ty);
52+
53+
// From LLVM's codegen:
54+
// FIXME: this isn't quite right! If there's a final unelided call
55+
// to a copy constructor, then according to [except.terminate]p1 we
56+
// must call std::terminate() if that constructor throws, because
57+
// technically that copy occurs after the exception expression is
58+
// evaluated but before the exception is caught. But the best way
59+
// to handle that is to teach EmitAggExpr to do the final copy
60+
// differently if it can't be elided.
61+
emitAnyExprToMem(e, typedAddr, e->getType().getQualifiers(),
62+
/*isInitializer=*/true);
63+
64+
// Deactivate the cleanup block.
65+
assert(!cir::MissingFeatures::ehCleanupScope());
4166
}

clang/lib/CIR/CodeGen/CIRGenFunction.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,6 +1090,8 @@ class CIRGenFunction : public CIRGenTypeCache {
10901090
/// even if no aggregate location is provided.
10911091
RValue emitAnyExprToTemp(const clang::Expr *e);
10921092

1093+
void emitAnyExprToExn(const Expr *e, Address addr);
1094+
10931095
void emitArrayDestroy(mlir::Value begin, mlir::Value numElements,
10941096
QualType elementType, CharUnits elementAlign,
10951097
Destroyer *destroyer);

0 commit comments

Comments
 (0)