[llvm] r249940 - Use emplace_back instead of a constructor call and push_back. NFC

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 12 20:55:43 PDT 2015


On Mon, Oct 12, 2015 at 11:06 AM, David Blaikie <dblaikie at gmail.com> wrote:

>
>
> On Fri, Oct 9, 2015 at 10:25 PM, Craig Topper via llvm-commits <
> llvm-commits at lists.llvm.org> wrote:
>
>> Author: ctopper
>> Date: Sat Oct 10 00:25:02 2015
>> New Revision: 249940
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=249940&view=rev
>> Log:
>> Use emplace_back instead of a constructor call and push_back. NFC
>>
>
> Any particular reason? I've tended to err away from emplace functions
> except where necessary (because the type isn't movable or the object
> identity is otherwise necessary)
>
> Just wondering what kind of motivation others are using for determining
> the choice - not suggesting any way is right/wrong/should be
> avoided/encouraged.
>

No good reason other than it was shorter and AsmRewrite objects are only
constructed when their being pushed to the vector.


>
>
>>
>> Modified:
>>     llvm/trunk/lib/MC/MCParser/AsmParser.cpp
>>     llvm/trunk/lib/Target/X86/AsmParser/X86AsmParser.cpp
>>
>> Modified: llvm/trunk/lib/MC/MCParser/AsmParser.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/AsmParser.cpp?rev=249940&r1=249939&r2=249940&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/lib/MC/MCParser/AsmParser.cpp (original)
>> +++ llvm/trunk/lib/MC/MCParser/AsmParser.cpp Sat Oct 10 00:25:02 2015
>> @@ -1337,8 +1337,8 @@ bool AsmParser::parseStatement(ParseStat
>>              SI->LookupInlineAsmLabel(IDVal, getSourceManager(), IDLoc,
>> true);
>>          assert(RewrittenLabel.size() &&
>>                 "We should have an internal name here.");
>> -        Info.AsmRewrites->push_back(AsmRewrite(AOK_Label, IDLoc,
>> -                                               IDVal.size(),
>> RewrittenLabel));
>> +        Info.AsmRewrites->emplace_back(AOK_Label, IDLoc, IDVal.size(),
>> +                                       RewrittenLabel);
>>          IDVal = RewrittenLabel;
>>        }
>>        Sym = getContext().getOrCreateSymbol(IDVal);
>> @@ -4498,7 +4498,7 @@ bool AsmParser::parseDirectiveMSEmit(SML
>>    if (!isUIntN(8, IntValue) && !isIntN(8, IntValue))
>>      return Error(ExprLoc, "literal value out of range for directive");
>>
>> -  Info.AsmRewrites->push_back(AsmRewrite(AOK_Emit, IDLoc, Len));
>> +  Info.AsmRewrites->emplace_back(AOK_Emit, IDLoc, Len);
>>    return false;
>>  }
>>
>> @@ -4514,8 +4514,7 @@ bool AsmParser::parseDirectiveMSAlign(SM
>>    if (!isPowerOf2_64(IntValue))
>>      return Error(ExprLoc, "literal value not a power of two greater then
>> zero");
>>
>> -  Info.AsmRewrites->push_back(
>> -      AsmRewrite(AOK_Align, IDLoc, 5, Log2_64(IntValue)));
>> +  Info.AsmRewrites->emplace_back(AOK_Align, IDLoc, 5, Log2_64(IntValue));
>>    return false;
>>  }
>>
>> @@ -4611,12 +4610,12 @@ bool AsmParser::parseMSInlineAsm(
>>          OutputDecls.push_back(OpDecl);
>>          OutputDeclsAddressOf.push_back(Operand.needAddressOf());
>>          OutputConstraints.push_back(("=" +
>> Operand.getConstraint()).str());
>> -        AsmStrRewrites.push_back(AsmRewrite(AOK_Output, Start,
>> SymName.size()));
>> +        AsmStrRewrites.emplace_back(AOK_Output, Start, SymName.size());
>>        } else {
>>          InputDecls.push_back(OpDecl);
>>          InputDeclsAddressOf.push_back(Operand.needAddressOf());
>>          InputConstraints.push_back(Operand.getConstraint().str());
>> -        AsmStrRewrites.push_back(AsmRewrite(AOK_Input, Start,
>> SymName.size()));
>> +        AsmStrRewrites.emplace_back(AOK_Input, Start, SymName.size());
>>        }
>>      }
>>
>>
>> Modified: llvm/trunk/lib/Target/X86/AsmParser/X86AsmParser.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/AsmParser/X86AsmParser.cpp?rev=249940&r1=249939&r2=249940&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/lib/Target/X86/AsmParser/X86AsmParser.cpp (original)
>> +++ llvm/trunk/lib/Target/X86/AsmParser/X86AsmParser.cpp Sat Oct 10
>> 00:25:02 2015
>> @@ -1072,8 +1072,8 @@ std::unique_ptr<X86Operand> X86AsmParser
>>      // Insert an explicit size if the user didn't have one.
>>      if (!Size) {
>>        Size = getPointerWidth();
>> -      InstInfo->AsmRewrites->push_back(AsmRewrite(AOK_SizeDirective,
>> Start,
>> -                                                  /*Len=*/0, Size));
>> +      InstInfo->AsmRewrites->emplace_back(AOK_SizeDirective, Start,
>> +                                          /*Len=*/0, Size);
>>      }
>>
>>      // Create an absolute memory reference in order to match against
>> @@ -1092,8 +1092,8 @@ std::unique_ptr<X86Operand> X86AsmParser
>>      if (!Size) {
>>        Size = Info.Type * 8; // Size is in terms of bits in this context.
>>        if (Size)
>> -        InstInfo->AsmRewrites->push_back(AsmRewrite(AOK_SizeDirective,
>> Start,
>> -                                                    /*Len=*/0, Size));
>> +        InstInfo->AsmRewrites->emplace_back(AOK_SizeDirective, Start,
>> +                                            /*Len=*/0, Size);
>>      }
>>    }
>>
>> @@ -1112,8 +1112,8 @@ RewriteIntelBracExpression(SmallVectorIm
>>                             int64_t FinalImmDisp, SMLoc &BracLoc,
>>                             SMLoc &StartInBrac, SMLoc &End) {
>>    // Remove the '[' and ']' from the IR string.
>> -  AsmRewrites->push_back(AsmRewrite(AOK_Skip, BracLoc, 1));
>> -  AsmRewrites->push_back(AsmRewrite(AOK_Skip, End, 1));
>> +  AsmRewrites->emplace_back(AOK_Skip, BracLoc, 1);
>> +  AsmRewrites->emplace_back(AOK_Skip, End, 1);
>>
>>    // If ImmDisp is non-zero, then we parsed a displacement before the
>>    // bracketed expression (i.e., ImmDisp [ BaseReg + Scale*IndexReg +
>> Disp])
>> @@ -1143,7 +1143,7 @@ RewriteIntelBracExpression(SmallVectorIm
>>        // We have a symbolic and an immediate displacement, but no
>> displacement
>>        // before the bracketed expression.  Put the immediate displacement
>>        // before the bracketed expression.
>> -      AsmRewrites->push_back(AsmRewrite(AOK_Imm, BracLoc, 0,
>> FinalImmDisp));
>> +      AsmRewrites->emplace_back(AOK_Imm, BracLoc, 0, FinalImmDisp);
>>      }
>>    }
>>    // Remove all the ImmPrefix rewrites within the brackets.
>> @@ -1158,13 +1158,13 @@ RewriteIntelBracExpression(SmallVectorIm
>>    // Skip everything before the symbol.
>>    if (unsigned Len = SymLocPtr - StartInBrac.getPointer()) {
>>      assert(Len > 0 && "Expected a non-negative length.");
>> -    AsmRewrites->push_back(AsmRewrite(AOK_Skip, StartInBrac, Len));
>> +    AsmRewrites.emplace_back(AOK_Skip, StartInBrac, Len);
>>    }
>>    // Skip everything after the symbol.
>>    if (unsigned Len = End.getPointer() - (SymLocPtr + SymName.size())) {
>>      SMLoc Loc = SMLoc::getFromPointer(SymLocPtr + SymName.size());
>>      assert(Len > 0 && "Expected a non-negative length.");
>> -    AsmRewrites->push_back(AsmRewrite(AOK_Skip, Loc, Len));
>> +    AsmRewrites.emplace_back(AOK_Skip, Loc, Len);
>>    }
>>  }
>>
>> @@ -1233,8 +1233,7 @@ bool X86AsmParser::ParseIntelExpression(
>>      case AsmToken::Integer: {
>>        StringRef ErrMsg;
>>        if (isParsingInlineAsm() && SM.getAddImmPrefix())
>> -        InstInfo->AsmRewrites->push_back(AsmRewrite(AOK_ImmPrefix,
>> -                                                    Tok.getLoc()));
>> +        InstInfo->AsmRewrites->emplace_back(AOK_ImmPrefix, Tok.getLoc());
>>        // Look for 'b' or 'f' following an Integer as a directional label
>>        SMLoc Loc = getTok().getLoc();
>>        int64_t IntVal = getTok().getIntVal();
>> @@ -1401,9 +1400,8 @@ bool X86AsmParser::ParseIntelIdentifier(
>>                                           Loc, false);
>>      assert(InternalName.size() && "We should have an internal name
>> here.");
>>      // Push a rewrite for replacing the identifier name with the
>> internal name.
>> -    InstInfo->AsmRewrites->push_back(AsmRewrite(AOK_Label, Loc,
>> -                                                Identifier.size(),
>> -                                                InternalName));
>> +    InstInfo->AsmRewrites->emplace_back(AOK_Label, Loc,
>> Identifier.size(),
>> +                                        InternalName);
>>    }
>>
>>    // Create the symbol reference.
>> @@ -1430,8 +1428,7 @@ X86AsmParser::ParseIntelSegmentOverride(
>>      AsmToken ImmDispToken = Parser.Lex(); // Eat the integer.
>>
>>      if (isParsingInlineAsm())
>> -      InstInfo->AsmRewrites->push_back(
>> -          AsmRewrite(AOK_ImmPrefix, ImmDispToken.getLoc()));
>> +      InstInfo->AsmRewrites->emplace_back(AOK_ImmPrefix,
>> ImmDispToken.getLoc());
>>
>>      if (getLexer().isNot(AsmToken::LBrac)) {
>>        // An immediate following a 'segment register', 'colon' token
>> sequence can
>> @@ -1600,8 +1597,7 @@ bool X86AsmParser::ParseIntelDotOperator
>>      SMLoc Loc = SMLoc::getFromPointer(DotDispStr.data());
>>      unsigned Len = DotDispStr.size();
>>      unsigned Val = OrigDispVal + DotDispVal;
>> -    InstInfo->AsmRewrites->push_back(AsmRewrite(AOK_DotOperator, Loc,
>> Len,
>> -                                                Val));
>> +    InstInfo->AsmRewrites->emplace_back(AOK_DotOperator, Loc, Len, Val);
>>    }
>>
>>    NewDisp = MCConstantExpr::create(OrigDispVal + DotDispVal,
>> getContext());
>> @@ -1625,7 +1621,7 @@ std::unique_ptr<X86Operand> X86AsmParser
>>      return nullptr;
>>
>>    // Don't emit the offset operator.
>> -  InstInfo->AsmRewrites->push_back(AsmRewrite(AOK_Skip, OffsetOfLoc, 7));
>> +  InstInfo->AsmRewrites->emplace_back(AOK_Skip, OffsetOfLoc, 7);
>>
>>    // The offset operator will have an 'r' constraint, thus we need to
>> create
>>    // register operand to ensure proper matching.  Just pick a GPR based
>> on
>> @@ -1676,7 +1672,7 @@ std::unique_ptr<X86Operand> X86AsmParser
>>    // Rewrite the type operator and the C or C++ type or variable in
>> terms of an
>>    // immediate.  E.g. TYPE foo -> $$4
>>    unsigned Len = End.getPointer() - TypeLoc.getPointer();
>> -  InstInfo->AsmRewrites->push_back(AsmRewrite(AOK_Imm, TypeLoc, Len,
>> CVal));
>> +  InstInfo->AsmRewrites->emplace_back(AOK_Imm, TypeLoc, Len, CVal);
>>
>>    const MCExpr *Imm = MCConstantExpr::create(CVal, getContext());
>>    return X86Operand::CreateImm(Imm, Start, End);
>> @@ -1723,10 +1719,10 @@ std::unique_ptr<X86Operand> X86AsmParser
>>        unsigned Len = Tok.getLoc().getPointer() - Start.getPointer();
>>        if (StartTok.getString().size() == Len)
>>          // Just add a prefix if this wasn't a complex immediate
>> expression.
>> -        InstInfo->AsmRewrites->push_back(AsmRewrite(AOK_ImmPrefix,
>> Start));
>> +        InstInfo->AsmRewrites->emplace_back(AOK_ImmPrefix, Start);
>>        else
>>          // Otherwise, rewrite the complex expression as a single
>> immediate.
>> -        InstInfo->AsmRewrites->push_back(AsmRewrite(AOK_Imm, Start, Len,
>> Imm));
>> +        InstInfo->AsmRewrites->emplace_back(AOK_Imm, Start, Len, Imm);
>>      }
>>
>>      if (getLexer().isNot(AsmToken::LBrac)) {
>>
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>>
>
>


-- 
~Craig
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151012/e03c4225/attachment.html>


More information about the llvm-commits mailing list