Skip to content

Commit 1e7085b

Browse files
SC llvm teamSC llvm team
authored andcommitted
Merged main:243588df15ed into amd-gfx:467adee02669
Local branch amd-gfx 467adee Merged main:4c1c32c377c4 into amd-gfx:019a2b2df387 Remote branch main 243588d [bazel] add missing dependency to //clang:ast after 1c6c01f
2 parents 467adee + 243588d commit 1e7085b

File tree

71 files changed

+1724
-1022
lines changed

Some content is hidden

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

71 files changed

+1724
-1022
lines changed

.github/workflows/pr-code-format.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ jobs:
1010
- name: Fetch LLVM sources
1111
uses: actions/checkout@v4
1212
with:
13-
fetch-depth: 2
13+
fetch-depth: 2 # Fetches only the last 2 commits
1414

1515
- name: Get changed files
1616
id: changed-files
1717
uses: tj-actions/changed-files@v39
1818
with:
1919
separator: ","
20-
fetch_depth: 100 # Fetches only the last 10 commits
20+
fetch_depth: 2000 # Fetches only the last 2000 commits
2121

2222
- name: "Listed files"
2323
run: |

.github/workflows/scorecard.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# This workflow uses actions that are not certified by GitHub. They are provided
2+
# by a third-party and are governed by separate terms of service, privacy
3+
# policy, and support documentation.
4+
5+
# Check current LLVM-Project results here: https://securityscorecards.dev/viewer/?uri=github.com/llvm/llvm-project
6+
7+
name: Scorecard supply-chain security
8+
on:
9+
# For Branch-Protection check. Only the default branch is supported. See
10+
# https://github.com/ossf/scorecard/blob/main/docs/checks.md#branch-protection
11+
branch_protection_rule:
12+
# To guarantee Maintained check is occasionally updated. See
13+
# https://github.com/ossf/scorecard/blob/main/docs/checks.md#maintained
14+
schedule:
15+
- cron: '38 20 * * 4'
16+
push:
17+
branches: [ "main" ]
18+
19+
# Declare default permissions as read only.
20+
permissions:
21+
contents: read
22+
23+
jobs:
24+
analysis:
25+
name: Scorecard analysis
26+
runs-on: ubuntu-latest
27+
permissions:
28+
# Needed to upload the results to code-scanning dashboard.
29+
security-events: write
30+
# Needed to publish results and get a badge (see publish_results below).
31+
id-token: write
32+
33+
steps:
34+
- name: "Checkout code"
35+
uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
36+
with:
37+
persist-credentials: false
38+
39+
- name: "Run analysis"
40+
uses: ossf/scorecard-action@e38b1902ae4f44df626f11ba0734b14fb91f8f86 # v2.1.2
41+
with:
42+
results_file: results.sarif
43+
results_format: sarif
44+
45+
# - Publish results to OpenSSF REST API for easy access by consumers
46+
# - Allows the repository to include the Scorecard badge.
47+
# - See https://github.com/ossf/scorecard-action#publishing-results.
48+
publish_results: true
49+
50+
# Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF
51+
# format to the repository Actions tab.
52+
- name: "Upload artifact"
53+
uses: actions/upload-artifact@3cea5372237819ed00197afe530f5a7ea3e805c8 # v3.1.0
54+
with:
55+
name: SARIF file
56+
path: results.sarif
57+
retention-days: 5
58+
59+
# Upload the results to GitHub's code scanning dashboard.
60+
- name: "Upload to code-scanning"
61+
uses: github/codeql-action/upload-sarif@17573ee1cc1b9d061760f3a006fc4aac4f944fd5 # v2.2.4
62+
with:
63+
sarif_file: results.sarif

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# The LLVM Compiler Infrastructure
22

3+
[![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/llvm/llvm-project/badge)](https://securityscorecards.dev/viewer/?uri=github.com/llvm/llvm-project)
4+
35
Welcome to the LLVM project!
46

57
This repository contains the source code for LLVM, a toolkit for the

clang-tools-extra/modularize/ModularizeUtilities.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ std::error_code ModularizeUtilities::loadModuleMap(
322322
// Walks the modules and collects referenced headers into
323323
// HeaderFileNames.
324324
bool ModularizeUtilities::collectModuleMapHeaders(clang::ModuleMap *ModMap) {
325-
SmallVector<std::pair<StringRef, const Module *>, 0> Vec;
325+
SmallVector<std::pair<StringRef, const clang::Module *>, 0> Vec;
326326
for (auto &M : ModMap->modules())
327327
Vec.emplace_back(M.first(), M.second);
328328
llvm::sort(Vec, llvm::less_first());
@@ -349,14 +349,14 @@ bool ModularizeUtilities::collectModuleHeaders(const clang::Module &Mod) {
349349
for (auto *Submodule : Mod.submodules())
350350
collectModuleHeaders(*Submodule);
351351

352-
if (std::optional<Module::Header> UmbrellaHeader =
352+
if (std::optional<clang::Module::Header> UmbrellaHeader =
353353
Mod.getUmbrellaHeaderAsWritten()) {
354354
std::string HeaderPath = getCanonicalPath(UmbrellaHeader->Entry.getName());
355355
// Collect umbrella header.
356356
HeaderFileNames.push_back(HeaderPath);
357357

358358
// FUTURE: When needed, umbrella header header collection goes here.
359-
} else if (std::optional<Module::DirectoryName> UmbrellaDir =
359+
} else if (std::optional<clang::Module::DirectoryName> UmbrellaDir =
360360
Mod.getUmbrellaDirAsWritten()) {
361361
// If there normal headers, assume these are umbrellas and skip collection.
362362
if (Mod.Headers->size() == 0) {

clang/include/clang/AST/Attr.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@
1919
#include "clang/AST/Type.h"
2020
#include "clang/Basic/AttrKinds.h"
2121
#include "clang/Basic/AttributeCommonInfo.h"
22-
#include "clang/Basic/LangOptions.h"
2322
#include "clang/Basic/LLVM.h"
23+
#include "clang/Basic/LangOptions.h"
2424
#include "clang/Basic/OpenMPKinds.h"
2525
#include "clang/Basic/Sanitizers.h"
2626
#include "clang/Basic/SourceLocation.h"
27+
#include "llvm/Frontend/HLSL/HLSLResource.h"
2728
#include "llvm/Support/ErrorHandling.h"
2829
#include "llvm/Support/VersionTuple.h"
2930
#include "llvm/Support/raw_ostream.h"

clang/include/clang/Basic/Attr.td

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -277,23 +277,28 @@ class DefaultIntArgument<string name, int default> : IntArgument<name, 1> {
277277
int Default = default;
278278
}
279279

280-
// This argument is more complex, it includes the enumerator type name,
281-
// a list of strings to accept, and a list of enumerators to map them to.
280+
// This argument is more complex, it includes the enumerator type
281+
// name, whether the enum type is externally defined, a list of
282+
// strings to accept, and a list of enumerators to map them to.
282283
class EnumArgument<string name, string type, list<string> values,
283-
list<string> enums, bit opt = 0, bit fake = 0>
284+
list<string> enums, bit opt = 0, bit fake = 0,
285+
bit isExternalType = 0>
284286
: Argument<name, opt, fake> {
285287
string Type = type;
286288
list<string> Values = values;
287289
list<string> Enums = enums;
290+
bit IsExternalType = isExternalType;
288291
}
289292

290293
// FIXME: There should be a VariadicArgument type that takes any other type
291294
// of argument and generates the appropriate type.
292295
class VariadicEnumArgument<string name, string type, list<string> values,
293-
list<string> enums> : Argument<name, 1> {
296+
list<string> enums, bit isExternalType = 0>
297+
: Argument<name, 1> {
294298
string Type = type;
295299
list<string> Values = values;
296300
list<string> Enums = enums;
301+
bit IsExternalType = isExternalType;
297302
}
298303

299304
// This handles one spelling of an attribute.
@@ -4182,26 +4187,26 @@ def HLSLResource : InheritableAttr {
41824187
let Spellings = [];
41834188
let Subjects = SubjectList<[Struct]>;
41844189
let LangOpts = [HLSL];
4185-
let Args = [EnumArgument<"ResourceType", "ResourceClass",
4190+
let Args = [EnumArgument<"ResourceClass", "llvm::hlsl::ResourceClass",
41864191
["SRV", "UAV", "CBuffer", "Sampler"],
4187-
["SRV", "UAV", "CBuffer", "Sampler"]
4188-
>,
4189-
EnumArgument<"ResourceShape", "ResourceKind",
4192+
["SRV", "UAV", "CBuffer", "Sampler"],
4193+
/*opt=*/0, /*fake=*/0, /*isExternalType=*/1>,
4194+
EnumArgument<"ResourceKind", "llvm::hlsl::ResourceKind",
41904195
["Texture1D", "Texture2D", "Texture2DMS",
41914196
"Texture3D", "TextureCube", "Texture1DArray",
41924197
"Texture2DArray", "Texture2DMSArray",
41934198
"TextureCubeArray", "TypedBuffer", "RawBuffer",
4194-
"StructuredBuffer", "CBufferKind", "SamplerKind",
4195-
"TBuffer", "RTAccelerationStructure", "FeedbackTexture2D",
4196-
"FeedbackTexture2DArray"],
4199+
"StructuredBuffer", "CBuffer", "Sampler",
4200+
"TBuffer", "RTAccelerationStructure",
4201+
"FeedbackTexture2D", "FeedbackTexture2DArray"],
41974202
["Texture1D", "Texture2D", "Texture2DMS",
41984203
"Texture3D", "TextureCube", "Texture1DArray",
41994204
"Texture2DArray", "Texture2DMSArray",
42004205
"TextureCubeArray", "TypedBuffer", "RawBuffer",
4201-
"StructuredBuffer", "CBufferKind", "SamplerKind",
4202-
"TBuffer", "RTAccelerationStructure", "FeedbackTexture2D",
4203-
"FeedbackTexture2DArray"]
4204-
>
4206+
"StructuredBuffer", "CBuffer", "Sampler",
4207+
"TBuffer", "RTAccelerationStructure",
4208+
"FeedbackTexture2D", "FeedbackTexture2DArray"],
4209+
/*opt=*/0, /*fake=*/0, /*isExternalType=*/1>
42054210
];
42064211
let Documentation = [InternalOnly];
42074212
}

clang/include/clang/Driver/Options.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8326,3 +8326,5 @@ def dxc_disable_validation : DXCFlag<"Vd">,
83268326
def : Option<["/", "-"], "Qembed_debug", KIND_FLAG>, Group<dxc_Group>,
83278327
Flags<[Ignored]>, Visibility<[DXCOption]>,
83288328
HelpText<"Embed PDB in shader container (ignored)">;
8329+
def spirv : DXCFlag<"spirv">,
8330+
HelpText<"Generate SPIR-V code">;

clang/lib/CodeGen/CGHLSLRuntime.cpp

Lines changed: 3 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -223,56 +223,6 @@ void CGHLSLRuntime::addBufferResourceAnnotation(llvm::GlobalVariable *GV,
223223
ResourceMD->addOperand(Res.getMetadata());
224224
}
225225

226-
static llvm::hlsl::ResourceKind
227-
castResourceShapeToResourceKind(HLSLResourceAttr::ResourceKind RK) {
228-
switch (RK) {
229-
case HLSLResourceAttr::ResourceKind::Texture1D:
230-
return llvm::hlsl::ResourceKind::Texture1D;
231-
case HLSLResourceAttr::ResourceKind::Texture2D:
232-
return llvm::hlsl::ResourceKind::Texture2D;
233-
case HLSLResourceAttr::ResourceKind::Texture2DMS:
234-
return llvm::hlsl::ResourceKind::Texture2DMS;
235-
case HLSLResourceAttr::ResourceKind::Texture3D:
236-
return llvm::hlsl::ResourceKind::Texture3D;
237-
case HLSLResourceAttr::ResourceKind::TextureCube:
238-
return llvm::hlsl::ResourceKind::TextureCube;
239-
case HLSLResourceAttr::ResourceKind::Texture1DArray:
240-
return llvm::hlsl::ResourceKind::Texture1DArray;
241-
case HLSLResourceAttr::ResourceKind::Texture2DArray:
242-
return llvm::hlsl::ResourceKind::Texture2DArray;
243-
case HLSLResourceAttr::ResourceKind::Texture2DMSArray:
244-
return llvm::hlsl::ResourceKind::Texture2DMSArray;
245-
case HLSLResourceAttr::ResourceKind::TextureCubeArray:
246-
return llvm::hlsl::ResourceKind::TextureCubeArray;
247-
case HLSLResourceAttr::ResourceKind::TypedBuffer:
248-
return llvm::hlsl::ResourceKind::TypedBuffer;
249-
case HLSLResourceAttr::ResourceKind::RawBuffer:
250-
return llvm::hlsl::ResourceKind::RawBuffer;
251-
case HLSLResourceAttr::ResourceKind::StructuredBuffer:
252-
return llvm::hlsl::ResourceKind::StructuredBuffer;
253-
case HLSLResourceAttr::ResourceKind::CBufferKind:
254-
return llvm::hlsl::ResourceKind::CBuffer;
255-
case HLSLResourceAttr::ResourceKind::SamplerKind:
256-
return llvm::hlsl::ResourceKind::Sampler;
257-
case HLSLResourceAttr::ResourceKind::TBuffer:
258-
return llvm::hlsl::ResourceKind::TBuffer;
259-
case HLSLResourceAttr::ResourceKind::RTAccelerationStructure:
260-
return llvm::hlsl::ResourceKind::RTAccelerationStructure;
261-
case HLSLResourceAttr::ResourceKind::FeedbackTexture2D:
262-
return llvm::hlsl::ResourceKind::FeedbackTexture2D;
263-
case HLSLResourceAttr::ResourceKind::FeedbackTexture2DArray:
264-
return llvm::hlsl::ResourceKind::FeedbackTexture2DArray;
265-
}
266-
// Make sure to update HLSLResourceAttr::ResourceKind when add new Kind to
267-
// hlsl::ResourceKind. Assume FeedbackTexture2DArray is the last enum for
268-
// HLSLResourceAttr::ResourceKind.
269-
static_assert(
270-
static_cast<uint32_t>(
271-
HLSLResourceAttr::ResourceKind::FeedbackTexture2DArray) ==
272-
(static_cast<uint32_t>(llvm::hlsl::ResourceKind::NumEntries) - 2));
273-
llvm_unreachable("all switch cases should be covered");
274-
}
275-
276226
void CGHLSLRuntime::annotateHLSLResource(const VarDecl *D, GlobalVariable *GV) {
277227
const Type *Ty = D->getType()->getPointeeOrArrayElementType();
278228
if (!Ty)
@@ -284,15 +234,12 @@ void CGHLSLRuntime::annotateHLSLResource(const VarDecl *D, GlobalVariable *GV) {
284234
if (!Attr)
285235
return;
286236

287-
HLSLResourceAttr::ResourceClass RC = Attr->getResourceType();
288-
llvm::hlsl::ResourceKind RK =
289-
castResourceShapeToResourceKind(Attr->getResourceShape());
237+
llvm::hlsl::ResourceClass RC = Attr->getResourceClass();
238+
llvm::hlsl::ResourceKind RK = Attr->getResourceKind();
290239

291240
QualType QT(Ty, 0);
292241
BufferResBinding Binding(D->getAttr<HLSLResourceBindingAttr>());
293-
addBufferResourceAnnotation(GV, QT.getAsString(),
294-
static_cast<llvm::hlsl::ResourceClass>(RC), RK,
295-
Binding);
242+
addBufferResourceAnnotation(GV, QT.getAsString(), RC, RK, Binding);
296243
}
297244

298245
CGHLSLRuntime::BufferResBinding::BufferResBinding(

clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp

Lines changed: 28 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -803,8 +803,30 @@ void CGOpenMPRuntimeGPU::emitKernelDeinit(CodeGenFunction &CGF,
803803
if (!IsSPMD)
804804
emitGenericVarsEpilog(CGF);
805805

806+
// This is temporary until we remove the fixed sized buffer.
807+
ASTContext &C = CGM.getContext();
808+
RecordDecl *StaticRD = C.buildImplicitRecord(
809+
"_openmp_teams_reduction_type_$_", RecordDecl::TagKind::TTK_Union);
810+
StaticRD->startDefinition();
811+
for (const RecordDecl *TeamReductionRec : TeamsReductions) {
812+
QualType RecTy = C.getRecordType(TeamReductionRec);
813+
auto *Field = FieldDecl::Create(
814+
C, StaticRD, SourceLocation(), SourceLocation(), nullptr, RecTy,
815+
C.getTrivialTypeSourceInfo(RecTy, SourceLocation()),
816+
/*BW=*/nullptr, /*Mutable=*/false,
817+
/*InitStyle=*/ICIS_NoInit);
818+
Field->setAccess(AS_public);
819+
StaticRD->addDecl(Field);
820+
}
821+
StaticRD->completeDefinition();
822+
QualType StaticTy = C.getRecordType(StaticRD);
823+
llvm::Type *LLVMReductionsBufferTy =
824+
CGM.getTypes().ConvertTypeForMem(StaticTy);
825+
const auto &DL = CGM.getModule().getDataLayout();
826+
uint64_t BufferSize =
827+
DL.getTypeAllocSize(LLVMReductionsBufferTy).getFixedValue();
806828
CGBuilderTy &Bld = CGF.Builder;
807-
OMPBuilder.createTargetDeinit(Bld);
829+
OMPBuilder.createTargetDeinit(Bld, BufferSize);
808830
}
809831

810832
void CGOpenMPRuntimeGPU::emitSPMDKernel(const OMPExecutableDirective &D,
@@ -2998,15 +3020,10 @@ void CGOpenMPRuntimeGPU::emitReduction(
29983020
CGM.getContext(), PrivatesReductions, std::nullopt, VarFieldMap,
29993021
C.getLangOpts().OpenMPCUDAReductionBufNum);
30003022
TeamsReductions.push_back(TeamReductionRec);
3001-
if (!KernelTeamsReductionPtr) {
3002-
KernelTeamsReductionPtr = new llvm::GlobalVariable(
3003-
CGM.getModule(), CGM.VoidPtrTy, /*isConstant=*/true,
3004-
llvm::GlobalValue::InternalLinkage, nullptr,
3005-
"_openmp_teams_reductions_buffer_$_$ptr");
3006-
}
3007-
llvm::Value *GlobalBufferPtr = CGF.EmitLoadOfScalar(
3008-
Address(KernelTeamsReductionPtr, CGF.VoidPtrTy, CGM.getPointerAlign()),
3009-
/*Volatile=*/false, C.getPointerType(C.VoidPtrTy), Loc);
3023+
auto *KernelTeamsReductionPtr = CGF.EmitRuntimeCall(
3024+
OMPBuilder.getOrCreateRuntimeFunction(
3025+
CGM.getModule(), OMPRTL___kmpc_reduction_get_fixed_buffer),
3026+
{}, "_openmp_teams_reductions_buffer_$_$ptr");
30103027
llvm::Value *GlobalToBufferCpyFn = ::emitListToGlobalCopyFunction(
30113028
CGM, Privates, ReductionArrayTy, Loc, TeamReductionRec, VarFieldMap);
30123029
llvm::Value *GlobalToBufferRedFn = ::emitListToGlobalReduceFunction(
@@ -3021,7 +3038,7 @@ void CGOpenMPRuntimeGPU::emitReduction(
30213038
llvm::Value *Args[] = {
30223039
RTLoc,
30233040
ThreadId,
3024-
GlobalBufferPtr,
3041+
KernelTeamsReductionPtr,
30253042
CGF.Builder.getInt32(C.getLangOpts().OpenMPCUDAReductionBufNum),
30263043
RL,
30273044
ShuffleAndReduceFn,
@@ -3654,42 +3671,6 @@ void CGOpenMPRuntimeGPU::processRequiresDirective(
36543671
CGOpenMPRuntime::processRequiresDirective(D);
36553672
}
36563673

3657-
void CGOpenMPRuntimeGPU::clear() {
3658-
3659-
if (!TeamsReductions.empty()) {
3660-
ASTContext &C = CGM.getContext();
3661-
RecordDecl *StaticRD = C.buildImplicitRecord(
3662-
"_openmp_teams_reduction_type_$_", RecordDecl::TagKind::TTK_Union);
3663-
StaticRD->startDefinition();
3664-
for (const RecordDecl *TeamReductionRec : TeamsReductions) {
3665-
QualType RecTy = C.getRecordType(TeamReductionRec);
3666-
auto *Field = FieldDecl::Create(
3667-
C, StaticRD, SourceLocation(), SourceLocation(), nullptr, RecTy,
3668-
C.getTrivialTypeSourceInfo(RecTy, SourceLocation()),
3669-
/*BW=*/nullptr, /*Mutable=*/false,
3670-
/*InitStyle=*/ICIS_NoInit);
3671-
Field->setAccess(AS_public);
3672-
StaticRD->addDecl(Field);
3673-
}
3674-
StaticRD->completeDefinition();
3675-
QualType StaticTy = C.getRecordType(StaticRD);
3676-
llvm::Type *LLVMReductionsBufferTy =
3677-
CGM.getTypes().ConvertTypeForMem(StaticTy);
3678-
// FIXME: nvlink does not handle weak linkage correctly (object with the
3679-
// different size are reported as erroneous).
3680-
// Restore CommonLinkage as soon as nvlink is fixed.
3681-
auto *GV = new llvm::GlobalVariable(
3682-
CGM.getModule(), LLVMReductionsBufferTy,
3683-
/*isConstant=*/false, llvm::GlobalValue::InternalLinkage,
3684-
llvm::Constant::getNullValue(LLVMReductionsBufferTy),
3685-
"_openmp_teams_reductions_buffer_$_");
3686-
KernelTeamsReductionPtr->setInitializer(
3687-
llvm::ConstantExpr::getPointerBitCastOrAddrSpaceCast(GV,
3688-
CGM.VoidPtrTy));
3689-
}
3690-
CGOpenMPRuntime::clear();
3691-
}
3692-
36933674
llvm::Value *CGOpenMPRuntimeGPU::getGPUNumThreads(CodeGenFunction &CGF) {
36943675
CGBuilderTy &Bld = CGF.Builder;
36953676
llvm::Module *M = &CGF.CGM.getModule();

0 commit comments

Comments
 (0)