Skip to content

Commit

Permalink
[CIR][CIRGen][NFC] Update other remainig parts of buildAtomicExpr to …
Browse files Browse the repository at this point in the history
…match upstream
  • Loading branch information
bcardosolopes authored and lanza committed Apr 19, 2024
1 parent dce1725 commit c0061fc
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions clang/lib/CIR/CodeGen/CIRGenAtomic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -580,29 +580,24 @@ RValue CIRGenFunction::buildAtomicExpr(AtomicExpr *E) {
uint64_t Size = TInfo.Width.getQuantity();
unsigned MaxInlineWidthInBits = getTarget().getMaxAtomicInlineWidth();

bool Oversized = getContext().toBits(TInfo.Width) > MaxInlineWidthInBits;
bool Misaligned = (Ptr.getAlignment() % TInfo.Width) != 0;
bool UseLibcall = Misaligned | Oversized;
bool ShouldCastToIntPtrTy = true;

CharUnits MaxInlineWidth =
getContext().toCharUnitsFromBits(MaxInlineWidthInBits);

DiagnosticsEngine &Diags = CGM.getDiags();

bool Misaligned = (Ptr.getAlignment() % TInfo.Width) != 0;
bool Oversized = getContext().toBits(TInfo.Width) > MaxInlineWidthInBits;
if (Misaligned) {
Diags.Report(E->getBeginLoc(), diag::warn_atomic_op_misaligned)
<< (int)TInfo.Width.getQuantity()
<< (int)Ptr.getAlignment().getQuantity();
}

if (Oversized) {
Diags.Report(E->getBeginLoc(), diag::warn_atomic_op_oversized)
<< (int)TInfo.Width.getQuantity() << (int)MaxInlineWidth.getQuantity();
}

auto Order = buildScalarExpr(E->getOrder());
auto Scope = E->getScopeModel() ? buildScalarExpr(E->getScope()) : nullptr;
bool ShouldCastToIntPtrTy = true;

switch (E->getOp()) {
case AtomicExpr::AO__c11_atomic_init:
Expand Down Expand Up @@ -743,6 +738,9 @@ RValue CIRGenFunction::buildAtomicExpr(AtomicExpr *E) {
Dest = Atomics.castToAtomicIntPointer(Dest);
}

bool PowerOf2Size = (Size & (Size - 1)) == 0;
bool UseLibcall = !PowerOf2Size || (Size > 16);

// For atomics larger than 16 bytes, emit a libcall from the frontend. This
// avoids the overhead of dealing with excessively-large value types in IR.
// Non-power-of-2 values also lower to libcall here, as they are not currently
Expand Down

0 comments on commit c0061fc

Please sign in to comment.