diff options
author | Tim Northover <tnorthover@apple.com> | 2014-03-11 10:48:52 +0000 |
---|---|---|
committer | Tim Northover <tnorthover@apple.com> | 2014-03-11 10:48:52 +0000 |
commit | e94a518a22db4b21f4a4a9e34173a11e9dfc5fcc (patch) | |
tree | 054bf7c2cdd888931fdabadb91d82dbb78b05f2b /llvm/lib/AsmParser/LLParser.cpp | |
parent | aab3cfe023752c32da984afb281d322d631ad298 (diff) | |
download | bcm5719-llvm-e94a518a22db4b21f4a4a9e34173a11e9dfc5fcc.tar.gz bcm5719-llvm-e94a518a22db4b21f4a4a9e34173a11e9dfc5fcc.zip |
IR: add a second ordering operand to cmpxhg for failure
The syntax for "cmpxchg" should now look something like:
cmpxchg i32* %addr, i32 42, i32 3 acquire monotonic
where the second ordering argument gives the required semantics in the case
that no exchange takes place. It should be no stronger than the first ordering
constraint and cannot be either "release" or "acq_rel" (since no store will
have taken place).
rdar://problem/15996804
llvm-svn: 203559
Diffstat (limited to 'llvm/lib/AsmParser/LLParser.cpp')
-rw-r--r-- | llvm/lib/AsmParser/LLParser.cpp | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp index f29ceddf643..f75d3c944a5 100644 --- a/llvm/lib/AsmParser/LLParser.cpp +++ b/llvm/lib/AsmParser/LLParser.cpp @@ -1518,6 +1518,15 @@ bool LLParser::ParseScopeAndOrdering(bool isAtomic, SynchronizationScope &Scope, Scope = CrossThread; if (EatIfPresent(lltok::kw_singlethread)) Scope = SingleThread; + + return ParseOrdering(Ordering); +} + +/// ParseOrdering +/// ::= AtomicOrdering +/// +/// This sets Ordering to the parsed value. +bool LLParser::ParseOrdering(AtomicOrdering &Ordering) { switch (Lex.getKind()) { default: return TokError("Expected ordering on atomic instruction"); case lltok::kw_unordered: Ordering = Unordered; break; @@ -4193,11 +4202,12 @@ int LLParser::ParseStore(Instruction *&Inst, PerFunctionState &PFS) { /// ParseCmpXchg /// ::= 'cmpxchg' 'volatile'? TypeAndValue ',' TypeAndValue ',' TypeAndValue -/// 'singlethread'? AtomicOrdering +/// 'singlethread'? AtomicOrdering AtomicOrdering int LLParser::ParseCmpXchg(Instruction *&Inst, PerFunctionState &PFS) { Value *Ptr, *Cmp, *New; LocTy PtrLoc, CmpLoc, NewLoc; bool AteExtraComma = false; - AtomicOrdering Ordering = NotAtomic; + AtomicOrdering SuccessOrdering = NotAtomic; + AtomicOrdering FailureOrdering = NotAtomic; SynchronizationScope Scope = CrossThread; bool isVolatile = false; @@ -4209,11 +4219,16 @@ int LLParser::ParseCmpXchg(Instruction *&Inst, PerFunctionState &PFS) { ParseTypeAndValue(Cmp, CmpLoc, PFS) || ParseToken(lltok::comma, "expected ',' after cmpxchg cmp operand") || ParseTypeAndValue(New, NewLoc, PFS) || - ParseScopeAndOrdering(true /*Always atomic*/, Scope, Ordering)) + ParseScopeAndOrdering(true /*Always atomic*/, Scope, SuccessOrdering) || + ParseOrdering(FailureOrdering)) return true; - if (Ordering == Unordered) + if (SuccessOrdering == Unordered || FailureOrdering == Unordered) return TokError("cmpxchg cannot be unordered"); + if (SuccessOrdering < FailureOrdering) + return TokError("cmpxchg must be at least as ordered on success as failure"); + if (FailureOrdering == Release || FailureOrdering == AcquireRelease) + return TokError("cmpxchg failure ordering cannot include release semantics"); if (!Ptr->getType()->isPointerTy()) return Error(PtrLoc, "cmpxchg operand must be a pointer"); if (cast<PointerType>(Ptr->getType())->getElementType() != Cmp->getType()) @@ -4227,8 +4242,8 @@ int LLParser::ParseCmpXchg(Instruction *&Inst, PerFunctionState &PFS) { return Error(NewLoc, "cmpxchg operand must be power-of-two byte-sized" " integer"); - AtomicCmpXchgInst *CXI = - new AtomicCmpXchgInst(Ptr, Cmp, New, Ordering, Scope); + AtomicCmpXchgInst *CXI = new AtomicCmpXchgInst(Ptr, Cmp, New, SuccessOrdering, + FailureOrdering, Scope); CXI->setVolatile(isVolatile); Inst = CXI; return AteExtraComma ? InstExtraComma : InstNormal; |