Skip to content

Commit 3925431

Browse files
iclsrcjsji
authored andcommitted
Merge from 'main' to 'sycl-web' (8 commits)
CONFLICT (content): Merge conflict in llvm/test/CMakeLists.txt
2 parents 7320f9c + 0e14973 commit 3925431

File tree

24 files changed

+401
-109
lines changed

24 files changed

+401
-109
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/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

clang/lib/CodeGen/CGAtomic.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,7 @@ RValue CodeGenFunction::EmitAtomicExpr(AtomicExpr *E) {
881881
CharUnits MaxInlineWidth =
882882
getContext().toCharUnitsFromBits(MaxInlineWidthInBits);
883883
DiagnosticsEngine &Diags = CGM.getDiags();
884-
bool Misaligned = (Ptr.getAlignment() % TInfo.Width) != 0;
884+
bool Misaligned = !Ptr.getAlignment().isMultipleOf(TInfo.Width);
885885
bool Oversized = getContext().toBits(TInfo.Width) > MaxInlineWidthInBits;
886886
if (Misaligned) {
887887
Diags.Report(E->getBeginLoc(), diag::warn_atomic_op_misaligned)

0 commit comments

Comments
 (0)