diff --git a/compiler-rt/test/profile/Inputs/instrprof-gcov-multithread_fork.cpp b/compiler-rt/test/profile/Inputs/instrprof-gcov-multithread_fork.cpp index 94db50fc826550..0f043caedf3edf 100644 --- a/compiler-rt/test/profile/Inputs/instrprof-gcov-multithread_fork.cpp +++ b/compiler-rt/test/profile/Inputs/instrprof-gcov-multithread_fork.cpp @@ -1,27 +1,17 @@ #include #include #include -#include template void launcher(T func) { - std::vector pool; + auto t1 = std::thread(func); + auto t2 = std::thread(func); - for (int i = 0; i < 10; i++) { - pool.emplace_back(std::thread(func)); - } - - for (auto &t : pool) { - t.join(); - } + t1.join(); + t2.join(); } -void h() {} - -void g() { - fork(); - launcher<>(h); -} +void g() {} void f() { fork(); diff --git a/lldb/test/Shell/SymbolFile/DWARF/module-ownership.mm b/lldb/test/Shell/SymbolFile/DWARF/module-ownership.mm index f675c3aa8204ff..72f2c8865f9710 100644 --- a/lldb/test/Shell/SymbolFile/DWARF/module-ownership.mm +++ b/lldb/test/Shell/SymbolFile/DWARF/module-ownership.mm @@ -1,6 +1,8 @@ // RUN: %clang --target=x86_64-apple-macosx -g -gmodules \ // RUN: -fmodules -fmodules-cache-path=%t.cache \ // RUN: -c -o %t.o %s -I%S/Inputs +// RUN: lldb-test symbols -dump-clang-ast %t.o | FileCheck --check-prefix CHECK-ANON-S1 %s +// RUN: lldb-test symbols -dump-clang-ast %t.o | FileCheck --check-prefix CHECK-ANON-S2 %s // RUN: lldb-test symbols -dump-clang-ast %t.o | FileCheck %s // Verify that the owning module information from DWARF is preserved in the AST. @@ -20,11 +22,11 @@ // CHECK-TOPLEVELSTRUCT: -FieldDecl {{.*}} in A a 'int' Struct s2; -// CHECK-DAG: CXXRecordDecl {{.*}} imported in A struct +// CHECK-ANON-S1: CXXRecordDecl {{.*}} imported in A struct StructB s3; -// CHECK-DAG: CXXRecordDecl {{.*}} imported in A.B struct -// CHECK-DAG: -FieldDecl {{.*}} in A.B b 'int' +// CHECK-ANON-S2: CXXRecordDecl {{.*}} imported in A.B struct +// CHECK-ANON-S2: -FieldDecl {{.*}} in A.B b 'int' Nested s4; // CHECK-DAG: CXXRecordDecl {{.*}} imported in A struct Nested diff --git a/llvm/include/llvm/Remarks/Remark.h b/llvm/include/llvm/Remarks/Remark.h index 6211db4a8e96ed..160e8dc8db706a 100644 --- a/llvm/include/llvm/Remarks/Remark.h +++ b/llvm/include/llvm/Remarks/Remark.h @@ -14,8 +14,8 @@ #define LLVM_REMARKS_REMARK_H #include "llvm-c/Remarks.h" -#include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/Optional.h" +#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/CBindingWrapping.h" #include diff --git a/llvm/include/llvm/Remarks/RemarkStringTable.h b/llvm/include/llvm/Remarks/RemarkStringTable.h index c40bb5fa0ecdb0..60cf601e05aa7e 100644 --- a/llvm/include/llvm/Remarks/RemarkStringTable.h +++ b/llvm/include/llvm/Remarks/RemarkStringTable.h @@ -17,18 +17,18 @@ #define LLVM_REMARKS_REMARK_STRING_TABLE_H #include "llvm/ADT/StringMap.h" -#include "llvm/ADT/StringRef.h" -#include "llvm/Remarks/Remark.h" #include "llvm/Support/Allocator.h" #include namespace llvm { class raw_ostream; +class StringRef; namespace remarks { struct ParsedStringTable; +struct Remark; /// The string table used for serializing remarks. /// This table can be for example serialized in a section to be consumed after diff --git a/llvm/include/llvm/Support/AArch64TargetParser.h b/llvm/include/llvm/Support/AArch64TargetParser.h index f8b0c2d4b244b3..a1d9543fcc5822 100644 --- a/llvm/include/llvm/Support/AArch64TargetParser.h +++ b/llvm/include/llvm/Support/AArch64TargetParser.h @@ -15,12 +15,14 @@ #define LLVM_SUPPORT_AARCH64TARGETPARSERCOMMON_H #include "llvm/ADT/StringRef.h" -#include "llvm/ADT/Triple.h" #include "llvm/Support/ARMTargetParser.h" #include // FIXME:This should be made into class design,to avoid dupplication. namespace llvm { + +class Triple; + namespace AArch64 { // Arch extension modifiers for CPUs. diff --git a/llvm/include/llvm/Support/ARMTargetParser.h b/llvm/include/llvm/Support/ARMTargetParser.h index a378f739315c3d..322e89e3d06362 100644 --- a/llvm/include/llvm/Support/ARMTargetParser.h +++ b/llvm/include/llvm/Support/ARMTargetParser.h @@ -15,11 +15,13 @@ #define LLVM_SUPPORT_ARMTARGETPARSER_H #include "llvm/ADT/StringRef.h" -#include "llvm/ADT/Triple.h" #include "llvm/Support/ARMBuildAttributes.h" #include namespace llvm { + +class Triple; + namespace ARM { // Arch extension modifiers for CPUs. diff --git a/llvm/lib/Remarks/Remark.cpp b/llvm/lib/Remarks/Remark.cpp index 401ac514b0117c..057d1a378599fe 100644 --- a/llvm/lib/Remarks/Remark.cpp +++ b/llvm/lib/Remarks/Remark.cpp @@ -11,8 +11,7 @@ //===----------------------------------------------------------------------===// #include "llvm/Remarks/Remark.h" -#include "llvm-c/Remarks.h" -#include "llvm/Support/CBindingWrapping.h" +#include "llvm/ADT/ArrayRef.h" #include "llvm/Support/raw_ostream.h" using namespace llvm; diff --git a/llvm/lib/Remarks/RemarkStringTable.cpp b/llvm/lib/Remarks/RemarkStringTable.cpp index 51156465be5131..5f462f01bb9a60 100644 --- a/llvm/lib/Remarks/RemarkStringTable.cpp +++ b/llvm/lib/Remarks/RemarkStringTable.cpp @@ -11,10 +11,10 @@ //===----------------------------------------------------------------------===// #include "llvm/Remarks/RemarkStringTable.h" +#include "llvm/ADT/StringRef.h" #include "llvm/Remarks/Remark.h" #include "llvm/Remarks/RemarkParser.h" -#include "llvm/Support/EndianStream.h" -#include "llvm/Support/Error.h" +#include "llvm/Support/raw_ostream.h" #include using namespace llvm; diff --git a/llvm/lib/Support/AArch64TargetParser.cpp b/llvm/lib/Support/AArch64TargetParser.cpp index cce2d820829622..a6de44605675a3 100644 --- a/llvm/lib/Support/AArch64TargetParser.cpp +++ b/llvm/lib/Support/AArch64TargetParser.cpp @@ -12,8 +12,8 @@ //===----------------------------------------------------------------------===// #include "llvm/Support/AArch64TargetParser.h" -#include "llvm/ADT/StringRef.h" #include "llvm/ADT/StringSwitch.h" +#include "llvm/ADT/Triple.h" #include using namespace llvm; diff --git a/llvm/lib/Support/ARMTargetParser.cpp b/llvm/lib/Support/ARMTargetParser.cpp index 2c581248e1838d..56a91f7dc78762 100644 --- a/llvm/lib/Support/ARMTargetParser.cpp +++ b/llvm/lib/Support/ARMTargetParser.cpp @@ -13,6 +13,7 @@ #include "llvm/Support/ARMTargetParser.h" #include "llvm/ADT/StringSwitch.h" +#include "llvm/ADT/Triple.h" #include using namespace llvm; diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp index cb83d7ef6cea64..00a395921d3bd2 100644 --- a/llvm/lib/Target/X86/X86ISelLowering.cpp +++ b/llvm/lib/Target/X86/X86ISelLowering.cpp @@ -35565,7 +35565,8 @@ static SDValue combineTargetShuffle(SDValue N, SelectionDAG &DAG, // broadcast(bitcast(src)) -> bitcast(broadcast(src)) // 32-bit targets have to bitcast i64 to f64, so better to bitcast upward. if (Src.getOpcode() == ISD::BITCAST && - SrcVT.getScalarSizeInBits() == BCVT.getScalarSizeInBits()) { + SrcVT.getScalarSizeInBits() == BCVT.getScalarSizeInBits() && + DAG.getTargetLoweringInfo().isTypeLegal(BCVT)) { EVT NewVT = EVT::getVectorVT(*DAG.getContext(), BCVT.getScalarType(), VT.getVectorNumElements()); return DAG.getBitcast(VT, DAG.getNode(X86ISD::VBROADCAST, DL, NewVT, BC)); diff --git a/llvm/test/CodeGen/X86/vector-shuffle-combining-avx2.ll b/llvm/test/CodeGen/X86/vector-shuffle-combining-avx2.ll index bbd5bcb29a9808..076fed814478ad 100644 --- a/llvm/test/CodeGen/X86/vector-shuffle-combining-avx2.ll +++ b/llvm/test/CodeGen/X86/vector-shuffle-combining-avx2.ll @@ -778,6 +778,32 @@ define <32 x i8> @constant_fold_pshufb_256() { ret <32 x i8> %1 } +define i32 @broadcast_v2i64_multiuse(i64* %p0) { +; X86-LABEL: broadcast_v2i64_multiuse: +; X86: # %bb.0: # %entry +; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx +; X86-NEXT: vmovsd {{.*#+}} xmm0 = mem[0],zero +; X86-NEXT: vmovddup {{.*#+}} xmm0 = xmm0[0,0] +; X86-NEXT: vextractps $2, %xmm0, %eax +; X86-NEXT: addl (%ecx), %eax +; X86-NEXT: retl +; +; X64-LABEL: broadcast_v2i64_multiuse: +; X64: # %bb.0: # %entry +; X64-NEXT: movl (%rdi), %eax +; X64-NEXT: addl %eax, %eax +; X64-NEXT: retq +entry: + %tmp = load i64, i64* %p0, align 8 + %tmp1 = trunc i64 %tmp to i32 + %tmp2 = insertelement <2 x i64> undef, i64 %tmp, i32 0 + %tmp3 = shufflevector <2 x i64> %tmp2, <2 x i64> undef, <2 x i32> zeroinitializer + %tmp4 = trunc <2 x i64> %tmp3 to <2 x i32> + %tmp5 = extractelement <2 x i32> %tmp4, i32 1 + %tmp6 = add i32 %tmp1, %tmp5 + ret i32 %tmp6 +} + define <32 x i8> @PR27320(<8 x i32> %a0) { ; CHECK-LABEL: PR27320: ; CHECK: # %bb.0: diff --git a/mlir/include/mlir/Dialect/StandardOps/IR/Ops.td b/mlir/include/mlir/Dialect/StandardOps/IR/Ops.td index 4e04df9b92158d..354ff6a89e7c8e 100644 --- a/mlir/include/mlir/Dialect/StandardOps/IR/Ops.td +++ b/mlir/include/mlir/Dialect/StandardOps/IR/Ops.td @@ -109,6 +109,7 @@ class ArithmeticOp traits = []> : // integer tensor. The custom assembly form of the operation is as follows // // i %0, %1 : i32 +// class IntArithmeticOp traits = []> : ArithmeticOp, Arguments<(ins SignlessIntegerLike:$lhs, SignlessIntegerLike:$rhs)>; @@ -121,10 +122,23 @@ class IntArithmeticOp traits = []> : // is as follows // // f %0, %1 : f32 +// class FloatArithmeticOp traits = []> : ArithmeticOp, Arguments<(ins FloatLike:$lhs, FloatLike:$rhs)>; +// Base class for standard arithmetic operations on complex numbers with a +// floating-point element type. +// These operations take two operands and return one result, all of which must +// be complex numbers of the same type. +// The assembly format is as follows +// +// cf %0, %1 : complex +// +class ComplexFloatArithmeticOp traits = []> : + ArithmeticOp, + Arguments<(ins Complex:$lhs, Complex:$rhs)>; + // Base class for memref allocating ops: alloca and alloc. // // %0 = alloclike(%m)[%s] : memref<8x?xf32, (d0, d1)[s0] -> ((d0 + s0), d1)> @@ -201,6 +215,26 @@ def AbsFOp : FloatUnaryOp<"absf"> { }]; } +//===----------------------------------------------------------------------===// +// AddCFOp +//===----------------------------------------------------------------------===// + +def AddCFOp : ComplexFloatArithmeticOp<"addcf"> { + let summary = "complex number addition"; + let description = [{ + The `addcf` operation takes two complex number operands and returns their + sum, a single complex number. + All operands and result must be of the same type, a complex number with a + floating-point element type. + + Example: + + ```mlir + %a = addcf %b, %c : complex + ``` + }]; +} + //===----------------------------------------------------------------------===// // AddFOp //===----------------------------------------------------------------------===// @@ -2407,6 +2441,26 @@ def StoreOp : Std_Op<"store", }]; } +//===----------------------------------------------------------------------===// +// SubCFOp +//===----------------------------------------------------------------------===// + +def SubCFOp : ComplexFloatArithmeticOp<"subcf"> { + let summary = "complex number subtraction"; + let description = [{ + The `subcf` operation takes two complex number operands and returns their + difference, a single complex number. + All operands and result must be of the same type, a complex number with a + floating-point element type. + + Example: + + ```mlir + %a = subcf %b, %c : complex + ``` + }]; +} + //===----------------------------------------------------------------------===// // SubFOp //===----------------------------------------------------------------------===// diff --git a/mlir/include/mlir/IR/OpBase.td b/mlir/include/mlir/IR/OpBase.td index 8ced1b0667a2c9..ca7b5c2607a677 100644 --- a/mlir/include/mlir/IR/OpBase.td +++ b/mlir/include/mlir/IR/OpBase.td @@ -719,7 +719,6 @@ def SignlessIntegerOrFloatLike : TypeConstraint, "signless-integer-like or floating-point-like">; - //===----------------------------------------------------------------------===// // Attribute definitions //===----------------------------------------------------------------------===// diff --git a/mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp b/mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp index 1a01daa1188ed9..e9fd083b198e87 100644 --- a/mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp +++ b/mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp @@ -443,12 +443,12 @@ Value ComplexStructBuilder::real(OpBuilder &builder, Location loc) { return extractPtr(builder, loc, kRealPosInComplexNumberStruct); } -void ComplexStructBuilder ::setImaginary(OpBuilder &builder, Location loc, - Value imaginary) { +void ComplexStructBuilder::setImaginary(OpBuilder &builder, Location loc, + Value imaginary) { setPtr(builder, loc, kImaginaryPosInComplexNumberStruct, imaginary); } -Value ComplexStructBuilder ::imaginary(OpBuilder &builder, Location loc) { +Value ComplexStructBuilder::imaginary(OpBuilder &builder, Location loc) { return extractPtr(builder, loc, kImaginaryPosInComplexNumberStruct); } @@ -1326,8 +1326,7 @@ using UnsignedShiftRightOpLowering = OneToOneConvertToLLVMPattern; using XOrOpLowering = VectorConvertToLLVMPattern; -// Lowerings for operations on complex numbers, `CreateComplexOp`, `ReOp`, and -// `ImOp`. +// Lowerings for operations on complex numbers. struct CreateComplexOpLowering : public ConvertOpToLLVMPattern { @@ -1385,6 +1384,82 @@ struct ImOpLowering : public ConvertOpToLLVMPattern { } }; +struct BinaryComplexOperands { + Value lhsReal, lhsImag, rhsReal, rhsImag; +}; + +template +BinaryComplexOperands +unpackBinaryComplexOperands(OpTy op, ArrayRef operands, + ConversionPatternRewriter &rewriter) { + auto bop = cast(op); + auto loc = bop.getLoc(); + OperandAdaptor transformed(operands); + + // Extract real and imaginary values from operands. + BinaryComplexOperands unpacked; + ComplexStructBuilder lhs(transformed.lhs()); + unpacked.lhsReal = lhs.real(rewriter, loc); + unpacked.lhsImag = lhs.imaginary(rewriter, loc); + ComplexStructBuilder rhs(transformed.rhs()); + unpacked.rhsReal = rhs.real(rewriter, loc); + unpacked.rhsImag = rhs.imaginary(rewriter, loc); + + return unpacked; +} + +struct AddCFOpLowering : public ConvertOpToLLVMPattern { + using ConvertOpToLLVMPattern::ConvertOpToLLVMPattern; + + LogicalResult + matchAndRewrite(Operation *operation, ArrayRef operands, + ConversionPatternRewriter &rewriter) const override { + auto op = cast(operation); + auto loc = op.getLoc(); + BinaryComplexOperands arg = + unpackBinaryComplexOperands(op, operands, rewriter); + + // Initialize complex number struct for result. + auto structType = this->typeConverter.convertType(op.getType()); + auto result = ComplexStructBuilder::undef(rewriter, loc, structType); + + // Emit IR to add complex numbers. + Value real = rewriter.create(loc, arg.lhsReal, arg.rhsReal); + Value imag = rewriter.create(loc, arg.lhsImag, arg.rhsImag); + result.setReal(rewriter, loc, real); + result.setImaginary(rewriter, loc, imag); + + rewriter.replaceOp(op, {result}); + return success(); + } +}; + +struct SubCFOpLowering : public ConvertOpToLLVMPattern { + using ConvertOpToLLVMPattern::ConvertOpToLLVMPattern; + + LogicalResult + matchAndRewrite(Operation *operation, ArrayRef operands, + ConversionPatternRewriter &rewriter) const override { + auto op = cast(operation); + auto loc = op.getLoc(); + BinaryComplexOperands arg = + unpackBinaryComplexOperands(op, operands, rewriter); + + // Initialize complex number struct for result. + auto structType = this->typeConverter.convertType(op.getType()); + auto result = ComplexStructBuilder::undef(rewriter, loc, structType); + + // Emit IR to substract complex numbers. + Value real = rewriter.create(loc, arg.lhsReal, arg.rhsReal); + Value imag = rewriter.create(loc, arg.lhsImag, arg.rhsImag); + result.setReal(rewriter, loc, real); + result.setImaginary(rewriter, loc, imag); + + rewriter.replaceOp(op, {result}); + return success(); + } +}; + // Check if the MemRefType `type` is supported by the lowering. We currently // only support memrefs with identity maps. static bool isSupportedMemRefType(MemRefType type) { @@ -2874,6 +2949,7 @@ void mlir::populateStdToLLVMNonMemoryConversionPatterns( // clang-format off patterns.insert< AbsFOpLowering, + AddCFOpLowering, AddFOpLowering, AddIOpLowering, AllocaOpLowering, @@ -2921,6 +2997,7 @@ void mlir::populateStdToLLVMNonMemoryConversionPatterns( SplatOpLowering, SplatNdOpLowering, SqrtOpLowering, + SubCFOpLowering, SubFOpLowering, SubIOpLowering, TruncateIOpLowering, diff --git a/mlir/test/Conversion/StandardToLLVM/convert-to-llvmir.mlir b/mlir/test/Conversion/StandardToLLVM/convert-to-llvmir.mlir index b7cb13e51ca2cd..cd16539edf02a0 100644 --- a/mlir/test/Conversion/StandardToLLVM/convert-to-llvmir.mlir +++ b/mlir/test/Conversion/StandardToLLVM/convert-to-llvmir.mlir @@ -83,6 +83,48 @@ func @complex_numbers() { return } +// CHECK-LABEL: llvm.func @complex_addition() +// CHECK-DAG: %[[A_REAL:.*]] = llvm.extractvalue %[[A:.*]][0] : !llvm<"{ double, double }"> +// CHECK-DAG: %[[B_REAL:.*]] = llvm.extractvalue %[[B:.*]][0] : !llvm<"{ double, double }"> +// CHECK-DAG: %[[A_IMAG:.*]] = llvm.extractvalue %[[A]][1] : !llvm<"{ double, double }"> +// CHECK-DAG: %[[B_IMAG:.*]] = llvm.extractvalue %[[B]][1] : !llvm<"{ double, double }"> +// CHECK: %[[C0:.*]] = llvm.mlir.undef : !llvm<"{ double, double }"> +// CHECK-DAG: %[[C_REAL:.*]] = llvm.fadd %[[A_REAL]], %[[B_REAL]] : !llvm.double +// CHECK-DAG: %[[C_IMAG:.*]] = llvm.fadd %[[A_IMAG]], %[[B_IMAG]] : !llvm.double +// CHECK: %[[C1:.*]] = llvm.insertvalue %[[C_REAL]], %[[C0]][0] : !llvm<"{ double, double }"> +// CHECK: %[[C2:.*]] = llvm.insertvalue %[[C_IMAG]], %[[C1]][1] : !llvm<"{ double, double }"> +func @complex_addition() { + %a_re = constant 1.2 : f64 + %a_im = constant 3.4 : f64 + %a = create_complex %a_re, %a_im : complex + %b_re = constant 5.6 : f64 + %b_im = constant 7.8 : f64 + %b = create_complex %b_re, %b_im : complex + %c = addcf %a, %b : complex + return +} + +// CHECK-LABEL: llvm.func @complex_substraction() +// CHECK-DAG: %[[A_REAL:.*]] = llvm.extractvalue %[[A:.*]][0] : !llvm<"{ double, double }"> +// CHECK-DAG: %[[B_REAL:.*]] = llvm.extractvalue %[[B:.*]][0] : !llvm<"{ double, double }"> +// CHECK-DAG: %[[A_IMAG:.*]] = llvm.extractvalue %[[A]][1] : !llvm<"{ double, double }"> +// CHECK-DAG: %[[B_IMAG:.*]] = llvm.extractvalue %[[B]][1] : !llvm<"{ double, double }"> +// CHECK: %[[C0:.*]] = llvm.mlir.undef : !llvm<"{ double, double }"> +// CHECK-DAG: %[[C_REAL:.*]] = llvm.fsub %[[A_REAL]], %[[B_REAL]] : !llvm.double +// CHECK-DAG: %[[C_IMAG:.*]] = llvm.fsub %[[A_IMAG]], %[[B_IMAG]] : !llvm.double +// CHECK: %[[C1:.*]] = llvm.insertvalue %[[C_REAL]], %[[C0]][0] : !llvm<"{ double, double }"> +// CHECK: %[[C2:.*]] = llvm.insertvalue %[[C_IMAG]], %[[C1]][1] : !llvm<"{ double, double }"> +func @complex_substraction() { + %a_re = constant 1.2 : f64 + %a_im = constant 3.4 : f64 + %a = create_complex %a_re, %a_im : complex + %b_re = constant 5.6 : f64 + %b_im = constant 7.8 : f64 + %b = create_complex %b_re, %b_im : complex + %c = subcf %a, %b : complex + return +} + // CHECK-LABEL: func @simple_caller() { // CHECK-NEXT: llvm.call @simple_loop() : () -> () // CHECK-NEXT: llvm.return