Skip to content

Commit

Permalink
[CSKY] Add atomic expand pass to support atomic operation with libcall
Browse files Browse the repository at this point in the history
For now, just support atomic operations by libcall. Further, should investigate atomic
implementation in CSKY target and codegen with atomic and fence related instructions.
  • Loading branch information
zixuan-wu committed Apr 6, 2022
1 parent 586182a commit ec2de74
Show file tree
Hide file tree
Showing 7 changed files with 8,878 additions and 3 deletions.
4 changes: 1 addition & 3 deletions llvm/lib/Target/CSKY/CSKYISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,7 @@ CSKYTargetLowering::CSKYTargetLowering(const TargetMachine &TM,
setOperationAction(ISD::UDIV, MVT::i32, Expand);
}

if (!Subtarget.has3r2E3r3()) {
setOperationAction(ISD::ATOMIC_FENCE, MVT::Other, Expand);
}
setOperationAction(ISD::ATOMIC_FENCE, MVT::Other, Expand);

// Float

Expand Down
6 changes: 6 additions & 0 deletions llvm/lib/Target/CSKY/CSKYTargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class CSKYPassConfig : public TargetPassConfig {
return getTM<CSKYTargetMachine>();
}

void addIRPasses() override;
bool addInstSelector() override;
void addPreEmitPass() override;
};
Expand All @@ -106,6 +107,11 @@ TargetPassConfig *CSKYTargetMachine::createPassConfig(PassManagerBase &PM) {
return new CSKYPassConfig(*this, PM);
}

void CSKYPassConfig::addIRPasses() {
addPass(createAtomicExpandPass());
TargetPassConfig::addIRPasses();
}

bool CSKYPassConfig::addInstSelector() {
addPass(createCSKYISelDag(getCSKYTargetMachine()));

Expand Down
32 changes: 32 additions & 0 deletions llvm/test/CodeGen/CSKY/atomic-cmpxchg-flag.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
; RUN: llc -mtriple=csky -verify-machineinstrs -csky-no-aliases -mattr=+2e3 < %s \
; RUN: | FileCheck -check-prefix=CSKY %s

define i1 @cmpxchg_i32_seq_cst_seq_cst(i32* %ptr, i32 signext %cmp,
i32 signext %val) nounwind {
; CSKY-LABEL: cmpxchg_i32_seq_cst_seq_cst:
; CSKY: # %bb.0: # %entry
; CSKY-NEXT: subi16 sp, sp, 4
; CSKY-NEXT: st32.w lr, (sp, 0) # 4-byte Folded Spill
; CSKY-NEXT: subi16 sp, sp, 8
; CSKY-NEXT: st16.w a1, (sp, 4)
; CSKY-NEXT: movi16 a1, 5
; CSKY-NEXT: st16.w a1, (sp, 0)
; CSKY-NEXT: addi16 a1, sp, 4
; CSKY-NEXT: movi16 a3, 5
; CSKY-NEXT: jsri32 [.LCPI0_0]
; CSKY-NEXT: addi16 sp, sp, 8
; CSKY-NEXT: ld32.w lr, (sp, 0) # 4-byte Folded Reload
; CSKY-NEXT: addi16 sp, sp, 4
; CSKY-NEXT: rts16
; CSKY-NEXT: .p2align 1
; CSKY-NEXT: # %bb.1:
; CSKY-NEXT: .p2align 2
; CSKY-NEXT: .LCPI0_0:
; CSKY-NEXT: .long __atomic_compare_exchange_4
;
entry:
%0 = cmpxchg i32* %ptr, i32 %cmp, i32 %val seq_cst seq_cst
%1 = extractvalue { i32, i1 } %0, 1
ret i1 %1
}
Loading

0 comments on commit ec2de74

Please sign in to comment.