Skip to content

Commit 600c244

Browse files
authored
merge main into amd-staging (llvm#848)
2 parents a63ce5e + 42e7044 commit 600c244

File tree

79 files changed

+2587
-797
lines changed

Some content is hidden

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

79 files changed

+2587
-797
lines changed

clang/cmake/caches/Release.cmake

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,4 @@ endif()
143143
set_final_stage_var(CPACK_GENERATOR "TXZ" STRING)
144144
set_final_stage_var(CPACK_ARCHIVE_THREADS "0" STRING)
145145

146-
if(${CMAKE_HOST_SYSTEM_NAME} MATCHES "Darwin")
147-
set_final_stage_var(LLVM_USE_STATIC_ZSTD "ON" BOOL)
148-
endif()
146+
set_final_stage_var(LLVM_USE_STATIC_ZSTD "ON" BOOL)

clang/include/clang/AST/Decl.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5045,15 +5045,26 @@ class HLSLBufferDecl final : public NamedDecl, public DeclContext {
50455045
// LayoutStruct - Layout struct for the buffer
50465046
CXXRecordDecl *LayoutStruct;
50475047

5048+
// For default (implicit) constant buffer, an array of references of global
5049+
// decls that belong to the buffer. The decls are already parented by the
5050+
// translation unit context. The array is allocated by the ASTContext
5051+
// allocator in HLSLBufferDecl::CreateDefaultCBuffer.
5052+
ArrayRef<Decl *> DefaultBufferDecls;
5053+
50485054
HLSLBufferDecl(DeclContext *DC, bool CBuffer, SourceLocation KwLoc,
50495055
IdentifierInfo *ID, SourceLocation IDLoc,
50505056
SourceLocation LBrace);
50515057

5058+
void setDefaultBufferDecls(ArrayRef<Decl *> Decls);
5059+
50525060
public:
50535061
static HLSLBufferDecl *Create(ASTContext &C, DeclContext *LexicalParent,
50545062
bool CBuffer, SourceLocation KwLoc,
50555063
IdentifierInfo *ID, SourceLocation IDLoc,
50565064
SourceLocation LBrace);
5065+
static HLSLBufferDecl *
5066+
CreateDefaultCBuffer(ASTContext &C, DeclContext *LexicalParent,
5067+
ArrayRef<Decl *> DefaultCBufferDecls);
50575068
static HLSLBufferDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
50585069

50595070
SourceRange getSourceRange() const override LLVM_READONLY {
@@ -5079,6 +5090,28 @@ class HLSLBufferDecl final : public NamedDecl, public DeclContext {
50795090
return static_cast<HLSLBufferDecl *>(const_cast<DeclContext *>(DC));
50805091
}
50815092

5093+
// Iterator for the buffer decls. For constant buffers explicitly declared
5094+
// with `cbuffer` keyword this will the list of decls parented by this
5095+
// HLSLBufferDecl (equal to `decls()`).
5096+
// For implicit $Globals buffer this will be the list of default buffer
5097+
// declarations stored in DefaultBufferDecls plus the implicit layout
5098+
// struct (the only child of HLSLBufferDecl in this case).
5099+
//
5100+
// The iterator uses llvm::concat_iterator to concatenate the lists
5101+
// `decls()` and `DefaultBufferDecls`. For non-default buffers
5102+
// `DefaultBufferDecls` is always empty.
5103+
using buffer_decl_iterator =
5104+
llvm::concat_iterator<Decl *const, SmallVector<Decl *>::const_iterator,
5105+
decl_iterator>;
5106+
using buffer_decl_range = llvm::iterator_range<buffer_decl_iterator>;
5107+
5108+
buffer_decl_range buffer_decls() const {
5109+
return buffer_decl_range(buffer_decls_begin(), buffer_decls_end());
5110+
}
5111+
buffer_decl_iterator buffer_decls_begin() const;
5112+
buffer_decl_iterator buffer_decls_end() const;
5113+
bool buffer_decls_empty();
5114+
50825115
friend class ASTDeclReader;
50835116
friend class ASTDeclWriter;
50845117
};

clang/include/clang/Sema/SemaHLSL.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,13 @@ class SemaHLSL : public SemaBase {
105105
HLSLParamModifierAttr::Spelling Spelling);
106106
void ActOnTopLevelFunction(FunctionDecl *FD);
107107
void ActOnVariableDeclarator(VarDecl *VD);
108+
void ActOnEndOfTranslationUnit(TranslationUnitDecl *TU);
108109
void CheckEntryPoint(FunctionDecl *FD);
109110
void CheckSemanticAnnotation(FunctionDecl *EntryPoint, const Decl *Param,
110111
const HLSLAnnotationAttr *AnnotationAttr);
111112
void DiagnoseAttrStageMismatch(
112113
const Attr *A, llvm::Triple::EnvironmentType Stage,
113114
std::initializer_list<llvm::Triple::EnvironmentType> AllowedStages);
114-
void DiagnoseAvailabilityViolations(TranslationUnitDecl *TU);
115115

116116
QualType handleVectorBinOpConversion(ExprResult &LHS, ExprResult &RHS,
117117
QualType LHSType, QualType RHSType,
@@ -168,11 +168,17 @@ class SemaHLSL : public SemaBase {
168168
// List of all resource bindings
169169
ResourceBindings Bindings;
170170

171+
// Global declaration collected for the $Globals default constant
172+
// buffer which will be created at the end of the translation unit.
173+
llvm::SmallVector<Decl *> DefaultCBufferDecls;
174+
171175
private:
172176
void collectResourceBindingsOnVarDecl(VarDecl *D);
173177
void collectResourceBindingsOnUserRecordDecl(const VarDecl *VD,
174178
const RecordType *RT);
175179
void processExplicitBindingsOnDecl(VarDecl *D);
180+
181+
void diagnoseAvailabilityViolations(TranslationUnitDecl *TU);
176182
};
177183

178184
} // namespace clang

clang/lib/AST/Decl.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
#include "llvm/ADT/SmallVector.h"
5858
#include "llvm/ADT/StringRef.h"
5959
#include "llvm/ADT/StringSwitch.h"
60+
#include "llvm/ADT/iterator_range.h"
6061
#include "llvm/Support/Casting.h"
6162
#include "llvm/Support/ErrorHandling.h"
6263
#include "llvm/Support/raw_ostream.h"
@@ -5745,6 +5746,18 @@ HLSLBufferDecl *HLSLBufferDecl::Create(ASTContext &C,
57455746
return Result;
57465747
}
57475748

5749+
HLSLBufferDecl *
5750+
HLSLBufferDecl::CreateDefaultCBuffer(ASTContext &C, DeclContext *LexicalParent,
5751+
ArrayRef<Decl *> DefaultCBufferDecls) {
5752+
DeclContext *DC = LexicalParent;
5753+
IdentifierInfo *II = &C.Idents.get("$Globals", tok::TokenKind::identifier);
5754+
HLSLBufferDecl *Result = new (C, DC) HLSLBufferDecl(
5755+
DC, true, SourceLocation(), II, SourceLocation(), SourceLocation());
5756+
Result->setImplicit(true);
5757+
Result->setDefaultBufferDecls(DefaultCBufferDecls);
5758+
return Result;
5759+
}
5760+
57485761
HLSLBufferDecl *HLSLBufferDecl::CreateDeserialized(ASTContext &C,
57495762
GlobalDeclID ID) {
57505763
return new (C, ID) HLSLBufferDecl(nullptr, false, SourceLocation(), nullptr,
@@ -5757,6 +5770,36 @@ void HLSLBufferDecl::addLayoutStruct(CXXRecordDecl *LS) {
57575770
addDecl(LS);
57585771
}
57595772

5773+
void HLSLBufferDecl::setDefaultBufferDecls(ArrayRef<Decl *> Decls) {
5774+
assert(!Decls.empty());
5775+
assert(DefaultBufferDecls.empty() && "default decls are already set");
5776+
assert(isImplicit() &&
5777+
"default decls can only be added to the implicit/default constant "
5778+
"buffer $Globals");
5779+
5780+
// allocate array for default decls with ASTContext allocator
5781+
Decl **DeclsArray = new (getASTContext()) Decl *[Decls.size()];
5782+
std::copy(Decls.begin(), Decls.end(), DeclsArray);
5783+
DefaultBufferDecls = ArrayRef<Decl *>(DeclsArray, Decls.size());
5784+
}
5785+
5786+
HLSLBufferDecl::buffer_decl_iterator
5787+
HLSLBufferDecl::buffer_decls_begin() const {
5788+
return buffer_decl_iterator(llvm::iterator_range(DefaultBufferDecls.begin(),
5789+
DefaultBufferDecls.end()),
5790+
decl_range(decls_begin(), decls_end()));
5791+
}
5792+
5793+
HLSLBufferDecl::buffer_decl_iterator HLSLBufferDecl::buffer_decls_end() const {
5794+
return buffer_decl_iterator(
5795+
llvm::iterator_range(DefaultBufferDecls.end(), DefaultBufferDecls.end()),
5796+
decl_range(decls_end(), decls_end()));
5797+
}
5798+
5799+
bool HLSLBufferDecl::buffer_decls_empty() {
5800+
return DefaultBufferDecls.empty() && decls_empty();
5801+
}
5802+
57605803
//===----------------------------------------------------------------------===//
57615804
// ImportDecl Implementation
57625805
//===----------------------------------------------------------------------===//

clang/lib/CIR/Dialect/IR/CIRTypes.cpp

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,6 @@ uint64_t IntType::getABIAlignment(const mlir::DataLayout &dataLayout,
125125
return (uint64_t)(getWidth() / 8);
126126
}
127127

128-
uint64_t
129-
IntType::getPreferredAlignment(const ::mlir::DataLayout &dataLayout,
130-
::mlir::DataLayoutEntryListRef params) const {
131-
return (uint64_t)(getWidth() / 8);
132-
}
133-
134128
mlir::LogicalResult
135129
IntType::verify(llvm::function_ref<mlir::InFlightDiagnostic()> emitError,
136130
unsigned width, bool isSigned) {
@@ -163,12 +157,6 @@ SingleType::getABIAlignment(const mlir::DataLayout &dataLayout,
163157
return (uint64_t)(getWidth() / 8);
164158
}
165159

166-
uint64_t
167-
SingleType::getPreferredAlignment(const ::mlir::DataLayout &dataLayout,
168-
::mlir::DataLayoutEntryListRef params) const {
169-
return (uint64_t)(getWidth() / 8);
170-
}
171-
172160
const llvm::fltSemantics &DoubleType::getFloatSemantics() const {
173161
return llvm::APFloat::IEEEdouble();
174162
}
@@ -185,12 +173,6 @@ DoubleType::getABIAlignment(const mlir::DataLayout &dataLayout,
185173
return (uint64_t)(getWidth() / 8);
186174
}
187175

188-
uint64_t
189-
DoubleType::getPreferredAlignment(const ::mlir::DataLayout &dataLayout,
190-
::mlir::DataLayoutEntryListRef params) const {
191-
return (uint64_t)(getWidth() / 8);
192-
}
193-
194176
const llvm::fltSemantics &FP16Type::getFloatSemantics() const {
195177
return llvm::APFloat::IEEEhalf();
196178
}
@@ -206,12 +188,6 @@ uint64_t FP16Type::getABIAlignment(const mlir::DataLayout &dataLayout,
206188
return (uint64_t)(getWidth() / 8);
207189
}
208190

209-
uint64_t
210-
FP16Type::getPreferredAlignment(const ::mlir::DataLayout &dataLayout,
211-
::mlir::DataLayoutEntryListRef params) const {
212-
return (uint64_t)(getWidth() / 8);
213-
}
214-
215191
const llvm::fltSemantics &BF16Type::getFloatSemantics() const {
216192
return llvm::APFloat::BFloat();
217193
}
@@ -227,12 +203,6 @@ uint64_t BF16Type::getABIAlignment(const mlir::DataLayout &dataLayout,
227203
return (uint64_t)(getWidth() / 8);
228204
}
229205

230-
uint64_t
231-
BF16Type::getPreferredAlignment(const ::mlir::DataLayout &dataLayout,
232-
::mlir::DataLayoutEntryListRef params) const {
233-
return (uint64_t)(getWidth() / 8);
234-
}
235-
236206
const llvm::fltSemantics &FP80Type::getFloatSemantics() const {
237207
return llvm::APFloat::x87DoubleExtended();
238208
}
@@ -249,12 +219,6 @@ uint64_t FP80Type::getABIAlignment(const mlir::DataLayout &dataLayout,
249219
return 16;
250220
}
251221

252-
uint64_t
253-
FP80Type::getPreferredAlignment(const ::mlir::DataLayout &dataLayout,
254-
::mlir::DataLayoutEntryListRef params) const {
255-
return 16;
256-
}
257-
258222
const llvm::fltSemantics &FP128Type::getFloatSemantics() const {
259223
return llvm::APFloat::IEEEquad();
260224
}
@@ -270,12 +234,6 @@ uint64_t FP128Type::getABIAlignment(const mlir::DataLayout &dataLayout,
270234
return 16;
271235
}
272236

273-
uint64_t
274-
FP128Type::getPreferredAlignment(const ::mlir::DataLayout &dataLayout,
275-
::mlir::DataLayoutEntryListRef params) const {
276-
return 16;
277-
}
278-
279237
const llvm::fltSemantics &LongDoubleType::getFloatSemantics() const {
280238
return mlir::cast<cir::CIRFPTypeInterface>(getUnderlying())
281239
.getFloatSemantics();
@@ -295,13 +253,6 @@ LongDoubleType::getABIAlignment(const mlir::DataLayout &dataLayout,
295253
.getABIAlignment(dataLayout, params);
296254
}
297255

298-
uint64_t LongDoubleType::getPreferredAlignment(
299-
const ::mlir::DataLayout &dataLayout,
300-
mlir::DataLayoutEntryListRef params) const {
301-
return mlir::cast<mlir::DataLayoutTypeInterface>(getUnderlying())
302-
.getPreferredAlignment(dataLayout, params);
303-
}
304-
305256
LogicalResult
306257
LongDoubleType::verify(function_ref<InFlightDiagnostic()> emitError,
307258
mlir::Type underlying) {
@@ -397,12 +348,6 @@ BoolType::getABIAlignment(const ::mlir::DataLayout &dataLayout,
397348
return 1;
398349
}
399350

400-
uint64_t
401-
BoolType::getPreferredAlignment(const ::mlir::DataLayout &dataLayout,
402-
::mlir::DataLayoutEntryListRef params) const {
403-
return 1;
404-
}
405-
406351
//===----------------------------------------------------------------------===//
407352
// PointerType Definitions
408353
//===----------------------------------------------------------------------===//
@@ -421,13 +366,6 @@ PointerType::getABIAlignment(const ::mlir::DataLayout &dataLayout,
421366
return 8;
422367
}
423368

424-
uint64_t PointerType::getPreferredAlignment(
425-
const ::mlir::DataLayout &dataLayout,
426-
::mlir::DataLayoutEntryListRef params) const {
427-
// FIXME: improve this in face of address spaces
428-
return 8;
429-
}
430-
431369
mlir::LogicalResult
432370
PointerType::verify(llvm::function_ref<mlir::InFlightDiagnostic()> emitError,
433371
mlir::Type pointee) {

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22515,11 +22515,11 @@ Value *CodeGenFunction::EmitWebAssemblyBuiltinExpr(unsigned BuiltinID,
2251522515
Value *Tag = EmitScalarExpr(E->getArg(0));
2251622516
Value *Obj = EmitScalarExpr(E->getArg(1));
2251722517
Function *Callee = CGM.getIntrinsic(Intrinsic::wasm_throw);
22518-
return Builder.CreateCall(Callee, {Tag, Obj});
22518+
return EmitRuntimeCallOrInvoke(Callee, {Tag, Obj});
2251922519
}
2252022520
case WebAssembly::BI__builtin_wasm_rethrow: {
2252122521
Function *Callee = CGM.getIntrinsic(Intrinsic::wasm_rethrow);
22522-
return Builder.CreateCall(Callee);
22522+
return EmitRuntimeCallOrInvoke(Callee);
2252322523
}
2252422524
case WebAssembly::BI__builtin_wasm_memory_atomic_wait32: {
2252522525
Value *Addr = EmitScalarExpr(E->getArg(0));

clang/lib/CodeGen/CGHLSLRuntime.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ void CGHLSLRuntime::emitBufferGlobalsAndMetadata(const HLSLBufferDecl *BufDecl,
116116
BufGlobals.push_back(ValueAsMetadata::get(BufGV));
117117

118118
const auto *ElemIt = LayoutStruct->element_begin();
119-
for (Decl *D : BufDecl->decls()) {
119+
for (Decl *D : BufDecl->buffer_decls()) {
120120
if (isa<CXXRecordDecl, EmptyDecl>(D))
121121
// Nothing to do for this declaration.
122122
continue;

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5526,6 +5526,11 @@ void CodeGenModule::EmitGlobalVarDefinition(const VarDecl *D,
55265526
if (getLangOpts().OpenCL && ASTTy->isSamplerT())
55275527
return;
55285528

5529+
// HLSL default buffer constants will be emitted during HLSLBufferDecl codegen
5530+
if (getLangOpts().HLSL &&
5531+
D->getType().getAddressSpace() == LangAS::hlsl_constant)
5532+
return;
5533+
55295534
// If this is OpenMP device, check if it is legal to emit this global
55305535
// normally.
55315536
if (LangOpts.OpenMPIsTargetDevice && OpenMPRuntime &&

clang/lib/Sema/Sema.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1417,8 +1417,7 @@ void Sema::ActOnEndOfTranslationUnit() {
14171417
}
14181418

14191419
if (LangOpts.HLSL)
1420-
HLSL().DiagnoseAvailabilityViolations(
1421-
getASTContext().getTranslationUnitDecl());
1420+
HLSL().ActOnEndOfTranslationUnit(getASTContext().getTranslationUnitDecl());
14221421

14231422
// If there were errors, disable 'unused' warnings since they will mostly be
14241423
// noise. Don't warn for a use from a module: either we should warn on all

0 commit comments

Comments
 (0)