Skip to content

Commit 17c8077

Browse files
committed
merge main into amd-staging
2 parents 9056f30 + d099d95 commit 17c8077

File tree

215 files changed

+6376
-2098
lines changed

Some content is hidden

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

215 files changed

+6376
-2098
lines changed

.git-blame-ignore-revs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,9 @@ d33bf2e9df578ff7e44fd22504d6ad5a122b7ee6
100100

101101
# [lldb][NFC] clang-format MainLoopPosix.cpp
102102
66bdbfbaa08fa3d8e64a7fe136a8fb717f5cdbb7
103+
104+
# [clang-tidy][NFC] Run clang-format on "clang-tools-extra/clang-tidy"
105+
65d66625b3e2b8322ed99d82edabecbafcd0885b
106+
ce46adb8b7ce645353eccaedf31ed9765dab77bb
107+
68070f908bb7ac5f0b5fa9722caa504ecf723f6b
108+
5213c57cb1f0d78aad9a253b7f6a2b62ff4c7859

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ Resolutions to C++ Defect Reports
157157
`constraint-expression <https://cplusplus.github.io/CWG/issues/2517.html>`_.
158158
- Implemented `CWG3005 Function parameters should never be name-independent <https://wg21.link/CWG3005>`_.
159159

160+
- Implemented `CWG2496 ref-qualifiers and virtual overriding <https://wg21.link/CWG2496>`_.
161+
160162
C Language Changes
161163
------------------
162164

clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,11 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
278278
return createCast(loc, cir::CastKind::bitcast, src, newTy);
279279
}
280280

281+
mlir::Value createPtrBitcast(mlir::Value src, mlir::Type newPointeeTy) {
282+
assert(mlir::isa<cir::PointerType>(src.getType()) && "expected ptr src");
283+
return createBitcast(src, getPointerTo(newPointeeTy));
284+
}
285+
281286
//===--------------------------------------------------------------------===//
282287
// Binary Operators
283288
//===--------------------------------------------------------------------===//

clang/include/clang/CIR/Dialect/IR/CIROps.td

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2275,4 +2275,47 @@ def VecTernaryOp : CIR_Op<"vec.ternary",
22752275
let hasFolder = 1;
22762276
}
22772277

2278+
//===----------------------------------------------------------------------===//
2279+
// BaseClassAddrOp
2280+
//===----------------------------------------------------------------------===//
2281+
2282+
def BaseClassAddrOp : CIR_Op<"base_class_addr"> {
2283+
let summary = "Get the base class address for a class/struct";
2284+
let description = [{
2285+
The `cir.base_class_addr` operaration gets the address of a particular
2286+
non-virtual base class given a derived class pointer. The offset in bytes
2287+
of the base class must be passed in, since it is easier for the front end
2288+
to calculate that than the MLIR passes. The operation contains a flag for
2289+
whether or not the operand may be nullptr. That depends on the context and
2290+
cannot be known by the operation, and that information affects how the
2291+
operation is lowered.
2292+
2293+
Example:
2294+
```c++
2295+
struct Base { };
2296+
struct Derived : Base { };
2297+
Derived d;
2298+
Base& b = d;
2299+
```
2300+
will generate
2301+
```mlir
2302+
%3 = cir.base_class_addr %1 : !cir.ptr<!rec_Derived> nonnull [0] -> !cir.ptr<!rec_Base>
2303+
```
2304+
}];
2305+
2306+
// The validity of the relationship of derived and base cannot yet be
2307+
// verified, currently not worth adding a verifier.
2308+
let arguments = (ins
2309+
Arg<CIR_PointerType, "derived class pointer", [MemRead]>:$derived_addr,
2310+
IndexAttr:$offset, UnitAttr:$assume_not_null);
2311+
2312+
let results = (outs Res<CIR_PointerType, "">:$base_addr);
2313+
2314+
let assemblyFormat = [{
2315+
$derived_addr `:` qualified(type($derived_addr))
2316+
(`nonnull` $assume_not_null^)?
2317+
` ` `[` $offset `]` `->` qualified(type($base_addr)) attr-dict
2318+
}];
2319+
}
2320+
22782321
#endif // CLANG_CIR_DIALECT_IR_CIROPS_TD

clang/include/clang/CIR/MissingFeatures.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,11 @@ struct MissingFeatures {
151151
static bool cxxabiAppleARM64CXXABI() { return false; }
152152
static bool cxxabiStructorImplicitParam() { return false; }
153153

154+
// Address class
155+
static bool addressOffset() { return false; }
156+
static bool addressIsKnownNonNull() { return false; }
157+
static bool addressPointerAuthInfo() { return false; }
158+
154159
// Misc
155160
static bool cirgenABIInfo() { return false; }
156161
static bool abiArgInfo() { return false; }

clang/lib/Basic/Targets/X86.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,7 @@ class LLVM_LIBRARY_VISIBILITY CygwinX86_32TargetInfo : public X86_32TargetInfo {
647647
CygwinX86_32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
648648
: X86_32TargetInfo(Triple, Opts) {
649649
this->WCharType = TargetInfo::UnsignedShort;
650+
this->WIntType = TargetInfo::UnsignedInt;
650651
DoubleAlign = LongLongAlign = 64;
651652
resetDataLayout("e-m:x-p:32:32-p270:32:32-p271:32:32-p272:64:64-i64:64-"
652653
"i128:128-f80:32-n8:16:32-a:0:32-S32",
@@ -982,6 +983,7 @@ class LLVM_LIBRARY_VISIBILITY CygwinX86_64TargetInfo : public X86_64TargetInfo {
982983
CygwinX86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
983984
: X86_64TargetInfo(Triple, Opts) {
984985
this->WCharType = TargetInfo::UnsignedShort;
986+
this->WIntType = TargetInfo::UnsignedInt;
985987
}
986988

987989
void getTargetDefines(const LangOptions &Opts,

clang/lib/CIR/CodeGen/Address.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121

2222
namespace clang::CIRGen {
2323

24+
// Forward declaration to avoid a circular dependency
25+
class CIRGenBuilderTy;
26+
2427
class Address {
2528

2629
// The boolean flag indicates whether the pointer is known to be non-null.
@@ -65,11 +68,22 @@ class Address {
6568
return pointerAndKnownNonNull.getPointer() != nullptr;
6669
}
6770

71+
/// Return address with different element type, a bitcast pointer, and
72+
/// the same alignment.
73+
Address withElementType(CIRGenBuilderTy &builder, mlir::Type ElemTy) const;
74+
6875
mlir::Value getPointer() const {
6976
assert(isValid());
7077
return pointerAndKnownNonNull.getPointer();
7178
}
7279

80+
mlir::Value getBasePointer() const {
81+
// TODO(cir): Remove the version above when we catchup with OG codegen on
82+
// ptr auth.
83+
assert(isValid() && "pointer isn't valid");
84+
return getPointer();
85+
}
86+
7387
mlir::Type getType() const {
7488
assert(mlir::cast<cir::PointerType>(
7589
pointerAndKnownNonNull.getPointer().getType())

clang/lib/CIR/CodeGen/CIRGenBuilder.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,15 @@ mlir::Value CIRGenBuilderTy::getArrayElement(mlir::Location arrayLocBegin,
3838
const mlir::Type flatPtrTy = basePtr.getType();
3939
return create<cir::PtrStrideOp>(arrayLocEnd, flatPtrTy, basePtr, idx);
4040
}
41+
42+
// This can't be defined in Address.h because that file is included by
43+
// CIRGenBuilder.h
44+
Address Address::withElementType(CIRGenBuilderTy &builder,
45+
mlir::Type elemTy) const {
46+
assert(!cir::MissingFeatures::addressOffset());
47+
assert(!cir::MissingFeatures::addressIsKnownNonNull());
48+
assert(!cir::MissingFeatures::addressPointerAuthInfo());
49+
50+
return Address(builder.createPtrBitcast(getBasePointer(), elemTy), elemTy,
51+
getAlignment());
52+
}

clang/lib/CIR/CodeGen/CIRGenBuilder.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,18 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
309309
return create<cir::BinOp>(loc, cir::BinOpKind::Div, lhs, rhs);
310310
}
311311

312+
Address createBaseClassAddr(mlir::Location loc, Address addr,
313+
mlir::Type destType, unsigned offset,
314+
bool assumeNotNull) {
315+
if (destType == addr.getElementType())
316+
return addr;
317+
318+
auto ptrTy = getPointerTo(destType);
319+
auto baseAddr = create<cir::BaseClassAddrOp>(
320+
loc, ptrTy, addr.getPointer(), mlir::APInt(64, offset), assumeNotNull);
321+
return Address(baseAddr, destType, addr.getAlignment());
322+
}
323+
312324
cir::LoadOp createLoad(mlir::Location loc, Address addr,
313325
bool isVolatile = false) {
314326
mlir::IntegerAttr align = getAlignmentAttr(addr.getAlignment());
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// This contains code dealing with C++ code generation of classes
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#include "CIRGenFunction.h"
14+
15+
#include "clang/AST/RecordLayout.h"
16+
#include "clang/CIR/MissingFeatures.h"
17+
18+
using namespace clang;
19+
using namespace clang::CIRGen;
20+
21+
Address CIRGenFunction::getAddressOfBaseClass(
22+
Address value, const CXXRecordDecl *derived,
23+
llvm::iterator_range<CastExpr::path_const_iterator> path,
24+
bool nullCheckValue, SourceLocation loc) {
25+
assert(!path.empty() && "Base path should not be empty!");
26+
27+
if ((*path.begin())->isVirtual()) {
28+
// The implementation here is actually complete, but let's flag this
29+
// as an error until the rest of the virtual base class support is in place.
30+
cgm.errorNYI(loc, "getAddrOfBaseClass: virtual base");
31+
return Address::invalid();
32+
}
33+
34+
// Compute the static offset of the ultimate destination within its
35+
// allocating subobject (the virtual base, if there is one, or else
36+
// the "complete" object that we see).
37+
CharUnits nonVirtualOffset =
38+
cgm.computeNonVirtualBaseClassOffset(derived, path);
39+
40+
// Get the base pointer type.
41+
mlir::Type baseValueTy = convertType((path.end()[-1])->getType());
42+
assert(!cir::MissingFeatures::addressSpace());
43+
44+
// The if statement here is redundant now, but it will be needed when we add
45+
// support for virtual base classes.
46+
// If there is no virtual base, use cir.base_class_addr. It takes care of
47+
// the adjustment and the null pointer check.
48+
if (nonVirtualOffset.isZero()) {
49+
assert(!cir::MissingFeatures::sanitizers());
50+
return builder.createBaseClassAddr(getLoc(loc), value, baseValueTy, 0,
51+
/*assumeNotNull=*/true);
52+
}
53+
54+
assert(!cir::MissingFeatures::sanitizers());
55+
56+
// Apply the offset
57+
value = builder.createBaseClassAddr(getLoc(loc), value, baseValueTy,
58+
nonVirtualOffset.getQuantity(),
59+
/*assumeNotNull=*/true);
60+
61+
// Cast to the destination type.
62+
value = value.withElementType(builder, baseValueTy);
63+
64+
return value;
65+
}

0 commit comments

Comments
 (0)