Skip to content

Commit 735e88e

Browse files
committed
Merge from 'main' to 'sycl-web' (32 commits)
CONFLICT (content): Merge conflict in llvm/test/CodeGen/RISCV/O3-pipeline.ll Also revert 5c9f768. See:KhronosGroup/SPIRV-LLVM-Translator#2357 #12698
2 parents ca8cb53 + 7d40ea8 commit 735e88e

File tree

118 files changed

+3159
-1090
lines changed

Some content is hidden

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

118 files changed

+3159
-1090
lines changed

.ci/generate-buildkite-pipeline-premerge

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,10 @@ linux_projects=$(add-dependencies ${linux_projects_to_test} | sort | uniq)
233233

234234
windows_projects_to_test=$(exclude-windows $(compute-projects-to-test ${modified_projects}))
235235
windows_check_targets=$(check-targets ${windows_projects_to_test} | sort | uniq)
236-
windows_projects=$(add-dependencies ${windows_projects_to_test} | sort | uniq)
236+
# Temporary disable the windows job.
237+
# See https://discourse.llvm.org/t/rfc-future-of-windows-pre-commit-ci/76840
238+
#windows_projects=$(add-dependencies ${windows_projects_to_test} | sort | uniq)
239+
windows_projects=""
237240

238241
# Generate the appropriate pipeline
239242
if [[ "${linux_projects}" != "" ]]; then

.github/workflows/approved-prs.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: "Prompt reviewers to merge PRs on behalf of authors"
2+
3+
permissions:
4+
contents: read
5+
6+
on:
7+
pull_request_review:
8+
types:
9+
- submitted
10+
11+
jobs:
12+
merge-on-behalf-information-comment:
13+
runs-on: ubuntu-latest
14+
permissions:
15+
pull-requests: write
16+
if: >-
17+
(github.repository == 'llvm/llvm-project') &&
18+
(github.event.review.state == 'APPROVED')
19+
steps:
20+
- name: Checkout Automation Script
21+
uses: actions/checkout@v4
22+
with:
23+
sparse-checkout: llvm/utils/git/
24+
ref: main
25+
26+
- name: Setup Automation Script
27+
working-directory: ./llvm/utils/git/
28+
run: |
29+
pip install -r requirements.txt
30+
31+
- name: Add Merge On Behalf Comment
32+
working-directory: ./llvm/utils/git/
33+
run: |
34+
python3 ./github-automation.py \
35+
--token '${{ secrets.GITHUB_TOKEN }}' \
36+
pr-merge-on-behalf-information \
37+
--issue-number "${{ github.event.pull_request.number }}" \
38+
--author "${{ github.event.pull_request.user.login }}" \
39+
--reviewer "${{ github.event.review.user.login }}"

clang/docs/LanguageExtensions.rst

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2764,6 +2764,39 @@ Query for this feature with ``__has_builtin(__builtin_readcyclecounter)``. Note
27642764
that even if present, its use may depend on run-time privilege or other OS
27652765
controlled state.
27662766
2767+
``__builtin_readsteadycounter``
2768+
-------------------------------
2769+
2770+
``__builtin_readsteadycounter`` is used to access the fixed frequency counter
2771+
register (or a similar steady-rate clock) on those targets that support it.
2772+
The function is similar to ``__builtin_readcyclecounter`` above except that the
2773+
frequency is fixed, making it suitable for measuring elapsed time.
2774+
2775+
**Syntax**:
2776+
2777+
.. code-block:: c++
2778+
2779+
__builtin_readsteadycounter()
2780+
2781+
**Example of Use**:
2782+
2783+
.. code-block:: c++
2784+
2785+
unsigned long long t0 = __builtin_readsteadycounter();
2786+
do_something();
2787+
unsigned long long t1 = __builtin_readsteadycounter();
2788+
unsigned long long secs_to_do_something = (t1 - t0) / tick_rate;
2789+
2790+
**Description**:
2791+
2792+
The ``__builtin_readsteadycounter()`` builtin returns the frequency counter value.
2793+
When not supported by the target, the return value is always zero. This builtin
2794+
takes no arguments and produces an unsigned long long result. The builtin does
2795+
not guarantee any particular frequency, only that it is stable. Knowledge of the
2796+
counter's true frequency will need to be provided by the user.
2797+
2798+
Query for this feature with ``__has_builtin(__builtin_readsteadycounter)``.
2799+
27672800
``__builtin_dump_struct``
27682801
-------------------------
27692802

clang/docs/ReleaseNotes.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ C23 Feature Support
117117
Non-comprehensive list of changes in this release
118118
-------------------------------------------------
119119

120+
- Added ``__builtin_readsteadycounter`` for reading fixed frequency hardware
121+
counters.
122+
120123
New Compiler Flags
121124
------------------
122125

@@ -255,6 +258,8 @@ X86 Support
255258
Arm and AArch64 Support
256259
^^^^^^^^^^^^^^^^^^^^^^^
257260

261+
- Fixed the incorrect definition of the __ARM_ARCH macro for architectures greater than or equal to v8.1.
262+
258263
Android Support
259264
^^^^^^^^^^^^^^^
260265

clang/include/clang/Basic/Builtins.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@
2020
#include "llvm/ADT/StringRef.h"
2121
#include <cstring>
2222

23-
// VC++ defines 'alloca' as an object-like macro, which interferes with our
24-
// builtins.
25-
#undef alloca
26-
2723
namespace clang {
2824
class TargetInfo;
2925
class IdentifierTable;

clang/include/clang/Basic/Builtins.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,6 +1110,12 @@ def ReadCycleCounter : Builtin {
11101110
let Prototype = "unsigned long long int()";
11111111
}
11121112

1113+
def ReadSteadyCounter : Builtin {
1114+
let Spellings = ["__builtin_readsteadycounter"];
1115+
let Attributes = [NoThrow];
1116+
let Prototype = "unsigned long long int()";
1117+
}
1118+
11131119
def Trap : Builtin {
11141120
let Spellings = ["__builtin_trap"];
11151121
let Attributes = [NoThrow, NoReturn];

clang/include/clang/Driver/Options.td

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5612,7 +5612,7 @@ def print_rocm_search_dirs : Flag<["-", "--"], "print-rocm-search-dirs">,
56125612
HelpText<"Print the paths used for finding ROCm installation">,
56135613
Visibility<[ClangOption, CLOption]>;
56145614
def print_runtime_dir : Flag<["-", "--"], "print-runtime-dir">,
5615-
HelpText<"Print the directory pathname containing clangs runtime libraries">,
5615+
HelpText<"Print the directory pathname containing Clang's runtime libraries">,
56165616
Visibility<[ClangOption, CLOption]>;
56175617
def print_diagnostic_options : Flag<["-", "--"], "print-diagnostic-options">,
56185618
HelpText<"Print all of Clang's warning options">,
@@ -8860,8 +8860,8 @@ def _SLASH_ZW : CLJoined<"ZW">;
88608860
// clang-dxc Options
88618861
//===----------------------------------------------------------------------===//
88628862

8863-
def dxc_Group : OptionGroup<"<clang-dxc options>">, Visibility<[DXCOption]>,
8864-
HelpText<"dxc compatibility options">;
8863+
def dxc_Group : OptionGroup<"clang-dxc options">, Visibility<[DXCOption]>,
8864+
HelpText<"dxc compatibility options.">;
88658865
class DXCFlag<string name> : Option<["/", "-"], name, KIND_FLAG>,
88668866
Group<dxc_Group>, Visibility<[DXCOption]>;
88678867
class DXCJoinedOrSeparate<string name> : Option<["/", "-"], name,

clang/lib/Basic/Targets/AArch64.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,20 @@ void AArch64TargetInfo::getTargetDefines(const LangOptions &Opts,
367367

368368
// ACLE predefines. Many can only have one possible value on v8 AArch64.
369369
Builder.defineMacro("__ARM_ACLE", "200");
370-
Builder.defineMacro("__ARM_ARCH",
371-
std::to_string(ArchInfo->Version.getMajor()));
370+
371+
// __ARM_ARCH is defined as an integer value indicating the current ARM ISA.
372+
// For ISAs up to and including v8, __ARM_ARCH is equal to the major version
373+
// number. For ISAs from v8.1 onwards, __ARM_ARCH is scaled up to include the
374+
// minor version number, e.g. for ARM architecture ARMvX.Y:
375+
// __ARM_ARCH = X * 100 + Y.
376+
if (ArchInfo->Version.getMajor() == 8 && ArchInfo->Version.getMinor() == 0)
377+
Builder.defineMacro("__ARM_ARCH",
378+
std::to_string(ArchInfo->Version.getMajor()));
379+
else
380+
Builder.defineMacro("__ARM_ARCH",
381+
std::to_string(ArchInfo->Version.getMajor() * 100 +
382+
ArchInfo->Version.getMinor().value()));
383+
372384
Builder.defineMacro("__ARM_ARCH_PROFILE",
373385
std::string("'") + (char)ArchInfo->Profile + "'");
374386

clang/lib/Basic/Targets/ARM.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ void ARMTargetInfo::setArchInfo(llvm::ARM::ArchKind Kind) {
130130
SubArch = llvm::ARM::getSubArch(ArchKind);
131131
ArchProfile = llvm::ARM::parseArchProfile(SubArch);
132132
ArchVersion = llvm::ARM::parseArchVersion(SubArch);
133+
ArchMinorVersion = llvm::ARM::parseArchMinorVersion(SubArch);
133134

134135
// cache CPU related strings
135136
CPUAttr = getCPUAttr();
@@ -736,9 +737,16 @@ void ARMTargetInfo::getTargetDefines(const LangOptions &Opts,
736737
if (!CPUAttr.empty())
737738
Builder.defineMacro("__ARM_ARCH_" + CPUAttr + "__");
738739

739-
// ACLE 6.4.1 ARM/Thumb instruction set architecture
740-
// __ARM_ARCH is defined as an integer value indicating the current ARM ISA
741-
Builder.defineMacro("__ARM_ARCH", Twine(ArchVersion));
740+
// __ARM_ARCH is defined as an integer value indicating the current ARM ISA.
741+
// For ISAs up to and including v8, __ARM_ARCH is equal to the major version
742+
// number. For ISAs from v8.1 onwards, __ARM_ARCH is scaled up to include the
743+
// minor version number, e.g. for ARM architecture ARMvX.Y:
744+
// __ARM_ARCH = X * 100 + Y.
745+
if (ArchVersion >= 9 || ArchMinorVersion != 0)
746+
Builder.defineMacro("__ARM_ARCH",
747+
Twine(ArchVersion * 100 + ArchMinorVersion));
748+
else
749+
Builder.defineMacro("__ARM_ARCH", Twine(ArchVersion));
742750

743751
if (ArchVersion >= 8) {
744752
// ACLE 6.5.7 Crypto Extension

clang/lib/Basic/Targets/ARM.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class LLVM_LIBRARY_VISIBILITY ARMTargetInfo : public TargetInfo {
6060
llvm::ARM::ArchKind ArchKind = llvm::ARM::ArchKind::ARMV4T;
6161
llvm::ARM::ProfileKind ArchProfile;
6262
unsigned ArchVersion;
63+
unsigned ArchMinorVersion;
6364

6465
LLVM_PREFERRED_TYPE(FPUMode)
6566
unsigned FPU : 5;

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3523,6 +3523,10 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
35233523
Function *F = CGM.getIntrinsic(Intrinsic::readcyclecounter);
35243524
return RValue::get(Builder.CreateCall(F));
35253525
}
3526+
case Builtin::BI__builtin_readsteadycounter: {
3527+
Function *F = CGM.getIntrinsic(Intrinsic::readsteadycounter);
3528+
return RValue::get(Builder.CreateCall(F));
3529+
}
35263530
case Builtin::BI__builtin___clear_cache: {
35273531
Value *Begin = EmitScalarExpr(E->getArg(0));
35283532
Value *End = EmitScalarExpr(E->getArg(1));

clang/lib/CodeGen/CGCall.cpp

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,27 +1310,25 @@ static llvm::Value *CreateCoercedLoad(Address Src, llvm::Type *Ty,
13101310
// If coercing a fixed vector to a scalable vector for ABI compatibility, and
13111311
// the types match, use the llvm.vector.insert intrinsic to perform the
13121312
// conversion.
1313-
if (auto *ScalableDst = dyn_cast<llvm::ScalableVectorType>(Ty)) {
1314-
if (auto *FixedSrc = dyn_cast<llvm::FixedVectorType>(SrcTy)) {
1315-
// If we are casting a fixed i8 vector to a scalable 16 x i1 predicate
1313+
if (auto *ScalableDstTy = dyn_cast<llvm::ScalableVectorType>(Ty)) {
1314+
if (auto *FixedSrcTy = dyn_cast<llvm::FixedVectorType>(SrcTy)) {
1315+
// If we are casting a fixed i8 vector to a scalable i1 predicate
13161316
// vector, use a vector insert and bitcast the result.
1317-
bool NeedsBitcast = false;
1318-
auto PredType =
1319-
llvm::ScalableVectorType::get(CGF.Builder.getInt1Ty(), 16);
1320-
llvm::Type *OrigType = Ty;
1321-
if (ScalableDst == PredType &&
1322-
FixedSrc->getElementType() == CGF.Builder.getInt8Ty()) {
1323-
ScalableDst = llvm::ScalableVectorType::get(CGF.Builder.getInt8Ty(), 2);
1324-
NeedsBitcast = true;
1317+
if (ScalableDstTy->getElementType()->isIntegerTy(1) &&
1318+
ScalableDstTy->getElementCount().isKnownMultipleOf(8) &&
1319+
FixedSrcTy->getElementType()->isIntegerTy(8)) {
1320+
ScalableDstTy = llvm::ScalableVectorType::get(
1321+
FixedSrcTy->getElementType(),
1322+
ScalableDstTy->getElementCount().getKnownMinValue() / 8);
13251323
}
1326-
if (ScalableDst->getElementType() == FixedSrc->getElementType()) {
1324+
if (ScalableDstTy->getElementType() == FixedSrcTy->getElementType()) {
13271325
auto *Load = CGF.Builder.CreateLoad(Src);
1328-
auto *UndefVec = llvm::UndefValue::get(ScalableDst);
1326+
auto *UndefVec = llvm::UndefValue::get(ScalableDstTy);
13291327
auto *Zero = llvm::Constant::getNullValue(CGF.CGM.Int64Ty);
13301328
llvm::Value *Result = CGF.Builder.CreateInsertVector(
1331-
ScalableDst, UndefVec, Load, Zero, "cast.scalable");
1332-
if (NeedsBitcast)
1333-
Result = CGF.Builder.CreateBitCast(Result, OrigType);
1329+
ScalableDstTy, UndefVec, Load, Zero, "cast.scalable");
1330+
if (ScalableDstTy != Ty)
1331+
Result = CGF.Builder.CreateBitCast(Result, Ty);
13341332
return Result;
13351333
}
13361334
}
@@ -3281,13 +3279,14 @@ void CodeGenFunction::EmitFunctionProlog(const CGFunctionInfo &FI,
32813279
llvm::Value *Coerced = Fn->getArg(FirstIRArg);
32823280
if (auto *VecTyFrom =
32833281
dyn_cast<llvm::ScalableVectorType>(Coerced->getType())) {
3284-
// If we are casting a scalable 16 x i1 predicate vector to a fixed i8
3282+
// If we are casting a scalable i1 predicate vector to a fixed i8
32853283
// vector, bitcast the source and use a vector extract.
3286-
auto PredType =
3287-
llvm::ScalableVectorType::get(Builder.getInt1Ty(), 16);
3288-
if (VecTyFrom == PredType &&
3284+
if (VecTyFrom->getElementType()->isIntegerTy(1) &&
3285+
VecTyFrom->getElementCount().isKnownMultipleOf(8) &&
32893286
VecTyTo->getElementType() == Builder.getInt8Ty()) {
3290-
VecTyFrom = llvm::ScalableVectorType::get(Builder.getInt8Ty(), 2);
3287+
VecTyFrom = llvm::ScalableVectorType::get(
3288+
VecTyTo->getElementType(),
3289+
VecTyFrom->getElementCount().getKnownMinValue() / 8);
32913290
Coerced = Builder.CreateBitCast(Coerced, VecTyFrom);
32923291
}
32933292
if (VecTyFrom->getElementType() == VecTyTo->getElementType()) {
@@ -5984,12 +5983,13 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
59845983
// If coercing a fixed vector from a scalable vector for ABI
59855984
// compatibility, and the types match, use the llvm.vector.extract
59865985
// intrinsic to perform the conversion.
5987-
if (auto *FixedDst = dyn_cast<llvm::FixedVectorType>(RetIRTy)) {
5986+
if (auto *FixedDstTy = dyn_cast<llvm::FixedVectorType>(RetIRTy)) {
59885987
llvm::Value *V = CI;
5989-
if (auto *ScalableSrc = dyn_cast<llvm::ScalableVectorType>(V->getType())) {
5990-
if (FixedDst->getElementType() == ScalableSrc->getElementType()) {
5988+
if (auto *ScalableSrcTy =
5989+
dyn_cast<llvm::ScalableVectorType>(V->getType())) {
5990+
if (FixedDstTy->getElementType() == ScalableSrcTy->getElementType()) {
59915991
llvm::Value *Zero = llvm::Constant::getNullValue(CGM.Int64Ty);
5992-
V = Builder.CreateExtractVector(FixedDst, V, Zero, "cast.fixed");
5992+
V = Builder.CreateExtractVector(FixedDstTy, V, Zero, "cast.fixed");
59935993
return RValue::get(V);
59945994
}
59955995
}

clang/lib/CodeGen/CGExprScalar.cpp

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2163,26 +2163,24 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
21632163
// If Src is a fixed vector and Dst is a scalable vector, and both have the
21642164
// same element type, use the llvm.vector.insert intrinsic to perform the
21652165
// bitcast.
2166-
if (const auto *FixedSrc = dyn_cast<llvm::FixedVectorType>(SrcTy)) {
2167-
if (const auto *ScalableDst = dyn_cast<llvm::ScalableVectorType>(DstTy)) {
2168-
// If we are casting a fixed i8 vector to a scalable 16 x i1 predicate
2166+
if (auto *FixedSrcTy = dyn_cast<llvm::FixedVectorType>(SrcTy)) {
2167+
if (auto *ScalableDstTy = dyn_cast<llvm::ScalableVectorType>(DstTy)) {
2168+
// If we are casting a fixed i8 vector to a scalable i1 predicate
21692169
// vector, use a vector insert and bitcast the result.
2170-
bool NeedsBitCast = false;
2171-
auto PredType = llvm::ScalableVectorType::get(Builder.getInt1Ty(), 16);
2172-
llvm::Type *OrigType = DstTy;
2173-
if (ScalableDst == PredType &&
2174-
FixedSrc->getElementType() == Builder.getInt8Ty()) {
2175-
DstTy = llvm::ScalableVectorType::get(Builder.getInt8Ty(), 2);
2176-
ScalableDst = cast<llvm::ScalableVectorType>(DstTy);
2177-
NeedsBitCast = true;
2170+
if (ScalableDstTy->getElementType()->isIntegerTy(1) &&
2171+
ScalableDstTy->getElementCount().isKnownMultipleOf(8) &&
2172+
FixedSrcTy->getElementType()->isIntegerTy(8)) {
2173+
ScalableDstTy = llvm::ScalableVectorType::get(
2174+
FixedSrcTy->getElementType(),
2175+
ScalableDstTy->getElementCount().getKnownMinValue() / 8);
21782176
}
2179-
if (FixedSrc->getElementType() == ScalableDst->getElementType()) {
2180-
llvm::Value *UndefVec = llvm::UndefValue::get(DstTy);
2177+
if (FixedSrcTy->getElementType() == ScalableDstTy->getElementType()) {
2178+
llvm::Value *UndefVec = llvm::UndefValue::get(ScalableDstTy);
21812179
llvm::Value *Zero = llvm::Constant::getNullValue(CGF.CGM.Int64Ty);
21822180
llvm::Value *Result = Builder.CreateInsertVector(
2183-
DstTy, UndefVec, Src, Zero, "cast.scalable");
2184-
if (NeedsBitCast)
2185-
Result = Builder.CreateBitCast(Result, OrigType);
2181+
ScalableDstTy, UndefVec, Src, Zero, "cast.scalable");
2182+
if (Result->getType() != DstTy)
2183+
Result = Builder.CreateBitCast(Result, DstTy);
21862184
return Result;
21872185
}
21882186
}
@@ -2191,18 +2189,19 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
21912189
// If Src is a scalable vector and Dst is a fixed vector, and both have the
21922190
// same element type, use the llvm.vector.extract intrinsic to perform the
21932191
// bitcast.
2194-
if (const auto *ScalableSrc = dyn_cast<llvm::ScalableVectorType>(SrcTy)) {
2195-
if (const auto *FixedDst = dyn_cast<llvm::FixedVectorType>(DstTy)) {
2196-
// If we are casting a scalable 16 x i1 predicate vector to a fixed i8
2192+
if (auto *ScalableSrcTy = dyn_cast<llvm::ScalableVectorType>(SrcTy)) {
2193+
if (auto *FixedDstTy = dyn_cast<llvm::FixedVectorType>(DstTy)) {
2194+
// If we are casting a scalable i1 predicate vector to a fixed i8
21972195
// vector, bitcast the source and use a vector extract.
2198-
auto PredType = llvm::ScalableVectorType::get(Builder.getInt1Ty(), 16);
2199-
if (ScalableSrc == PredType &&
2200-
FixedDst->getElementType() == Builder.getInt8Ty()) {
2201-
SrcTy = llvm::ScalableVectorType::get(Builder.getInt8Ty(), 2);
2202-
ScalableSrc = cast<llvm::ScalableVectorType>(SrcTy);
2203-
Src = Builder.CreateBitCast(Src, SrcTy);
2196+
if (ScalableSrcTy->getElementType()->isIntegerTy(1) &&
2197+
ScalableSrcTy->getElementCount().isKnownMultipleOf(8) &&
2198+
FixedDstTy->getElementType()->isIntegerTy(8)) {
2199+
ScalableSrcTy = llvm::ScalableVectorType::get(
2200+
FixedDstTy->getElementType(),
2201+
ScalableSrcTy->getElementCount().getKnownMinValue() / 8);
2202+
Src = Builder.CreateBitCast(Src, ScalableSrcTy);
22042203
}
2205-
if (ScalableSrc->getElementType() == FixedDst->getElementType()) {
2204+
if (ScalableSrcTy->getElementType() == FixedDstTy->getElementType()) {
22062205
llvm::Value *Zero = llvm::Constant::getNullValue(CGF.CGM.Int64Ty);
22072206
return Builder.CreateExtractVector(DstTy, Src, Zero, "cast.fixed");
22082207
}

0 commit comments

Comments
 (0)