llvm.org GIT mirror llvm / 1a3fe2b
MIR: parse & print the atomic parts of a MachineMemOperand. We're going to need them very soon for GlobalISel. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294992 91177308-0d34-0410-b5e6-96231b3b80d8 Tim Northover 3 years ago
4 changed file(s) with 80 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
187187 bool parseMemoryOperandFlag(MachineMemOperand::Flags &Flags);
188188 bool parseMemoryPseudoSourceValue(const PseudoSourceValue *&PSV);
189189 bool parseMachinePointerInfo(MachinePointerInfo &Dest);
190 bool parseOptionalAtomicOrdering(AtomicOrdering &Order);
190191 bool parseMachineMemoryOperand(MachineMemOperand *&Dest);
191192
192193 private:
20392040 return false;
20402041 }
20412042
2043 bool MIParser::parseOptionalAtomicOrdering(AtomicOrdering &Order) {
2044 Order = AtomicOrdering::NotAtomic;
2045 if (Token.isNot(MIToken::Identifier))
2046 return false;
2047
2048 Order = StringSwitch(Token.stringValue())
2049 .Case("unordered", AtomicOrdering::Unordered)
2050 .Case("monotonic", AtomicOrdering::Monotonic)
2051 .Case("acquire", AtomicOrdering::Acquire)
2052 .Case("release", AtomicOrdering::Release)
2053 .Case("acq_rel", AtomicOrdering::AcquireRelease)
2054 .Case("seq_cst", AtomicOrdering::SequentiallyConsistent)
2055 .Default(AtomicOrdering::NotAtomic);
2056
2057 if (Order != AtomicOrdering::NotAtomic) {
2058 lex();
2059 return false;
2060 }
2061
2062 return error("expected an atomic scope, ordering or a size integer literal");
2063 }
2064
20422065 bool MIParser::parseMachineMemoryOperand(MachineMemOperand *&Dest) {
20432066 if (expectAndConsume(MIToken::lparen))
20442067 return true;
20552078 else
20562079 Flags |= MachineMemOperand::MOStore;
20572080 lex();
2081
2082 // Optional "singlethread" scope.
2083 SynchronizationScope Scope = SynchronizationScope::CrossThread;
2084 if (Token.is(MIToken::Identifier) && Token.stringValue() == "singlethread") {
2085 Scope = SynchronizationScope::SingleThread;
2086 lex();
2087 }
2088
2089 // Up to two atomic orderings (cmpxchg provides guarantees on failure).
2090 AtomicOrdering Order, FailureOrder;
2091 if (parseOptionalAtomicOrdering(Order))
2092 return true;
2093
2094 if (parseOptionalAtomicOrdering(FailureOrder))
2095 return true;
20582096
20592097 if (Token.isNot(MIToken::IntegerLiteral))
20602098 return error("expected the size integer literal after memory operation");
21102148 }
21112149 if (expectAndConsume(MIToken::rparen))
21122150 return true;
2113 Dest =
2114 MF.getMachineMemOperand(Ptr, Flags, Size, BaseAlignment, AAInfo, Range);
2151 Dest = MF.getMachineMemOperand(Ptr, Flags, Size, BaseAlignment, AAInfo, Range,
2152 Scope, Order, FailureOrder);
21152153 return false;
21162154 }
21172155
925925 assert(Op.isStore() && "Non load machine operand must be a store");
926926 OS << "store ";
927927 }
928
929 if (Op.getSynchScope() == SynchronizationScope::SingleThread)
930 OS << "singlethread ";
931
932 if (Op.getOrdering() != AtomicOrdering::NotAtomic)
933 OS << toIRString(Op.getOrdering()) << ' ';
934 if (Op.getFailureOrdering() != AtomicOrdering::NotAtomic)
935 OS << toIRString(Op.getFailureOrdering()) << ' ';
936
928937 OS << Op.getSize();
929938 if (const Value *Val = Op.getValue()) {
930939 OS << (Op.isLoad() ? " from " : " into ");
0 # RUN: llc -mtriple=aarch64-none-linux-gnu -run-pass none -o - %s | FileCheck %s
1
2 --- |
3
4 define void @atomic_memoperands() {
5 ret void
6 }
7
8 ...
9 ---
10 # CHECK-LABEL: name: atomic_memoperands
11 # CHECK: %1(s64) = G_LOAD %0(p0) :: (load unordered 8)
12 # CHECK: %2(s32) = G_LOAD %0(p0) :: (load monotonic 4)
13 # CHECK: %3(s16) = G_LOAD %0(p0) :: (load acquire 2)
14 # CHECK: G_STORE %3(s16), %0(p0) :: (store release 2)
15 # CHECK: G_STORE %2(s32), %0(p0) :: (store acq_rel 4)
16 # CHECK: G_STORE %1(s64), %0(p0) :: (store singlethread seq_cst 8)
17 name: atomic_memoperands
18 body: |
19 bb.0:
20
21 %0:_(p0) = COPY %x0
22 %1:_(s64) = G_LOAD %0(p0) :: (load unordered 8)
23 %2:_(s32) = G_LOAD %0(p0) :: (load monotonic 4)
24 %3:_(s16) = G_LOAD %0(p0) :: (load acquire 2)
25 G_STORE %3(s16), %0(p0) :: (store release 2)
26 G_STORE %2(s32), %0(p0) :: (store acq_rel 4)
27 G_STORE %1(s64), %0(p0) :: (store singlethread seq_cst 8)
28 RET_ReallyLR
29 ...
1616 body: |
1717 bb.0.entry:
1818 liveins: %rdi
19 ; CHECK: [[@LINE+1]]:53: expected the size integer literal after memory operation
19 ; CHECK: [[@LINE+1]]:53: expected an atomic scope, ordering or a size integer literal
2020 %eax = MOV32rm killed %rdi, 1, _, 0, _ :: (load from %ir.a)
2121 RETQ %eax
2222 ...