Skip to content

Commit 5a5869e

Browse files
committed
merge main into amd-staging
2 parents 011e73b + a9ab8a0 commit 5a5869e

File tree

860 files changed

+5648
-74169
lines changed

Some content is hidden

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

860 files changed

+5648
-74169
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,10 @@ Bug Fixes to Attribute Support
402402
or too few attribute argument indicies for the specified callback function.
403403
(#GH47451)
404404

405+
- No longer crashing on ``__attribute__((align_value(N)))`` during template
406+
instantiation when the function parameter type is not a pointer or reference.
407+
(#GH26612)
408+
405409
Bug Fixes to C++ Support
406410
^^^^^^^^^^^^^^^^^^^^^^^^
407411

clang/include/clang/AST/DeclCXX.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4166,7 +4166,7 @@ class StaticAssertDecl : public Decl {
41664166
/// DecompositionDecl of type 'int (&)[3]'.
41674167
class BindingDecl : public ValueDecl {
41684168
/// The declaration that this binding binds to part of.
4169-
ValueDecl *Decomp;
4169+
ValueDecl *Decomp = nullptr;
41704170
/// The binding represented by this declaration. References to this
41714171
/// declaration are effectively equivalent to this expression (except
41724172
/// that it is only evaluated once at the point of declaration of the

clang/include/clang/AST/OpenACCClause.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class OpenACCClause {
3838
OpenACCClauseKind getClauseKind() const { return Kind; }
3939
SourceLocation getBeginLoc() const { return Location.getBegin(); }
4040
SourceLocation getEndLoc() const { return Location.getEnd(); }
41+
SourceRange getSourceRange() const { return Location; }
4142

4243
static bool classof(const OpenACCClause *) { return true; }
4344

@@ -1315,11 +1316,13 @@ template <class Impl> class OpenACCClauseVisitor {
13151316
switch (C->getClauseKind()) {
13161317
#define VISIT_CLAUSE(CLAUSE_NAME) \
13171318
case OpenACCClauseKind::CLAUSE_NAME: \
1318-
Visit##CLAUSE_NAME##Clause(*cast<OpenACC##CLAUSE_NAME##Clause>(C)); \
1319+
getDerived().Visit##CLAUSE_NAME##Clause( \
1320+
*cast<OpenACC##CLAUSE_NAME##Clause>(C)); \
13191321
return;
13201322
#define CLAUSE_ALIAS(ALIAS_NAME, CLAUSE_NAME, DEPRECATED) \
13211323
case OpenACCClauseKind::ALIAS_NAME: \
1322-
Visit##CLAUSE_NAME##Clause(*cast<OpenACC##CLAUSE_NAME##Clause>(C)); \
1324+
getDerived().Visit##CLAUSE_NAME##Clause( \
1325+
*cast<OpenACC##CLAUSE_NAME##Clause>(C)); \
13231326
return;
13241327
#include "clang/Basic/OpenACCClauses.def"
13251328

@@ -1332,7 +1335,7 @@ template <class Impl> class OpenACCClauseVisitor {
13321335
#define VISIT_CLAUSE(CLAUSE_NAME) \
13331336
void Visit##CLAUSE_NAME##Clause( \
13341337
const OpenACC##CLAUSE_NAME##Clause &Clause) { \
1335-
return getDerived().Visit##CLAUSE_NAME##Clause(Clause); \
1338+
return getDerived().VisitClause(Clause); \
13361339
}
13371340

13381341
#include "clang/Basic/OpenACCClauses.def"

clang/include/clang/Sema/Sema.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4510,7 +4510,7 @@ class Sema final : public SemaBase {
45104510
getAttrLoc(const AttrInfo &AL) {
45114511
return AL.getLocation();
45124512
}
4513-
SourceLocation getAttrLoc(const ParsedAttr &AL);
4513+
SourceLocation getAttrLoc(const AttributeCommonInfo &CI);
45144514

45154515
/// If Expr is a valid integer constant, get the value of the integer
45164516
/// expression and return success or failure. May output an error.

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6823,7 +6823,7 @@ bool Compiler<Emitter>::emitDestruction(const Descriptor *Desc,
68236823
return true;
68246824
}
68256825

6826-
if (size_t N = Desc->getNumElems()) {
6826+
if (unsigned N = Desc->getNumElems()) {
68276827
for (ssize_t I = N - 1; I >= 0; --I) {
68286828
if (!this->emitConstUint64(I, Loc))
68296829
return false;

clang/lib/Basic/Targets/SPIR.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,20 @@ class LLVM_LIBRARY_VISIBILITY SPIRV64TargetInfo : public BaseSPIRVTargetInfo {
374374
const llvm::omp::GV &getGridValue() const override {
375375
return llvm::omp::SPIRVGridValues;
376376
}
377+
378+
std::optional<LangAS> getConstantAddressSpace() const override {
379+
return ConstantAS;
380+
}
381+
void adjust(DiagnosticsEngine &Diags, LangOptions &Opts) override {
382+
BaseSPIRVTargetInfo::adjust(Diags, Opts);
383+
// opencl_constant will map to UniformConstant in SPIR-V
384+
if (Opts.OpenCL)
385+
ConstantAS = LangAS::opencl_constant;
386+
}
387+
388+
private:
389+
// opencl_global will map to CrossWorkgroup in SPIR-V
390+
LangAS ConstantAS = LangAS::opencl_global;
377391
};
378392

379393
class LLVM_LIBRARY_VISIBILITY SPIRV64AMDGCNTargetInfo final

clang/lib/CIR/CodeGen/CIRGenFunction.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,19 @@ class CIRGenFunction : public CIRGenTypeCache {
570570
//===--------------------------------------------------------------------===//
571571
// OpenACC Emission
572572
//===--------------------------------------------------------------------===//
573+
private:
574+
template <typename Op>
575+
mlir::LogicalResult
576+
emitOpenACCOp(mlir::Location start,
577+
llvm::ArrayRef<const OpenACCClause *> clauses);
578+
// Function to do the basic implementation of an operation with an Associated
579+
// Statement. Models AssociatedStmtConstruct.
580+
template <typename Op, typename TermOp>
581+
mlir::LogicalResult
582+
emitOpenACCOpAssociatedStmt(mlir::Location start, mlir::Location end,
583+
llvm::ArrayRef<const OpenACCClause *> clauses,
584+
const Stmt *associatedStmt);
585+
573586
public:
574587
mlir::LogicalResult
575588
emitOpenACCComputeConstruct(const OpenACCComputeConstruct &s);

clang/lib/CIR/CodeGen/CIRGenStmtOpenACC.cpp

Lines changed: 129 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,143 @@
1212

1313
#include "CIRGenBuilder.h"
1414
#include "CIRGenFunction.h"
15+
#include "clang/AST/OpenACCClause.h"
1516
#include "clang/AST/StmtOpenACC.h"
1617

18+
#include "mlir/Dialect/OpenACC/OpenACC.h"
19+
1720
using namespace clang;
1821
using namespace clang::CIRGen;
1922
using namespace cir;
23+
using namespace mlir::acc;
24+
25+
namespace {
26+
class OpenACCClauseCIREmitter final
27+
: public OpenACCClauseVisitor<OpenACCClauseCIREmitter> {
28+
CIRGenModule &cgm;
29+
30+
struct AttributeData {
31+
// Value of the 'default' attribute, added on 'data' and 'compute'/etc
32+
// constructs as a 'default-attr'.
33+
std::optional<ClauseDefaultValue> defaultVal = std::nullopt;
34+
} attrData;
35+
36+
void clauseNotImplemented(const OpenACCClause &c) {
37+
cgm.errorNYI(c.getSourceRange(), "OpenACC Clause", c.getClauseKind());
38+
}
39+
40+
public:
41+
OpenACCClauseCIREmitter(CIRGenModule &cgm) : cgm(cgm) {}
42+
43+
void VisitClause(const OpenACCClause &clause) {
44+
clauseNotImplemented(clause);
45+
}
46+
47+
void VisitDefaultClause(const OpenACCDefaultClause &clause) {
48+
switch (clause.getDefaultClauseKind()) {
49+
case OpenACCDefaultClauseKind::None:
50+
attrData.defaultVal = ClauseDefaultValue::None;
51+
break;
52+
case OpenACCDefaultClauseKind::Present:
53+
attrData.defaultVal = ClauseDefaultValue::Present;
54+
break;
55+
case OpenACCDefaultClauseKind::Invalid:
56+
break;
57+
}
58+
}
59+
60+
// Apply any of the clauses that resulted in an 'attribute'.
61+
template <typename Op> void applyAttributes(Op &op) {
62+
if (attrData.defaultVal.has_value())
63+
op.setDefaultAttr(*attrData.defaultVal);
64+
}
65+
};
66+
} // namespace
67+
68+
template <typename Op, typename TermOp>
69+
mlir::LogicalResult CIRGenFunction::emitOpenACCOpAssociatedStmt(
70+
mlir::Location start, mlir::Location end,
71+
llvm::ArrayRef<const OpenACCClause *> clauses, const Stmt *associatedStmt) {
72+
mlir::LogicalResult res = mlir::success();
73+
74+
llvm::SmallVector<mlir::Type> retTy;
75+
llvm::SmallVector<mlir::Value> operands;
76+
77+
// Clause-emitter must be here because it might modify operands.
78+
OpenACCClauseCIREmitter clauseEmitter(getCIRGenModule());
79+
clauseEmitter.VisitClauseList(clauses);
80+
81+
auto op = builder.create<Op>(start, retTy, operands);
82+
83+
// Apply the attributes derived from the clauses.
84+
clauseEmitter.applyAttributes(op);
85+
86+
mlir::Block &block = op.getRegion().emplaceBlock();
87+
mlir::OpBuilder::InsertionGuard guardCase(builder);
88+
builder.setInsertionPointToEnd(&block);
89+
90+
LexicalScope ls{*this, start, builder.getInsertionBlock()};
91+
res = emitStmt(associatedStmt, /*useCurrentScope=*/true);
92+
93+
builder.create<TermOp>(end);
94+
return res;
95+
}
96+
97+
template <typename Op>
98+
mlir::LogicalResult
99+
CIRGenFunction::emitOpenACCOp(mlir::Location start,
100+
llvm::ArrayRef<const OpenACCClause *> clauses) {
101+
mlir::LogicalResult res = mlir::success();
102+
103+
llvm::SmallVector<mlir::Type> retTy;
104+
llvm::SmallVector<mlir::Value> operands;
105+
106+
// Clause-emitter must be here because it might modify operands.
107+
OpenACCClauseCIREmitter clauseEmitter(getCIRGenModule());
108+
clauseEmitter.VisitClauseList(clauses);
109+
110+
builder.create<Op>(start, retTy, operands);
111+
return res;
112+
}
20113

21114
mlir::LogicalResult
22115
CIRGenFunction::emitOpenACCComputeConstruct(const OpenACCComputeConstruct &s) {
23-
getCIRGenModule().errorNYI(s.getSourceRange(), "OpenACC Compute Construct");
24-
return mlir::failure();
116+
mlir::Location start = getLoc(s.getSourceRange().getEnd());
117+
mlir::Location end = getLoc(s.getSourceRange().getEnd());
118+
119+
switch (s.getDirectiveKind()) {
120+
case OpenACCDirectiveKind::Parallel:
121+
return emitOpenACCOpAssociatedStmt<ParallelOp, mlir::acc::YieldOp>(
122+
start, end, s.clauses(), s.getStructuredBlock());
123+
case OpenACCDirectiveKind::Serial:
124+
return emitOpenACCOpAssociatedStmt<SerialOp, mlir::acc::YieldOp>(
125+
start, end, s.clauses(), s.getStructuredBlock());
126+
case OpenACCDirectiveKind::Kernels:
127+
return emitOpenACCOpAssociatedStmt<KernelsOp, mlir::acc::TerminatorOp>(
128+
start, end, s.clauses(), s.getStructuredBlock());
129+
default:
130+
llvm_unreachable("invalid compute construct kind");
131+
}
132+
}
133+
134+
mlir::LogicalResult
135+
CIRGenFunction::emitOpenACCDataConstruct(const OpenACCDataConstruct &s) {
136+
mlir::Location start = getLoc(s.getSourceRange().getEnd());
137+
mlir::Location end = getLoc(s.getSourceRange().getEnd());
138+
139+
return emitOpenACCOpAssociatedStmt<DataOp, mlir::acc::TerminatorOp>(
140+
start, end, s.clauses(), s.getStructuredBlock());
141+
}
142+
143+
mlir::LogicalResult
144+
CIRGenFunction::emitOpenACCInitConstruct(const OpenACCInitConstruct &s) {
145+
mlir::Location start = getLoc(s.getSourceRange().getEnd());
146+
return emitOpenACCOp<InitOp>(start, s.clauses());
147+
}
148+
mlir::LogicalResult CIRGenFunction::emitOpenACCShutdownConstruct(
149+
const OpenACCShutdownConstruct &s) {
150+
mlir::Location start = getLoc(s.getSourceRange().getEnd());
151+
return emitOpenACCOp<ShutdownOp>(start, s.clauses());
25152
}
26153

27154
mlir::LogicalResult
@@ -34,11 +161,6 @@ mlir::LogicalResult CIRGenFunction::emitOpenACCCombinedConstruct(
34161
getCIRGenModule().errorNYI(s.getSourceRange(), "OpenACC Combined Construct");
35162
return mlir::failure();
36163
}
37-
mlir::LogicalResult
38-
CIRGenFunction::emitOpenACCDataConstruct(const OpenACCDataConstruct &s) {
39-
getCIRGenModule().errorNYI(s.getSourceRange(), "OpenACC Data Construct");
40-
return mlir::failure();
41-
}
42164
mlir::LogicalResult CIRGenFunction::emitOpenACCEnterDataConstruct(
43165
const OpenACCEnterDataConstruct &s) {
44166
getCIRGenModule().errorNYI(s.getSourceRange(), "OpenACC EnterData Construct");
@@ -60,16 +182,6 @@ CIRGenFunction::emitOpenACCWaitConstruct(const OpenACCWaitConstruct &s) {
60182
return mlir::failure();
61183
}
62184
mlir::LogicalResult
63-
CIRGenFunction::emitOpenACCInitConstruct(const OpenACCInitConstruct &s) {
64-
getCIRGenModule().errorNYI(s.getSourceRange(), "OpenACC Init Construct");
65-
return mlir::failure();
66-
}
67-
mlir::LogicalResult CIRGenFunction::emitOpenACCShutdownConstruct(
68-
const OpenACCShutdownConstruct &s) {
69-
getCIRGenModule().errorNYI(s.getSourceRange(), "OpenACC Shutdown Construct");
70-
return mlir::failure();
71-
}
72-
mlir::LogicalResult
73185
CIRGenFunction::emitOpenACCSetConstruct(const OpenACCSetConstruct &s) {
74186
getCIRGenModule().errorNYI(s.getSourceRange(), "OpenACC Set Construct");
75187
return mlir::failure();

clang/lib/CIR/CodeGen/CIRGenerator.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "CIRGenModule.h"
1414

15+
#include "mlir/Dialect/OpenACC/OpenACC.h"
1516
#include "mlir/IR/MLIRContext.h"
1617

1718
#include "clang/AST/DeclGroup.h"
@@ -36,6 +37,7 @@ void CIRGenerator::Initialize(ASTContext &astContext) {
3637

3738
mlirContext = std::make_unique<mlir::MLIRContext>();
3839
mlirContext->loadDialect<cir::CIRDialect>();
40+
mlirContext->getOrLoadDialect<mlir::acc::OpenACCDialect>();
3941
cgm = std::make_unique<clang::CIRGen::CIRGenModule>(
4042
*mlirContext.get(), astContext, codeGenOpts, diags);
4143
}

clang/lib/CodeGen/CGCUDANV.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1281,7 +1281,8 @@ llvm::Function *CGNVCUDARuntime::finalizeModule() {
12811281
return nullptr;
12821282
}
12831283
if (CGM.getLangOpts().OffloadViaLLVM ||
1284-
(CGM.getLangOpts().OffloadingNewDriver && RelocatableDeviceCode))
1284+
(CGM.getLangOpts().OffloadingNewDriver &&
1285+
(CGM.getLangOpts().HIP || RelocatableDeviceCode)))
12851286
createOffloadingEntries();
12861287
else
12871288
return makeModuleCtorFunction();

0 commit comments

Comments
 (0)