Skip to content

Commit dfce48e

Browse files
author
z1_cciauto
authored
merge main into amd-staging (llvm#3685)
2 parents 04ac394 + 6e8f809 commit dfce48e

File tree

186 files changed

+8469
-3909
lines changed

Some content is hidden

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

186 files changed

+8469
-3909
lines changed

.ci/monolithic-linux.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ cmake -S "${MONOREPO_ROOT}"/llvm -B "${BUILD_DIR}" \
6060
-D MLIR_ENABLE_BINDINGS_PYTHON=ON \
6161
-D LLDB_ENABLE_PYTHON=ON \
6262
-D LLDB_ENFORCE_STRICT_TEST_REQUIREMENTS=ON \
63-
-D CMAKE_INSTALL_PREFIX="${INSTALL_DIR}"
63+
-D CMAKE_INSTALL_PREFIX="${INSTALL_DIR}" \
64+
-D CMAKE_EXE_LINKER_FLAGS="-no-pie"
6465

6566
start-group "ninja"
6667

clang/docs/ReleaseNotes.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,6 @@ Bug Fixes in This Version
475475
cast chain. (#GH149967).
476476
- Fixed a crash with incompatible pointer to integer conversions in designated
477477
initializers involving string literals. (#GH154046)
478-
- Clang's ``<stddef.h>`` now properly declares ``nullptr_t`` in C++ mode. (#GH154577).
479478

480479
Bug Fixes to Compiler Builtins
481480
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

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

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,45 @@ class CIR_UnitAttr<string name, string attrMnemonic, list<Trait> traits = []>
5050
let isOptional = 1;
5151
}
5252

53+
//===----------------------------------------------------------------------===//
54+
// SourceLanguageAttr
55+
//===----------------------------------------------------------------------===//
56+
57+
// TODO: Add cases for other languages that Clang supports.
58+
59+
def CIR_SourceLanguage : CIR_I32EnumAttr<"SourceLanguage", "source language", [
60+
I32EnumAttrCase<"C", 1, "c">,
61+
I32EnumAttrCase<"CXX", 2, "cxx">
62+
]> {
63+
// The enum attr class is defined in `CIR_SourceLanguageAttr` below,
64+
// so that it can define extra class methods.
65+
let genSpecializedAttr = 0;
66+
}
67+
68+
def CIR_SourceLanguageAttr : CIR_EnumAttr<CIR_SourceLanguage, "lang"> {
69+
70+
let summary = "Module source language";
71+
let description = [{
72+
Represents the source language used to generate the module.
73+
74+
Example:
75+
```
76+
// Module compiled from C.
77+
module attributes {cir.lang = cir.lang<c>} {}
78+
// Module compiled from C++.
79+
module attributes {cir.lang = cir.lang<cxx>} {}
80+
```
81+
82+
Module source language attribute name is `cir.lang` is defined by
83+
`getSourceLanguageAttrName` method in CIRDialect class.
84+
}];
85+
86+
let extraClassDeclaration = [{
87+
bool isC() const { return getValue() == SourceLanguage::C; }
88+
bool isCXX() const { return getValue() == SourceLanguage::CXX; }
89+
}];
90+
}
91+
5392
//===----------------------------------------------------------------------===//
5493
// OptInfoAttr
5594
//===----------------------------------------------------------------------===//
@@ -496,6 +535,72 @@ def CIR_GlobalViewAttr : CIR_Attr<"GlobalView", "global_view", [
496535
}];
497536
}
498537

538+
//===----------------------------------------------------------------------===//
539+
// VTableAttr
540+
//===----------------------------------------------------------------------===//
541+
542+
def CIR_VTableAttr : CIR_Attr<"VTable", "vtable", [TypedAttrInterface]> {
543+
let summary = "Represents a C++ vtable";
544+
let description = [{
545+
Wraps a #cir.const_record containing one or more vtable arrays.
546+
547+
In most cases, the anonymous record type wrapped by this attribute will
548+
contain a single array corresponding to the vtable for one class. However,
549+
in the case of multiple inheritence, the anonymous structure may contain
550+
multiple arrays, each of which is a vtable.
551+
552+
Example 1 (single vtable):
553+
```mlir
554+
cir.global linkonce_odr @_ZTV6Mother =
555+
#cir.vtable<{
556+
#cir.const_array<[
557+
#cir.ptr<null> : !cir.ptr<!u8i>,
558+
#cir.global_view<@_ZTI6Mother> : !cir.ptr<!u8i>,
559+
#cir.global_view<@_ZN6Mother9MotherFooEv> : !cir.ptr<!u8i>,
560+
#cir.global_view<@_ZN6Mother10MotherFoo2Ev> : !cir.ptr<!u8i>
561+
]> : !cir.array<!cir.ptr<!u8i> x 4>
562+
}> : !rec_anon_struct1
563+
```
564+
565+
Example 2 (multiple vtables):
566+
```mlir
567+
cir.global linkonce_odr @_ZTV5Child =
568+
#cir.vtable<{
569+
#cir.const_array<[
570+
#cir.ptr<null> : !cir.ptr<!u8i>,
571+
#cir.global_view<@_ZTI5Child> : !cir.ptr<!u8i>,
572+
#cir.global_view<@_ZN5Child9MotherFooEv> : !cir.ptr<!u8i>,
573+
#cir.global_view<@_ZN6Mother10MotherFoo2Ev> : !cir.ptr<!u8i>
574+
]> : !cir.array<!cir.ptr<!u8i> x 4>,
575+
#cir.const_array<[
576+
#cir.ptr<-8 : i64> : !cir.ptr<!u8i>,
577+
#cir.global_view<@_ZTI5Child> : !cir.ptr<!u8i>,
578+
#cir.global_view<@_ZN6Father9FatherFooEv> : !cir.ptr<!u8i>
579+
]> : !cir.array<!cir.ptr<!u8i> x 3>
580+
}> : !rec_anon_struct2
581+
```
582+
}];
583+
584+
// `data` is a const record with one element, containing an array of
585+
// vtable information.
586+
let parameters = (ins
587+
AttributeSelfTypeParameter<"">:$type,
588+
"mlir::ArrayAttr":$data
589+
);
590+
591+
let builders = [
592+
AttrBuilderWithInferredContext<(ins "mlir::Type":$type,
593+
"mlir::ArrayAttr":$data), [{
594+
return $_get(type.getContext(), type, data);
595+
}]>
596+
];
597+
598+
let genVerifyDecl = 1;
599+
let assemblyFormat = [{
600+
`<` custom<RecordMembers>($data) `>`
601+
}];
602+
}
603+
499604
//===----------------------------------------------------------------------===//
500605
// ConstComplexAttr
501606
//===----------------------------------------------------------------------===//

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def CIR_Dialect : Dialect {
3535
let hasConstantMaterializer = 1;
3636

3737
let extraClassDeclaration = [{
38+
static llvm::StringRef getSourceLanguageAttrName() { return "cir.lang"; }
3839
static llvm::StringRef getTripleAttrName() { return "cir.triple"; }
3940
static llvm::StringRef getOptInfoAttrName() { return "cir.opt_info"; }
4041
static llvm::StringRef getCalleeAttrName() { return "callee"; }

clang/include/clang/CIR/Dialect/Passes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ std::unique_ptr<Pass> createCIRSimplifyPass();
2626
std::unique_ptr<Pass> createHoistAllocasPass();
2727
std::unique_ptr<Pass> createLoweringPreparePass();
2828
std::unique_ptr<Pass> createLoweringPreparePass(clang::ASTContext *astCtx);
29+
std::unique_ptr<Pass> createGotoSolverPass();
2930

3031
void populateCIRPreLoweringPasses(mlir::OpPassManager &pm);
3132

clang/include/clang/CIR/Dialect/Passes.td

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,16 @@ def CIRFlattenCFG : Pass<"cir-flatten-cfg"> {
7272
let dependentDialects = ["cir::CIRDialect"];
7373
}
7474

75+
def GotoSolver : Pass<"cir-goto-solver"> {
76+
let summary = "Replaces goto operations with branches";
77+
let description = [{
78+
This pass transforms CIR and replaces goto-s with branch
79+
operations to the proper blocks.
80+
}];
81+
let constructor = "mlir::createGotoSolverPass()";
82+
let dependentDialects = ["cir::CIRDialect"];
83+
}
84+
7585
def LoweringPrepare : Pass<"cir-lowering-prepare"> {
7686
let summary = "Lower to more fine-grained CIR operations before lowering to "
7787
"other dialects";

clang/include/clang/CIR/MissingFeatures.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ struct MissingFeatures {
264264
static bool setNonGC() { return false; }
265265
static bool setObjCGCLValueClass() { return false; }
266266
static bool setTargetAttributes() { return false; }
267+
static bool sourceLanguageCases() { return false; }
267268
static bool stackBase() { return false; }
268269
static bool stackSaveOp() { return false; }
269270
static bool targetCIRGenInfoArch() { return false; }

clang/include/clang/Driver/Options.td

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9758,8 +9758,12 @@ def fspv_target_env_EQ : Joined<["-"], "fspv-target-env=">, Group<dxc_Group>,
97589758
def fspv_extension_EQ
97599759
: Joined<["-"], "fspv-extension=">,
97609760
Group<dxc_Group>,
9761-
HelpText<"Specify the available SPIR-V extensions. If this option is not "
9762-
"specified, then all extensions are available.">;
9761+
HelpText<
9762+
"Specify the available SPIR-V extensions. If this option is not "
9763+
"specified, then all extensions are available. If KHR is specified, "
9764+
"then all KHR extensions will be available. If DXC is specifided, "
9765+
"then all extensions implemented by the DirectX Shader compiler will "
9766+
"be available. This option is useful for moving from DXC to Clang.">;
97639767
def fvk_use_dx_layout
97649768
: DXCFlag<"fvk-use-dx-layout">,
97659769
HelpText<"Use DirectX memory layout for Vulkan resources.">;

clang/lib/AST/ByteCode/InterpBuiltin.cpp

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,14 +205,19 @@ static bool interp__builtin_strcmp(InterpState &S, CodePtr OpPC,
205205

206206
if (A.isDummy() || B.isDummy())
207207
return false;
208+
if (!A.isBlockPointer() || !B.isBlockPointer())
209+
return false;
208210

209211
bool IsWide = ID == Builtin::BIwcscmp || ID == Builtin::BIwcsncmp ||
210212
ID == Builtin::BI__builtin_wcscmp ||
211213
ID == Builtin::BI__builtin_wcsncmp;
212214
assert(A.getFieldDesc()->isPrimitiveArray());
213215
assert(B.getFieldDesc()->isPrimitiveArray());
214216

215-
assert(getElemType(A).getTypePtr() == getElemType(B).getTypePtr());
217+
// Different element types shouldn't happen, but with casts they can.
218+
if (!S.getASTContext().hasSameUnqualifiedType(getElemType(A), getElemType(B)))
219+
return false;
220+
216221
PrimType ElemT = *S.getContext().classify(getElemType(A));
217222

218223
auto returnResult = [&](int V) -> bool {
@@ -2778,6 +2783,40 @@ static bool interp__builtin_elementwise_fma(InterpState &S, CodePtr OpPC,
27782783
return true;
27792784
}
27802785

2786+
/// AVX512 predicated move: "Result = Mask[] ? LHS[] : RHS[]".
2787+
static bool interp__builtin_select(InterpState &S, CodePtr OpPC,
2788+
const CallExpr *Call) {
2789+
const Pointer &RHS = S.Stk.pop<Pointer>();
2790+
const Pointer &LHS = S.Stk.pop<Pointer>();
2791+
PrimType MaskT = *S.getContext().classify(Call->getArg(0));
2792+
APSInt Mask = popToAPSInt(S.Stk, MaskT);
2793+
const Pointer &Dst = S.Stk.peek<Pointer>();
2794+
2795+
assert(LHS.getNumElems() == RHS.getNumElems());
2796+
assert(LHS.getNumElems() == Dst.getNumElems());
2797+
unsigned NumElems = LHS.getNumElems();
2798+
PrimType ElemT = LHS.getFieldDesc()->getPrimType();
2799+
PrimType DstElemT = Dst.getFieldDesc()->getPrimType();
2800+
2801+
for (unsigned I = 0; I != NumElems; ++I) {
2802+
if (ElemT == PT_Float) {
2803+
assert(DstElemT == PT_Float);
2804+
Dst.elem<Floating>(I) =
2805+
Mask[I] ? LHS.elem<Floating>(I) : RHS.elem<Floating>(I);
2806+
} else {
2807+
APSInt Elem;
2808+
INT_TYPE_SWITCH(ElemT, {
2809+
Elem = Mask[I] ? LHS.elem<T>(I).toAPSInt() : RHS.elem<T>(I).toAPSInt();
2810+
});
2811+
INT_TYPE_SWITCH_NO_BOOL(DstElemT,
2812+
{ Dst.elem<T>(I) = static_cast<T>(Elem); });
2813+
}
2814+
}
2815+
Dst.initializeAllElements();
2816+
2817+
return true;
2818+
}
2819+
27812820
bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
27822821
uint32_t BuiltinID) {
27832822
if (!S.getASTContext().BuiltinInfo.isConstantEvaluated(BuiltinID))
@@ -3210,9 +3249,36 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
32103249
case clang::X86::BI__builtin_ia32_pmuludq256:
32113250
case clang::X86::BI__builtin_ia32_pmuludq512:
32123251
return interp__builtin_ia32_pmul(S, OpPC, Call, BuiltinID);
3252+
32133253
case Builtin::BI__builtin_elementwise_fma:
32143254
return interp__builtin_elementwise_fma(S, OpPC, Call);
32153255

3256+
case X86::BI__builtin_ia32_selectb_128:
3257+
case X86::BI__builtin_ia32_selectb_256:
3258+
case X86::BI__builtin_ia32_selectb_512:
3259+
case X86::BI__builtin_ia32_selectw_128:
3260+
case X86::BI__builtin_ia32_selectw_256:
3261+
case X86::BI__builtin_ia32_selectw_512:
3262+
case X86::BI__builtin_ia32_selectd_128:
3263+
case X86::BI__builtin_ia32_selectd_256:
3264+
case X86::BI__builtin_ia32_selectd_512:
3265+
case X86::BI__builtin_ia32_selectq_128:
3266+
case X86::BI__builtin_ia32_selectq_256:
3267+
case X86::BI__builtin_ia32_selectq_512:
3268+
case X86::BI__builtin_ia32_selectph_128:
3269+
case X86::BI__builtin_ia32_selectph_256:
3270+
case X86::BI__builtin_ia32_selectph_512:
3271+
case X86::BI__builtin_ia32_selectpbf_128:
3272+
case X86::BI__builtin_ia32_selectpbf_256:
3273+
case X86::BI__builtin_ia32_selectpbf_512:
3274+
case X86::BI__builtin_ia32_selectps_128:
3275+
case X86::BI__builtin_ia32_selectps_256:
3276+
case X86::BI__builtin_ia32_selectps_512:
3277+
case X86::BI__builtin_ia32_selectpd_128:
3278+
case X86::BI__builtin_ia32_selectpd_256:
3279+
case X86::BI__builtin_ia32_selectpd_512:
3280+
return interp__builtin_select(S, OpPC, Call);
3281+
32163282
default:
32173283
S.FFDiag(S.Current->getLocation(OpPC),
32183284
diag::note_invalid_subexpr_in_const_expr)

clang/lib/AST/ByteCode/Pointer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,8 @@ class Pointer {
341341
QualType getType() const {
342342
if (isTypeidPointer())
343343
return QualType(Typeid.TypeInfoType, 0);
344+
if (isFunctionPointer())
345+
return asFunctionPointer().getFunction()->getDecl()->getType();
344346

345347
if (inPrimitiveArray() && Offset != asBlockPointer().Base) {
346348
// Unfortunately, complex and vector types are not array types in clang,

0 commit comments

Comments
 (0)