Skip to content

Commit 8b549f6

Browse files
committed
Merge from 'main' to 'sycl-web' (43 commits)
CONFLICT (content): Merge conflict in llvm/unittests/Support/Base64Test.cpp CONFLICT (add/add): Merge conflict in llvm/lib/Support/Base64.cpp CONFLICT (content): Merge conflict in llvm/include/llvm/Support/Base64.h
2 parents c518ab0 + ea9ac35 commit 8b549f6

File tree

132 files changed

+3007
-1000
lines changed

Some content is hidden

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

132 files changed

+3007
-1000
lines changed

clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ void ProBoundsConstantArrayIndexCheck::check(
6161
const auto *Matched = Result.Nodes.getNodeAs<Expr>("expr");
6262
const auto *IndexExpr = Result.Nodes.getNodeAs<Expr>("index");
6363

64+
// This expression can only appear inside ArrayInitLoopExpr, which
65+
// is always implicitly generated. ArrayInitIndexExpr is not a
66+
// constant, but we shouldn't report a warning for it.
67+
if (isa<ArrayInitIndexExpr>(IndexExpr))
68+
return;
69+
6470
if (IndexExpr->isValueDependent())
6571
return; // We check in the specialization.
6672

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-constant-array-index.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,34 @@ void customOperator() {
7575
s[i] = 3; // OK, custom operator
7676
}
7777

78+
namespace ArrayInitIndexExpr {
7879
struct A {
7980
// The compiler-generated copy constructor uses an ArraySubscriptExpr. Don't warn.
8081
int x[3];
8182
};
8283

83-
void use_A() {
84+
void implicitCopyMoveCtor() {
8485
// Force the compiler to generate a copy constructor.
8586
A a;
8687
A a2(a);
88+
89+
// Force the compiler to generate a move constructor.
90+
A a3 = (A&&) a;
91+
}
92+
93+
void lambdaCapture() {
94+
int arr[3];
95+
96+
// Capturing an array by value uses an ArraySubscriptExpr. Don't warn.
97+
[arr](){};
98+
}
99+
100+
#if __cplusplus >= 201703L
101+
void structuredBindings() {
102+
int arr[3];
103+
104+
// Creating structured bindings by value uses an ArraySubscriptExpr. Don't warn.
105+
auto [a,b,c] = arr;
87106
}
107+
#endif
108+
} // namespace ArrayInitIndexExpr

clang/docs/HLSL/EntryFunctions.rst

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
====================
2+
HLSL Entry Functions
3+
====================
4+
5+
.. contents::
6+
:local:
7+
8+
Usage
9+
=====
10+
11+
In HLSL, entry functions denote the starting point for shader execution. They
12+
must be known at compile time. For all non-library shaders, the compiler assumes
13+
the default entry function name ``main``, unless the DXC ``/E`` option is
14+
provided to specify an alternate entry point. For library shaders entry points
15+
are denoted using the ``[shader(...)]`` attribute.
16+
17+
All scalar parameters to entry functions must have semantic annotations, and all
18+
struct parameters must have semantic annotations on every field in the struct
19+
declaration. Additionally if the entry function has a return type, a semantic
20+
annotation must be provided for the return type as well.
21+
22+
HLSL entry functions can be called from other parts of the shader, which has
23+
implications on code generation.
24+
25+
Implementation Details
26+
======================
27+
28+
In Clang, the DXC ``/E`` option is translated to the cc1 flag ``-hlsl-entry``,
29+
which in turn applies the ``HLSLShader`` attribute to the function with the
30+
specified name. This allows code generation for entry functions to always key
31+
off the presence of the ``HLSLShader`` attribute, regardless of what shader
32+
profile you are compiling.
33+
34+
In code generation, two functions are generated. One is the user defined
35+
function, which is code generated as a mangled C++ function with internal
36+
linkage following normal function code generation.
37+
38+
The actual exported entry function which can be called by the GPU driver is a
39+
``void(void)`` function that isn't name mangled. In code generation we generate
40+
the unmangled entry function, instantiations of the parameters with their
41+
semantic values populated, and a call to the user-defined function. After the
42+
call instruction the return value (if any) is saved using a target-appropriate
43+
intrinsic for storing outputs (for DirectX, the ``llvm.dx.store.output``).
44+
45+
.. note::
46+
47+
HLSL support in Clang is currently focused on compute shaders, which do not
48+
support output semantics. Support for output semantics will not be
49+
implemented until other shader profiles are supported.
50+
51+
Below is example IR that represents the planned implementation, subject to
52+
change as the ``llvm.dx.store.output`` and ``llvm.dx.load.input`` intrinsics are
53+
not yet implemented.
54+
55+
.. code-block:: none
56+
57+
; Function Attrs: norecurse
58+
define void @main() #1 {
59+
entry:
60+
%0 = call i32 @llvm.dx.load.input.i32(...)
61+
%1 = call i32 @"?main@@YAXII@Z"(i32 %0)
62+
call @llvm.dx.store.output.i32(%1, ...)
63+
ret void
64+
}
65+

clang/docs/HLSL/HLSLDocs.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ HLSL Design and Implementation
1212
:maxdepth: 1
1313

1414
ResourceTypes
15+
EntryFunctions

clang/docs/HLSL/ResourceTypes.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
============
2-
HLSL Support
3-
============
1+
===================
2+
HLSL Resource Types
3+
===================
44

55
.. contents::
66
:local:

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,11 @@ C++20 Feature Support
198198
and `DR1734 <https://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1734>`_.
199199
- Class member variables are now in scope when parsing a ``requires`` clause. Fixes
200200
`GH55216 <https://github.com/llvm/llvm-project/issues/55216>`_.
201-
202201
- Correctly set expression evaluation context as 'immediate function context' in
203202
consteval functions.
204203
This fixes `GH51182 <https://github.com/llvm/llvm-project/issues/51182>`
204+
- Fixes an assert crash caused by looking up missing vtable information on ``consteval``
205+
virtual functions. Fixes `GH55065 <https://github.com/llvm/llvm-project/issues/55065>`_.
205206

206207

207208
C++2b Feature Support

clang/lib/CodeGen/CGDebugInfo.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "clang/AST/Expr.h"
2727
#include "clang/AST/RecordLayout.h"
2828
#include "clang/AST/RecursiveASTVisitor.h"
29+
#include "clang/AST/VTableBuilder.h"
2930
#include "clang/Basic/CodeGenOptions.h"
3031
#include "clang/Basic/FileManager.h"
3132
#include "clang/Basic/SourceManager.h"
@@ -1765,7 +1766,7 @@ llvm::DISubprogram *CGDebugInfo::CreateCXXMemberFunction(
17651766
llvm::DISubprogram::DISPFlags SPFlags = llvm::DISubprogram::SPFlagZero;
17661767
int ThisAdjustment = 0;
17671768

1768-
if (Method->isVirtual()) {
1769+
if (VTableContextBase::hasVtableSlot(Method)) {
17691770
if (Method->isPure())
17701771
SPFlags |= llvm::DISubprogram::SPFlagPureVirtual;
17711772
else

clang/lib/Lex/ModuleMap.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2026,8 +2026,7 @@ void ModuleMapParser::parseModuleDecl() {
20262026
ActiveModule->IsSystem = true;
20272027
if (Attrs.IsExternC)
20282028
ActiveModule->IsExternC = true;
2029-
if (Attrs.NoUndeclaredIncludes ||
2030-
(!ActiveModule->Parent && ModuleName == "Darwin"))
2029+
if (Attrs.NoUndeclaredIncludes)
20312030
ActiveModule->NoUndeclaredIncludes = true;
20322031
ActiveModule->Directory = Directory;
20332032

clang/test/CodeGenCXX/cxx20-consteval-crash.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: %clang_cc1 -no-opaque-pointers -triple x86_64-unknown-linux-gnu -std=c++20 %s -emit-llvm -o - | FileCheck %s
2+
// RUN: %clang_cc1 -emit-obj -debug-info-kind=constructor -std=c++20 %s -o -
23

34
namespace PR50787 {
45
// This code would previously cause a crash.
@@ -71,3 +72,23 @@ int foo() {
7172
return function(Item{'a'}, Item{'a'});
7273
}
7374
} // namespace Issue58871
75+
76+
namespace Issue55065 {
77+
struct Base {
78+
consteval virtual int Get() const = 0;
79+
};
80+
81+
struct Derived : Base {
82+
consteval int Get() const override {
83+
return 42;
84+
}
85+
};
86+
87+
int foo() {
88+
constexpr Derived a;
89+
90+
auto val = a.Get();
91+
return val;
92+
}
93+
} // namespace Issue55065
94+

compiler-rt/lib/profile/InstrProfilingWriter.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,9 +276,6 @@ lprofWriteDataImpl(ProfDataWriter *Writer, const __llvm_profile_data *DataBegin,
276276
/* Create the header. */
277277
__llvm_profile_header Header;
278278

279-
if (!NumData && (!DebugInfoCorrelate || !NumCounters))
280-
return 0;
281-
282279
/* Determine how much padding is needed before/after the counters and after
283280
* the names. */
284281
uint64_t PaddingBytesBeforeCounters, PaddingBytesAfterCounters,
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Test a profile with only a header is generated when a src file is not in the
2+
// selected files list provided via -fprofile-list.
3+
4+
// RUN: mkdir -p %t.d
5+
// RUN: echo "src:other.c" > %t-file.list
6+
// RUN: %clang_profgen -fprofile-list=%t-file.list -o %t %s
7+
// RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t
8+
// RUN: llvm-profdata show %t.profraw | FileCheck %s --check-prefix=RAW-PROFILE-HEADER-ONLY
9+
10+
// RUN: llvm-profdata merge -o %t.profdata %t.profraw
11+
// RUN: llvm-profdata show %t.profdata | FileCheck %s --check-prefix=INDEXED-PROFILE-HEADER-ONLY
12+
13+
int main() { return 0; }
14+
15+
// RAW-PROFILE-HEADER-ONLY: Instrumentation level: Front-end
16+
// RAW-PROFILE-HEADER-ONLY-NEXT: Total functions: 0
17+
// RAW-PROFILE-HEADER-ONLY-NEXT: Maximum function count: 0
18+
// RAW-PROFILE-HEADER-ONLY-NEXT: Maximum internal block count: 0
19+
20+
// INDEXED-PROFILE-HEADER-ONLY: Instrumentation level: Front-end
21+
// INDEXED-PROFILE-HEADER-ONLY-NEXT: Total functions: 0
22+
// INDEXED-PROFILE-HEADER-ONLY-NEXT: Maximum function count: 0
23+
// INDEXED-PROFILE-HEADER-ONLY-NEXT: Maximum internal block count: 0
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
"""
2+
This test produces two shared libraries:
3+
4+
1. libt-instr.so is instrumented
5+
2. libt-no-instr.so is built with profile rt linked in (via -u<hook>), but the object file is built
6+
with instrumentation turned off.
7+
8+
The test verifies concatenating profiles with only headers and no profile data and counters.
9+
"""
10+
11+
RUN: mkdir -p %t.d
12+
RUN: %clang_profgen -o %t.d/libt-instr.so -fPIC -shared %S/../Inputs/instrprof-shared-lib.c
13+
RUN: %clang -c -o %t.d/instrprof-shared-lib-no-instr.o -fPIC %S/../Inputs/instrprof-shared-lib.c
14+
RUN: %clang_profgen -o %t.d/libt-no-instr.so -fPIC -shared %t.d/instrprof-shared-lib-no-instr.o
15+
16+
# Header + Header
17+
RUN: echo "src:other.c" > %t-file.list
18+
RUN: %clang_profgen -fprofile-list=%t-file.list -o %t-no-instr-no-instr -L%t.d -rpath %t.d -lt-no-instr %S/../Inputs/instrprof-shared-main.c
19+
RUN: env LLVM_PROFILE_FILE=%t-no-instr-no-instr.profraw %run %t-no-instr-no-instr
20+
RUN: llvm-profdata show %t-no-instr-no-instr.profraw | FileCheck %s --check-prefix=HEADER-HEADER
21+
// HEADER-HEADER: Instrumentation level: Front-end
22+
// HEADER-HEADER-NEXT: Total functions: 0
23+
// HEADER-HEADER-NEXT: Maximum function count: 0
24+
// HEADER-HEADER-NEXT: Maximum internal block count: 0
25+
26+
# Header + Profile
27+
RUN: %clang_profgen -fprofile-list=%t-file.list -o %t-no-instr-instr -L%t.d -rpath %t.d -lt-instr %S/../Inputs/instrprof-shared-main.c
28+
RUN: env LLVM_PROFILE_FILE=%t-no-instr-instr.profraw %run %t-no-instr-instr
29+
RUN: llvm-profdata show %t-no-instr-instr.profraw | FileCheck %s --check-prefix=HEADER-PROFILE
30+
// HEADER-PROFILE: Instrumentation level: Front-end
31+
// HEADER-PROFILE-NEXT: Total functions: 1
32+
// HEADER-PROFILE-NEXT: Maximum function count: 1000000
33+
// HEADER-PROFILE-NEXT: Maximum internal block count: 360000
34+
35+
# Profile + Header
36+
RUN: %clang_profgen -o %t-instr-no-instr -L%t.d -rpath %t.d -lt-no-instr %S/../Inputs/instrprof-shared-main.c
37+
RUN: env LLVM_PROFILE_FILE=%t-instr-no-instr.profraw %run %t-instr-no-instr
38+
RUN: llvm-profdata show %t-instr-no-instr.profraw | FileCheck %s --check-prefix=PROFILE-HEADER
39+
// PROFILE-HEADER: Instrumentation level: Front-end
40+
// PROFILE-HEADER-NEXT: Total functions: 1
41+
// PROFILE-HEADER-NEXT: Maximum function count: 1
42+
// PROFILE-HEADER-NEXT: Maximum internal block count: 1000000

flang/lib/Lower/IntrinsicCall.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1153,6 +1153,12 @@ static mlir::FunctionType genF32IntF32FuncType(mlir::MLIRContext *context) {
11531153
return mlir::FunctionType::get(context, {itype, ftype}, {ftype});
11541154
}
11551155

1156+
template <int Bits>
1157+
static mlir::FunctionType genIntIntIntFuncType(mlir::MLIRContext *context) {
1158+
auto itype = mlir::IntegerType::get(context, Bits);
1159+
return mlir::FunctionType::get(context, {itype, itype}, {itype});
1160+
}
1161+
11561162
/// Callback type for generating lowering for a math operation.
11571163
using MathGeneratorTy = mlir::Value (*)(fir::FirOpBuilder &, mlir::Location,
11581164
llvm::StringRef, mlir::FunctionType,
@@ -1220,7 +1226,12 @@ static mlir::Value genMathOp(fir::FirOpBuilder &builder, mlir::Location loc,
12201226
// can be also lowered to libm calls for "fast" and "relaxed"
12211227
// modes.
12221228
mlir::Value result;
1223-
if (mathRuntimeVersion == preciseVersion) {
1229+
if (mathRuntimeVersion == preciseVersion &&
1230+
// Some operations do not have to be lowered as conservative
1231+
// calls, since they do not affect strict FP behavior.
1232+
// For example, purely integer operations like exponentiation
1233+
// with integer operands fall into this class.
1234+
!mathLibFuncName.empty()) {
12241235
result = genLibCall(builder, loc, mathLibFuncName, mathLibFuncType, args);
12251236
} else {
12261237
LLVM_DEBUG(llvm::dbgs() << "Generating '" << mathLibFuncName
@@ -1310,6 +1321,10 @@ static constexpr MathOperation mathOperations[] = {
13101321
{"nint", "llvm.lround.i64.f32", genIntF32FuncType<64>, genLibCall},
13111322
{"nint", "llvm.lround.i32.f64", genIntF64FuncType<32>, genLibCall},
13121323
{"nint", "llvm.lround.i32.f32", genIntF32FuncType<32>, genLibCall},
1324+
{"pow", {}, genIntIntIntFuncType<8>, genMathOp<mlir::math::IPowIOp>},
1325+
{"pow", {}, genIntIntIntFuncType<16>, genMathOp<mlir::math::IPowIOp>},
1326+
{"pow", {}, genIntIntIntFuncType<32>, genMathOp<mlir::math::IPowIOp>},
1327+
{"pow", {}, genIntIntIntFuncType<64>, genMathOp<mlir::math::IPowIOp>},
13131328
{"pow", "powf", genF32F32F32FuncType, genMathOp<mlir::math::PowFOp>},
13141329
{"pow", "pow", genF64F64F64FuncType, genMathOp<mlir::math::PowFOp>},
13151330
// TODO: add PowIOp in math and complex dialects.

flang/lib/Optimizer/CodeGen/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ add_flang_library(FIRCodeGen
1717
FIRBuilder
1818
FIRDialect
1919
FIRSupport
20+
MLIRMathToFuncs
2021
MLIRMathToLLVM
2122
MLIRMathToLibm
2223
MLIROpenMPToLLVM

flang/lib/Optimizer/CodeGen/CodeGen.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@
2323
#include "mlir/Conversion/ControlFlowToLLVM/ControlFlowToLLVM.h"
2424
#include "mlir/Conversion/FuncToLLVM/ConvertFuncToLLVM.h"
2525
#include "mlir/Conversion/LLVMCommon/Pattern.h"
26+
#include "mlir/Conversion/MathToFuncs/MathToFuncs.h"
2627
#include "mlir/Conversion/MathToLLVM/MathToLLVM.h"
2728
#include "mlir/Conversion/MathToLibm/MathToLibm.h"
2829
#include "mlir/Conversion/OpenMPToLLVM/ConvertOpenMPToLLVM.h"
2930
#include "mlir/IR/BuiltinTypes.h"
3031
#include "mlir/IR/Matchers.h"
3132
#include "mlir/Pass/Pass.h"
33+
#include "mlir/Pass/PassManager.h"
3234
#include "mlir/Target/LLVMIR/ModuleTranslation.h"
3335
#include "llvm/ADT/ArrayRef.h"
3436

@@ -3291,6 +3293,18 @@ class FIRToLLVMLowering : public fir::FIRToLLVMLoweringBase<FIRToLLVMLowering> {
32913293
if (!forcedTargetTriple.empty())
32923294
fir::setTargetTriple(mod, forcedTargetTriple);
32933295

3296+
// Run dynamic pass pipeline for converting Math dialect
3297+
// operations into other dialects (llvm, func, etc.).
3298+
// Some conversions of Math operations cannot be done
3299+
// by just using conversion patterns. This is true for
3300+
// conversions that affect the ModuleOp, e.g. create new
3301+
// function operations in it. We have to run such conversions
3302+
// as passes here.
3303+
mlir::OpPassManager mathConvertionPM("builtin.module");
3304+
mathConvertionPM.addPass(mlir::createConvertMathToFuncsPass());
3305+
if (mlir::failed(runPipeline(mathConvertionPM, mod)))
3306+
return signalPassFailure();
3307+
32943308
auto *context = getModule().getContext();
32953309
fir::LLVMTypeConverter typeConverter{getModule()};
32963310
mlir::RewritePatternSet pattern(context);

flang/test/Intrinsics/math-codegen.fir

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1466,6 +1466,19 @@ func.func private @powf(f32, f32) -> f32
14661466
func.func private @llvm.powi.f64.i32(f64, i32) -> f64
14671467
func.func private @pow(f64, f64) -> f64
14681468

1469+
//--- exponentiation_integer.fir
1470+
// RUN: fir-opt %t/exponentiation_integer.fir --fir-to-llvm-ir="target=x86_64-unknown-linux-gnu" | FileCheck %t/exponentiation_integer.fir
1471+
// CHECK: @_QPtest_int4
1472+
// CHECK: llvm.call @__mlir_math_ipowi_i32({{%[A-Za-z0-9._]+}}, {{%[A-Za-z0-9._]+}}) : (i32, i32) -> i32
1473+
1474+
func.func @_QPtest_int4(%arg0: !fir.ref<i32> {fir.bindc_name = "x"}, %arg1: !fir.ref<i32> {fir.bindc_name = "y"}, %arg2: !fir.ref<i32> {fir.bindc_name = "z"}) {
1475+
%0 = fir.load %arg0 : !fir.ref<i32>
1476+
%1 = fir.load %arg1 : !fir.ref<i32>
1477+
%2 = math.ipowi %0, %1 : i32
1478+
fir.store %2 to %arg2 : !fir.ref<i32>
1479+
return
1480+
}
1481+
14691482
//--- sign_fast.fir
14701483
// RUN: fir-opt %t/sign_fast.fir --fir-to-llvm-ir="target=x86_64-unknown-linux-gnu" | FileCheck %t/sign_fast.fir
14711484
// CHECK: @_QPtest_real4

0 commit comments

Comments
 (0)