@@ -87,6 +87,9 @@ bool RISCVExpandPseudo::expandMI(MachineBasicBlock &MBB,
87
87
case RISCV::PseudoAtomicLoadNand32:
88
88
return expandAtomicBinOp (MBB, MBBI, AtomicRMWInst::Nand, false , 32 ,
89
89
NextMBBI);
90
+ case RISCV::PseudoAtomicLoadNand64:
91
+ return expandAtomicBinOp (MBB, MBBI, AtomicRMWInst::Nand, false , 64 ,
92
+ NextMBBI);
90
93
case RISCV::PseudoMaskedAtomicSwap32:
91
94
return expandAtomicBinOp (MBB, MBBI, AtomicRMWInst::Xchg, true , 32 ,
92
95
NextMBBI);
@@ -111,6 +114,8 @@ bool RISCVExpandPseudo::expandMI(MachineBasicBlock &MBB,
111
114
NextMBBI);
112
115
case RISCV::PseudoCmpXchg32:
113
116
return expandAtomicCmpXchg (MBB, MBBI, false , 32 , NextMBBI);
117
+ case RISCV::PseudoCmpXchg64:
118
+ return expandAtomicCmpXchg (MBB, MBBI, false , 64 , NextMBBI);
114
119
case RISCV::PseudoMaskedCmpXchg32:
115
120
return expandAtomicCmpXchg (MBB, MBBI, true , 32 , NextMBBI);
116
121
}
@@ -152,12 +157,61 @@ static unsigned getSCForRMW32(AtomicOrdering Ordering) {
152
157
}
153
158
}
154
159
160
+ static unsigned getLRForRMW64 (AtomicOrdering Ordering) {
161
+ switch (Ordering) {
162
+ default :
163
+ llvm_unreachable (" Unexpected AtomicOrdering" );
164
+ case AtomicOrdering::Monotonic:
165
+ return RISCV::LR_D;
166
+ case AtomicOrdering::Acquire:
167
+ return RISCV::LR_D_AQ;
168
+ case AtomicOrdering::Release:
169
+ return RISCV::LR_D;
170
+ case AtomicOrdering::AcquireRelease:
171
+ return RISCV::LR_D_AQ;
172
+ case AtomicOrdering::SequentiallyConsistent:
173
+ return RISCV::LR_D_AQ_RL;
174
+ }
175
+ }
176
+
177
+ static unsigned getSCForRMW64 (AtomicOrdering Ordering) {
178
+ switch (Ordering) {
179
+ default :
180
+ llvm_unreachable (" Unexpected AtomicOrdering" );
181
+ case AtomicOrdering::Monotonic:
182
+ return RISCV::SC_D;
183
+ case AtomicOrdering::Acquire:
184
+ return RISCV::SC_D;
185
+ case AtomicOrdering::Release:
186
+ return RISCV::SC_D_RL;
187
+ case AtomicOrdering::AcquireRelease:
188
+ return RISCV::SC_D_RL;
189
+ case AtomicOrdering::SequentiallyConsistent:
190
+ return RISCV::SC_D_AQ_RL;
191
+ }
192
+ }
193
+
194
+ static unsigned getLRForRMW (AtomicOrdering Ordering, int Width) {
195
+ if (Width == 32 )
196
+ return getLRForRMW32 (Ordering);
197
+ if (Width == 64 )
198
+ return getLRForRMW64 (Ordering);
199
+ llvm_unreachable (" Unexpected LR width\n " );
200
+ }
201
+
202
+ static unsigned getSCForRMW (AtomicOrdering Ordering, int Width) {
203
+ if (Width == 32 )
204
+ return getSCForRMW32 (Ordering);
205
+ if (Width == 64 )
206
+ return getSCForRMW64 (Ordering);
207
+ llvm_unreachable (" Unexpected SC width\n " );
208
+ }
209
+
155
210
static void doAtomicBinOpExpansion (const RISCVInstrInfo *TII, MachineInstr &MI,
156
211
DebugLoc DL, MachineBasicBlock *ThisMBB,
157
212
MachineBasicBlock *LoopMBB,
158
213
MachineBasicBlock *DoneMBB,
159
214
AtomicRMWInst::BinOp BinOp, int Width) {
160
- assert (Width == 32 && " RV64 atomic expansion currently unsupported" );
161
215
unsigned DestReg = MI.getOperand (0 ).getReg ();
162
216
unsigned ScratchReg = MI.getOperand (1 ).getReg ();
163
217
unsigned AddrReg = MI.getOperand (2 ).getReg ();
@@ -166,11 +220,11 @@ static void doAtomicBinOpExpansion(const RISCVInstrInfo *TII, MachineInstr &MI,
166
220
static_cast <AtomicOrdering>(MI.getOperand (4 ).getImm ());
167
221
168
222
// .loop:
169
- // lr.w dest, (addr)
223
+ // lr.[w|d] dest, (addr)
170
224
// binop scratch, dest, val
171
- // sc.w scratch, scratch, (addr)
225
+ // sc.[w|d] scratch, scratch, (addr)
172
226
// bnez scratch, loop
173
- BuildMI (LoopMBB, DL, TII->get (getLRForRMW32 (Ordering)), DestReg)
227
+ BuildMI (LoopMBB, DL, TII->get (getLRForRMW (Ordering, Width )), DestReg)
174
228
.addReg (AddrReg);
175
229
switch (BinOp) {
176
230
default :
@@ -184,7 +238,7 @@ static void doAtomicBinOpExpansion(const RISCVInstrInfo *TII, MachineInstr &MI,
184
238
.addImm (-1 );
185
239
break ;
186
240
}
187
- BuildMI (LoopMBB, DL, TII->get (getSCForRMW32 (Ordering)), ScratchReg)
241
+ BuildMI (LoopMBB, DL, TII->get (getSCForRMW (Ordering, Width )), ScratchReg)
188
242
.addReg (AddrReg)
189
243
.addReg (ScratchReg);
190
244
BuildMI (LoopMBB, DL, TII->get (RISCV::BNE))
@@ -219,7 +273,7 @@ static void doMaskedAtomicBinOpExpansion(
219
273
const RISCVInstrInfo *TII, MachineInstr &MI, DebugLoc DL,
220
274
MachineBasicBlock *ThisMBB, MachineBasicBlock *LoopMBB,
221
275
MachineBasicBlock *DoneMBB, AtomicRMWInst::BinOp BinOp, int Width) {
222
- assert (Width == 32 && " RV64 atomic expansion currently unsupported " );
276
+ assert (Width == 32 && " Should never need to expand masked 64-bit operations " );
223
277
unsigned DestReg = MI.getOperand (0 ).getReg ();
224
278
unsigned ScratchReg = MI.getOperand (1 ).getReg ();
225
279
unsigned AddrReg = MI.getOperand (2 ).getReg ();
@@ -333,7 +387,7 @@ bool RISCVExpandPseudo::expandAtomicMinMaxOp(
333
387
MachineBasicBlock::iterator &NextMBBI) {
334
388
assert (IsMasked == true &&
335
389
" Should only need to expand masked atomic max/min" );
336
- assert (Width == 32 && " RV64 atomic expansion currently unsupported " );
390
+ assert (Width == 32 && " Should never need to expand masked 64-bit operations " );
337
391
338
392
MachineInstr &MI = *MBBI;
339
393
DebugLoc DL = MI.getDebugLoc ();
@@ -451,7 +505,6 @@ bool RISCVExpandPseudo::expandAtomicMinMaxOp(
451
505
bool RISCVExpandPseudo::expandAtomicCmpXchg (
452
506
MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, bool IsMasked,
453
507
int Width, MachineBasicBlock::iterator &NextMBBI) {
454
- assert (Width == 32 && " RV64 atomic expansion currently unsupported" );
455
508
MachineInstr &MI = *MBBI;
456
509
DebugLoc DL = MI.getDebugLoc ();
457
510
MachineFunction *MF = MBB.getParent ();
@@ -483,18 +536,18 @@ bool RISCVExpandPseudo::expandAtomicCmpXchg(
483
536
484
537
if (!IsMasked) {
485
538
// .loophead:
486
- // lr.w dest, (addr)
539
+ // lr.[w|d] dest, (addr)
487
540
// bne dest, cmpval, done
488
- BuildMI (LoopHeadMBB, DL, TII->get (getLRForRMW32 (Ordering)), DestReg)
541
+ BuildMI (LoopHeadMBB, DL, TII->get (getLRForRMW (Ordering, Width )), DestReg)
489
542
.addReg (AddrReg);
490
543
BuildMI (LoopHeadMBB, DL, TII->get (RISCV::BNE))
491
544
.addReg (DestReg)
492
545
.addReg (CmpValReg)
493
546
.addMBB (DoneMBB);
494
547
// .looptail:
495
- // sc.w scratch, newval, (addr)
548
+ // sc.[w|d] scratch, newval, (addr)
496
549
// bnez scratch, loophead
497
- BuildMI (LoopTailMBB, DL, TII->get (getSCForRMW32 (Ordering)), ScratchReg)
550
+ BuildMI (LoopTailMBB, DL, TII->get (getSCForRMW (Ordering, Width )), ScratchReg)
498
551
.addReg (AddrReg)
499
552
.addReg (NewValReg);
500
553
BuildMI (LoopTailMBB, DL, TII->get (RISCV::BNE))
@@ -507,7 +560,7 @@ bool RISCVExpandPseudo::expandAtomicCmpXchg(
507
560
// and scratch, dest, mask
508
561
// bne scratch, cmpval, done
509
562
unsigned MaskReg = MI.getOperand (5 ).getReg ();
510
- BuildMI (LoopHeadMBB, DL, TII->get (getLRForRMW32 (Ordering)), DestReg)
563
+ BuildMI (LoopHeadMBB, DL, TII->get (getLRForRMW (Ordering, Width )), DestReg)
511
564
.addReg (AddrReg);
512
565
BuildMI (LoopHeadMBB, DL, TII->get (RISCV::AND), ScratchReg)
513
566
.addReg (DestReg)
@@ -525,7 +578,7 @@ bool RISCVExpandPseudo::expandAtomicCmpXchg(
525
578
// bnez scratch, loophead
526
579
insertMaskedMerge (TII, DL, LoopTailMBB, ScratchReg, DestReg, NewValReg,
527
580
MaskReg, ScratchReg);
528
- BuildMI (LoopTailMBB, DL, TII->get (getSCForRMW32 (Ordering)), ScratchReg)
581
+ BuildMI (LoopTailMBB, DL, TII->get (getSCForRMW (Ordering, Width )), ScratchReg)
529
582
.addReg (AddrReg)
530
583
.addReg (ScratchReg);
531
584
BuildMI (LoopTailMBB, DL, TII->get (RISCV::BNE))
0 commit comments