summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen/MIRParser/MILexer.cpp
diff options
context:
space:
mode:
authorAlex Lorenz <arphaman@gmail.com>2015-08-13 23:10:16 +0000
committerAlex Lorenz <arphaman@gmail.com>2015-08-13 23:10:16 +0000
commit5022f6bb817321c0e687ef9ce49df29e15d9c213 (patch)
tree6b9e04cc072b6041a75f25699a87f4fb582874b3 /llvm/lib/CodeGen/MIRParser/MILexer.cpp
parent2038b54eaec38824af90969d61e06f2d58a30c0c (diff)
downloadbcm5719-llvm-5022f6bb817321c0e687ef9ce49df29e15d9c213.tar.gz
bcm5719-llvm-5022f6bb817321c0e687ef9ce49df29e15d9c213.zip
MIR Serialization: Change MIR syntax - use custom syntax for MBBs.
This commit modifies the way the machine basic blocks are serialized - now the machine basic blocks are serialized using a custom syntax instead of relying on YAML primitives. Instead of using YAML mappings to represent the individual machine basic blocks in a machine function's body, the new syntax uses a single YAML block scalar which contains all of the machine basic blocks and instructions for that function. This is an example of a function's body that uses the old syntax: body: - id: 0 name: entry instructions: - '%eax = MOV32r0 implicit-def %eflags' - 'RETQ %eax' ... The same body is now written like this: body: | bb.0.entry: %eax = MOV32r0 implicit-def %eflags RETQ %eax ... This syntax change is motivated by the fact that the bundled machine instructions didn't map that well to the old syntax which was using a single YAML sequence to store all of the machine instructions in a block. The bundled machine instructions internally use flags like BundledPred and BundledSucc to determine the bundles, and serializing them as MI flags using the old syntax would have had a negative impact on the readability and the ease of editing for MIR files. The new syntax allows me to serialize the bundled machine instructions using a block construct without relying on the internal flags, for example: BUNDLE implicit-def dead %itstate, implicit-def %s1 ... { t2IT 1, 24, implicit-def %itstate %s1 = VMOVS killed %s0, 1, killed %cpsr, implicit killed %itstate } This commit also converts the MIR testcases to the new syntax. I developed a script that can convert from the old syntax to the new one. I will post the script on the llvm-commits mailing list in the thread for this commit. llvm-svn: 244982
Diffstat (limited to 'llvm/lib/CodeGen/MIRParser/MILexer.cpp')
-rw-r--r--llvm/lib/CodeGen/MIRParser/MILexer.cpp48
1 files changed, 39 insertions, 9 deletions
diff --git a/llvm/lib/CodeGen/MIRParser/MILexer.cpp b/llvm/lib/CodeGen/MIRParser/MILexer.cpp
index 25afedff973..450d318f8c8 100644
--- a/llvm/lib/CodeGen/MIRParser/MILexer.cpp
+++ b/llvm/lib/CodeGen/MIRParser/MILexer.cpp
@@ -79,7 +79,18 @@ MIToken &MIToken::setIntegerValue(APSInt IntVal) {
/// Skip the leading whitespace characters and return the updated cursor.
static Cursor skipWhitespace(Cursor C) {
- while (isspace(C.peek()))
+ while (isblank(C.peek()))
+ C.advance();
+ return C;
+}
+
+static bool isNewlineChar(char C) { return C == '\n' || C == '\r'; }
+
+/// Skip a line comment and return the updated cursor.
+static Cursor skipComment(Cursor C) {
+ if (C.peek() != ';')
+ return C;
+ while (!isNewlineChar(C.peek()) && !C.isEOF())
C.advance();
return C;
}
@@ -127,7 +138,7 @@ static Cursor lexStringConstant(
function_ref<void(StringRef::iterator Loc, const Twine &)> ErrorCallback) {
assert(C.peek() == '"');
for (C.advance(); C.peek() != '"'; C.advance()) {
- if (C.isEOF()) {
+ if (C.isEOF() || isNewlineChar(C.peek())) {
ErrorCallback(
C.location(),
"end of machine instruction reached before the closing '\"'");
@@ -206,6 +217,10 @@ static MIToken::TokenKind getIdentifierKind(StringRef Identifier) {
.Case("jump-table", MIToken::kw_jump_table)
.Case("constant-pool", MIToken::kw_constant_pool)
.Case("liveout", MIToken::kw_liveout)
+ .Case("address-taken", MIToken::kw_address_taken)
+ .Case("landing-pad", MIToken::kw_landing_pad)
+ .Case("liveins", MIToken::kw_liveins)
+ .Case("successors", MIToken::kw_successors)
.Default(MIToken::Identifier);
}
@@ -224,10 +239,12 @@ static Cursor maybeLexIdentifier(Cursor C, MIToken &Token) {
static Cursor maybeLexMachineBasicBlock(
Cursor C, MIToken &Token,
function_ref<void(StringRef::iterator Loc, const Twine &)> ErrorCallback) {
- if (!C.remaining().startswith("%bb."))
+ bool IsReference = C.remaining().startswith("%bb.");
+ if (!IsReference && !C.remaining().startswith("bb."))
return None;
auto Range = C;
- C.advance(4); // Skip '%bb.'
+ unsigned PrefixLength = IsReference ? 4 : 3;
+ C.advance(PrefixLength); // Skip '%bb.' or 'bb.'
if (!isdigit(C.peek())) {
Token.reset(MIToken::Error, C.remaining());
ErrorCallback(C.location(), "expected a number after '%bb.'");
@@ -237,14 +254,16 @@ static Cursor maybeLexMachineBasicBlock(
while (isdigit(C.peek()))
C.advance();
StringRef Number = NumberRange.upto(C);
- unsigned StringOffset = 4 + Number.size(); // Drop '%bb.<id>'
+ unsigned StringOffset = PrefixLength + Number.size(); // Drop '%bb.<id>'
if (C.peek() == '.') {
C.advance(); // Skip '.'
++StringOffset;
while (isIdentifierChar(C.peek()))
C.advance();
}
- Token.reset(MIToken::MachineBasicBlock, Range.upto(C))
+ Token.reset(IsReference ? MIToken::MachineBasicBlock
+ : MIToken::MachineBasicBlockLabel,
+ Range.upto(C))
.setIntegerValue(APSInt(Number))
.setStringValue(Range.upto(C).drop_front(StringOffset));
return C;
@@ -460,10 +479,19 @@ static Cursor maybeLexSymbol(Cursor C, MIToken &Token) {
return C;
}
+static Cursor maybeLexNewline(Cursor C, MIToken &Token) {
+ if (!isNewlineChar(C.peek()))
+ return None;
+ auto Range = C;
+ C.advance();
+ Token.reset(MIToken::Newline, Range.upto(C));
+ return C;
+}
+
StringRef llvm::lexMIToken(
StringRef Source, MIToken &Token,
function_ref<void(StringRef::iterator Loc, const Twine &)> ErrorCallback) {
- auto C = skipWhitespace(Cursor(Source));
+ auto C = skipComment(skipWhitespace(Cursor(Source)));
if (C.isEOF()) {
Token.reset(MIToken::Eof, C.remaining());
return C.remaining();
@@ -471,10 +499,10 @@ StringRef llvm::lexMIToken(
if (Cursor R = maybeLexIntegerType(C, Token))
return R.remaining();
- if (Cursor R = maybeLexIdentifier(C, Token))
- return R.remaining();
if (Cursor R = maybeLexMachineBasicBlock(C, Token, ErrorCallback))
return R.remaining();
+ if (Cursor R = maybeLexIdentifier(C, Token))
+ return R.remaining();
if (Cursor R = maybeLexJumpTableIndex(C, Token))
return R.remaining();
if (Cursor R = maybeLexStackObject(C, Token))
@@ -499,6 +527,8 @@ StringRef llvm::lexMIToken(
return R.remaining();
if (Cursor R = maybeLexSymbol(C, Token))
return R.remaining();
+ if (Cursor R = maybeLexNewline(C, Token))
+ return R.remaining();
Token.reset(MIToken::Error, C.remaining());
ErrorCallback(C.location(),
OpenPOWER on IntegriCloud