Skip to content

Commit 572b169

Browse files
authored
Merge branch 'main' into openmp-fix
2 parents ace1588 + 94b2617 commit 572b169

File tree

54 files changed

+806
-241
lines changed

Some content is hidden

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

54 files changed

+806
-241
lines changed

clang/include/clang/AST/CharUnits.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ namespace clang {
141141
/// Among other things, this promises that
142142
/// self.alignTo(N) will just return self.
143143
bool isMultipleOf(CharUnits N) const {
144-
return (*this % N) == 0;
144+
return (*this % N) == CharUnits::Zero();
145145
}
146146

147147
// Arithmetic operators.
@@ -165,8 +165,8 @@ namespace clang {
165165
CharUnits operator% (QuantityType N) const {
166166
return CharUnits(Quantity % N);
167167
}
168-
QuantityType operator% (const CharUnits &Other) const {
169-
return Quantity % Other.Quantity;
168+
CharUnits operator%(const CharUnits &Other) const {
169+
return CharUnits(Quantity % Other.Quantity);
170170
}
171171
CharUnits operator+ (const CharUnits &Other) const {
172172
return CharUnits(Quantity + Other.Quantity);

clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,10 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
148148
}
149149

150150
mlir::Value createComplexReal(mlir::Location loc, mlir::Value operand) {
151-
auto operandTy = mlir::cast<cir::ComplexType>(operand.getType());
152-
return cir::ComplexRealOp::create(*this, loc, operandTy.getElementType(),
153-
operand);
151+
auto resultType = operand.getType();
152+
if (auto complexResultType = mlir::dyn_cast<cir::ComplexType>(resultType))
153+
resultType = complexResultType.getElementType();
154+
return cir::ComplexRealOp::create(*this, loc, resultType, operand);
154155
}
155156

156157
mlir::Value createComplexImag(mlir::Location loc, mlir::Value operand) {

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3260,18 +3260,20 @@ def CIR_ComplexCreateOp : CIR_Op<"complex.create", [Pure, SameTypeOperands]> {
32603260
def CIR_ComplexRealOp : CIR_Op<"complex.real", [Pure]> {
32613261
let summary = "Extract the real part of a complex value";
32623262
let description = [{
3263-
`cir.complex.real` operation takes an operand of `!cir.complex` type and
3264-
yields the real part of it.
3263+
`cir.complex.real` operation takes an operand of `!cir.complex`, `!cir.int`
3264+
or `!cir.float`. If the operand is `!cir.complex`, the real part of it will
3265+
be returned, otherwise the value returned unmodified.
32653266

32663267
Example:
32673268

32683269
```mlir
3269-
%1 = cir.complex.real %0 : !cir.complex<!cir.float> -> !cir.float
3270+
%real = cir.complex.real %complex : !cir.complex<!cir.float> -> !cir.float
3271+
%real = cir.complex.real %scalar : !cir.float -> !cir.float
32703272
```
32713273
}];
32723274

32733275
let results = (outs CIR_AnyIntOrFloatType:$result);
3274-
let arguments = (ins CIR_ComplexType:$operand);
3276+
let arguments = (ins CIR_AnyComplexOrIntOrFloatType:$operand);
32753277

32763278
let assemblyFormat = [{
32773279
$operand `:` qualified(type($operand)) `->` qualified(type($result))

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,12 @@ def CIR_AnyIntOrFloatType : AnyTypeOf<[CIR_AnyFloatType, CIR_AnyIntType],
165165

166166
def CIR_AnyComplexType : CIR_TypeBase<"::cir::ComplexType", "complex type">;
167167

168+
def CIR_AnyComplexOrIntOrFloatType : AnyTypeOf<[
169+
CIR_AnyComplexType, CIR_AnyFloatType, CIR_AnyIntType
170+
], "complex, integer or floating point type"> {
171+
let cppFunctionName = "isComplexOrIntegerOrFloatingPointType";
172+
}
173+
168174
//===----------------------------------------------------------------------===//
169175
// Array Type predicates
170176
//===----------------------------------------------------------------------===//

clang/lib/AST/APValue.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@ void APValue::printPretty(raw_ostream &Out, const PrintingPolicy &Policy,
784784
if (!O.isZero()) {
785785
if (IsReference)
786786
Out << "*(";
787-
if (S.isZero() || O % S) {
787+
if (S.isZero() || !O.isMultipleOf(S)) {
788788
Out << "(char*)";
789789
S = CharUnits::One();
790790
}

clang/lib/AST/RecordLayoutBuilder.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2087,9 +2087,8 @@ void ItaniumRecordLayoutBuilder::LayoutField(const FieldDecl *D,
20872087
if (InsertExtraPadding) {
20882088
CharUnits ASanAlignment = CharUnits::fromQuantity(8);
20892089
CharUnits ExtraSizeForAsan = ASanAlignment;
2090-
if (FieldSize % ASanAlignment)
2091-
ExtraSizeForAsan +=
2092-
ASanAlignment - CharUnits::fromQuantity(FieldSize % ASanAlignment);
2090+
if (!FieldSize.isMultipleOf(ASanAlignment))
2091+
ExtraSizeForAsan += ASanAlignment - (FieldSize % ASanAlignment);
20932092
EffectiveFieldSize = FieldSize = FieldSize + ExtraSizeForAsan;
20942093
}
20952094

@@ -2119,10 +2118,10 @@ void ItaniumRecordLayoutBuilder::LayoutField(const FieldDecl *D,
21192118
if (RD->hasAttr<PackedAttr>() || !MaxFieldAlignment.isZero())
21202119
if (FieldAlign < OriginalFieldAlign)
21212120
if (D->getType()->isRecordType()) {
2122-
// If the offset is a multiple of the alignment of
2121+
// If the offset is not a multiple of the alignment of
21232122
// the type, raise the warning.
21242123
// TODO: Takes no account the alignment of the outer struct
2125-
if (FieldOffset % OriginalFieldAlign != 0)
2124+
if (!FieldOffset.isMultipleOf(OriginalFieldAlign))
21262125
Diag(D->getLocation(), diag::warn_unaligned_access)
21272126
<< Context.getCanonicalTagType(RD) << D->getName()
21282127
<< D->getType();

clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2151,8 +2151,10 @@ mlir::Value ScalarExprEmitter::VisitRealImag(const UnaryOperator *e,
21512151
}
21522152

21532153
if (e->getOpcode() == UO_Real) {
2154-
return promotionTy.isNull() ? Visit(op)
2155-
: cgf.emitPromotedScalarExpr(op, promotionTy);
2154+
mlir::Value operand = promotionTy.isNull()
2155+
? Visit(op)
2156+
: cgf.emitPromotedScalarExpr(op, promotionTy);
2157+
return builder.createComplexReal(loc, operand);
21562158
}
21572159

21582160
// __imag on a scalar returns zero. Emit the subexpr to ensure side

clang/lib/CIR/CodeGen/CIRGenRecordLayoutBuilder.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -615,20 +615,20 @@ void CIRRecordLowering::determinePacked(bool nvBaseType) {
615615
continue;
616616
// If any member falls at an offset that it not a multiple of its alignment,
617617
// then the entire record must be packed.
618-
if (member.offset % getAlignment(member.data))
618+
if (!member.offset.isMultipleOf(getAlignment(member.data)))
619619
packed = true;
620620
if (member.offset < nvSize)
621621
nvAlignment = std::max(nvAlignment, getAlignment(member.data));
622622
alignment = std::max(alignment, getAlignment(member.data));
623623
}
624624
// If the size of the record (the capstone's offset) is not a multiple of the
625625
// record's alignment, it must be packed.
626-
if (members.back().offset % alignment)
626+
if (!members.back().offset.isMultipleOf(alignment))
627627
packed = true;
628628
// If the non-virtual sub-object is not a multiple of the non-virtual
629629
// sub-object's alignment, it must be packed. We cannot have a packed
630630
// non-virtual sub-object and an unpacked complete object or vise versa.
631-
if (nvSize % nvAlignment)
631+
if (!nvSize.isMultipleOf(nvAlignment))
632632
packed = true;
633633
// Update the alignment of the sentinel.
634634
if (!packed)
@@ -824,7 +824,7 @@ void CIRRecordLowering::lowerUnion() {
824824
appendPaddingBytes(layoutSize - getSize(storageType));
825825

826826
// Set packed if we need it.
827-
if (layoutSize % getAlignment(storageType))
827+
if (!layoutSize.isMultipleOf(getAlignment(storageType)))
828828
packed = true;
829829
}
830830

clang/lib/CIR/Dialect/IR/CIRDialect.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2388,14 +2388,23 @@ OpFoldResult cir::ComplexCreateOp::fold(FoldAdaptor adaptor) {
23882388
//===----------------------------------------------------------------------===//
23892389

23902390
LogicalResult cir::ComplexRealOp::verify() {
2391-
if (getType() != getOperand().getType().getElementType()) {
2391+
mlir::Type operandTy = getOperand().getType();
2392+
if (auto complexOperandTy = mlir::dyn_cast<cir::ComplexType>(operandTy)) {
2393+
operandTy = complexOperandTy.getElementType();
2394+
}
2395+
2396+
if (getType() != operandTy) {
23922397
emitOpError() << ": result type does not match operand type";
23932398
return failure();
23942399
}
2400+
23952401
return success();
23962402
}
23972403

23982404
OpFoldResult cir::ComplexRealOp::fold(FoldAdaptor adaptor) {
2405+
if (!mlir::isa<cir::ComplexType>(getOperand().getType()))
2406+
return nullptr;
2407+
23992408
if (auto complexCreateOp = getOperand().getDefiningOp<cir::ComplexCreateOp>())
24002409
return complexCreateOp.getOperand(0);
24012410

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2999,8 +2999,13 @@ mlir::LogicalResult CIRToLLVMComplexRealOpLowering::matchAndRewrite(
29992999
cir::ComplexRealOp op, OpAdaptor adaptor,
30003000
mlir::ConversionPatternRewriter &rewriter) const {
30013001
mlir::Type resultLLVMTy = getTypeConverter()->convertType(op.getType());
3002-
rewriter.replaceOpWithNewOp<mlir::LLVM::ExtractValueOp>(
3003-
op, resultLLVMTy, adaptor.getOperand(), llvm::ArrayRef<std::int64_t>{0});
3002+
mlir::Value operand = adaptor.getOperand();
3003+
if (mlir::isa<cir::ComplexType>(op.getOperand().getType())) {
3004+
operand = mlir::LLVM::ExtractValueOp::create(
3005+
rewriter, op.getLoc(), resultLLVMTy, operand,
3006+
llvm::ArrayRef<std::int64_t>{0});
3007+
}
3008+
rewriter.replaceOp(op, operand);
30043009
return mlir::success();
30053010
}
30063011

0 commit comments

Comments
 (0)