llvm.org GIT mirror llvm / d4feaf8
Simplify the visitation of target expressions. No functionality change. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@211707 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 6 years ago
15 changed file(s) with 43 addition(s) and 171 deletion(s). Raw diff Collapse all Expand all
2020 class MCContext;
2121 class MCSection;
2222 class MCSectionData;
23 class MCObjectStreamer;
2324 class MCSymbol;
2425 class MCValue;
2526 class raw_ostream;
523524 virtual void PrintImpl(raw_ostream &OS) const = 0;
524525 virtual bool EvaluateAsRelocatableImpl(MCValue &Res,
525526 const MCAsmLayout *Layout) const = 0;
526 virtual void AddValueSymbols(MCAssembler *) const = 0;
527 virtual void visitUsedExpr(MCObjectStreamer& Streamer) const = 0;
527528 virtual const MCSection *FindAssociatedSection() const = 0;
528529
529530 virtual void fixELFSymbolsInTLSFixups(MCAssembler &) const = 0;
7777 /// fragment is not a data fragment.
7878 MCDataFragment *getOrCreateDataFragment() const;
7979
80 void AddValueSymbols(const MCExpr *Value);
80 public:
81 void visitUsedExpr(const MCExpr &Expr);
82 void visitUsedSymbol(const MCSymbol &Sym);
8183
82 public:
8384 MCAssembler &getAssembler() { return *Assembler; }
8485
8586 /// @name MCStreamer Interface
8282 return F;
8383 }
8484
85 void MCObjectStreamer::AddValueSymbols(const MCExpr *Value) {
86 switch (Value->getKind()) {
85 void MCObjectStreamer::visitUsedSymbol(const MCSymbol &Sym) {
86 Assembler->getOrCreateSymbolData(Sym);
87 }
88
89 void MCObjectStreamer::visitUsedExpr(const MCExpr &Expr) {
90 switch (Expr.getKind()) {
8791 case MCExpr::Target:
88 cast(Value)->AddValueSymbols(Assembler);
92 cast(Expr).visitUsedExpr(*this);
8993 break;
9094
9195 case MCExpr::Constant:
9296 break;
9397
9498 case MCExpr::Binary: {
95 const MCBinaryExpr *BE = cast(Value);
96 AddValueSymbols(BE->getLHS());
97 AddValueSymbols(BE->getRHS());
99 const MCBinaryExpr &BE = cast(Expr);
100 visitUsedExpr(*BE.getLHS());
101 visitUsedExpr(*BE.getRHS());
98102 break;
99103 }
100104
101105 case MCExpr::SymbolRef:
102 Assembler->getOrCreateSymbolData(cast(Value)->getSymbol());
106 visitUsedSymbol(cast(Expr).getSymbol());
103107 break;
104108
105109 case MCExpr::Unary:
106 AddValueSymbols(cast(Value)->getSubExpr());
110 visitUsedExpr(*cast(Expr).getSubExpr());
107111 break;
108112 }
109113 }
122126
123127 // Avoid fixups when possible.
124128 int64_t AbsValue;
125 AddValueSymbols(Value);
129 visitUsedExpr(*Value);
126130 if (Value->EvaluateAsAbsolute(AbsValue, getAssembler())) {
127131 EmitIntValue(AbsValue, Size);
128132 return;
202206
203207 void MCObjectStreamer::EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) {
204208 getAssembler().getOrCreateSymbolData(*Symbol);
205 AddValueSymbols(Value);
209 visitUsedExpr(*Value);
206210 MCStreamer::EmitAssignment(Symbol, Value);
207211 }
208212
210214 // Scan for values.
211215 for (unsigned i = Inst.getNumOperands(); i--; )
212216 if (Inst.getOperand(i).isExpr())
213 AddValueSymbols(Inst.getOperand(i).getExpr());
217 visitUsedExpr(*Inst.getOperand(i).getExpr());
214218
215219 MCSectionData *SD = getCurrentSectionData();
216220 SD->setHasInstructions(true);
1515 #include "llvm/MC/MCAssembler.h"
1616 #include "llvm/MC/MCContext.h"
1717 #include "llvm/MC/MCELF.h"
18 #include "llvm/MC/MCObjectStreamer.h"
1819 #include "llvm/MC/MCSymbol.h"
1920 #include "llvm/MC/MCValue.h"
2021 #include "llvm/Object/ELF.h"
8081 OS << *Expr;
8182 }
8283
83 // FIXME: This basically copies MCObjectStreamer::AddValueSymbols. Perhaps
84 // that method should be made public?
85 // FIXME: really do above: now that two backends are using it.
86 static void AddValueSymbolsImpl(const MCExpr *Value, MCAssembler *Asm) {
87 switch (Value->getKind()) {
88 case MCExpr::Target:
89 llvm_unreachable("Can't handle nested target expr!");
90 break;
91
92 case MCExpr::Constant:
93 break;
94
95 case MCExpr::Binary: {
96 const MCBinaryExpr *BE = cast(Value);
97 AddValueSymbolsImpl(BE->getLHS(), Asm);
98 AddValueSymbolsImpl(BE->getRHS(), Asm);
99 break;
100 }
101
102 case MCExpr::SymbolRef:
103 Asm->getOrCreateSymbolData(cast(Value)->getSymbol());
104 break;
105
106 case MCExpr::Unary:
107 AddValueSymbolsImpl(cast(Value)->getSubExpr(), Asm);
108 break;
109 }
110 }
111
112 void AArch64MCExpr::AddValueSymbols(MCAssembler *Asm) const {
113 AddValueSymbolsImpl(getSubExpr(), Asm);
84 void AArch64MCExpr::visitUsedExpr(MCObjectStreamer &Streamer) const {
85 Streamer.visitUsedExpr(*getSubExpr());
11486 }
11587
11688 const MCSection *AArch64MCExpr::FindAssociatedSection() const {
146146
147147 void PrintImpl(raw_ostream &OS) const override;
148148
149 void AddValueSymbols(MCAssembler *) const override;
149 void visitUsedExpr(MCObjectStreamer &Streamer) const override;
150150
151151 const MCSection *FindAssociatedSection() const override;
152152
11591159 const MCSymbolRefExpr *PersonalityRef = MCSymbolRefExpr::Create(
11601160 PersonalitySym, MCSymbolRefExpr::VK_ARM_NONE, getContext());
11611161
1162 AddValueSymbols(PersonalityRef);
1162 visitUsedExpr(*PersonalityRef);
11631163 MCDataFragment *DF = getOrCreateDataFragment();
11641164 DF->getFixups().push_back(MCFixup::Create(DF->getContents().size(),
11651165 PersonalityRef,
99 #include "ARMMCExpr.h"
1010 #include "llvm/MC/MCAssembler.h"
1111 #include "llvm/MC/MCContext.h"
12 #include "llvm/MC/MCObjectStreamer.h"
1213 using namespace llvm;
1314
1415 #define DEBUG_TYPE "armmcexpr"
4041 return false;
4142 }
4243
43 // FIXME: This basically copies MCObjectStreamer::AddValueSymbols. Perhaps
44 // that method should be made public?
45 static void AddValueSymbols_(const MCExpr *Value, MCAssembler *Asm) {
46 switch (Value->getKind()) {
47 case MCExpr::Target:
48 llvm_unreachable("Can't handle nested target expr!");
49
50 case MCExpr::Constant:
51 break;
52
53 case MCExpr::Binary: {
54 const MCBinaryExpr *BE = cast(Value);
55 AddValueSymbols_(BE->getLHS(), Asm);
56 AddValueSymbols_(BE->getRHS(), Asm);
57 break;
58 }
59
60 case MCExpr::SymbolRef:
61 Asm->getOrCreateSymbolData(cast(Value)->getSymbol());
62 break;
63
64 case MCExpr::Unary:
65 AddValueSymbols_(cast(Value)->getSubExpr(), Asm);
66 break;
67 }
44 void ARMMCExpr::visitUsedExpr(MCObjectStreamer &Streamer) const {
45 Streamer.visitUsedExpr(*getSubExpr());
6846 }
69
70 void ARMMCExpr::AddValueSymbols(MCAssembler *Asm) const {
71 AddValueSymbols_(getSubExpr(), Asm);
72 }
5858 void PrintImpl(raw_ostream &OS) const override;
5959 bool EvaluateAsRelocatableImpl(MCValue &Res,
6060 const MCAsmLayout *Layout) const override;
61 void AddValueSymbols(MCAssembler *) const override;
61 void visitUsedExpr(MCObjectStreamer &Streamer) const override;
6262 const MCSection *FindAssociatedSection() const override {
6363 return getSubExpr()->FindAssociatedSection();
6464 }
1010 #include "llvm/MC/MCAsmInfo.h"
1111 #include "llvm/MC/MCAssembler.h"
1212 #include "llvm/MC/MCContext.h"
13 #include "llvm/MC/MCObjectStreamer.h"
1314
1415 using namespace llvm;
1516
8283 return getSubExpr()->EvaluateAsRelocatable(Res, Layout);
8384 }
8485
85 // FIXME: This basically copies MCObjectStreamer::AddValueSymbols. Perhaps
86 // that method should be made public?
87 static void AddValueSymbolsImpl(const MCExpr *Value, MCAssembler *Asm) {
88 switch (Value->getKind()) {
89 case MCExpr::Target:
90 llvm_unreachable("Can't handle nested target expr!");
91
92 case MCExpr::Constant:
93 break;
94
95 case MCExpr::Binary: {
96 const MCBinaryExpr *BE = cast(Value);
97 AddValueSymbolsImpl(BE->getLHS(), Asm);
98 AddValueSymbolsImpl(BE->getRHS(), Asm);
99 break;
100 }
101
102 case MCExpr::SymbolRef:
103 Asm->getOrCreateSymbolData(cast(Value)->getSymbol());
104 break;
105
106 case MCExpr::Unary:
107 AddValueSymbolsImpl(cast(Value)->getSubExpr(), Asm);
108 break;
109 }
86 void MipsMCExpr::visitUsedExpr(MCObjectStreamer &Streamer) const {
87 Streamer.visitUsedExpr(*getSubExpr());
11088 }
111
112 void MipsMCExpr::AddValueSymbols(MCAssembler *Asm) const {
113 AddValueSymbolsImpl(getSubExpr(), Asm);
114 }
4848 void PrintImpl(raw_ostream &OS) const override;
4949 bool EvaluateAsRelocatableImpl(MCValue &Res,
5050 const MCAsmLayout *Layout) const override;
51 void AddValueSymbols(MCAssembler *) const override;
51 void visitUsedExpr(MCObjectStreamer &Streamer) const override;
5252 const MCSection *FindAssociatedSection() const override {
5353 return getSubExpr()->FindAssociatedSection();
5454 }
6565 const MCAsmLayout *Layout) const override {
6666 return false;
6767 }
68 void AddValueSymbols(MCAssembler *) const override {};
68 void visitUsedExpr(MCObjectStreamer &Streamer) const override {};
6969 const MCSection *FindAssociatedSection() const override {
7070 return nullptr;
7171 }
1010 #include "llvm/MC/MCAsmInfo.h"
1111 #include "llvm/MC/MCAssembler.h"
1212 #include "llvm/MC/MCContext.h"
13 #include "llvm/MC/MCObjectStreamer.h"
1314
1415 using namespace llvm;
1516
126127 return true;
127128 }
128129
129 // FIXME: This basically copies MCObjectStreamer::AddValueSymbols. Perhaps
130 // that method should be made public?
131 static void AddValueSymbols_(const MCExpr *Value, MCAssembler *Asm) {
132 switch (Value->getKind()) {
133 case MCExpr::Target:
134 llvm_unreachable("Can't handle nested target expr!");
135
136 case MCExpr::Constant:
137 break;
138
139 case MCExpr::Binary: {
140 const MCBinaryExpr *BE = cast(Value);
141 AddValueSymbols_(BE->getLHS(), Asm);
142 AddValueSymbols_(BE->getRHS(), Asm);
143 break;
144 }
145
146 case MCExpr::SymbolRef:
147 Asm->getOrCreateSymbolData(cast(Value)->getSymbol());
148 break;
149
150 case MCExpr::Unary:
151 AddValueSymbols_(cast(Value)->getSubExpr(), Asm);
152 break;
153 }
130 void PPCMCExpr::visitUsedExpr(MCObjectStreamer &Streamer) const {
131 Streamer.visitUsedExpr(*getSubExpr());
154132 }
155
156 void PPCMCExpr::AddValueSymbols(MCAssembler *Asm) const {
157 AddValueSymbols_(getSubExpr(), Asm);
158 }
7878 void PrintImpl(raw_ostream &OS) const override;
7979 bool EvaluateAsRelocatableImpl(MCValue &Res,
8080 const MCAsmLayout *Layout) const override;
81 void AddValueSymbols(MCAssembler *) const override;
81 void visitUsedExpr(MCObjectStreamer &Streamer) const override;
8282 const MCSection *FindAssociatedSection() const override {
8383 return getSubExpr()->FindAssociatedSection();
8484 }
1515 #include "llvm/MC/MCAssembler.h"
1616 #include "llvm/MC/MCContext.h"
1717 #include "llvm/MC/MCELF.h"
18 #include "llvm/MC/MCObjectStreamer.h"
1819 #include "llvm/MC/MCSymbol.h"
1920 #include "llvm/Object/ELF.h"
2021
218219 fixELFSymbolsInTLSFixupsImpl(getSubExpr(), Asm);
219220 }
220221
221 // FIXME: This basically copies MCObjectStreamer::AddValueSymbols. Perhaps
222 // that method should be made public?
223 // FIXME: really do above: now that at least three other backends are using it.
224 static void AddValueSymbolsImpl(const MCExpr *Value, MCAssembler *Asm) {
225 switch (Value->getKind()) {
226 case MCExpr::Target:
227 llvm_unreachable("Can't handle nested target expr!");
228 break;
229
230 case MCExpr::Constant:
231 break;
232
233 case MCExpr::Binary: {
234 const MCBinaryExpr *BE = cast(Value);
235 AddValueSymbolsImpl(BE->getLHS(), Asm);
236 AddValueSymbolsImpl(BE->getRHS(), Asm);
237 break;
238 }
239
240 case MCExpr::SymbolRef:
241 Asm->getOrCreateSymbolData(cast(Value)->getSymbol());
242 break;
243
244 case MCExpr::Unary:
245 AddValueSymbolsImpl(cast(Value)->getSubExpr(), Asm);
246 break;
247 }
248 }
249
250 void SparcMCExpr::AddValueSymbols(MCAssembler *Asm) const {
251 AddValueSymbolsImpl(getSubExpr(), Asm);
252 }
222 void SparcMCExpr::visitUsedExpr(MCObjectStreamer &Streamer) const {
223 Streamer.visitUsedExpr(*getSubExpr());
224 }
8787 void PrintImpl(raw_ostream &OS) const override;
8888 bool EvaluateAsRelocatableImpl(MCValue &Res,
8989 const MCAsmLayout *Layout) const override;
90 void AddValueSymbols(MCAssembler *) const override;
90 void visitUsedExpr(MCObjectStreamer &Streamer) const override;
9191 const MCSection *FindAssociatedSection() const override {
9292 return getSubExpr()->FindAssociatedSection();
9393 }