Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(23)

Side by Side Diff: lib/MC/MCObjectStreamer.cpp

Issue 1133723005: Cherry-pick r234714: [MC] Write padding into fragments when -mc-relax-all flag is used (Closed) Base URL: http://git.chromium.org/native_client/pnacl-llvm.git@master
Patch Set: Rebase Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/MC/MCELFStreamer.cpp ('k') | test/MC/X86/AlignedBundling/bundle-group-too-large-error.s » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 //===- lib/MC/MCObjectStreamer.cpp - Object File MCStreamer Interface -----===// 1 //===- lib/MC/MCObjectStreamer.cpp - Object File MCStreamer Interface -----===//
2 // 2 //
3 // The LLVM Compiler Infrastructure 3 // The LLVM Compiler Infrastructure
4 // 4 //
5 // This file is distributed under the University of Illinois Open Source 5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details. 6 // License. See LICENSE.TXT for details.
7 // 7 //
8 //===----------------------------------------------------------------------===// 8 //===----------------------------------------------------------------------===//
9 9
10 #include "llvm/MC/MCObjectStreamer.h" 10 #include "llvm/MC/MCObjectStreamer.h"
(...skipping 24 matching lines...) Expand all
35 : MCStreamer(Context), Assembler(_Assembler), CurSectionData(nullptr), 35 : MCStreamer(Context), Assembler(_Assembler), CurSectionData(nullptr),
36 EmitEHFrame(true), EmitDebugFrame(false) {} 36 EmitEHFrame(true), EmitDebugFrame(false) {}
37 37
38 MCObjectStreamer::~MCObjectStreamer() { 38 MCObjectStreamer::~MCObjectStreamer() {
39 delete &Assembler->getBackend(); 39 delete &Assembler->getBackend();
40 delete &Assembler->getEmitter(); 40 delete &Assembler->getEmitter();
41 delete &Assembler->getWriter(); 41 delete &Assembler->getWriter();
42 delete Assembler; 42 delete Assembler;
43 } 43 }
44 44
45 void MCObjectStreamer::flushPendingLabels(MCFragment *F) { 45 void MCObjectStreamer::flushPendingLabels(MCFragment *F, uint64_t FOffset) {
46 if (PendingLabels.size()) { 46 if (PendingLabels.size()) {
47 if (!F) { 47 if (!F) {
48 F = new MCDataFragment(); 48 F = new MCDataFragment();
49 CurSectionData->getFragmentList().insert(CurInsertionPoint, F); 49 CurSectionData->getFragmentList().insert(CurInsertionPoint, F);
50 F->setParent(CurSectionData); 50 F->setParent(CurSectionData);
51 } 51 }
52 for (MCSymbolData *SD : PendingLabels) { 52 for (MCSymbolData *SD : PendingLabels) {
53 SD->setFragment(F); 53 SD->setFragment(F);
54 SD->setOffset(0); 54 SD->setOffset(FOffset);
55 } 55 }
56 PendingLabels.clear(); 56 PendingLabels.clear();
57 } 57 }
58 } 58 }
59 59
60 void MCObjectStreamer::reset() { 60 void MCObjectStreamer::reset() {
61 if (Assembler) 61 if (Assembler)
62 Assembler->reset(); 62 Assembler->reset();
63 CurSectionData = nullptr; 63 CurSectionData = nullptr;
64 CurInsertionPoint = MCSectionData::iterator(); 64 CurInsertionPoint = MCSectionData::iterator();
(...skipping 20 matching lines...) Expand all
85 if (CurInsertionPoint != getCurrentSectionData()->getFragmentList().begin()) 85 if (CurInsertionPoint != getCurrentSectionData()->getFragmentList().begin())
86 return std::prev(CurInsertionPoint); 86 return std::prev(CurInsertionPoint);
87 87
88 return nullptr; 88 return nullptr;
89 } 89 }
90 90
91 MCDataFragment *MCObjectStreamer::getOrCreateDataFragment() { 91 MCDataFragment *MCObjectStreamer::getOrCreateDataFragment() {
92 MCDataFragment *F = dyn_cast_or_null<MCDataFragment>(getCurrentFragment()); 92 MCDataFragment *F = dyn_cast_or_null<MCDataFragment>(getCurrentFragment());
93 // When bundling is enabled, we don't want to add data to a fragment that 93 // When bundling is enabled, we don't want to add data to a fragment that
94 // already has instructions (see MCELFStreamer::EmitInstToData for details) 94 // already has instructions (see MCELFStreamer::EmitInstToData for details)
95 if (!F || (Assembler->isBundlingEnabled() && F->hasInstructions())) { 95 if (!F || (Assembler->isBundlingEnabled() && !Assembler->getRelaxAll() &&
96 F->hasInstructions())) {
96 F = new MCDataFragment(); 97 F = new MCDataFragment();
97 insert(F); 98 insert(F);
98 } 99 }
99 return F; 100 return F;
100 } 101 }
101 102
102 void MCObjectStreamer::visitUsedSymbol(const MCSymbol &Sym) { 103 void MCObjectStreamer::visitUsedSymbol(const MCSymbol &Sym) {
103 Assembler->getOrCreateSymbolData(Sym); 104 Assembler->getOrCreateSymbolData(Sym);
104 } 105 }
105 106
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 142
142 void MCObjectStreamer::EmitLabel(MCSymbol *Symbol) { 143 void MCObjectStreamer::EmitLabel(MCSymbol *Symbol) {
143 MCStreamer::EmitLabel(Symbol); 144 MCStreamer::EmitLabel(Symbol);
144 145
145 MCSymbolData &SD = getAssembler().getOrCreateSymbolData(*Symbol); 146 MCSymbolData &SD = getAssembler().getOrCreateSymbolData(*Symbol);
146 assert(!SD.getFragment() && "Unexpected fragment on symbol data!"); 147 assert(!SD.getFragment() && "Unexpected fragment on symbol data!");
147 148
148 // If there is a current fragment, mark the symbol as pointing into it. 149 // If there is a current fragment, mark the symbol as pointing into it.
149 // Otherwise queue the label and set its fragment pointer when we emit the 150 // Otherwise queue the label and set its fragment pointer when we emit the
150 // next fragment. 151 // next fragment.
151 if (auto *F = dyn_cast_or_null<MCDataFragment>(getCurrentFragment())) { 152 auto *F = dyn_cast_or_null<MCDataFragment>(getCurrentFragment());
153 if (F && !(getAssembler().isBundlingEnabled() &&
154 getAssembler().getRelaxAll())) {
152 SD.setFragment(F); 155 SD.setFragment(F);
153 SD.setOffset(F->getContents().size()); 156 SD.setOffset(F->getContents().size());
154 } else { 157 } else {
155 PendingLabels.push_back(&SD); 158 PendingLabels.push_back(&SD);
156 } 159 }
157 } 160 }
158 161
159 void MCObjectStreamer::EmitULEB128Value(const MCExpr *Value) { 162 void MCObjectStreamer::EmitULEB128Value(const MCExpr *Value) {
160 int64_t IntValue; 163 int64_t IntValue;
161 if (Value->EvaluateAsAbsolute(IntValue, getAssembler())) { 164 if (Value->EvaluateAsAbsolute(IntValue, getAssembler())) {
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 EmitInstToData(Relaxed, STI); 243 EmitInstToData(Relaxed, STI);
241 return; 244 return;
242 } 245 }
243 246
244 // Otherwise emit to a separate fragment. 247 // Otherwise emit to a separate fragment.
245 EmitInstToFragment(Inst, STI); 248 EmitInstToFragment(Inst, STI);
246 } 249 }
247 250
248 void MCObjectStreamer::EmitInstToFragment(const MCInst &Inst, 251 void MCObjectStreamer::EmitInstToFragment(const MCInst &Inst,
249 const MCSubtargetInfo &STI) { 252 const MCSubtargetInfo &STI) {
253 if (getAssembler().getRelaxAll() && getAssembler().isBundlingEnabled())
254 llvm_unreachable("All instructions should have already been relaxed");
255
250 // Always create a new, separate fragment here, because its size can change 256 // Always create a new, separate fragment here, because its size can change
251 // during relaxation. 257 // during relaxation.
252 MCRelaxableFragment *IF = new MCRelaxableFragment(Inst, STI); 258 MCRelaxableFragment *IF = new MCRelaxableFragment(Inst, STI);
253 insert(IF); 259 insert(IF);
254 260
255 SmallString<128> Code; 261 SmallString<128> Code;
256 raw_svector_ostream VecOS(Code); 262 raw_svector_ostream VecOS(Code);
257 getAssembler().getEmitter().EncodeInstruction(Inst, VecOS, IF->getFixups(), 263 getAssembler().getEmitter().EncodeInstruction(Inst, VecOS, IF->getFixups(),
258 STI); 264 STI);
259 VecOS.flush(); 265 VecOS.flush();
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 // If we are generating dwarf for assembly source files dump out the sections. 426 // If we are generating dwarf for assembly source files dump out the sections.
421 if (getContext().getGenDwarfForAssembly()) 427 if (getContext().getGenDwarfForAssembly())
422 MCGenDwarfInfo::Emit(this); 428 MCGenDwarfInfo::Emit(this);
423 429
424 // Dump out the dwarf file & directory tables and line tables. 430 // Dump out the dwarf file & directory tables and line tables.
425 MCDwarfLineTable::Emit(this); 431 MCDwarfLineTable::Emit(this);
426 432
427 flushPendingLabels(nullptr); 433 flushPendingLabels(nullptr);
428 getAssembler().Finish(); 434 getAssembler().Finish();
429 } 435 }
OLDNEW
« no previous file with comments | « lib/MC/MCELFStreamer.cpp ('k') | test/MC/X86/AlignedBundling/bundle-group-too-large-error.s » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698