Skip to content

Commit 56c1a58

Browse files
authored
merge main into amd-staging (#575)
2 parents c3103eb + f4093c8 commit 56c1a58

File tree

229 files changed

+8952
-6280
lines changed

Some content is hidden

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

229 files changed

+8952
-6280
lines changed

.github/workflows/bazel-checks.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ jobs:
3333
3434
bazel-build:
3535
name: "Bazel Build/Test"
36-
runs-on: llvm-premerge-linux-runners
36+
# Only run on US Central workers so we only have to keep one cache warm as
37+
# the cache buckets are per cluster.
38+
runs-on:
39+
group: llvm-premerge-cluster-us-central
40+
labels: llvm-premerge-linux-runners
3741
if: github.repository == 'llvm/llvm-project'
3842
steps:
3943
- name: Fetch LLVM sources
@@ -44,7 +48,7 @@ jobs:
4448
- name: Setup System Dependencies
4549
run: |
4650
sudo apt-get update
47-
sudo apt-get install -y libmpfr-dev libpfm4-dev
51+
sudo apt-get install -y libmpfr-dev libpfm4-dev m4 libedit-dev
4852
sudo curl -L https://github.com/bazelbuild/bazelisk/releases/download/v1.27.0/bazelisk-amd64.deb > /tmp/bazelisk.deb
4953
sudo apt-get install -y /tmp/bazelisk.deb
5054
rm /tmp/bazelisk.deb
@@ -54,4 +58,4 @@ jobs:
5458
bazelisk test --config=ci --sandbox_base="" \
5559
--remote_cache=https://storage.googleapis.com/$CACHE_GCS_BUCKET-bazel \
5660
--google_default_credentials \
57-
@llvm-project//llvm/unittests:adt_tests
61+
@llvm-project//... //...

clang/include/clang/Analysis/Analyses/LifetimeSafety/FactsGenerator.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class FactsGenerator : public ConstStmtVisitor<FactsGenerator> {
4343
void VisitUnaryOperator(const UnaryOperator *UO);
4444
void VisitReturnStmt(const ReturnStmt *RS);
4545
void VisitBinaryOperator(const BinaryOperator *BO);
46+
void VisitConditionalOperator(const ConditionalOperator *CO);
4647
void VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *OCE);
4748
void VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *FCE);
4849
void VisitInitListExpr(const InitListExpr *ILE);

clang/include/clang/CIR/MissingFeatures.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ struct MissingFeatures {
153153
static bool coroEndBuiltinCall() { return false; }
154154
static bool coroutineFrame() { return false; }
155155
static bool emitBodyAndFallthrough() { return false; }
156+
static bool coroOutsideFrameMD() { return false; }
156157

157158
// Various handling of deferred processing in CIRGenModule.
158159
static bool cgmRelease() { return false; }
@@ -298,6 +299,7 @@ struct MissingFeatures {
298299
static bool opTBAA() { return false; }
299300
static bool peepholeProtection() { return false; }
300301
static bool pgoUse() { return false; }
302+
static bool pointerAuthentication() { return false; }
301303
static bool pointerOverflowSanitizer() { return false; }
302304
static bool preservedAccessIndexRegion() { return false; }
303305
static bool requiresCleanups() { return false; }

clang/lib/Analysis/LifetimeSafety/FactsGenerator.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,15 @@ void FactsGenerator::VisitBinaryOperator(const BinaryOperator *BO) {
176176
handleAssignment(BO->getLHS(), BO->getRHS());
177177
}
178178

179+
void FactsGenerator::VisitConditionalOperator(const ConditionalOperator *CO) {
180+
if (hasOrigin(CO)) {
181+
// Merge origins from both branches of the conditional operator.
182+
// We kill to clear the initial state and merge both origins into it.
183+
killAndFlowOrigin(*CO, *CO->getTrueExpr());
184+
flowOrigin(*CO, *CO->getFalseExpr());
185+
}
186+
}
187+
179188
void FactsGenerator::VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *OCE) {
180189
// Assignment operators have special "kill-then-propagate" semantics
181190
// and are handled separately.

clang/lib/CIR/CodeGen/CIRGenCoroutine.cpp

Lines changed: 102 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "CIRGenFunction.h"
1414
#include "mlir/Support/LLVM.h"
1515
#include "clang/AST/StmtCXX.h"
16+
#include "clang/AST/StmtVisitor.h"
1617
#include "clang/Basic/TargetInfo.h"
1718
#include "clang/CIR/Dialect/IR/CIRTypes.h"
1819
#include "clang/CIR/MissingFeatures.h"
@@ -33,6 +34,65 @@ struct clang::CIRGen::CGCoroData {
3334
CIRGenFunction::CGCoroInfo::CGCoroInfo() {}
3435
CIRGenFunction::CGCoroInfo::~CGCoroInfo() {}
3536

37+
namespace {
38+
// FIXME: both GetParamRef and ParamReferenceReplacerRAII are good template
39+
// candidates to be shared among LLVM / CIR codegen.
40+
41+
// Hunts for the parameter reference in the parameter copy/move declaration.
42+
struct GetParamRef : public StmtVisitor<GetParamRef> {
43+
public:
44+
DeclRefExpr *expr = nullptr;
45+
GetParamRef() {}
46+
void VisitDeclRefExpr(DeclRefExpr *e) {
47+
assert(expr == nullptr && "multilple declref in param move");
48+
expr = e;
49+
}
50+
void VisitStmt(Stmt *s) {
51+
for (Stmt *c : s->children()) {
52+
if (c)
53+
Visit(c);
54+
}
55+
}
56+
};
57+
58+
// This class replaces references to parameters to their copies by changing
59+
// the addresses in CGF.LocalDeclMap and restoring back the original values in
60+
// its destructor.
61+
struct ParamReferenceReplacerRAII {
62+
CIRGenFunction::DeclMapTy savedLocals;
63+
CIRGenFunction::DeclMapTy &localDeclMap;
64+
65+
ParamReferenceReplacerRAII(CIRGenFunction::DeclMapTy &localDeclMap)
66+
: localDeclMap(localDeclMap) {}
67+
68+
void addCopy(const DeclStmt *pm) {
69+
// Figure out what param it refers to.
70+
71+
assert(pm->isSingleDecl());
72+
const VarDecl *vd = static_cast<const VarDecl *>(pm->getSingleDecl());
73+
const Expr *initExpr = vd->getInit();
74+
GetParamRef visitor;
75+
visitor.Visit(const_cast<Expr *>(initExpr));
76+
assert(visitor.expr);
77+
DeclRefExpr *dreOrig = visitor.expr;
78+
auto *pd = dreOrig->getDecl();
79+
80+
auto it = localDeclMap.find(pd);
81+
assert(it != localDeclMap.end() && "parameter is not found");
82+
savedLocals.insert({pd, it->second});
83+
84+
auto copyIt = localDeclMap.find(vd);
85+
assert(copyIt != localDeclMap.end() && "parameter copy is not found");
86+
it->second = copyIt->getSecond();
87+
}
88+
89+
~ParamReferenceReplacerRAII() {
90+
for (auto &&savedLocal : savedLocals) {
91+
localDeclMap.insert({savedLocal.first, savedLocal.second});
92+
}
93+
}
94+
};
95+
} // namespace
3696
static void createCoroData(CIRGenFunction &cgf,
3797
CIRGenFunction::CGCoroInfo &curCoro,
3898
cir::CallOp coroId) {
@@ -149,7 +209,47 @@ CIRGenFunction::emitCoroutineBody(const CoroutineBodyStmt &s) {
149209
if (s.getReturnStmtOnAllocFailure())
150210
cgm.errorNYI("handle coroutine return alloc failure");
151211

152-
assert(!cir::MissingFeatures::generateDebugInfo());
153-
assert(!cir::MissingFeatures::emitBodyAndFallthrough());
212+
{
213+
assert(!cir::MissingFeatures::generateDebugInfo());
214+
ParamReferenceReplacerRAII paramReplacer(localDeclMap);
215+
// Create mapping between parameters and copy-params for coroutine
216+
// function.
217+
llvm::ArrayRef<const Stmt *> paramMoves = s.getParamMoves();
218+
assert((paramMoves.size() == 0 || (paramMoves.size() == fnArgs.size())) &&
219+
"ParamMoves and FnArgs should be the same size for coroutine "
220+
"function");
221+
// For zipping the arg map into debug info.
222+
assert(!cir::MissingFeatures::generateDebugInfo());
223+
224+
// Create parameter copies. We do it before creating a promise, since an
225+
// evolution of coroutine TS may allow promise constructor to observe
226+
// parameter copies.
227+
assert(!cir::MissingFeatures::coroOutsideFrameMD());
228+
for (auto *pm : paramMoves) {
229+
if (emitStmt(pm, /*useCurrentScope=*/true).failed())
230+
return mlir::failure();
231+
paramReplacer.addCopy(cast<DeclStmt>(pm));
232+
}
233+
234+
if (emitStmt(s.getPromiseDeclStmt(), /*useCurrentScope=*/true).failed())
235+
return mlir::failure();
236+
// returnValue should be valid as long as the coroutine's return type
237+
// is not void. The assertion could help us to reduce the check later.
238+
assert(returnValue.isValid() == (bool)s.getReturnStmt());
239+
// Now we have the promise, initialize the GRO.
240+
// We need to emit `get_return_object` first. According to:
241+
// [dcl.fct.def.coroutine]p7
242+
// The call to get_return_­object is sequenced before the call to
243+
// initial_suspend and is invoked at most once.
244+
//
245+
// So we couldn't emit return value when we emit return statment,
246+
// otherwise the call to get_return_object wouldn't be in front
247+
// of initial_suspend.
248+
if (returnValue.isValid())
249+
emitAnyExprToMem(s.getReturnValue(), returnValue,
250+
s.getReturnValue()->getType().getQualifiers(),
251+
/*isInit*/ true);
252+
assert(!cir::MissingFeatures::emitBodyAndFallthrough());
253+
}
154254
return mlir::success();
155255
}

clang/lib/CIR/CodeGen/CIRGenExpr.cpp

Lines changed: 0 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -2134,79 +2134,6 @@ RValue CIRGenFunction::emitCXXMemberCallExpr(const CXXMemberCallExpr *ce,
21342134
ce, md, returnValue, hasQualifier, qualifier, isArrow, base);
21352135
}
21362136

2137-
void CIRGenFunction::emitCXXConstructExpr(const CXXConstructExpr *e,
2138-
AggValueSlot dest) {
2139-
assert(!dest.isIgnored() && "Must have a destination!");
2140-
const CXXConstructorDecl *cd = e->getConstructor();
2141-
2142-
// If we require zero initialization before (or instead of) calling the
2143-
// constructor, as can be the case with a non-user-provided default
2144-
// constructor, emit the zero initialization now, unless destination is
2145-
// already zeroed.
2146-
if (e->requiresZeroInitialization() && !dest.isZeroed()) {
2147-
switch (e->getConstructionKind()) {
2148-
case CXXConstructionKind::Delegating:
2149-
case CXXConstructionKind::Complete:
2150-
emitNullInitialization(getLoc(e->getSourceRange()), dest.getAddress(),
2151-
e->getType());
2152-
break;
2153-
case CXXConstructionKind::VirtualBase:
2154-
case CXXConstructionKind::NonVirtualBase:
2155-
cgm.errorNYI(e->getSourceRange(),
2156-
"emitCXXConstructExpr: base requires initialization");
2157-
break;
2158-
}
2159-
}
2160-
2161-
// If this is a call to a trivial default constructor, do nothing.
2162-
if (cd->isTrivial() && cd->isDefaultConstructor())
2163-
return;
2164-
2165-
// Elide the constructor if we're constructing from a temporary
2166-
if (getLangOpts().ElideConstructors && e->isElidable()) {
2167-
// FIXME: This only handles the simplest case, where the source object is
2168-
// passed directly as the first argument to the constructor. This
2169-
// should also handle stepping through implicit casts and conversion
2170-
// sequences which involve two steps, with a conversion operator
2171-
// follwed by a converting constructor.
2172-
const Expr *srcObj = e->getArg(0);
2173-
assert(srcObj->isTemporaryObject(getContext(), cd->getParent()));
2174-
assert(
2175-
getContext().hasSameUnqualifiedType(e->getType(), srcObj->getType()));
2176-
emitAggExpr(srcObj, dest);
2177-
return;
2178-
}
2179-
2180-
if (const ArrayType *arrayType = getContext().getAsArrayType(e->getType())) {
2181-
assert(!cir::MissingFeatures::sanitizers());
2182-
emitCXXAggrConstructorCall(cd, arrayType, dest.getAddress(), e, false);
2183-
} else {
2184-
2185-
clang::CXXCtorType type = Ctor_Complete;
2186-
bool forVirtualBase = false;
2187-
bool delegating = false;
2188-
2189-
switch (e->getConstructionKind()) {
2190-
case CXXConstructionKind::Complete:
2191-
type = Ctor_Complete;
2192-
break;
2193-
case CXXConstructionKind::Delegating:
2194-
// We should be emitting a constructor; GlobalDecl will assert this
2195-
type = curGD.getCtorType();
2196-
delegating = true;
2197-
break;
2198-
case CXXConstructionKind::VirtualBase:
2199-
forVirtualBase = true;
2200-
[[fallthrough]];
2201-
case CXXConstructionKind::NonVirtualBase:
2202-
type = Ctor_Base;
2203-
break;
2204-
}
2205-
2206-
emitCXXConstructorCall(cd, type, forVirtualBase, delegating, dest, e);
2207-
}
2208-
}
2209-
22102137
RValue CIRGenFunction::emitReferenceBindingToExpr(const Expr *e) {
22112138
// Emit the expression as an lvalue.
22122139
LValue lv = emitLValue(e);

clang/lib/CIR/CodeGen/CIRGenExprAggregate.cpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -779,8 +779,8 @@ void AggExprEmitter::visitCXXParenListOrInitListExpr(
779779
Expr *e, ArrayRef<Expr *> args, FieldDecl *initializedFieldInUnion,
780780
Expr *arrayFiller) {
781781

782-
const AggValueSlot dest =
783-
ensureSlot(cgf.getLoc(e->getSourceRange()), e->getType());
782+
const mlir::Location loc = cgf.getLoc(e->getSourceRange());
783+
const AggValueSlot dest = ensureSlot(loc, e->getType());
784784

785785
if (e->getType()->isConstantArrayType()) {
786786
cir::ArrayType arrayTy =
@@ -819,10 +819,23 @@ void AggExprEmitter::visitCXXParenListOrInitListExpr(
819819
if (auto *cxxrd = dyn_cast<CXXRecordDecl>(record)) {
820820
assert(numInitElements >= cxxrd->getNumBases() &&
821821
"missing initializer for base class");
822-
if (cxxrd->getNumBases() > 0) {
823-
cgf.cgm.errorNYI(e->getSourceRange(),
824-
"visitCXXParenListOrInitListExpr base class init");
825-
return;
822+
for (auto &base : cxxrd->bases()) {
823+
assert(!base.isVirtual() && "should not see vbases here");
824+
CXXRecordDecl *baseRD = base.getType()->getAsCXXRecordDecl();
825+
Address address = cgf.getAddressOfDirectBaseInCompleteClass(
826+
loc, dest.getAddress(), cxxrd, baseRD,
827+
/*baseIsVirtual=*/false);
828+
assert(!cir::MissingFeatures::aggValueSlotGC());
829+
AggValueSlot aggSlot = AggValueSlot::forAddr(
830+
address, Qualifiers(), AggValueSlot::IsDestructed,
831+
AggValueSlot::IsNotAliased,
832+
cgf.getOverlapForBaseInit(cxxrd, baseRD, false));
833+
cgf.emitAggExpr(args[curInitIndex++], aggSlot);
834+
if (base.getType().isDestructedType()) {
835+
cgf.cgm.errorNYI(e->getSourceRange(),
836+
"push deferred deactivation cleanup");
837+
return;
838+
}
826839
}
827840
}
828841

0 commit comments

Comments
 (0)