Skip to content

Commit

Permalink
[GlobalISel] Update MachineIRBuilder::buildAtomicRMW interface (#86851
Browse files Browse the repository at this point in the history
)
  • Loading branch information
shiltian authored Mar 27, 2024
1 parent 0a43ca7 commit a8b90c0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 31 deletions.
11 changes: 6 additions & 5 deletions llvm/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -1333,9 +1333,9 @@ class MachineIRBuilder {
///
/// \return a MachineInstrBuilder for the newly created instruction.
MachineInstrBuilder
buildAtomicCmpXchgWithSuccess(Register OldValRes, Register SuccessRes,
Register Addr, Register CmpVal, Register NewVal,
MachineMemOperand &MMO);
buildAtomicCmpXchgWithSuccess(const DstOp &OldValRes, const DstOp &SuccessRes,
const SrcOp &Addr, const SrcOp &CmpVal,
const SrcOp &NewVal, MachineMemOperand &MMO);

/// Build and insert `OldValRes<def> = G_ATOMIC_CMPXCHG Addr, CmpVal, NewVal,
/// MMO`.
Expand All @@ -1351,8 +1351,9 @@ class MachineIRBuilder {
/// registers of the same type.
///
/// \return a MachineInstrBuilder for the newly created instruction.
MachineInstrBuilder buildAtomicCmpXchg(Register OldValRes, Register Addr,
Register CmpVal, Register NewVal,
MachineInstrBuilder buildAtomicCmpXchg(const DstOp &OldValRes,
const SrcOp &Addr, const SrcOp &CmpVal,
const SrcOp &NewVal,
MachineMemOperand &MMO);

/// Build and insert `OldValRes<def> = G_ATOMICRMW_<Opcode> Addr, Val, MMO`.
Expand Down
54 changes: 28 additions & 26 deletions llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -930,14 +930,14 @@ MachineIRBuilder::buildExtractVectorElement(const DstOp &Res, const SrcOp &Val,
}

MachineInstrBuilder MachineIRBuilder::buildAtomicCmpXchgWithSuccess(
Register OldValRes, Register SuccessRes, Register Addr, Register CmpVal,
Register NewVal, MachineMemOperand &MMO) {
const DstOp &OldValRes, const DstOp &SuccessRes, const SrcOp &Addr,
const SrcOp &CmpVal, const SrcOp &NewVal, MachineMemOperand &MMO) {
#ifndef NDEBUG
LLT OldValResTy = getMRI()->getType(OldValRes);
LLT SuccessResTy = getMRI()->getType(SuccessRes);
LLT AddrTy = getMRI()->getType(Addr);
LLT CmpValTy = getMRI()->getType(CmpVal);
LLT NewValTy = getMRI()->getType(NewVal);
LLT OldValResTy = OldValRes.getLLTTy(*getMRI());
LLT SuccessResTy = SuccessRes.getLLTTy(*getMRI());
LLT AddrTy = Addr.getLLTTy(*getMRI());
LLT CmpValTy = CmpVal.getLLTTy(*getMRI());
LLT NewValTy = NewVal.getLLTTy(*getMRI());
assert(OldValResTy.isScalar() && "invalid operand type");
assert(SuccessResTy.isScalar() && "invalid operand type");
assert(AddrTy.isPointer() && "invalid operand type");
Expand All @@ -947,24 +947,25 @@ MachineInstrBuilder MachineIRBuilder::buildAtomicCmpXchgWithSuccess(
assert(OldValResTy == NewValTy && "type mismatch");
#endif

return buildInstr(TargetOpcode::G_ATOMIC_CMPXCHG_WITH_SUCCESS)
.addDef(OldValRes)
.addDef(SuccessRes)
.addUse(Addr)
.addUse(CmpVal)
.addUse(NewVal)
.addMemOperand(&MMO);
auto MIB = buildInstr(TargetOpcode::G_ATOMIC_CMPXCHG_WITH_SUCCESS);
OldValRes.addDefToMIB(*getMRI(), MIB);
SuccessRes.addDefToMIB(*getMRI(), MIB);
Addr.addSrcToMIB(MIB);
CmpVal.addSrcToMIB(MIB);
NewVal.addSrcToMIB(MIB);
MIB.addMemOperand(&MMO);
return MIB;
}

MachineInstrBuilder
MachineIRBuilder::buildAtomicCmpXchg(Register OldValRes, Register Addr,
Register CmpVal, Register NewVal,
MachineIRBuilder::buildAtomicCmpXchg(const DstOp &OldValRes, const SrcOp &Addr,
const SrcOp &CmpVal, const SrcOp &NewVal,
MachineMemOperand &MMO) {
#ifndef NDEBUG
LLT OldValResTy = getMRI()->getType(OldValRes);
LLT AddrTy = getMRI()->getType(Addr);
LLT CmpValTy = getMRI()->getType(CmpVal);
LLT NewValTy = getMRI()->getType(NewVal);
LLT OldValResTy = OldValRes.getLLTTy(*getMRI());
LLT AddrTy = Addr.getLLTTy(*getMRI());
LLT CmpValTy = CmpVal.getLLTTy(*getMRI());
LLT NewValTy = NewVal.getLLTTy(*getMRI());
assert(OldValResTy.isScalar() && "invalid operand type");
assert(AddrTy.isPointer() && "invalid operand type");
assert(CmpValTy.isValid() && "invalid operand type");
Expand All @@ -973,12 +974,13 @@ MachineIRBuilder::buildAtomicCmpXchg(Register OldValRes, Register Addr,
assert(OldValResTy == NewValTy && "type mismatch");
#endif

return buildInstr(TargetOpcode::G_ATOMIC_CMPXCHG)
.addDef(OldValRes)
.addUse(Addr)
.addUse(CmpVal)
.addUse(NewVal)
.addMemOperand(&MMO);
auto MIB = buildInstr(TargetOpcode::G_ATOMIC_CMPXCHG);
OldValRes.addDefToMIB(*getMRI(), MIB);
Addr.addSrcToMIB(MIB);
CmpVal.addSrcToMIB(MIB);
NewVal.addSrcToMIB(MIB);
MIB.addMemOperand(&MMO);
return MIB;
}

MachineInstrBuilder MachineIRBuilder::buildAtomicRMW(
Expand Down

0 comments on commit a8b90c0

Please sign in to comment.