Simplify the visitation of target expressions. No functionality change.

llvm-svn: 211707
This commit is contained in:
Rafael Espindola 2014-06-25 15:29:54 +00:00
parent 144829d3e9
commit 2be1281d43
15 changed files with 42 additions and 170 deletions

View File

@ -21,6 +21,7 @@ class MCAssembler;
class MCContext;
class MCSection;
class MCSectionData;
class MCObjectStreamer;
class MCSymbol;
class MCValue;
class raw_ostream;
@ -524,7 +525,7 @@ public:
virtual void PrintImpl(raw_ostream &OS) const = 0;
virtual bool EvaluateAsRelocatableImpl(MCValue &Res,
const MCAsmLayout *Layout) const = 0;
virtual void AddValueSymbols(MCAssembler *) const = 0;
virtual void visitUsedExpr(MCObjectStreamer& Streamer) const = 0;
virtual const MCSection *FindAssociatedSection() const = 0;
virtual void fixELFSymbolsInTLSFixups(MCAssembler &) const = 0;

View File

@ -78,9 +78,10 @@ protected:
/// fragment is not a data fragment.
MCDataFragment *getOrCreateDataFragment() const;
void AddValueSymbols(const MCExpr *Value);
public:
void visitUsedExpr(const MCExpr &Expr);
void visitUsedSymbol(const MCSymbol &Sym);
MCAssembler &getAssembler() { return *Assembler; }
/// @name MCStreamer Interface

View File

@ -83,28 +83,32 @@ MCDataFragment *MCObjectStreamer::getOrCreateDataFragment() const {
return F;
}
void MCObjectStreamer::AddValueSymbols(const MCExpr *Value) {
switch (Value->getKind()) {
void MCObjectStreamer::visitUsedSymbol(const MCSymbol &Sym) {
Assembler->getOrCreateSymbolData(Sym);
}
void MCObjectStreamer::visitUsedExpr(const MCExpr &Expr) {
switch (Expr.getKind()) {
case MCExpr::Target:
cast<MCTargetExpr>(Value)->AddValueSymbols(Assembler);
cast<MCTargetExpr>(Expr).visitUsedExpr(*this);
break;
case MCExpr::Constant:
break;
case MCExpr::Binary: {
const MCBinaryExpr *BE = cast<MCBinaryExpr>(Value);
AddValueSymbols(BE->getLHS());
AddValueSymbols(BE->getRHS());
const MCBinaryExpr &BE = cast<MCBinaryExpr>(Expr);
visitUsedExpr(*BE.getLHS());
visitUsedExpr(*BE.getRHS());
break;
}
case MCExpr::SymbolRef:
Assembler->getOrCreateSymbolData(cast<MCSymbolRefExpr>(Value)->getSymbol());
visitUsedSymbol(cast<MCSymbolRefExpr>(Expr).getSymbol());
break;
case MCExpr::Unary:
AddValueSymbols(cast<MCUnaryExpr>(Value)->getSubExpr());
visitUsedExpr(*cast<MCUnaryExpr>(Expr).getSubExpr());
break;
}
}
@ -123,7 +127,7 @@ void MCObjectStreamer::EmitValueImpl(const MCExpr *Value, unsigned Size,
// Avoid fixups when possible.
int64_t AbsValue;
AddValueSymbols(Value);
visitUsedExpr(*Value);
if (Value->EvaluateAsAbsolute(AbsValue, getAssembler())) {
EmitIntValue(AbsValue, Size);
return;
@ -203,7 +207,7 @@ void MCObjectStreamer::ChangeSection(const MCSection *Section,
void MCObjectStreamer::EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) {
getAssembler().getOrCreateSymbolData(*Symbol);
AddValueSymbols(Value);
visitUsedExpr(*Value);
MCStreamer::EmitAssignment(Symbol, Value);
}
@ -211,7 +215,7 @@ void MCObjectStreamer::EmitInstruction(const MCInst &Inst, const MCSubtargetInfo
// Scan for values.
for (unsigned i = Inst.getNumOperands(); i--; )
if (Inst.getOperand(i).isExpr())
AddValueSymbols(Inst.getOperand(i).getExpr());
visitUsedExpr(*Inst.getOperand(i).getExpr());
MCSectionData *SD = getCurrentSectionData();
SD->setHasInstructions(true);

View File

@ -16,6 +16,7 @@
#include "llvm/MC/MCAssembler.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCELF.h"
#include "llvm/MC/MCObjectStreamer.h"
#include "llvm/MC/MCSymbol.h"
#include "llvm/MC/MCValue.h"
#include "llvm/Object/ELF.h"
@ -81,37 +82,8 @@ void AArch64MCExpr::PrintImpl(raw_ostream &OS) const {
OS << *Expr;
}
// FIXME: This basically copies MCObjectStreamer::AddValueSymbols. Perhaps
// that method should be made public?
// FIXME: really do above: now that two backends are using it.
static void AddValueSymbolsImpl(const MCExpr *Value, MCAssembler *Asm) {
switch (Value->getKind()) {
case MCExpr::Target:
llvm_unreachable("Can't handle nested target expr!");
break;
case MCExpr::Constant:
break;
case MCExpr::Binary: {
const MCBinaryExpr *BE = cast<MCBinaryExpr>(Value);
AddValueSymbolsImpl(BE->getLHS(), Asm);
AddValueSymbolsImpl(BE->getRHS(), Asm);
break;
}
case MCExpr::SymbolRef:
Asm->getOrCreateSymbolData(cast<MCSymbolRefExpr>(Value)->getSymbol());
break;
case MCExpr::Unary:
AddValueSymbolsImpl(cast<MCUnaryExpr>(Value)->getSubExpr(), Asm);
break;
}
}
void AArch64MCExpr::AddValueSymbols(MCAssembler *Asm) const {
AddValueSymbolsImpl(getSubExpr(), Asm);
void AArch64MCExpr::visitUsedExpr(MCObjectStreamer &Streamer) const {
Streamer.visitUsedExpr(*getSubExpr());
}
const MCSection *AArch64MCExpr::FindAssociatedSection() const {

View File

@ -147,7 +147,7 @@ public:
void PrintImpl(raw_ostream &OS) const override;
void AddValueSymbols(MCAssembler *) const override;
void visitUsedExpr(MCObjectStreamer &Streamer) const override;
const MCSection *FindAssociatedSection() const override;

View File

@ -1160,7 +1160,7 @@ void ARMELFStreamer::EmitPersonalityFixup(StringRef Name) {
const MCSymbolRefExpr *PersonalityRef = MCSymbolRefExpr::Create(
PersonalitySym, MCSymbolRefExpr::VK_ARM_NONE, getContext());
AddValueSymbols(PersonalityRef);
visitUsedExpr(*PersonalityRef);
MCDataFragment *DF = getOrCreateDataFragment();
DF->getFixups().push_back(MCFixup::Create(DF->getContents().size(),
PersonalityRef,

View File

@ -10,6 +10,7 @@
#include "ARMMCExpr.h"
#include "llvm/MC/MCAssembler.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCObjectStreamer.h"
using namespace llvm;
#define DEBUG_TYPE "armmcexpr"
@ -41,33 +42,6 @@ ARMMCExpr::EvaluateAsRelocatableImpl(MCValue &Res,
return false;
}
// FIXME: This basically copies MCObjectStreamer::AddValueSymbols. Perhaps
// that method should be made public?
static void AddValueSymbols_(const MCExpr *Value, MCAssembler *Asm) {
switch (Value->getKind()) {
case MCExpr::Target:
llvm_unreachable("Can't handle nested target expr!");
case MCExpr::Constant:
break;
case MCExpr::Binary: {
const MCBinaryExpr *BE = cast<MCBinaryExpr>(Value);
AddValueSymbols_(BE->getLHS(), Asm);
AddValueSymbols_(BE->getRHS(), Asm);
break;
}
case MCExpr::SymbolRef:
Asm->getOrCreateSymbolData(cast<MCSymbolRefExpr>(Value)->getSymbol());
break;
case MCExpr::Unary:
AddValueSymbols_(cast<MCUnaryExpr>(Value)->getSubExpr(), Asm);
break;
}
}
void ARMMCExpr::AddValueSymbols(MCAssembler *Asm) const {
AddValueSymbols_(getSubExpr(), Asm);
void ARMMCExpr::visitUsedExpr(MCObjectStreamer &Streamer) const {
Streamer.visitUsedExpr(*getSubExpr());
}

View File

@ -59,7 +59,7 @@ public:
void PrintImpl(raw_ostream &OS) const override;
bool EvaluateAsRelocatableImpl(MCValue &Res,
const MCAsmLayout *Layout) const override;
void AddValueSymbols(MCAssembler *) const override;
void visitUsedExpr(MCObjectStreamer &Streamer) const override;
const MCSection *FindAssociatedSection() const override {
return getSubExpr()->FindAssociatedSection();
}

View File

@ -11,6 +11,7 @@
#include "llvm/MC/MCAsmInfo.h"
#include "llvm/MC/MCAssembler.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCObjectStreamer.h"
using namespace llvm;
@ -83,33 +84,6 @@ MipsMCExpr::EvaluateAsRelocatableImpl(MCValue &Res,
return getSubExpr()->EvaluateAsRelocatable(Res, Layout);
}
// FIXME: This basically copies MCObjectStreamer::AddValueSymbols. Perhaps
// that method should be made public?
static void AddValueSymbolsImpl(const MCExpr *Value, MCAssembler *Asm) {
switch (Value->getKind()) {
case MCExpr::Target:
llvm_unreachable("Can't handle nested target expr!");
case MCExpr::Constant:
break;
case MCExpr::Binary: {
const MCBinaryExpr *BE = cast<MCBinaryExpr>(Value);
AddValueSymbolsImpl(BE->getLHS(), Asm);
AddValueSymbolsImpl(BE->getRHS(), Asm);
break;
}
case MCExpr::SymbolRef:
Asm->getOrCreateSymbolData(cast<MCSymbolRefExpr>(Value)->getSymbol());
break;
case MCExpr::Unary:
AddValueSymbolsImpl(cast<MCUnaryExpr>(Value)->getSubExpr(), Asm);
break;
}
}
void MipsMCExpr::AddValueSymbols(MCAssembler *Asm) const {
AddValueSymbolsImpl(getSubExpr(), Asm);
void MipsMCExpr::visitUsedExpr(MCObjectStreamer &Streamer) const {
Streamer.visitUsedExpr(*getSubExpr());
}

View File

@ -49,7 +49,7 @@ public:
void PrintImpl(raw_ostream &OS) const override;
bool EvaluateAsRelocatableImpl(MCValue &Res,
const MCAsmLayout *Layout) const override;
void AddValueSymbols(MCAssembler *) const override;
void visitUsedExpr(MCObjectStreamer &Streamer) const override;
const MCSection *FindAssociatedSection() const override {
return getSubExpr()->FindAssociatedSection();
}

View File

@ -66,7 +66,7 @@ public:
const MCAsmLayout *Layout) const override {
return false;
}
void AddValueSymbols(MCAssembler *) const override {};
void visitUsedExpr(MCObjectStreamer &Streamer) const override {};
const MCSection *FindAssociatedSection() const override {
return nullptr;
}

View File

@ -11,6 +11,7 @@
#include "llvm/MC/MCAsmInfo.h"
#include "llvm/MC/MCAssembler.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCObjectStreamer.h"
using namespace llvm;
@ -127,33 +128,6 @@ PPCMCExpr::EvaluateAsRelocatableImpl(MCValue &Res,
return true;
}
// FIXME: This basically copies MCObjectStreamer::AddValueSymbols. Perhaps
// that method should be made public?
static void AddValueSymbols_(const MCExpr *Value, MCAssembler *Asm) {
switch (Value->getKind()) {
case MCExpr::Target:
llvm_unreachable("Can't handle nested target expr!");
case MCExpr::Constant:
break;
case MCExpr::Binary: {
const MCBinaryExpr *BE = cast<MCBinaryExpr>(Value);
AddValueSymbols_(BE->getLHS(), Asm);
AddValueSymbols_(BE->getRHS(), Asm);
break;
}
case MCExpr::SymbolRef:
Asm->getOrCreateSymbolData(cast<MCSymbolRefExpr>(Value)->getSymbol());
break;
case MCExpr::Unary:
AddValueSymbols_(cast<MCUnaryExpr>(Value)->getSubExpr(), Asm);
break;
}
}
void PPCMCExpr::AddValueSymbols(MCAssembler *Asm) const {
AddValueSymbols_(getSubExpr(), Asm);
void PPCMCExpr::visitUsedExpr(MCObjectStreamer &Streamer) const {
Streamer.visitUsedExpr(*getSubExpr());
}

View File

@ -79,7 +79,7 @@ public:
void PrintImpl(raw_ostream &OS) const override;
bool EvaluateAsRelocatableImpl(MCValue &Res,
const MCAsmLayout *Layout) const override;
void AddValueSymbols(MCAssembler *) const override;
void visitUsedExpr(MCObjectStreamer &Streamer) const override;
const MCSection *FindAssociatedSection() const override {
return getSubExpr()->FindAssociatedSection();
}

View File

@ -16,6 +16,7 @@
#include "llvm/MC/MCAssembler.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCELF.h"
#include "llvm/MC/MCObjectStreamer.h"
#include "llvm/MC/MCSymbol.h"
#include "llvm/Object/ELF.h"
@ -219,35 +220,6 @@ void SparcMCExpr::fixELFSymbolsInTLSFixups(MCAssembler &Asm) const {
fixELFSymbolsInTLSFixupsImpl(getSubExpr(), Asm);
}
// FIXME: This basically copies MCObjectStreamer::AddValueSymbols. Perhaps
// that method should be made public?
// FIXME: really do above: now that at least three other backends are using it.
static void AddValueSymbolsImpl(const MCExpr *Value, MCAssembler *Asm) {
switch (Value->getKind()) {
case MCExpr::Target:
llvm_unreachable("Can't handle nested target expr!");
break;
case MCExpr::Constant:
break;
case MCExpr::Binary: {
const MCBinaryExpr *BE = cast<MCBinaryExpr>(Value);
AddValueSymbolsImpl(BE->getLHS(), Asm);
AddValueSymbolsImpl(BE->getRHS(), Asm);
break;
}
case MCExpr::SymbolRef:
Asm->getOrCreateSymbolData(cast<MCSymbolRefExpr>(Value)->getSymbol());
break;
case MCExpr::Unary:
AddValueSymbolsImpl(cast<MCUnaryExpr>(Value)->getSubExpr(), Asm);
break;
}
}
void SparcMCExpr::AddValueSymbols(MCAssembler *Asm) const {
AddValueSymbolsImpl(getSubExpr(), Asm);
void SparcMCExpr::visitUsedExpr(MCObjectStreamer &Streamer) const {
Streamer.visitUsedExpr(*getSubExpr());
}

View File

@ -88,7 +88,7 @@ public:
void PrintImpl(raw_ostream &OS) const override;
bool EvaluateAsRelocatableImpl(MCValue &Res,
const MCAsmLayout *Layout) const override;
void AddValueSymbols(MCAssembler *) const override;
void visitUsedExpr(MCObjectStreamer &Streamer) const override;
const MCSection *FindAssociatedSection() const override {
return getSubExpr()->FindAssociatedSection();
}