Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
902b07f
[LLVM][InstCombine][SVE] Improve isAllActivePredicate by looking thro…
paulwalker-arm Oct 23, 2025
6b19a54
[LV] Bundle partial reductions inside VPExpressionRecipe (#147302)
SamTebbs33 Oct 23, 2025
11bbee9
Adding to execute_region_op some missing support (#164159)
ddubov100 Oct 23, 2025
daf0182
[ConstraintElim] Apply add with neg constant first during decomp. (#1…
fhahn Oct 23, 2025
b11f0e1
[mlir][tosa] Stop folding pad into avg_pool2d (#164599)
Lallapallooza Oct 23, 2025
911e5aa
[flang][NFC] fix build warning about unused argument (#164776)
jeanPerier Oct 23, 2025
0591297
[clang][bytecode] Fix initializing primitive fields via initlist (#16…
tbaederr Oct 23, 2025
3107c2f
[CIR] Upstream handling for __builtin_prefetch (#164387)
kimsh02 Oct 23, 2025
249883d
[test][Transforms] Remove unsafe-fp-math uses part 2 (NFC) (#164786)
paperchalice Oct 23, 2025
3f47a7b
[SPIRV] Upd SPV_KHR_shader_clock extension (#160147)
KornevNikita Oct 23, 2025
a242a20
[ARM] Update more MVE costmodel tests with -cost-kind=all. NFC
davemgreen Oct 23, 2025
53b9441
[clang-format] Break the line within ObjC `@selector` (#164674)
sstwcw Oct 23, 2025
ece83ed
[clang][bytecode] Fix instance pointer in IndirectFieldDecl inits (#1…
tbaederr Oct 23, 2025
90b51c3
[MLIR][ExecutionEngine] don't leak -Wweak-vtables (#164498)
makslevental Oct 23, 2025
d43b067
[mlir][bufferize] Cleanup TensorCopyInsertion.cpp (NFC) (#164541)
linuxlonelyeagle Oct 23, 2025
865cd8e
[HLSL] Allow input semantics on structs (#159047)
Keenuts Oct 23, 2025
2d18c49
[MemRef] Implement value bounds interface for ExpandShapeOp (#164438)
jtuyls Oct 23, 2025
0ba6d6d
[AArch64] Correct am_indexed used in bitcast loadext patterns. (#164588)
davemgreen Oct 23, 2025
5c30a5c
[ExecutionEngine] Call hash_combine_range with a range (NFC) (#164755)
kazutakahirata Oct 23, 2025
d7c87c7
[llvm] Proofread TableGen/index.rst (#164756)
kazutakahirata Oct 23, 2025
c5f1c69
[ExecutionEngine] Add "override" where appropriate (NFC) (#164757)
kazutakahirata Oct 23, 2025
9c7b304
[WPD] Reduce ThinLTO link time by avoiding unnecessary summary analys…
teresajohnson Oct 23, 2025
8048496
merge main into amd-staging
ronlieb Oct 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions clang/include/clang/AST/Attr.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,8 @@ class HLSLSemanticAttr : public HLSLAnnotationAttr {
LLVM_PREFERRED_TYPE(bool)
unsigned SemanticExplicitIndex : 1;

Decl *TargetDecl = nullptr;

protected:
HLSLSemanticAttr(ASTContext &Context, const AttributeCommonInfo &CommonInfo,
attr::Kind AK, bool IsLateParsed,
Expand All @@ -259,6 +261,11 @@ class HLSLSemanticAttr : public HLSLAnnotationAttr {

unsigned getSemanticIndex() const { return SemanticIndex; }

bool isSemanticIndexExplicit() const { return SemanticExplicitIndex; }

void setTargetDecl(Decl *D) { TargetDecl = D; }
Decl *getTargetDecl() const { return TargetDecl; }

// Implement isa/cast/dyncast/etc.
static bool classof(const Attr *A) {
return A->getKind() >= attr::FirstHLSLSemanticAttr &&
Expand Down
2 changes: 2 additions & 0 deletions clang/include/clang/Basic/Attr.td
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,8 @@ class HLSLSemanticAttr<bit Indexable> : HLSLAnnotationAttr {
let Spellings = [];
let Subjects = SubjectList<[ParmVar, Field, Function]>;
let LangOpts = [HLSL];
let Args = [DeclArgument<Named, "Target">, IntArgument<"SemanticIndex">,
BoolArgument<"SemanticExplicitIndex">];
}

/// A target-specific attribute. This class is meant to be used as a mixin
Expand Down
4 changes: 0 additions & 4 deletions clang/include/clang/Basic/DiagnosticFrontendKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -404,10 +404,6 @@ def warn_hlsl_langstd_minimal :
"recommend using %1 instead">,
InGroup<HLSLDXCCompat>;

def err_hlsl_semantic_missing : Error<"semantic annotations must be present "
"for all input and outputs of an entry "
"function or patch constant function">;

// ClangIR frontend errors
def err_cir_to_cir_transform_failed : Error<
"CIR-to-CIR transformation failed">, DefaultFatal;
Expand Down
1 change: 1 addition & 0 deletions clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -13173,6 +13173,7 @@ def err_hlsl_duplicate_parameter_modifier : Error<"duplicate parameter modifier
def err_hlsl_missing_semantic_annotation : Error<
"semantic annotations must be present for all parameters of an entry "
"function or patch constant function">;
def note_hlsl_semantic_used_here : Note<"%0 used here">;
def err_hlsl_unknown_semantic : Error<"unknown HLSL semantic %0">;
def err_hlsl_semantic_output_not_supported
: Error<"semantic %0 does not support output">;
Expand Down
37 changes: 37 additions & 0 deletions clang/include/clang/CIR/Dialect/IR/CIROps.td
Original file line number Diff line number Diff line change
Expand Up @@ -4052,6 +4052,43 @@ def CIR_ExpectOp : CIR_Op<"expect", [
}];
}

//===----------------------------------------------------------------------===//
// PrefetchOp
//===----------------------------------------------------------------------===//

def CIR_PrefetchOp : CIR_Op<"prefetch"> {
let summary = "Prefetch operation";
let description = [{
The `cir.prefetch` operation is a hint to the code generator to insert a
prefetch instruction if supported; otherwise, it is a noop. Prefetches
have no effect on the behavior of the program but can change its
performance characteristics.

```mlir
cir.prefetch(%0 : !cir.ptr<!void>) locality(1) write
```

$locality is a temporal locality specifier ranging from (0) - no locality,
to (3) - extremely local, keep in cache. If $locality is not present, the
default value is 3.

$isWrite specifies whether the prefetch is for a 'read' or 'write'. If
$isWrite is not specified, it means that prefetch is prepared for 'read'.
}];

let arguments = (ins CIR_VoidPtrType:$addr,
DefaultValuedAttr<ConfinedAttr<I32Attr, [IntMinValue<0>, IntMaxValue<3>]>,
"3">:$locality,
UnitAttr:$isWrite);

let assemblyFormat = [{
(`write` $isWrite^) : (`read`)?
`locality` `(` $locality `)`
$addr `:` qualified(type($addr))
attr-dict
}];
}

//===----------------------------------------------------------------------===//
// PtrDiffOp
//===----------------------------------------------------------------------===//
Expand Down
30 changes: 21 additions & 9 deletions clang/include/clang/Sema/SemaHLSL.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,6 @@ class SemaHLSL : public SemaBase {
bool ActOnUninitializedVarDecl(VarDecl *D);
void ActOnEndOfTranslationUnit(TranslationUnitDecl *TU);
void CheckEntryPoint(FunctionDecl *FD);
bool isSemanticValid(FunctionDecl *FD, DeclaratorDecl *D);
void CheckSemanticAnnotation(FunctionDecl *EntryPoint, const Decl *Param,
const HLSLAnnotationAttr *AnnotationAttr);
bool CheckResourceBinOp(BinaryOperatorKind Opc, Expr *LHSExpr, Expr *RHSExpr,
SourceLocation Loc);
void DiagnoseAttrStageMismatch(
Expand Down Expand Up @@ -179,17 +176,17 @@ class SemaHLSL : public SemaBase {
bool handleResourceTypeAttr(QualType T, const ParsedAttr &AL);

template <typename T>
T *createSemanticAttr(const ParsedAttr &AL,
T *createSemanticAttr(const AttributeCommonInfo &ACI, NamedDecl *TargetDecl,
std::optional<unsigned> Location) {
T *Attr = ::new (getASTContext()) T(getASTContext(), AL);
if (Attr->isSemanticIndexable())
Attr->setSemanticIndex(Location ? *Location : 0);
else if (Location.has_value()) {
T *Attr =
::new (getASTContext()) T(getASTContext(), ACI, TargetDecl,
Location.value_or(0), Location.has_value());

if (!Attr->isSemanticIndexable() && Location.has_value()) {
Diag(Attr->getLocation(), diag::err_hlsl_semantic_indexing_not_supported)
<< Attr->getAttrName()->getName();
return nullptr;
}

return Attr;
}

Expand Down Expand Up @@ -247,10 +244,25 @@ class SemaHLSL : public SemaBase {

IdentifierInfo *RootSigOverrideIdent = nullptr;

struct SemanticInfo {
HLSLSemanticAttr *Semantic;
std::optional<uint32_t> Index;
};

private:
void collectResourceBindingsOnVarDecl(VarDecl *D);
void collectResourceBindingsOnUserRecordDecl(const VarDecl *VD,
const RecordType *RT);

void checkSemanticAnnotation(FunctionDecl *EntryPoint, const Decl *Param,
const HLSLSemanticAttr *SemanticAttr);
HLSLSemanticAttr *createSemantic(const SemanticInfo &Semantic,
DeclaratorDecl *TargetDecl);
bool determineActiveSemanticOnScalar(FunctionDecl *FD, DeclaratorDecl *D,
SemanticInfo &ActiveSemantic);
bool determineActiveSemantic(FunctionDecl *FD, DeclaratorDecl *D,
SemanticInfo &ActiveSemantic);

void processExplicitBindingsOnDecl(VarDecl *D);

void diagnoseAvailabilityViolations(TranslationUnitDecl *TU);
Expand Down
91 changes: 48 additions & 43 deletions clang/lib/AST/ByteCode/Compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1842,7 +1842,6 @@ bool Compiler<Emitter>::visitInitList(ArrayRef<const Expr *> Inits,
const Expr *Init, PrimType T,
bool Activate = false) -> bool {
InitStackScope<Emitter> ISS(this, isa<CXXDefaultInitExpr>(Init));
InitLinkScope<Emitter> ILS(this, InitLink::Field(FieldToInit->Offset));
if (!this->visit(Init))
return false;

Expand Down Expand Up @@ -5385,55 +5384,57 @@ bool Compiler<Emitter>::VisitCXXThisExpr(const CXXThisExpr *E) {
// instance pointer of the current function frame, but e.g. to the declaration
// currently being initialized. Here we emit the necessary instruction(s) for
// this scenario.
if (!InitStackActive)
if (!InitStackActive || InitStack.empty())
return this->emitThis(E);

if (!InitStack.empty()) {
// If our init stack is, for example:
// 0 Stack: 3 (decl)
// 1 Stack: 6 (init list)
// 2 Stack: 1 (field)
// 3 Stack: 6 (init list)
// 4 Stack: 1 (field)
//
// We want to find the LAST element in it that's an init list,
// which is marked with the K_InitList marker. The index right
// before that points to an init list. We need to find the
// elements before the K_InitList element that point to a base
// (e.g. a decl or This), optionally followed by field, elem, etc.
// In the example above, we want to emit elements [0..2].
unsigned StartIndex = 0;
unsigned EndIndex = 0;
// Find the init list.
for (StartIndex = InitStack.size() - 1; StartIndex > 0; --StartIndex) {
if (InitStack[StartIndex].Kind == InitLink::K_InitList ||
InitStack[StartIndex].Kind == InitLink::K_This) {
EndIndex = StartIndex;
--StartIndex;
break;
}
// If our init stack is, for example:
// 0 Stack: 3 (decl)
// 1 Stack: 6 (init list)
// 2 Stack: 1 (field)
// 3 Stack: 6 (init list)
// 4 Stack: 1 (field)
//
// We want to find the LAST element in it that's an init list,
// which is marked with the K_InitList marker. The index right
// before that points to an init list. We need to find the
// elements before the K_InitList element that point to a base
// (e.g. a decl or This), optionally followed by field, elem, etc.
// In the example above, we want to emit elements [0..2].
unsigned StartIndex = 0;
unsigned EndIndex = 0;
// Find the init list.
for (StartIndex = InitStack.size() - 1; StartIndex > 0; --StartIndex) {
if (InitStack[StartIndex].Kind == InitLink::K_InitList ||
InitStack[StartIndex].Kind == InitLink::K_This) {
EndIndex = StartIndex;
--StartIndex;
break;
}
}

// Walk backwards to find the base.
for (; StartIndex > 0; --StartIndex) {
if (InitStack[StartIndex].Kind == InitLink::K_InitList)
continue;
// Walk backwards to find the base.
for (; StartIndex > 0; --StartIndex) {
if (InitStack[StartIndex].Kind == InitLink::K_InitList)
continue;

if (InitStack[StartIndex].Kind != InitLink::K_Field &&
InitStack[StartIndex].Kind != InitLink::K_Elem)
break;
}
if (InitStack[StartIndex].Kind != InitLink::K_Field &&
InitStack[StartIndex].Kind != InitLink::K_Elem)
break;
}

// Emit the instructions.
for (unsigned I = StartIndex; I != EndIndex; ++I) {
if (InitStack[I].Kind == InitLink::K_InitList)
continue;
if (!InitStack[I].template emit<Emitter>(this, E))
return false;
}
return true;
if (StartIndex == 0 && EndIndex == 0)
EndIndex = InitStack.size() - 1;

assert(StartIndex < EndIndex);

// Emit the instructions.
for (unsigned I = StartIndex; I != (EndIndex + 1); ++I) {
if (InitStack[I].Kind == InitLink::K_InitList)
continue;
if (!InitStack[I].template emit<Emitter>(this, E))
return false;
}
return this->emitThis(E);
return true;
}

template <class Emitter> bool Compiler<Emitter>::visitStmt(const Stmt *S) {
Expand Down Expand Up @@ -6295,6 +6296,10 @@ bool Compiler<Emitter>::compileConstructor(const CXXConstructorDecl *Ctor) {
}
assert(NestedField);

unsigned FirstLinkOffset =
R->getField(cast<FieldDecl>(IFD->chain()[0]))->Offset;
InitStackScope<Emitter> ISS(this, isa<CXXDefaultInitExpr>(InitExpr));
InitLinkScope<Emitter> ILS(this, InitLink::Field(FirstLinkOffset));
if (!emitFieldInitializer(NestedField, NestedFieldOffset, InitExpr,
IsUnion))
return false;
Expand Down
21 changes: 21 additions & 0 deletions clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,27 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl &gd, unsigned builtinID,
assert(!cir::MissingFeatures::coroSizeBuiltinCall());
return getUndefRValue(e->getType());
}
case Builtin::BI__builtin_prefetch: {
auto evaluateOperandAsInt = [&](const Expr *arg) {
Expr::EvalResult res;
[[maybe_unused]] bool evalSucceed =
arg->EvaluateAsInt(res, cgm.getASTContext());
assert(evalSucceed && "expression should be able to evaluate as int");
return res.Val.getInt().getZExtValue();
};

bool isWrite = false;
if (e->getNumArgs() > 1)
isWrite = evaluateOperandAsInt(e->getArg(1));

int locality = 3;
if (e->getNumArgs() > 2)
locality = evaluateOperandAsInt(e->getArg(2));

mlir::Value address = emitScalarExpr(e->getArg(0));
cir::PrefetchOp::create(builder, loc, address, locality, isWrite);
return RValue::get(nullptr);
}
}

// If this is an alias for a lib function (e.g. __builtin_sin), emit
Expand Down
9 changes: 9 additions & 0 deletions clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1695,6 +1695,15 @@ static uint64_t getTypeSize(mlir::Type type, mlir::Operation &op) {
return llvm::divideCeil(layout.getTypeSizeInBits(type), 8);
}

mlir::LogicalResult CIRToLLVMPrefetchOpLowering::matchAndRewrite(
cir::PrefetchOp op, OpAdaptor adaptor,
mlir::ConversionPatternRewriter &rewriter) const {
rewriter.replaceOpWithNewOp<mlir::LLVM::Prefetch>(
op, adaptor.getAddr(), adaptor.getIsWrite(), adaptor.getLocality(),
/*DataCache=*/1);
return mlir::success();
}

mlir::LogicalResult CIRToLLVMPtrDiffOpLowering::matchAndRewrite(
cir::PtrDiffOp op, OpAdaptor adaptor,
mlir::ConversionPatternRewriter &rewriter) const {
Expand Down
Loading