Skip to content

Commit 8762ba4

Browse files
authored
Merge branch 'main' into support-x86-builtin-rotate
2 parents e556764 + ebf5d9e commit 8762ba4

File tree

48 files changed

+1671
-2146
lines changed

Some content is hidden

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

48 files changed

+1671
-2146
lines changed

clang/cmake/caches/Fuchsia-stage2.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ set(CMAKE_CXX_VISIBILITY_PRESET default CACHE STRING "")
5858

5959
set(CMAKE_BUILD_TYPE Release CACHE STRING "")
6060
if (APPLE)
61-
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.13" CACHE STRING "")
61+
set(CMAKE_OSX_DEPLOYMENT_TARGET "11.0" CACHE STRING "")
6262
elseif(WIN32)
6363
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded" CACHE STRING "")
6464
endif()
@@ -83,7 +83,7 @@ if(APPLE)
8383
set(LIBCXX_ENABLE_STATIC_ABI_LIBRARY ON CACHE BOOL "")
8484
set(LIBCXX_HARDENING_MODE "none" CACHE STRING "")
8585
set(LIBCXX_USE_COMPILER_RT ON CACHE BOOL "")
86-
set(RUNTIMES_CMAKE_ARGS "-DCMAKE_OSX_DEPLOYMENT_TARGET=10.13;-DCMAKE_OSX_ARCHITECTURES=arm64|x86_64" CACHE STRING "")
86+
set(RUNTIMES_CMAKE_ARGS "-DCMAKE_OSX_DEPLOYMENT_TARGET=11.0;-DCMAKE_OSX_ARCHITECTURES=arm64|x86_64" CACHE STRING "")
8787
endif()
8888

8989
if(WIN32 OR LLVM_WINSYSROOT)

clang/cmake/caches/Fuchsia.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ set(LLVM_ENABLE_ASSERTIONS ON CACHE BOOL "")
9797
set(LLVM_ENABLE_BACKTRACES ON CACHE BOOL "")
9898
set(CMAKE_BUILD_TYPE Release CACHE STRING "")
9999
if(APPLE)
100-
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.13" CACHE STRING "")
100+
set(CMAKE_OSX_DEPLOYMENT_TARGET "11.0" CACHE STRING "")
101101
elseif(WIN32)
102102
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded" CACHE STRING "")
103103
endif()
@@ -140,7 +140,7 @@ else()
140140
set(SANITIZER_TEST_CXX "libc++" CACHE STRING "")
141141
set(SANITIZER_TEST_CXX_INTREE ON CACHE BOOL "")
142142
set(LLVM_ENABLE_RUNTIMES "compiler-rt;libcxx;libcxxabi;libunwind" CACHE STRING "")
143-
set(RUNTIMES_CMAKE_ARGS "-DCMAKE_OSX_DEPLOYMENT_TARGET=10.13;-DCMAKE_OSX_ARCHITECTURES=arm64|x86_64" CACHE STRING "")
143+
set(RUNTIMES_CMAKE_ARGS "-DCMAKE_OSX_DEPLOYMENT_TARGET=11.0;-DCMAKE_OSX_ARCHITECTURES=arm64|x86_64" CACHE STRING "")
144144
endif()
145145

146146
if(BOOTSTRAP_CMAKE_SYSTEM_NAME)

clang/include/clang/CIR/MissingFeatures.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ struct MissingFeatures {
151151

152152
// Coroutines
153153
static bool coroEndBuiltinCall() { return false; }
154-
static bool coroutineFrame() { return false; }
155154
static bool emitBodyAndFallthrough() { return false; }
156155
static bool coroOutsideFrameMD() { return false; }
157156

clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -502,9 +502,7 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl &gd, unsigned builtinID,
502502
return getUndefRValue(e->getType());
503503

504504
case Builtin::BI__builtin_coro_frame: {
505-
cgm.errorNYI(e->getSourceRange(), "BI__builtin_coro_frame NYI");
506-
assert(!cir::MissingFeatures::coroutineFrame());
507-
return getUndefRValue(e->getType());
505+
return emitCoroutineFrame();
508506
}
509507
case Builtin::BI__builtin_coro_free:
510508
case Builtin::BI__builtin_coro_size: {

clang/lib/CIR/CodeGen/CIRGenCXXABI.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,9 @@ class CIRGenCXXABI {
192192
QualType elementType,
193193
const CXXDestructorDecl *dtor) = 0;
194194

195+
virtual size_t getSrcArgforCopyCtor(const CXXConstructorDecl *,
196+
FunctionArgList &args) const = 0;
197+
195198
/// Checks if ABI requires extra virtual offset for vtable field.
196199
virtual bool
197200
isVirtualOffsetNeededForVTableField(CIRGenFunction &cgf,

clang/lib/CIR/CodeGen/CIRGenClass.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,24 @@ static void emitMemberInitializer(CIRGenFunction &cgf,
111111
// NOTE(cir): CodeGen allows record types to be memcpy'd if applicable,
112112
// whereas ClangIR wants to represent all object construction explicitly.
113113
if (!baseElementTy->isRecordType()) {
114-
cgf.cgm.errorNYI(memberInit->getSourceRange(),
115-
"emitMemberInitializer: array of non-record type");
114+
unsigned srcArgIndex =
115+
cgf.cgm.getCXXABI().getSrcArgforCopyCtor(constructor, args);
116+
cir::LoadOp srcPtr = cgf.getBuilder().createLoad(
117+
cgf.getLoc(memberInit->getSourceLocation()),
118+
cgf.getAddrOfLocalVar(args[srcArgIndex]));
119+
LValue thisRhslv = cgf.makeNaturalAlignAddrLValue(srcPtr, recordTy);
120+
LValue src = cgf.emitLValueForFieldInitialization(thisRhslv, field,
121+
field->getName());
122+
123+
// Copy the aggregate.
124+
cgf.emitAggregateCopy(lhs, src, fieldType,
125+
cgf.getOverlapForFieldInit(field),
126+
lhs.isVolatileQualified());
127+
// Ensure that we destroy the objects if an exception is thrown later in
128+
// the constructor.
129+
QualType::DestructionKind dtorKind = fieldType.isDestructedType();
130+
assert(!cgf.needsEHCleanup(dtorKind) &&
131+
"Arrays of non-record types shouldn't need EH cleanup");
116132
return;
117133
}
118134
}

clang/lib/CIR/CodeGen/CIRGenCoroutine.cpp

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,15 @@ struct ParamReferenceReplacerRAII {
9797
}
9898
};
9999
} // namespace
100+
101+
RValue CIRGenFunction::emitCoroutineFrame() {
102+
if (curCoro.data && curCoro.data->coroBegin) {
103+
return RValue::get(curCoro.data->coroBegin);
104+
}
105+
cgm.errorNYI("NYI");
106+
return RValue();
107+
}
108+
100109
static void createCoroData(CIRGenFunction &cgf,
101110
CIRGenFunction::CGCoroInfo &curCoro,
102111
cir::CallOp coroId) {
@@ -302,11 +311,24 @@ emitSuspendExpression(CIRGenFunction &cgf, CGCoroData &coro,
302311
builder, cgf.getLoc(s.getSourceRange()), kind,
303312
/*readyBuilder=*/
304313
[&](mlir::OpBuilder &b, mlir::Location loc) {
305-
builder.createCondition(
306-
cgf.createDummyValue(loc, cgf.getContext().BoolTy));
314+
Expr *condExpr = s.getReadyExpr()->IgnoreParens();
315+
builder.createCondition(cgf.evaluateExprAsBool(condExpr));
307316
},
308317
/*suspendBuilder=*/
309318
[&](mlir::OpBuilder &b, mlir::Location loc) {
319+
// Note that differently from LLVM codegen we do not emit coro.save
320+
// and coro.suspend here, that should be done as part of lowering this
321+
// to LLVM dialect (or some other MLIR dialect)
322+
323+
// A invalid suspendRet indicates "void returning await_suspend"
324+
mlir::Value suspendRet = cgf.emitScalarExpr(s.getSuspendExpr());
325+
326+
// Veto suspension if requested by bool returning await_suspend.
327+
if (suspendRet) {
328+
cgf.cgm.errorNYI("Veto await_suspend");
329+
}
330+
331+
// Signals the parent that execution flows to next region.
310332
cir::YieldOp::create(builder, loc);
311333
},
312334
/*resumeBuilder=*/

clang/lib/CIR/CodeGen/CIRGenFunction.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,6 +1418,7 @@ class CIRGenFunction : public CIRGenTypeCache {
14181418
cir::CallOp emitCoroAllocBuiltinCall(mlir::Location loc);
14191419
cir::CallOp emitCoroBeginBuiltinCall(mlir::Location loc,
14201420
mlir::Value coroframeAddr);
1421+
RValue emitCoroutineFrame();
14211422

14221423
void emitDestroy(Address addr, QualType type, Destroyer *destroyer);
14231424

clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,12 @@ class CIRGenItaniumCXXABI : public CIRGenCXXABI {
123123
return true;
124124
}
125125

126+
size_t getSrcArgforCopyCtor(const CXXConstructorDecl *,
127+
FunctionArgList &args) const override {
128+
assert(!args.empty() && "expected the arglist to not be empty!");
129+
return args.size() - 1;
130+
}
131+
126132
void emitBadCastCall(CIRGenFunction &cgf, mlir::Location loc) override;
127133

128134
mlir::Value

clang/lib/CodeGen/CGExpr.cpp

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2801,26 +2801,56 @@ void CodeGenFunction::EmitStoreThroughExtVectorComponentLValue(RValue Src,
28012801
LValue Dst) {
28022802
llvm::Value *SrcVal = Src.getScalarVal();
28032803
Address DstAddr = Dst.getExtVectorAddress();
2804+
const llvm::Constant *Elts = Dst.getExtVectorElts();
28042805
if (DstAddr.getElementType()->getScalarSizeInBits() >
28052806
SrcVal->getType()->getScalarSizeInBits())
28062807
SrcVal = Builder.CreateZExt(
28072808
SrcVal, convertTypeForLoadStore(Dst.getType(), SrcVal->getType()));
28082809

2809-
// HLSL allows storing to scalar values through ExtVector component LValues.
2810-
// To support this we need to handle the case where the destination address is
2811-
// a scalar.
2812-
if (!DstAddr.getElementType()->isVectorTy()) {
2813-
assert(!Dst.getType()->isVectorType() &&
2814-
"this should only occur for non-vector l-values");
2815-
Builder.CreateStore(SrcVal, DstAddr, Dst.isVolatileQualified());
2810+
if (getLangOpts().HLSL) {
2811+
llvm::Type *DestAddrTy = DstAddr.getElementType();
2812+
// HLSL allows storing to scalar values through ExtVector component LValues.
2813+
// To support this we need to handle the case where the destination address
2814+
// is a scalar.
2815+
if (!DestAddrTy->isVectorTy()) {
2816+
assert(!Dst.getType()->isVectorType() &&
2817+
"this should only occur for non-vector l-values");
2818+
Builder.CreateStore(SrcVal, DstAddr, Dst.isVolatileQualified());
2819+
return;
2820+
}
2821+
2822+
// HLSL allows direct access to vector elements, so storing to individual
2823+
// elements of a vector through ExtVector is handled as separate store
2824+
// instructions.
2825+
// If we are updating multiple elements, Dst and Src are vectors; for
2826+
// a single element update they are scalars.
2827+
const VectorType *VTy = Dst.getType()->getAs<VectorType>();
2828+
unsigned NumSrcElts = VTy ? VTy->getNumElements() : 1;
2829+
CharUnits ElemAlign = CharUnits::fromQuantity(
2830+
CGM.getDataLayout().getPrefTypeAlign(DestAddrTy->getScalarType()));
2831+
llvm::Value *Zero = llvm::ConstantInt::get(Int32Ty, 0);
2832+
2833+
for (unsigned I = 0; I != NumSrcElts; ++I) {
2834+
llvm::Value *Val = VTy ? Builder.CreateExtractElement(
2835+
SrcVal, llvm::ConstantInt::get(Int32Ty, I))
2836+
: SrcVal;
2837+
unsigned FieldNo = getAccessedFieldNo(I, Elts);
2838+
Address DstElemAddr = Address::invalid();
2839+
if (FieldNo == 0)
2840+
DstElemAddr = DstAddr.withAlignment(ElemAlign);
2841+
else
2842+
DstElemAddr = Builder.CreateGEP(
2843+
DstAddr, {Zero, llvm::ConstantInt::get(Int32Ty, FieldNo)},
2844+
DestAddrTy, ElemAlign);
2845+
Builder.CreateStore(Val, DstElemAddr, Dst.isVolatileQualified());
2846+
}
28162847
return;
28172848
}
28182849

28192850
// This access turns into a read/modify/write of the vector. Load the input
28202851
// value now.
28212852
llvm::Value *Vec = Builder.CreateLoad(DstAddr, Dst.isVolatileQualified());
28222853
llvm::Type *VecTy = Vec->getType();
2823-
const llvm::Constant *Elts = Dst.getExtVectorElts();
28242854

28252855
if (const VectorType *VTy = Dst.getType()->getAs<VectorType>()) {
28262856
unsigned NumSrcElts = VTy->getNumElements();

0 commit comments

Comments
 (0)