Skip to content

Commit fa56c68

Browse files
authored
Merge branch 'main' into fix-mlir-tblgen
2 parents 0e28604 + b7908e3 commit fa56c68

File tree

67 files changed

+932
-502
lines changed

Some content is hidden

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

67 files changed

+932
-502
lines changed

.github/renovate.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
3+
"extends": [
4+
"config:recommended"
5+
],
6+
"includePaths": [".github/**"],
7+
"schedule": "* 0 * * 1",
8+
"minimumReleaseAge": "3 days",
9+
"assignees": ["boomanaiden154"],
10+
"ignorePaths": [".github/workflows/containers/**"],
11+
"groupName": "[Github] Update GHA Dependencies"
12+
}

clang/include/clang/CIR/MissingFeatures.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ struct MissingFeatures {
214214
static bool ehCleanupScopeRequiresEHCleanup() { return false; }
215215
static bool ehCleanupBranchFixups() { return false; }
216216
static bool ehstackBranches() { return false; }
217+
static bool emitBranchThroughCleanup() { return false; }
217218
static bool emitCheckedInBoundsGEP() { return false; }
218219
static bool emitCondLikelihoodViaExpectIntrinsic() { return false; }
219220
static bool emitLifetimeMarkers() { return false; }

clang/include/clang/Tooling/Refactoring/RefactoringOptionVisitor.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ namespace internal {
3737
template <typename T> struct HasHandle {
3838
private:
3939
template <typename ClassT>
40-
static auto check(ClassT *) -> typename std::is_same<
41-
decltype(std::declval<RefactoringOptionVisitor>().visit(
42-
std::declval<RefactoringOption>(),
43-
*std::declval<std::optional<T> *>())),
44-
void>::type;
40+
static auto check(ClassT *)
41+
-> std::is_same<decltype(std::declval<RefactoringOptionVisitor>().visit(
42+
std::declval<RefactoringOption>(),
43+
*std::declval<std::optional<T> *>())),
44+
void>;
4545

4646
template <typename> static std::false_type check(...);
4747

clang/lib/CIR/CodeGen/CIRGenCall.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ class ReturnValueSlot {
256256
ReturnValueSlot() = default;
257257
ReturnValueSlot(Address addr) : addr(addr) {}
258258

259+
bool isNull() const { return !addr.isValid(); }
259260
Address getValue() const { return addr; }
260261
};
261262

clang/lib/CIR/CodeGen/CIRGenClass.cpp

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,86 @@ void CIRGenFunction::emitImplicitAssignmentOperatorBody(FunctionArgList &args) {
778778
s->getStmtClassName());
779779
}
780780

781+
void CIRGenFunction::emitForwardingCallToLambda(
782+
const CXXMethodDecl *callOperator, CallArgList &callArgs) {
783+
// Get the address of the call operator.
784+
const CIRGenFunctionInfo &calleeFnInfo =
785+
cgm.getTypes().arrangeCXXMethodDeclaration(callOperator);
786+
cir::FuncOp calleePtr = cgm.getAddrOfFunction(
787+
GlobalDecl(callOperator), cgm.getTypes().getFunctionType(calleeFnInfo));
788+
789+
// Prepare the return slot.
790+
const FunctionProtoType *fpt =
791+
callOperator->getType()->castAs<FunctionProtoType>();
792+
QualType resultType = fpt->getReturnType();
793+
ReturnValueSlot returnSlot;
794+
795+
// We don't need to separately arrange the call arguments because
796+
// the call can't be variadic anyway --- it's impossible to forward
797+
// variadic arguments.
798+
799+
// Now emit our call.
800+
CIRGenCallee callee =
801+
CIRGenCallee::forDirect(calleePtr, GlobalDecl(callOperator));
802+
RValue rv = emitCall(calleeFnInfo, callee, returnSlot, callArgs);
803+
804+
// If necessary, copy the returned value into the slot.
805+
if (!resultType->isVoidType() && returnSlot.isNull()) {
806+
if (getLangOpts().ObjCAutoRefCount && resultType->isObjCRetainableType())
807+
cgm.errorNYI(callOperator->getSourceRange(),
808+
"emitForwardingCallToLambda: ObjCAutoRefCount");
809+
emitReturnOfRValue(*currSrcLoc, rv, resultType);
810+
} else {
811+
cgm.errorNYI(callOperator->getSourceRange(),
812+
"emitForwardingCallToLambda: return slot is not null");
813+
}
814+
}
815+
816+
void CIRGenFunction::emitLambdaDelegatingInvokeBody(const CXXMethodDecl *md) {
817+
const CXXRecordDecl *lambda = md->getParent();
818+
819+
// Start building arguments for forwarding call
820+
CallArgList callArgs;
821+
822+
QualType lambdaType = getContext().getCanonicalTagType(lambda);
823+
QualType thisType = getContext().getPointerType(lambdaType);
824+
Address thisPtr =
825+
createMemTemp(lambdaType, getLoc(md->getSourceRange()), "unused.capture");
826+
callArgs.add(RValue::get(thisPtr.getPointer()), thisType);
827+
828+
// Add the rest of the parameters.
829+
for (auto *param : md->parameters())
830+
emitDelegateCallArg(callArgs, param, param->getBeginLoc());
831+
832+
const CXXMethodDecl *callOp = lambda->getLambdaCallOperator();
833+
// For a generic lambda, find the corresponding call operator specialization
834+
// to which the call to the static-invoker shall be forwarded.
835+
if (lambda->isGenericLambda()) {
836+
assert(md->isFunctionTemplateSpecialization());
837+
const TemplateArgumentList *tal = md->getTemplateSpecializationArgs();
838+
FunctionTemplateDecl *callOpTemplate =
839+
callOp->getDescribedFunctionTemplate();
840+
void *InsertPos = nullptr;
841+
FunctionDecl *correspondingCallOpSpecialization =
842+
callOpTemplate->findSpecialization(tal->asArray(), InsertPos);
843+
assert(correspondingCallOpSpecialization);
844+
callOp = cast<CXXMethodDecl>(correspondingCallOpSpecialization);
845+
}
846+
emitForwardingCallToLambda(callOp, callArgs);
847+
}
848+
849+
void CIRGenFunction::emitLambdaStaticInvokeBody(const CXXMethodDecl *md) {
850+
if (md->isVariadic()) {
851+
// Codgen for LLVM doesn't emit code for this as well, it says:
852+
// FIXME: Making this work correctly is nasty because it requires either
853+
// cloning the body of the call operator or making the call operator
854+
// forward.
855+
cgm.errorNYI(md->getSourceRange(), "emitLambdaStaticInvokeBody: variadic");
856+
}
857+
858+
emitLambdaDelegatingInvokeBody(md);
859+
}
860+
781861
void CIRGenFunction::destroyCXXObject(CIRGenFunction &cgf, Address addr,
782862
QualType type) {
783863
const auto *record = type->castAsCXXRecordDecl();

clang/lib/CIR/CodeGen/CIRGenExprCXX.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,8 @@ static void storeAnyExprIntoOneUnit(CIRGenFunction &cgf, const Expr *init,
238238
cgf.makeAddrLValue(newPtr, allocType), false);
239239
return;
240240
case cir::TEK_Complex:
241-
cgf.cgm.errorNYI(init->getSourceRange(),
242-
"storeAnyExprIntoOneUnit: complex");
241+
cgf.emitComplexExprIntoLValue(init, cgf.makeAddrLValue(newPtr, allocType),
242+
/*isInit*/ true);
243243
return;
244244
case cir::TEK_Aggregate: {
245245
assert(!cir::MissingFeatures::aggValueSlotGC());

clang/lib/CIR/CodeGen/CIRGenFunction.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,10 @@ cir::FuncOp CIRGenFunction::generateCode(clang::GlobalDecl gd, cir::FuncOp fn,
577577
getCIRGenModule().errorNYI(bodyRange, "CUDA kernel");
578578
} else if (isa<CXXMethodDecl>(funcDecl) &&
579579
cast<CXXMethodDecl>(funcDecl)->isLambdaStaticInvoker()) {
580-
getCIRGenModule().errorNYI(bodyRange, "Lambda static invoker");
580+
// The lambda static invoker function is special, because it forwards or
581+
// clones the body of the function call operator (but is actually
582+
// static).
583+
emitLambdaStaticInvokeBody(cast<CXXMethodDecl>(funcDecl));
581584
} else if (funcDecl->isDefaulted() && isa<CXXMethodDecl>(funcDecl) &&
582585
(cast<CXXMethodDecl>(funcDecl)->isCopyAssignmentOperator() ||
583586
cast<CXXMethodDecl>(funcDecl)->isMoveAssignmentOperator())) {

clang/lib/CIR/CodeGen/CIRGenFunction.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,6 +1274,8 @@ class CIRGenFunction : public CIRGenTypeCache {
12741274

12751275
mlir::Value emitPromotedValue(mlir::Value result, QualType promotionType);
12761276

1277+
void emitReturnOfRValue(mlir::Location loc, RValue rv, QualType ty);
1278+
12771279
/// Emit the computation of the specified expression of scalar type.
12781280
mlir::Value emitScalarExpr(const clang::Expr *e);
12791281

@@ -1293,6 +1295,9 @@ class CIRGenFunction : public CIRGenTypeCache {
12931295

12941296
mlir::LogicalResult emitForStmt(const clang::ForStmt &s);
12951297

1298+
void emitForwardingCallToLambda(const CXXMethodDecl *lambdaCallOperator,
1299+
CallArgList &callArgs);
1300+
12961301
/// Emit the computation of the specified expression of complex type,
12971302
/// returning the result.
12981303
mlir::Value emitComplexExpr(const Expr *e);
@@ -1355,6 +1360,9 @@ class CIRGenFunction : public CIRGenTypeCache {
13551360
mlir::LogicalResult emitLabel(const clang::LabelDecl &d);
13561361
mlir::LogicalResult emitLabelStmt(const clang::LabelStmt &s);
13571362

1363+
void emitLambdaDelegatingInvokeBody(const CXXMethodDecl *md);
1364+
void emitLambdaStaticInvokeBody(const CXXMethodDecl *md);
1365+
13581366
mlir::LogicalResult emitIfStmt(const clang::IfStmt &s);
13591367

13601368
/// Emit code to compute the specified expression,

clang/lib/CIR/CodeGen/CIRGenStmt.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,8 +488,11 @@ mlir::LogicalResult CIRGenFunction::emitReturnStmt(const ReturnStmt &s) {
488488
auto *retBlock = curLexScope->getOrCreateRetBlock(*this, loc);
489489
// This should emit a branch through the cleanup block if one exists.
490490
builder.create<cir::BrOp>(loc, retBlock);
491+
assert(!cir::MissingFeatures::emitBranchThroughCleanup());
491492
if (ehStack.stable_begin() != currentCleanupStackDepth)
492493
cgm.errorNYI(s.getSourceRange(), "return with cleanup stack");
494+
495+
// Insert the new block to continue codegen after branch to ret block.
493496
builder.createBlock(builder.getBlock()->getParent());
494497

495498
return mlir::success();
@@ -1041,3 +1044,21 @@ mlir::LogicalResult CIRGenFunction::emitSwitchStmt(const clang::SwitchStmt &s) {
10411044

10421045
return res;
10431046
}
1047+
1048+
void CIRGenFunction::emitReturnOfRValue(mlir::Location loc, RValue rv,
1049+
QualType ty) {
1050+
if (rv.isScalar()) {
1051+
builder.createStore(loc, rv.getValue(), returnValue);
1052+
} else if (rv.isAggregate()) {
1053+
LValue dest = makeAddrLValue(returnValue, ty);
1054+
LValue src = makeAddrLValue(rv.getAggregateAddress(), ty);
1055+
emitAggregateCopy(dest, src, ty, getOverlapForReturnValue());
1056+
} else {
1057+
cgm.errorNYI(loc, "emitReturnOfRValue: complex return type");
1058+
}
1059+
mlir::Block *retBlock = curLexScope->getOrCreateRetBlock(*this, loc);
1060+
assert(!cir::MissingFeatures::emitBranchThroughCleanup());
1061+
builder.create<cir::BrOp>(loc, retBlock);
1062+
if (ehStack.stable_begin() != currentCleanupStackDepth)
1063+
cgm.errorNYI(loc, "return with cleanup stack");
1064+
}

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1941,8 +1941,14 @@ mlir::LogicalResult CIRToLLVMUnaryOpLowering::matchAndRewrite(
19411941
// Pointer unary operations: + only. (++ and -- of pointers are implemented
19421942
// with cir.ptr_stride, not cir.unary.)
19431943
if (mlir::isa<cir::PointerType>(elementType)) {
1944-
return op.emitError()
1945-
<< "Unary operation on pointer types is not yet implemented";
1944+
switch (op.getKind()) {
1945+
case cir::UnaryOpKind::Plus:
1946+
rewriter.replaceOp(op, adaptor.getInput());
1947+
return mlir::success();
1948+
default:
1949+
op.emitError() << "Unknown pointer unary operation during CIR lowering";
1950+
return mlir::failure();
1951+
}
19461952
}
19471953

19481954
return op.emitError() << "Unary operation has unsupported type: "

0 commit comments

Comments
 (0)