Commit 5396514e authored by Hans Wennborg's avatar Hans Wennborg
Browse files

Merging r339895 and r339896:

------------------------------------------------------------------------
r339895 | niravd | 2018-08-16 18:31:14 +0200 (Thu, 16 Aug 2018) | 13 lines

[MC][X86] Enhance X86 Register expression handling to more closely match GCC.

Allow the comparison of x86 registers in the evaluation of assembler
directives. This generalizes and simplifies the extension from r334022
to catch another case found in the Linux kernel.

Reviewers: rnk, void

Reviewed By: rnk

Subscribers: hiraditya, nickdesaulniers, llvm-commits

Differential Revision: https://reviews.llvm.org/D50795
------------------------------------------------------------------------

------------------------------------------------------------------------
r339896 | d0k | 2018-08-16 18:50:23 +0200 (Thu, 16 Aug 2018) | 1 line

[MC] Remove unused variable
------------------------------------------------------------------------

llvm-svn: 340329
parent e71890b6
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -588,6 +588,8 @@ public:
  virtual bool evaluateAsRelocatableImpl(MCValue &Res,
                                         const MCAsmLayout *Layout,
                                         const MCFixup *Fixup) const = 0;
  // allow Target Expressions to be checked for equality
  virtual bool isEqualTo(const MCExpr *x) const { return false; }
  // This should be set when assigned expressions are not valid ".set"
  // expressions, e.g. registers, and must be inlined.
  virtual bool inlineAssignedExpr() const { return false; }
+1 −1
Original line number Diff line number Diff line
@@ -25,7 +25,7 @@ namespace MCParserUtils {
/// On success, returns false and sets the Symbol and Value output parameters.
bool parseAssignmentExpression(StringRef Name, bool allow_redef,
                               MCAsmParser &Parser, MCSymbol *&Symbol,
                               const MCExpr *&Value, bool AllowExtendedExpr = false);
                               const MCExpr *&Value);

} // namespace MCParserUtils

+3 −3
Original line number Diff line number Diff line
@@ -372,9 +372,9 @@ public:
    SemaCallback = Callback;
  }

  // Target-specific parsing of assembler-level variable assignment.
  virtual bool parseAssignmentExpression(const MCExpr *&Res, SMLoc &EndLoc) {
    return getParser().parseExpression(Res, EndLoc);
  // Target-specific parsing of expression.
  virtual bool parsePrimaryExpr(const MCExpr *&Res, SMLoc &EndLoc) {
    return getParser().parsePrimaryExpr(Res, EndLoc);
  }

  virtual bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc,
+15 −1
Original line number Diff line number Diff line
@@ -750,8 +750,22 @@ bool MCExpr::evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm,
    if (!ABE->getLHS()->evaluateAsRelocatableImpl(LHSValue, Asm, Layout, Fixup,
                                                  Addrs, InSet) ||
        !ABE->getRHS()->evaluateAsRelocatableImpl(RHSValue, Asm, Layout, Fixup,
                                                  Addrs, InSet))
                                                  Addrs, InSet)) {
      // Check if both are Target Expressions, see if we can compare them.
      if (const MCTargetExpr *L = dyn_cast<MCTargetExpr>(ABE->getLHS()))
        if (const MCTargetExpr *R = cast<MCTargetExpr>(ABE->getRHS())) {
          switch (ABE->getOpcode()) {
          case MCBinaryExpr::EQ:
            Res = MCValue::get((L->isEqualTo(R)) ? -1 : 0);
            return true;
          case MCBinaryExpr::NE:
            Res = MCValue::get((R->isEqualTo(R)) ? 0 : -1);
            return true;
          default: {}
          }
        }
      return false;
    }

    // We only support a few operations on non-constant expressions, handle
    // those first.
+10 −14
Original line number Diff line number Diff line
@@ -337,7 +337,7 @@ private:
  StringRef parseStringToComma();

  bool parseAssignment(StringRef Name, bool allow_redef,
                       bool NoDeadStrip = false, bool AllowExtendedExpr = false);
                       bool NoDeadStrip = false);

  unsigned getBinOpPrecedence(AsmToken::TokenKind K,
                              MCBinaryExpr::Opcode &Kind);
@@ -1363,7 +1363,8 @@ void AsmParser::altMacroString(StringRef AltMacroStr,std::string &Res) {
bool AsmParser::parseExpression(const MCExpr *&Res, SMLoc &EndLoc) {
  // Parse the expression.
  Res = nullptr;
  if (parsePrimaryExpr(Res, EndLoc) || parseBinOpRHS(1, Res, EndLoc))
  if (getTargetParser().parsePrimaryExpr(Res, EndLoc) ||
      parseBinOpRHS(1, Res, EndLoc))
    return true;

  // As a special case, we support 'a op b @ modifier' by rewriting the
@@ -1617,7 +1618,7 @@ bool AsmParser::parseBinOpRHS(unsigned Precedence, const MCExpr *&Res,

    // Eat the next primary expression.
    const MCExpr *RHS;
    if (parsePrimaryExpr(RHS, EndLoc))
    if (getTargetParser().parsePrimaryExpr(RHS, EndLoc))
      return true;

    // If BinOp binds less tightly with RHS than the operator after RHS, let
@@ -1826,7 +1827,7 @@ bool AsmParser::parseStatement(ParseStatementInfo &Info,
    // identifier '=' ... -> assignment statement
    Lex();

    return parseAssignment(IDVal, true, /*NoDeadStrip*/ false, /*AllowExtendedExpr*/true);
    return parseAssignment(IDVal, true);

  default: // Normal instruction or directive.
    break;
@@ -2766,11 +2767,11 @@ void AsmParser::handleMacroExit() {
}

bool AsmParser::parseAssignment(StringRef Name, bool allow_redef,
                                bool NoDeadStrip, bool AllowExtendedExpr) {
                                bool NoDeadStrip) {
  MCSymbol *Sym;
  const MCExpr *Value;
  if (MCParserUtils::parseAssignmentExpression(Name, allow_redef, *this, Sym,
                                               Value, AllowExtendedExpr))
                                               Value))
    return true;

  if (!Sym) {
@@ -5839,16 +5840,11 @@ static bool isSymbolUsedInExpression(const MCSymbol *Sym, const MCExpr *Value) {

bool parseAssignmentExpression(StringRef Name, bool allow_redef,
                               MCAsmParser &Parser, MCSymbol *&Sym,
                               const MCExpr *&Value, bool AllowExtendedExpr) {
                               const MCExpr *&Value) {

  // FIXME: Use better location, we should use proper tokens.
  SMLoc EqualLoc = Parser.getTok().getLoc();
  SMLoc EndLoc;
  if (AllowExtendedExpr) {
    if (Parser.getTargetParser().parseAssignmentExpression(Value, EndLoc)) {
      return Parser.TokError("missing expression");
    }
  } else if (Parser.parseExpression(Value, EndLoc))
  if (Parser.parseExpression(Value))
    return Parser.TokError("missing expression");

  // Note: we don't count b as used in "a = b". This is to allow
Loading