Skip to content

Commit bd4398b

Browse files
committed
[𝘀𝗽𝗿] changes introduced through rebase
Created using spr 1.3.8-beta.1 [skip ci]
2 parents c9de635 + 8dbc152 commit bd4398b

File tree

66 files changed

+17784
-296
lines changed

Some content is hidden

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

66 files changed

+17784
-296
lines changed

clang/include/clang/CIR/Dialect/IR/CIROps.td

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4457,6 +4457,79 @@ def CIR_TryOp : CIR_Op<"try",[
44574457
// Atomic operations
44584458
//===----------------------------------------------------------------------===//
44594459

4460+
def CIR_AtomicFetchKind : CIR_I32EnumAttr<
4461+
"AtomicFetchKind", "Binary opcode for atomic fetch-and-update operations", [
4462+
I32EnumAttrCase<"Add", 0, "add">,
4463+
I32EnumAttrCase<"Sub", 1, "sub">,
4464+
I32EnumAttrCase<"And", 2, "and">,
4465+
I32EnumAttrCase<"Xor", 3, "xor">,
4466+
I32EnumAttrCase<"Or", 4, "or">,
4467+
I32EnumAttrCase<"Nand", 5, "nand">,
4468+
I32EnumAttrCase<"Max", 6, "max">,
4469+
I32EnumAttrCase<"Min", 7, "min">
4470+
]>;
4471+
4472+
def CIR_AtomicFetchOp : CIR_Op<"atomic.fetch", [
4473+
AllTypesMatch<["result", "val"]>,
4474+
TypesMatchWith<"type of 'val' must match the pointee type of 'ptr'",
4475+
"ptr", "val", "mlir::cast<cir::PointerType>($_self).getPointee()">
4476+
]> {
4477+
let summary = "Atomic fetch-and-update operation";
4478+
let description = [{
4479+
C/C++ atomic fetch-and-update operation. This operation implements the C/C++
4480+
builtin functions `__atomic_<binop>_fetch`, `__atomic_fetch_<binop>`, and
4481+
`__c11_atomic_fetch_<binop>`, where `<binop>` is one of the following binary
4482+
opcodes: `add`, `sub`, `and`, `xor`, `or`, `nand`, `max`, and `min`.
4483+
4484+
This operation takes 2 arguments: a pointer `ptr` and a value `val`. The
4485+
type of `val` must match the pointee type of `ptr`. If the binary operation
4486+
is `add`, `sub`, `max`, or `min`, the type of `val` may either be an integer
4487+
type or a floating-point type. Otherwise, `val` must be an integer.
4488+
4489+
This operation atomically loads the value from `ptr`, performs the binary
4490+
operation as indicated by `binop` on the loaded value and `val`, and stores
4491+
the result back to `ptr`. If the `fetch_first` flag is present, the result
4492+
of this operation is the old value loaded from `ptr` before the binary
4493+
operation. Otherwise, the result of this operation is the result of the
4494+
binary operation.
4495+
4496+
Example:
4497+
%res = cir.atomic.fetch add seq_cst %ptr, %val
4498+
: (!cir.ptr<!s32i>, !s32i) -> !s32i
4499+
}];
4500+
let results = (outs CIR_AnyIntOrFloatType:$result);
4501+
let arguments = (ins
4502+
Arg<CIR_PtrToIntOrFloatType, "", [MemRead, MemWrite]>:$ptr,
4503+
CIR_AnyIntOrFloatType:$val,
4504+
CIR_AtomicFetchKind:$binop,
4505+
Arg<CIR_MemOrder, "memory order">:$mem_order,
4506+
UnitAttr:$is_volatile,
4507+
UnitAttr:$fetch_first
4508+
);
4509+
4510+
let assemblyFormat = [{
4511+
$binop $mem_order
4512+
(`fetch_first` $fetch_first^)?
4513+
$ptr `,` $val
4514+
(`volatile` $is_volatile^)?
4515+
`:` `(` qualified(type($ptr)) `,` qualified(type($val)) `)`
4516+
`->` type($result) attr-dict
4517+
}];
4518+
4519+
let hasVerifier = 1;
4520+
4521+
let extraLLVMLoweringPatternDecl = [{
4522+
mlir::Value buildPostOp(cir::AtomicFetchOp op, OpAdaptor adaptor,
4523+
mlir::ConversionPatternRewriter &rewriter,
4524+
mlir::Value rmwVal, bool isInt) const;
4525+
4526+
mlir::Value buildMinMaxPostOp(cir::AtomicFetchOp op, OpAdaptor adaptor,
4527+
mlir::ConversionPatternRewriter &rewriter,
4528+
mlir::Value rmwVal, bool isInt,
4529+
bool isSigned) const;
4530+
}];
4531+
}
4532+
44604533
def CIR_AtomicXchgOp : CIR_Op<"atomic.xchg", [
44614534
AllTypesMatch<["result", "val"]>,
44624535
TypesMatchWith<"type of 'val' must match the pointee type of 'ptr'",

clang/include/clang/Sema/Sema.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10021,7 +10021,7 @@ class Sema final : public SemaBase {
1002110021
public:
1002210022
DeferDiagsRAII(Sema &S, bool DeferDiags)
1002310023
: S(S), SavedDeferDiags(S.DeferDiags) {
10024-
S.DeferDiags = DeferDiags;
10024+
S.DeferDiags = SavedDeferDiags || DeferDiags;
1002510025
}
1002610026
~DeferDiagsRAII() { S.DeferDiags = SavedDeferDiags; }
1002710027
};

clang/include/clang/Sema/SemaBase.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -212,16 +212,13 @@ class SemaBase {
212212
};
213213

214214
/// Emit a diagnostic.
215-
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID,
216-
bool DeferHint = false);
215+
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID);
217216

218217
/// Emit a partial diagnostic.
219-
SemaDiagnosticBuilder Diag(SourceLocation Loc, const PartialDiagnostic &PD,
220-
bool DeferHint = false);
218+
SemaDiagnosticBuilder Diag(SourceLocation Loc, const PartialDiagnostic &PD);
221219

222220
/// Emit a compatibility diagnostic.
223-
SemaDiagnosticBuilder DiagCompat(SourceLocation Loc, unsigned CompatDiagId,
224-
bool DeferHint = false);
221+
SemaDiagnosticBuilder DiagCompat(SourceLocation Loc, unsigned CompatDiagId);
225222

226223
/// Build a partial diagnostic.
227224
PartialDiagnostic PDiag(unsigned DiagID = 0);

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 48 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -4841,46 +4841,39 @@ Compiler<Emitter>::visitVarDecl(const VarDecl *VD, const Expr *Init,
48414841
return !NeedsOp || this->emitCheckDecl(VD, VD);
48424842
};
48434843

4844-
auto initGlobal = [&](unsigned GlobalIndex) -> bool {
4845-
assert(Init);
4846-
4847-
if (VarT) {
4848-
if (!this->visit(Init))
4849-
return checkDecl() && false;
4850-
4851-
return checkDecl() && this->emitInitGlobal(*VarT, GlobalIndex, VD);
4852-
}
4853-
4854-
if (!checkDecl())
4855-
return false;
4856-
4857-
if (!this->emitGetPtrGlobal(GlobalIndex, Init))
4858-
return false;
4859-
4860-
if (!visitInitializer(Init))
4861-
return false;
4862-
4863-
return this->emitFinishInitGlobal(Init);
4864-
};
4865-
48664844
DeclScope<Emitter> LocalScope(this, VD);
48674845

4868-
// We've already seen and initialized this global.
4869-
if (UnsignedOrNone GlobalIndex = P.getGlobal(VD)) {
4846+
UnsignedOrNone GlobalIndex = P.getGlobal(VD);
4847+
if (GlobalIndex) {
4848+
// We've already seen and initialized this global.
48704849
if (P.getPtrGlobal(*GlobalIndex).isInitialized())
48714850
return checkDecl();
4872-
48734851
// The previous attempt at initialization might've been unsuccessful,
48744852
// so let's try this one.
4875-
return !Init || (checkDecl() && initGlobal(*GlobalIndex));
4853+
} else if ((GlobalIndex = P.createGlobal(VD, Init))) {
4854+
} else {
4855+
return false;
48764856
}
4857+
if (!Init)
4858+
return true;
48774859

4878-
UnsignedOrNone GlobalIndex = P.createGlobal(VD, Init);
4860+
if (!checkDecl())
4861+
return false;
48794862

4880-
if (!GlobalIndex)
4863+
if (VarT) {
4864+
if (!this->visit(Init))
4865+
return false;
4866+
4867+
return this->emitInitGlobal(*VarT, *GlobalIndex, VD);
4868+
}
4869+
4870+
if (!this->emitGetPtrGlobal(*GlobalIndex, Init))
4871+
return false;
4872+
4873+
if (!visitInitializer(Init))
48814874
return false;
48824875

4883-
return !Init || (checkDecl() && initGlobal(*GlobalIndex));
4876+
return this->emitFinishInitGlobal(Init);
48844877
}
48854878
// Local variables.
48864879
InitLinkScope<Emitter> ILS(this, InitLink::Decl(VD));
@@ -4890,36 +4883,37 @@ Compiler<Emitter>::visitVarDecl(const VarDecl *VD, const Expr *Init,
48904883
VD, *VarT, VD->getType().isConstQualified(),
48914884
VD->getType().isVolatileQualified(), nullptr, ScopeKind::Block,
48924885
IsConstexprUnknown);
4893-
if (Init) {
4894-
// If this is a toplevel declaration, create a scope for the
4895-
// initializer.
4896-
if (Toplevel) {
4897-
LocalScope<Emitter> Scope(this);
4898-
if (!this->visit(Init))
4899-
return false;
4900-
return this->emitSetLocal(*VarT, Offset, VD) && Scope.destroyLocals();
4901-
}
4902-
if (!this->visit(Init))
4903-
return false;
4904-
return this->emitSetLocal(*VarT, Offset, VD);
4905-
}
4906-
} else {
4907-
if (UnsignedOrNone Offset = this->allocateLocal(
4908-
VD, VD->getType(), nullptr, ScopeKind::Block, IsConstexprUnknown)) {
4909-
if (!Init)
4910-
return true;
49114886

4912-
if (!this->emitGetPtrLocal(*Offset, Init))
4913-
return false;
4887+
if (!Init)
4888+
return true;
49144889

4915-
if (!visitInitializer(Init))
4890+
// If this is a toplevel declaration, create a scope for the
4891+
// initializer.
4892+
if (Toplevel) {
4893+
LocalScope<Emitter> Scope(this);
4894+
if (!this->visit(Init))
49164895
return false;
4917-
4918-
return this->emitFinishInitPop(Init);
4896+
return this->emitSetLocal(*VarT, Offset, VD) && Scope.destroyLocals();
49194897
}
4920-
return false;
4898+
if (!this->visit(Init))
4899+
return false;
4900+
return this->emitSetLocal(*VarT, Offset, VD);
49214901
}
4922-
return true;
4902+
// Local composite variables.
4903+
if (UnsignedOrNone Offset = this->allocateLocal(
4904+
VD, VD->getType(), nullptr, ScopeKind::Block, IsConstexprUnknown)) {
4905+
if (!Init)
4906+
return true;
4907+
4908+
if (!this->emitGetPtrLocal(*Offset, Init))
4909+
return false;
4910+
4911+
if (!visitInitializer(Init))
4912+
return false;
4913+
4914+
return this->emitFinishInitPop(Init);
4915+
}
4916+
return false;
49234917
}
49244918

49254919
template <class Emitter>

clang/lib/Basic/Targets/RISCV.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,11 @@ void RISCVTargetInfo::getTargetDefines(const LangOptions &Opts,
192192
Builder.defineMacro("__riscv_muldiv");
193193
}
194194

195-
if (ISAInfo->hasExtension("a")) {
195+
// The "a" extension is composed of "zalrsc" and "zaamo"
196+
if (ISAInfo->hasExtension("a"))
196197
Builder.defineMacro("__riscv_atomic");
198+
199+
if (ISAInfo->hasExtension("zalrsc")) {
197200
Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1");
198201
Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2");
199202
Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4");

clang/lib/Basic/Targets/RISCV.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,8 @@ class LLVM_LIBRARY_VISIBILITY RISCV32TargetInfo : public RISCVTargetInfo {
195195
void setMaxAtomicWidth() override {
196196
MaxAtomicPromoteWidth = 128;
197197

198-
if (ISAInfo->hasExtension("a"))
198+
// "a" implies "zalrsc" which is sufficient to inline atomics
199+
if (ISAInfo->hasExtension("zalrsc"))
199200
MaxAtomicInlineWidth = 32;
200201
}
201202
};
@@ -225,7 +226,8 @@ class LLVM_LIBRARY_VISIBILITY RISCV64TargetInfo : public RISCVTargetInfo {
225226
void setMaxAtomicWidth() override {
226227
MaxAtomicPromoteWidth = 128;
227228

228-
if (ISAInfo->hasExtension("a"))
229+
// "a" implies "zalrsc" which is sufficient to inline atomics
230+
if (ISAInfo->hasExtension("zalrsc"))
229231
MaxAtomicInlineWidth = 64;
230232
}
231233
};

0 commit comments

Comments
 (0)