llvm.org GIT mirror llvm / 251040b
Renamed MCInstFragment to MCRelaxableFragment and added some comments. No change in functionality. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@171822 91177308-0d34-0410-b5e6-96231b3b80d8 Eli Bendersky 7 years ago
12 changed file(s) with 57 addition(s) and 50 deletion(s). Raw diff Collapse all Expand all
2121 struct MCFixupKindInfo;
2222 class MCFragment;
2323 class MCInst;
24 class MCInstFragment;
24 class MCRelaxableFragment;
2525 class MCObjectWriter;
2626 class MCSection;
2727 class MCValue;
129129 /// fixup requires the associated instruction to be relaxed.
130130 virtual bool fixupNeedsRelaxation(const MCFixup &Fixup,
131131 uint64_t Value,
132 const MCInstFragment *DF,
132 const MCRelaxableFragment *DF,
133133 const MCAsmLayout &Layout) const = 0;
134134
135135 /// RelaxInstruction - Relax the instruction in the given fragment to the next
4747 FT_Align,
4848 FT_Data,
4949 FT_Fill,
50 FT_Inst,
50 FT_Relaxable,
5151 FT_Org,
5252 FT_Dwarf,
5353 FT_DwarfFrame,
157157
158158 static bool classof(const MCFragment *F) {
159159 MCFragment::FragmentType Kind = F->getKind();
160 return Kind == MCFragment::FT_Inst || Kind == MCFragment::FT_Data;
161 }
162 };
163
160 return Kind == MCFragment::FT_Relaxable || Kind == MCFragment::FT_Data;
161 }
162 };
163
164 /// Fragment for data and encoded instructions.
165 ///
164166 class MCDataFragment : public MCEncodedFragment {
165167 virtual void anchor();
166168
209211 }
210212 };
211213
212 class MCInstFragment : public MCEncodedFragment {
214 /// A relaxable fragment holds on to its MCInst, since it may need to be
215 /// relaxed during the assembler layout and relaxation stage.
216 ///
217 class MCRelaxableFragment : public MCEncodedFragment {
213218 virtual void anchor();
214219
215220 /// Inst - The instruction this is a fragment for.
222227 SmallVector Fixups;
223228
224229 public:
225 MCInstFragment(const MCInst &_Inst, MCSectionData *SD = 0)
226 : MCEncodedFragment(FT_Inst, SD), Inst(_Inst) {
230 MCRelaxableFragment(const MCInst &_Inst, MCSectionData *SD = 0)
231 : MCEncodedFragment(FT_Relaxable, SD), Inst(_Inst) {
227232 }
228233
229234 virtual SmallVectorImpl &getContents() { return Contents; }
250255 const_fixup_iterator fixup_end() const {return Fixups.end();}
251256
252257 static bool classof(const MCFragment *F) {
253 return F->getKind() == MCFragment::FT_Inst;
258 return F->getKind() == MCFragment::FT_Relaxable;
254259 }
255260 };
256261
816821
817822 /// Check whether a fixup can be satisfied, or whether it needs to be relaxed
818823 /// (increased in size, in order to hold its value correctly).
819 bool fixupNeedsRelaxation(const MCFixup &Fixup, const MCInstFragment *DF,
824 bool fixupNeedsRelaxation(const MCFixup &Fixup, const MCRelaxableFragment *DF,
820825 const MCAsmLayout &Layout) const;
821826
822827 /// Check whether the given fragment needs relaxation.
823 bool fragmentNeedsRelaxation(const MCInstFragment *IF,
828 bool fragmentNeedsRelaxation(const MCRelaxableFragment *IF,
824829 const MCAsmLayout &Layout) const;
825830
826831 /// \brief Perform one layout iteration and return true if any offsets
831836 /// if any offsets were adjusted.
832837 bool layoutSectionOnce(MCAsmLayout &Layout, MCSectionData &SD);
833838
834 bool relaxInstruction(MCAsmLayout &Layout, MCInstFragment &IF);
839 bool relaxInstruction(MCAsmLayout &Layout, MCRelaxableFragment &IF);
835840
836841 bool relaxLEB(MCAsmLayout &Layout, MCLEBFragment &IF);
837842
389389 return cast(F).getContents().size();
390390 case MCFragment::FT_Fill:
391391 return cast(F).getSize();
392 case MCFragment::FT_Inst:
393 return cast(F).getInstSize();
392 case MCFragment::FT_Relaxable:
393 return cast(F).getInstSize();
394394
395395 case MCFragment::FT_LEB:
396396 return cast(F).getContents().size();
565565 writeFragmentContents(F, OW);
566566 break;
567567
568 case MCFragment::FT_Inst:
568 case MCFragment::FT_Relaxable:
569569 ++stats::EmittedInstFragments;
570570 writeFragmentContents(F, OW);
571571 break;
762762 }
763763
764764 bool MCAssembler::fixupNeedsRelaxation(const MCFixup &Fixup,
765 const MCInstFragment *DF,
765 const MCRelaxableFragment *DF,
766766 const MCAsmLayout &Layout) const {
767767 // If we cannot resolve the fixup value, it requires relaxation.
768768 MCValue Target;
773773 return getBackend().fixupNeedsRelaxation(Fixup, Value, DF, Layout);
774774 }
775775
776 bool MCAssembler::fragmentNeedsRelaxation(const MCInstFragment *IF,
776 bool MCAssembler::fragmentNeedsRelaxation(const MCRelaxableFragment *F,
777777 const MCAsmLayout &Layout) const {
778778 // If this inst doesn't ever need relaxation, ignore it. This occurs when we
779779 // are intentionally pushing out inst fragments, or because we relaxed a
780780 // previous instruction to one that doesn't need relaxation.
781 if (!getBackend().mayNeedRelaxation(IF->getInst()))
781 if (!getBackend().mayNeedRelaxation(F->getInst()))
782782 return false;
783783
784 for (MCInstFragment::const_fixup_iterator it = IF->fixup_begin(),
785 ie = IF->fixup_end(); it != ie; ++it)
786 if (fixupNeedsRelaxation(*it, IF, Layout))
784 for (MCRelaxableFragment::const_fixup_iterator it = F->fixup_begin(),
785 ie = F->fixup_end(); it != ie; ++it)
786 if (fixupNeedsRelaxation(*it, F, Layout))
787787 return true;
788788
789789 return false;
790790 }
791791
792792 bool MCAssembler::relaxInstruction(MCAsmLayout &Layout,
793 MCInstFragment &IF) {
794 if (!fragmentNeedsRelaxation(&IF, Layout))
793 MCRelaxableFragment &F) {
794 if (!fragmentNeedsRelaxation(&F, Layout))
795795 return false;
796796
797797 ++stats::RelaxedInstructions;
802802 // Relax the fragment.
803803
804804 MCInst Relaxed;
805 getBackend().relaxInstruction(IF.getInst(), Relaxed);
805 getBackend().relaxInstruction(F.getInst(), Relaxed);
806806
807807 // Encode the new instruction.
808808 //
814814 getEmitter().EncodeInstruction(Relaxed, VecOS, Fixups);
815815 VecOS.flush();
816816
817 // Update the instruction fragment.
818 IF.setInst(Relaxed);
819 IF.getContents() = Code;
820 IF.getFixups() = Fixups;
817 // Update the fragment.
818 F.setInst(Relaxed);
819 F.getContents() = Code;
820 F.getFixups() = Fixups;
821821
822822 return true;
823823 }
885885 switch(I->getKind()) {
886886 default:
887887 break;
888 case MCFragment::FT_Inst:
888 case MCFragment::FT_Relaxable:
889889 assert(!getRelaxAll() &&
890 "Did not expect a MCInstFragment in RelaxAll mode");
891 RelaxedFrag = relaxInstruction(Layout, *cast(I));
890 "Did not expect a MCRelaxableFragment in RelaxAll mode");
891 RelaxedFrag = relaxInstruction(Layout, *cast(I));
892892 break;
893893 case MCFragment::FT_Dwarf:
894894 RelaxedFrag = relaxDwarfLineAddr(Layout,
955955 case MCFragment::FT_Align: OS << "MCAlignFragment"; break;
956956 case MCFragment::FT_Data: OS << "MCDataFragment"; break;
957957 case MCFragment::FT_Fill: OS << "MCFillFragment"; break;
958 case MCFragment::FT_Inst: OS << "MCInstFragment"; break;
958 case MCFragment::FT_Relaxable: OS << "MCRelaxableFragment"; break;
959959 case MCFragment::FT_Org: OS << "MCOrgFragment"; break;
960960 case MCFragment::FT_Dwarf: OS << "MCDwarfFragment"; break;
961961 case MCFragment::FT_DwarfFrame: OS << "MCDwarfCallFrameFragment"; break;
10071007 << " Size:" << FF->getSize();
10081008 break;
10091009 }
1010 case MCFragment::FT_Inst: {
1011 const MCInstFragment *IF = cast(this);
1010 case MCFragment::FT_Relaxable: {
1011 const MCRelaxableFragment *F = cast(this);
10121012 OS << "\n ";
10131013 OS << " Inst:";
1014 IF->getInst().dump_pretty(OS);
1014 F->getInst().dump_pretty(OS);
10151015 break;
10161016 }
10171017 case MCFragment::FT_Org: {
10951095 // anchors for MC*Fragment vtables
10961096 void MCEncodedFragment::anchor() { }
10971097 void MCDataFragment::anchor() { }
1098 void MCInstFragment::anchor() { }
1098 void MCRelaxableFragment::anchor() { }
10991099 void MCAlignFragment::anchor() { }
11001100 void MCFillFragment::anchor() { }
11011101 void MCOrgFragment::anchor() { }
342342
343343 void MCELFStreamer::EmitInstToFragment(const MCInst &Inst) {
344344 this->MCObjectStreamer::EmitInstToFragment(Inst);
345 MCInstFragment &F = *castFragment>(getCurrentFragment());
345 MCRelaxableFragment &F = *castFragment>(getCurrentFragment());
346346
347347 for (unsigned i = 0, e = F.getFixups().size(); i != e; ++i)
348348 fixSymbolsInTLSFixups(F.getFixups()[i].getValue());
216216 void MCObjectStreamer::EmitInstToFragment(const MCInst &Inst) {
217217 // Always create a new, separate fragment here, because its size can change
218218 // during relaxation.
219 MCInstFragment *IF = new MCInstFragment(Inst, getCurrentSectionData());
219 MCRelaxableFragment *IF =
220 new MCRelaxableFragment(Inst, getCurrentSectionData());
220221
221222 SmallString<128> Code;
222223 raw_svector_ostream VecOS(Code);
187187 }
188188
189189 void MCPureStreamer::EmitInstToFragment(const MCInst &Inst) {
190 MCInstFragment *IF = new MCInstFragment(Inst, getCurrentSectionData());
190 MCRelaxableFragment *IF =
191 new MCRelaxableFragment(Inst, getCurrentSectionData());
191192
192193 // Add the fixups and data.
193194 //
121121
122122 bool fixupNeedsRelaxation(const MCFixup &Fixup,
123123 uint64_t Value,
124 const MCInstFragment *DF,
124 const MCRelaxableFragment *DF,
125125 const MCAsmLayout &Layout) const;
126126
127127 void relaxInstruction(const MCInst &Inst, MCInst &Res) const;
164164
165165 bool ARMAsmBackend::fixupNeedsRelaxation(const MCFixup &Fixup,
166166 uint64_t Value,
167 const MCInstFragment *DF,
167 const MCRelaxableFragment *DF,
168168 const MCAsmLayout &Layout) const {
169169 switch ((unsigned)Fixup.getKind()) {
170170 case ARM::fixup_arm_thumb_br: {
5353
5454 bool fixupNeedsRelaxation(const MCFixup &Fixup,
5555 uint64_t Value,
56 const MCInstFragment *DF,
56 const MCRelaxableFragment *DF,
5757 const MCAsmLayout &Layout) const;
5858
5959 void relaxInstruction(const MCInst &Inst, MCInst &Res) const;
8787
8888 bool MBlazeAsmBackend::fixupNeedsRelaxation(const MCFixup &Fixup,
8989 uint64_t Value,
90 const MCInstFragment *DF,
90 const MCRelaxableFragment *DF,
9191 const MCAsmLayout &Layout) const {
9292 // FIXME: Is this right? It's what the "generic" code was doing before,
9393 // but is X86 specific. Is it actually true for MBlaze also, or was it
212212 /// fixup requires the associated instruction to be relaxed.
213213 bool fixupNeedsRelaxation(const MCFixup &Fixup,
214214 uint64_t Value,
215 const MCInstFragment *DF,
215 const MCRelaxableFragment *DF,
216216 const MCAsmLayout &Layout) const {
217217 // FIXME.
218218 assert(0 && "RelaxInstruction() unimplemented");
118118
119119 bool fixupNeedsRelaxation(const MCFixup &Fixup,
120120 uint64_t Value,
121 const MCInstFragment *DF,
121 const MCRelaxableFragment *DF,
122122 const MCAsmLayout &Layout) const {
123123 // FIXME.
124124 llvm_unreachable("relaxInstruction() unimplemented");
4848 virtual void applyFixup(const MCFixup &Fixup, char *Data, unsigned DataSize,
4949 uint64_t Value) const;
5050 virtual bool fixupNeedsRelaxation(const MCFixup &Fixup, uint64_t Value,
51 const MCInstFragment *DF,
51 const MCRelaxableFragment *DF,
5252 const MCAsmLayout &Layout) const {
5353 return false;
5454 }
112112
113113 bool fixupNeedsRelaxation(const MCFixup &Fixup,
114114 uint64_t Value,
115 const MCInstFragment *DF,
115 const MCRelaxableFragment *DF,
116116 const MCAsmLayout &Layout) const;
117117
118118 void relaxInstruction(const MCInst &Inst, MCInst &Res) const;
254254
255255 bool X86AsmBackend::fixupNeedsRelaxation(const MCFixup &Fixup,
256256 uint64_t Value,
257 const MCInstFragment *DF,
257 const MCRelaxableFragment *DF,
258258 const MCAsmLayout &Layout) const {
259259 // Relax if the value is too big for a (signed) i8.
260260 return int64_t(Value) != int64_t(int8_t(Value));