From b82063e6e5e09d8dfa57dfd32dedc7acd40fdd17 Mon Sep 17 00:00:00 2001 From: Alex Lorenz Date: Tue, 28 Jul 2015 17:09:52 +0000 Subject: [PATCH] MIR Parser: Extract the method 'parseGlobalValue'. NFC. This commit extracts the code that parses a global value from the method 'parseGlobalAddressOperand' into a new method 'parseGlobalValue', so that this code can be reused by the method which will parse the block address machine operands. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@243450 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/MIRParser/MIParser.cpp | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/lib/CodeGen/MIRParser/MIParser.cpp b/lib/CodeGen/MIRParser/MIParser.cpp index 1bdaedb5d3a..6fb4fdddbc7 100644 --- a/lib/CodeGen/MIRParser/MIParser.cpp +++ b/lib/CodeGen/MIRParser/MIParser.cpp @@ -113,6 +113,7 @@ public: bool parseMBBOperand(MachineOperand &Dest); bool parseStackObjectOperand(MachineOperand &Dest); bool parseFixedStackObjectOperand(MachineOperand &Dest); + bool parseGlobalValue(GlobalValue *&GV); bool parseGlobalAddressOperand(MachineOperand &Dest); bool parseConstantPoolIndexOperand(MachineOperand &Dest); bool parseJumpTableIndexOperand(MachineOperand &Dest); @@ -576,18 +577,17 @@ bool MIParser::parseFixedStackObjectOperand(MachineOperand &Dest) { return false; } -bool MIParser::parseGlobalAddressOperand(MachineOperand &Dest) { +bool MIParser::parseGlobalValue(GlobalValue *&GV) { switch (Token.kind()) { case MIToken::NamedGlobalValue: case MIToken::QuotedNamedGlobalValue: { StringValueUtility Name(Token); const Module *M = MF.getFunction()->getParent(); - if (const auto *GV = M->getNamedValue(Name)) { - Dest = MachineOperand::CreateGA(GV, /*Offset=*/0); - break; - } - return error(Twine("use of undefined global value '@") + - Token.rawStringValue() + "'"); + GV = M->getNamedValue(Name); + if (!GV) + return error(Twine("use of undefined global value '@") + + Token.rawStringValue() + "'"); + break; } case MIToken::GlobalValue: { unsigned GVIdx; @@ -596,13 +596,20 @@ bool MIParser::parseGlobalAddressOperand(MachineOperand &Dest) { if (GVIdx >= IRSlots.GlobalValues.size()) return error(Twine("use of undefined global value '@") + Twine(GVIdx) + "'"); - Dest = MachineOperand::CreateGA(IRSlots.GlobalValues[GVIdx], - /*Offset=*/0); + GV = IRSlots.GlobalValues[GVIdx]; break; } default: llvm_unreachable("The current token should be a global value"); } + return false; +} + +bool MIParser::parseGlobalAddressOperand(MachineOperand &Dest) { + GlobalValue *GV = nullptr; + if (parseGlobalValue(GV)) + return true; + Dest = MachineOperand::CreateGA(GV, /*Offset=*/0); // TODO: Parse offset and target flags. lex(); return false; -- 2.34.1