summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen/MIRParser
diff options
context:
space:
mode:
authorAlex Lorenz <arphaman@gmail.com>2015-07-28 17:28:03 +0000
committerAlex Lorenz <arphaman@gmail.com>2015-07-28 17:28:03 +0000
commitdeb534907e418641b866ca8747e9f20939c19ab3 (patch)
treed74918e885b2b34ec4f19d57b56242de801af3e2 /llvm/lib/CodeGen/MIRParser
parentae7eebd429963b02a7bc90bee9c7038faaff0b5a (diff)
downloadbcm5719-llvm-deb534907e418641b866ca8747e9f20939c19ab3.tar.gz
bcm5719-llvm-deb534907e418641b866ca8747e9f20939c19ab3.zip
MIR Serialization: Serialize the block address machine operands.
llvm-svn: 243453
Diffstat (limited to 'llvm/lib/CodeGen/MIRParser')
-rw-r--r--llvm/lib/CodeGen/MIRParser/MILexer.cpp19
-rw-r--r--llvm/lib/CodeGen/MIRParser/MILexer.h8
-rw-r--r--llvm/lib/CodeGen/MIRParser/MIParser.cpp69
3 files changed, 92 insertions, 4 deletions
diff --git a/llvm/lib/CodeGen/MIRParser/MILexer.cpp b/llvm/lib/CodeGen/MIRParser/MILexer.cpp
index 5cdf9cfb7a7..e2b378a7559 100644
--- a/llvm/lib/CodeGen/MIRParser/MILexer.cpp
+++ b/llvm/lib/CodeGen/MIRParser/MILexer.cpp
@@ -147,6 +147,7 @@ static MIToken::TokenKind getIdentifierKind(StringRef Identifier) {
.Case(".cfi_offset", MIToken::kw_cfi_offset)
.Case(".cfi_def_cfa_register", MIToken::kw_cfi_def_cfa_register)
.Case(".cfi_def_cfa_offset", MIToken::kw_cfi_def_cfa_offset)
+ .Case("blockaddress", MIToken::kw_blockaddress)
.Default(MIToken::Identifier);
}
@@ -239,8 +240,16 @@ static Cursor maybeLexConstantPoolItem(Cursor C, MIToken &Token) {
return maybeLexIndex(C, Token, "%const.", MIToken::ConstantPoolItem);
}
-static Cursor maybeLexIRBlock(Cursor C, MIToken &Token) {
- return maybeLexIndex(C, Token, "%ir-block.", MIToken::IRBlock);
+static Cursor maybeLexIRBlock(
+ Cursor C, MIToken &Token,
+ function_ref<void(StringRef::iterator Loc, const Twine &)> ErrorCallback) {
+ const StringRef Rule = "%ir-block.";
+ if (!C.remaining().startswith(Rule))
+ return None;
+ if (isdigit(C.peek(Rule.size())))
+ return maybeLexIndex(C, Token, Rule, MIToken::IRBlock);
+ return lexName(C, Token, MIToken::NamedIRBlock, MIToken::QuotedNamedIRBlock,
+ Rule.size(), ErrorCallback);
}
static Cursor lexVirtualRegister(Cursor C, MIToken &Token) {
@@ -319,6 +328,10 @@ static MIToken::TokenKind symbolToken(char C) {
return MIToken::colon;
case '!':
return MIToken::exclaim;
+ case '(':
+ return MIToken::lparen;
+ case ')':
+ return MIToken::rparen;
default:
return MIToken::Error;
}
@@ -355,7 +368,7 @@ StringRef llvm::lexMIToken(
return R.remaining();
if (Cursor R = maybeLexConstantPoolItem(C, Token))
return R.remaining();
- if (Cursor R = maybeLexIRBlock(C, Token))
+ if (Cursor R = maybeLexIRBlock(C, Token, ErrorCallback))
return R.remaining();
if (Cursor R = maybeLexRegister(C, Token))
return R.remaining();
diff --git a/llvm/lib/CodeGen/MIRParser/MILexer.h b/llvm/lib/CodeGen/MIRParser/MILexer.h
index 06fa1f256dd..8721ba858f9 100644
--- a/llvm/lib/CodeGen/MIRParser/MILexer.h
+++ b/llvm/lib/CodeGen/MIRParser/MILexer.h
@@ -37,6 +37,8 @@ struct MIToken {
underscore,
colon,
exclaim,
+ lparen,
+ rparen,
// Keywords
kw_implicit,
@@ -49,6 +51,7 @@ struct MIToken {
kw_cfi_offset,
kw_cfi_def_cfa_register,
kw_cfi_def_cfa_offset,
+ kw_blockaddress,
// Identifier tokens
Identifier,
@@ -67,6 +70,8 @@ struct MIToken {
VirtualRegister,
ConstantPoolItem,
JumpTableIndex,
+ NamedIRBlock,
+ QuotedNamedIRBlock,
IRBlock,
};
@@ -105,7 +110,8 @@ public:
StringRef::iterator location() const { return Range.begin(); }
bool isStringValueQuoted() const {
- return Kind == QuotedNamedGlobalValue || Kind == QuotedExternalSymbol;
+ return Kind == QuotedNamedGlobalValue || Kind == QuotedExternalSymbol ||
+ Kind == QuotedNamedIRBlock;
}
/// Return the token's raw string value.
diff --git a/llvm/lib/CodeGen/MIRParser/MIParser.cpp b/llvm/lib/CodeGen/MIRParser/MIParser.cpp
index 6fb4fdddbc7..135a36f2526 100644
--- a/llvm/lib/CodeGen/MIRParser/MIParser.cpp
+++ b/llvm/lib/CodeGen/MIRParser/MIParser.cpp
@@ -22,8 +22,10 @@
#include "llvm/CodeGen/MachineInstrBuilder.h"
#include "llvm/CodeGen/MachineModuleInfo.h"
#include "llvm/IR/Instructions.h"
+#include "llvm/IR/Constants.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/ModuleSlotTracker.h"
+#include "llvm/IR/ValueSymbolTable.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Target/TargetSubtargetInfo.h"
@@ -123,6 +125,8 @@ public:
bool parseCFIOffset(int &Offset);
bool parseCFIRegister(unsigned &Reg);
bool parseCFIOperand(MachineOperand &Dest);
+ bool parseIRBlock(BasicBlock *&BB, const Function &F);
+ bool parseBlockAddressOperand(MachineOperand &Dest);
bool parseMachineOperand(MachineOperand &Dest);
private:
@@ -200,6 +204,10 @@ static const char *toString(MIToken::TokenKind TokenKind) {
switch (TokenKind) {
case MIToken::comma:
return "','";
+ case MIToken::lparen:
+ return "'('";
+ case MIToken::rparen:
+ return "')'";
default:
return "<unknown token>";
}
@@ -741,6 +749,65 @@ bool MIParser::parseCFIOperand(MachineOperand &Dest) {
return false;
}
+bool MIParser::parseIRBlock(BasicBlock *&BB, const Function &F) {
+ switch (Token.kind()) {
+ case MIToken::NamedIRBlock:
+ case MIToken::QuotedNamedIRBlock: {
+ StringValueUtility Name(Token);
+ BB = dyn_cast_or_null<BasicBlock>(F.getValueSymbolTable().lookup(Name));
+ if (!BB)
+ return error(Twine("use of undefined IR block '%ir-block.") +
+ Token.rawStringValue() + "'");
+ break;
+ }
+ case MIToken::IRBlock: {
+ unsigned SlotNumber = 0;
+ if (getUnsigned(SlotNumber))
+ return true;
+ BB = const_cast<BasicBlock *>(getIRBlock(SlotNumber));
+ if (!BB)
+ return error(Twine("use of undefined IR block '%ir-block.") +
+ Twine(SlotNumber) + "'");
+ break;
+ }
+ default:
+ llvm_unreachable("The current token should be an IR block reference");
+ }
+ return false;
+}
+
+bool MIParser::parseBlockAddressOperand(MachineOperand &Dest) {
+ assert(Token.is(MIToken::kw_blockaddress));
+ lex();
+ if (expectAndConsume(MIToken::lparen))
+ return true;
+ if (Token.isNot(MIToken::GlobalValue) &&
+ Token.isNot(MIToken::NamedGlobalValue) &&
+ Token.isNot(MIToken::QuotedNamedGlobalValue))
+ return error("expected a global value");
+ GlobalValue *GV = nullptr;
+ if (parseGlobalValue(GV))
+ return true;
+ auto *F = dyn_cast<Function>(GV);
+ if (!F)
+ return error("expected an IR function reference");
+ lex();
+ if (expectAndConsume(MIToken::comma))
+ return true;
+ BasicBlock *BB = nullptr;
+ if (Token.isNot(MIToken::IRBlock) && Token.isNot(MIToken::NamedIRBlock) &&
+ Token.isNot(MIToken::QuotedNamedIRBlock))
+ return error("expected an IR block reference");
+ if (parseIRBlock(BB, *F))
+ return true;
+ lex();
+ if (expectAndConsume(MIToken::rparen))
+ return true;
+ // TODO: parse offset and target flags.
+ Dest = MachineOperand::CreateBA(BlockAddress::get(F, BB), /*Offset=*/0);
+ return false;
+}
+
bool MIParser::parseMachineOperand(MachineOperand &Dest) {
switch (Token.kind()) {
case MIToken::kw_implicit:
@@ -777,6 +844,8 @@ bool MIParser::parseMachineOperand(MachineOperand &Dest) {
case MIToken::kw_cfi_def_cfa_register:
case MIToken::kw_cfi_def_cfa_offset:
return parseCFIOperand(Dest);
+ case MIToken::kw_blockaddress:
+ return parseBlockAddressOperand(Dest);
case MIToken::Error:
return true;
case MIToken::Identifier:
OpenPOWER on IntegriCloud