[llvm] r243923 - MIR Serialization: Serialize the 'volatile' machine memory operand flag.
Alex Lorenz
arphaman at gmail.com
Mon Aug 3 17:24:45 PDT 2015
Author: arphaman
Date: Mon Aug 3 19:24:45 2015
New Revision: 243923
URL: http://llvm.org/viewvc/llvm-project?rev=243923&view=rev
Log:
MIR Serialization: Serialize the 'volatile' machine memory operand flag.
Modified:
llvm/trunk/lib/CodeGen/MIRParser/MILexer.cpp
llvm/trunk/lib/CodeGen/MIRParser/MILexer.h
llvm/trunk/lib/CodeGen/MIRParser/MIParser.cpp
llvm/trunk/lib/CodeGen/MIRPrinter.cpp
llvm/trunk/test/CodeGen/MIR/X86/memory-operands.mir
Modified: llvm/trunk/lib/CodeGen/MIRParser/MILexer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MIRParser/MILexer.cpp?rev=243923&r1=243922&r2=243923&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MIRParser/MILexer.cpp (original)
+++ llvm/trunk/lib/CodeGen/MIRParser/MILexer.cpp Mon Aug 3 19:24:45 2015
@@ -156,6 +156,7 @@ static MIToken::TokenKind getIdentifierK
.Case("x86_fp80", MIToken::kw_x86_fp80)
.Case("fp128", MIToken::kw_fp128)
.Case("ppc_fp128", MIToken::kw_ppc_fp128)
+ .Case("volatile", MIToken::kw_volatile)
.Default(MIToken::Identifier);
}
Modified: llvm/trunk/lib/CodeGen/MIRParser/MILexer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MIRParser/MILexer.h?rev=243923&r1=243922&r2=243923&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MIRParser/MILexer.h (original)
+++ llvm/trunk/lib/CodeGen/MIRParser/MILexer.h Mon Aug 3 19:24:45 2015
@@ -61,6 +61,7 @@ struct MIToken {
kw_x86_fp80,
kw_fp128,
kw_ppc_fp128,
+ kw_volatile,
// Identifier tokens
Identifier,
@@ -115,6 +116,8 @@ public:
Kind == kw_dead || Kind == kw_killed || Kind == kw_undef;
}
+ bool isMemoryOperandFlag() const { return Kind == kw_volatile; }
+
bool is(TokenKind K) const { return Kind == K; }
bool isNot(TokenKind K) const { return Kind != K; }
Modified: llvm/trunk/lib/CodeGen/MIRParser/MIParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MIRParser/MIParser.cpp?rev=243923&r1=243922&r2=243923&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MIRParser/MIParser.cpp (original)
+++ llvm/trunk/lib/CodeGen/MIRParser/MIParser.cpp Mon Aug 3 19:24:45 2015
@@ -135,6 +135,7 @@ public:
bool parseTargetIndexOperand(MachineOperand &Dest);
bool parseMachineOperand(MachineOperand &Dest);
bool parseIRValue(Value *&V);
+ bool parseMemoryOperandFlag(unsigned &Flags);
bool parseMachineMemoryOperand(MachineMemOperand *&Dest);
private:
@@ -987,14 +988,31 @@ bool MIParser::getUint64(uint64_t &Resul
return false;
}
+bool MIParser::parseMemoryOperandFlag(unsigned &Flags) {
+ switch (Token.kind()) {
+ case MIToken::kw_volatile:
+ Flags |= MachineMemOperand::MOVolatile;
+ break;
+ // TODO: report an error when we specify the same flag more than once.
+ // TODO: parse the other memory operand flags.
+ default:
+ llvm_unreachable("The current token should be a memory operand flag");
+ }
+ lex();
+ return false;
+}
+
bool MIParser::parseMachineMemoryOperand(MachineMemOperand *&Dest) {
if (expectAndConsume(MIToken::lparen))
return true;
- // TODO: Parse the operand's flags.
+ unsigned Flags = 0;
+ while (Token.isMemoryOperandFlag()) {
+ if (parseMemoryOperandFlag(Flags))
+ return true;
+ }
if (Token.isNot(MIToken::Identifier) ||
(Token.stringValue() != "load" && Token.stringValue() != "store"))
return error("expected 'load' or 'store' memory operation");
- unsigned Flags = 0;
if (Token.stringValue() == "load")
Flags |= MachineMemOperand::MOLoad;
else
Modified: llvm/trunk/lib/CodeGen/MIRPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MIRPrinter.cpp?rev=243923&r1=243922&r2=243923&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MIRPrinter.cpp (original)
+++ llvm/trunk/lib/CodeGen/MIRPrinter.cpp Mon Aug 3 19:24:45 2015
@@ -608,6 +608,8 @@ void MIPrinter::print(const MachineOpera
void MIPrinter::print(const MachineMemOperand &Op) {
OS << '(';
// TODO: Print operand's other flags.
+ if (Op.isVolatile())
+ OS << "volatile ";
if (Op.isLoad())
OS << "load ";
else {
Modified: llvm/trunk/test/CodeGen/MIR/X86/memory-operands.mir
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/MIR/X86/memory-operands.mir?rev=243923&r1=243922&r2=243923&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/MIR/X86/memory-operands.mir (original)
+++ llvm/trunk/test/CodeGen/MIR/X86/memory-operands.mir Mon Aug 3 19:24:45 2015
@@ -19,6 +19,14 @@
ret void
}
+ define i32 @volatile_inc(i32* %x) {
+ entry:
+ %0 = load volatile i32, i32* %x
+ %1 = add i32 %0, 1
+ store volatile i32 %1, i32* %x
+ ret i32 %1
+ }
+
...
---
name: test
@@ -50,3 +58,21 @@ body:
- 'INC32m killed %rdi, 1, _, 0, _, implicit-def dead %eflags :: (store 4 into %ir."a value"), (load 4 from %ir."a value")'
- RETQ
...
+---
+name: volatile_inc
+tracksRegLiveness: true
+liveins:
+ - { reg: '%rdi' }
+body:
+ - id: 0
+ name: entry
+ liveins: [ '%rdi' ]
+ instructions:
+ # CHECK: name: volatile_inc
+ # CHECK: %eax = MOV32rm %rdi, 1, _, 0, _ :: (volatile load 4 from %ir.x)
+ # CHECK: MOV32mr killed %rdi, 1, _, 0, _, %eax :: (volatile store 4 into %ir.x)
+ - '%eax = MOV32rm %rdi, 1, _, 0, _ :: (volatile load 4 from %ir.x)'
+ - '%eax = INC32r killed %eax, implicit-def dead %eflags'
+ - 'MOV32mr killed %rdi, 1, _, 0, _, %eax :: (volatile store 4 into %ir.x)'
+ - 'RETQ %eax'
+...
More information about the llvm-commits
mailing list