From 32a006e606742b1c5401e49607e33717bb5441f0 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Fri, 3 Dec 2010 00:55:40 +0000 Subject: Try to resolve symbol differences early, and if successful create a plain data fragment. This reduces the time to assemble the test in 8711 from 60s to 54s. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120767 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/MC/MCExpr.cpp | 73 +++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 52 insertions(+), 21 deletions(-) (limited to 'lib/MC/MCExpr.cpp') diff --git a/lib/MC/MCExpr.cpp b/lib/MC/MCExpr.cpp index 64c57b3..3d47608 100644 --- a/lib/MC/MCExpr.cpp +++ b/lib/MC/MCExpr.cpp @@ -237,7 +237,24 @@ void MCTargetExpr::Anchor() {} /* *** */ -bool MCExpr::EvaluateAsAbsolute(int64_t &Res, const MCAsmLayout *Layout) const { +bool MCExpr::EvaluateAsAbsolute(int64_t &Res) const { + return EvaluateAsAbsolute(Res, 0, 0); +} + +bool MCExpr::EvaluateAsAbsolute(int64_t &Res, + const MCAsmLayout *Layout) const { + if (Layout) + return EvaluateAsAbsolute(Res, &Layout->getAssembler(), Layout); + else + return EvaluateAsAbsolute(Res, 0, 0); +} + +bool MCExpr::EvaluateAsAbsolute(int64_t &Res, const MCAssembler *Asm) const { + return EvaluateAsAbsolute(Res, Asm, 0); +} + +bool MCExpr::EvaluateAsAbsolute(int64_t &Res, const MCAssembler *Asm, + const MCAsmLayout *Layout) const { MCValue Value; // Fast path constants. @@ -246,7 +263,8 @@ bool MCExpr::EvaluateAsAbsolute(int64_t &Res, const MCAsmLayout *Layout) const { return true; } - if (!EvaluateAsRelocatable(Value, Layout) || !Value.isAbsolute()) { + if (!EvaluateAsRelocatableImpl(Value, Asm, Layout, false) || + !Value.isAbsolute()) { // EvaluateAsAbsolute is defined to return the "current value" of // the expression if we are given a Layout object, even in cases // when the value is not fixed. @@ -268,7 +286,9 @@ bool MCExpr::EvaluateAsAbsolute(int64_t &Res, const MCAsmLayout *Layout) const { return true; } -static bool EvaluateSymbolicAdd(const MCAsmLayout *Layout, bool InSet, +static bool EvaluateSymbolicAdd(const MCAsmLayout *Layout, + const MCAssembler *Asm, + bool InSet, const MCValue &LHS,const MCSymbolRefExpr *RHS_A, const MCSymbolRefExpr *RHS_B, int64_t RHS_Cst, MCValue &Res) { @@ -291,14 +311,15 @@ static bool EvaluateSymbolicAdd(const MCAsmLayout *Layout, bool InSet, // Absolutize symbol differences between defined symbols when we have a // layout object and the target requests it. - if (Layout && A && B) { + assert(!(Layout && !Asm)); + + if ((Layout || Asm) && A && B) { const MCSymbol &SA = A->getSymbol(); const MCSymbol &SB = B->getSymbol(); - const MCAssembler &Asm = Layout->getAssembler(); - const MCObjectFormat &F = Asm.getBackend().getObjectFormat(); + const MCObjectFormat &F = Asm->getBackend().getObjectFormat(); if (SA.isDefined() && SB.isDefined() && F.isAbsolute(InSet, SA, SB)) { - MCSymbolData &AD = Asm.getSymbolData(A->getSymbol()); - MCSymbolData &BD = Asm.getSymbolData(B->getSymbol()); + MCSymbolData &AD = Asm->getSymbolData(A->getSymbol()); + MCSymbolData &BD = Asm->getSymbolData(B->getSymbol()); if (AD.getFragment() == BD.getFragment()) { Res = MCValue::get(+ AD.getOffset() @@ -308,25 +329,31 @@ static bool EvaluateSymbolicAdd(const MCAsmLayout *Layout, bool InSet, return true; } - Res = MCValue::get(+ Layout->getSymbolAddress(&AD) - - Layout->getSymbolAddress(&BD) - + LHS.getConstant() - + RHS_Cst); - return true; + if (Layout) { + Res = MCValue::get(+ Layout->getSymbolAddress(&AD) + - Layout->getSymbolAddress(&BD) + + LHS.getConstant() + + RHS_Cst); + return true; + } } } - Res = MCValue::get(A, B, LHS.getConstant() + RHS_Cst); return true; } bool MCExpr::EvaluateAsRelocatable(MCValue &Res, const MCAsmLayout *Layout) const { - return EvaluateAsRelocatableImpl(Res, Layout, false); + if (Layout) + return EvaluateAsRelocatableImpl(Res, &Layout->getAssembler(), Layout, + false); + else + return EvaluateAsRelocatableImpl(Res, 0, 0, false); } bool MCExpr::EvaluateAsRelocatableImpl(MCValue &Res, + const MCAssembler *Asm, const MCAsmLayout *Layout, bool InSet) const { ++stats::MCExprEvaluate; @@ -345,7 +372,8 @@ bool MCExpr::EvaluateAsRelocatableImpl(MCValue &Res, // Evaluate recursively if this is a variable. if (Sym.isVariable() && SRE->getKind() == MCSymbolRefExpr::VK_None) { - bool Ret = Sym.getVariableValue()->EvaluateAsRelocatableImpl(Res, Layout, + bool Ret = Sym.getVariableValue()->EvaluateAsRelocatableImpl(Res, Asm, + Layout, true); // If we failed to simplify this to a constant, let the target // handle it. @@ -361,7 +389,8 @@ bool MCExpr::EvaluateAsRelocatableImpl(MCValue &Res, const MCUnaryExpr *AUE = cast(this); MCValue Value; - if (!AUE->getSubExpr()->EvaluateAsRelocatableImpl(Value, Layout, InSet)) + if (!AUE->getSubExpr()->EvaluateAsRelocatableImpl(Value, Asm, Layout, + InSet)) return false; switch (AUE->getOpcode()) { @@ -394,8 +423,10 @@ bool MCExpr::EvaluateAsRelocatableImpl(MCValue &Res, const MCBinaryExpr *ABE = cast(this); MCValue LHSValue, RHSValue; - if (!ABE->getLHS()->EvaluateAsRelocatableImpl(LHSValue, Layout, InSet) || - !ABE->getRHS()->EvaluateAsRelocatableImpl(RHSValue, Layout, InSet)) + if (!ABE->getLHS()->EvaluateAsRelocatableImpl(LHSValue, Asm, Layout, + InSet) || + !ABE->getRHS()->EvaluateAsRelocatableImpl(RHSValue, Asm, Layout, + InSet)) return false; // We only support a few operations on non-constant expressions, handle @@ -406,13 +437,13 @@ bool MCExpr::EvaluateAsRelocatableImpl(MCValue &Res, return false; case MCBinaryExpr::Sub: // Negate RHS and add. - return EvaluateSymbolicAdd(Layout, InSet, LHSValue, + return EvaluateSymbolicAdd(Layout, Asm, InSet, LHSValue, RHSValue.getSymB(), RHSValue.getSymA(), -RHSValue.getConstant(), Res); case MCBinaryExpr::Add: - return EvaluateSymbolicAdd(Layout, InSet, LHSValue, + return EvaluateSymbolicAdd(Layout, Asm, InSet, LHSValue, RHSValue.getSymA(), RHSValue.getSymB(), RHSValue.getConstant(), Res); -- cgit v1.1