Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 1 | //===- MCFragment.h - Fragment type hierarchy -------------------*- C++ -*-===// |
| 2 | // |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame^] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #ifndef LLVM_MC_MCFRAGMENT_H |
| 10 | #define LLVM_MC_MCFRAGMENT_H |
| 11 | |
| 12 | #include "llvm/ADT/ArrayRef.h" |
| 13 | #include "llvm/ADT/SmallString.h" |
| 14 | #include "llvm/ADT/SmallVector.h" |
| 15 | #include "llvm/ADT/StringRef.h" |
| 16 | #include "llvm/ADT/ilist_node.h" |
| 17 | #include "llvm/MC/MCFixup.h" |
| 18 | #include "llvm/MC/MCInst.h" |
| 19 | #include "llvm/Support/Casting.h" |
| 20 | #include "llvm/Support/SMLoc.h" |
| 21 | #include <cstdint> |
| 22 | #include <utility> |
| 23 | |
| 24 | namespace llvm { |
| 25 | |
| 26 | class MCSection; |
| 27 | class MCSubtargetInfo; |
| 28 | class MCSymbol; |
| 29 | |
| 30 | class MCFragment : public ilist_node_with_parent<MCFragment, MCSection> { |
| 31 | friend class MCAsmLayout; |
| 32 | |
| 33 | public: |
| 34 | enum FragmentType : uint8_t { |
| 35 | FT_Align, |
| 36 | FT_Data, |
| 37 | FT_CompactEncodedInst, |
| 38 | FT_Fill, |
| 39 | FT_Relaxable, |
| 40 | FT_Org, |
| 41 | FT_Dwarf, |
| 42 | FT_DwarfFrame, |
| 43 | FT_LEB, |
| 44 | FT_Padding, |
| 45 | FT_SymbolId, |
| 46 | FT_CVInlineLines, |
| 47 | FT_CVDefRange, |
| 48 | FT_Dummy |
| 49 | }; |
| 50 | |
| 51 | private: |
| 52 | FragmentType Kind; |
| 53 | |
| 54 | protected: |
| 55 | bool HasInstructions; |
| 56 | |
| 57 | private: |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 58 | /// LayoutOrder - The layout order of this fragment. |
| 59 | unsigned LayoutOrder; |
| 60 | |
| 61 | /// The data for the section this fragment is in. |
| 62 | MCSection *Parent; |
| 63 | |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 64 | /// Atom - The atom this fragment is in, as represented by its defining |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 65 | /// symbol. |
| 66 | const MCSymbol *Atom; |
| 67 | |
| 68 | /// \name Assembler Backend Data |
| 69 | /// @{ |
| 70 | // |
| 71 | // FIXME: This could all be kept private to the assembler implementation. |
| 72 | |
| 73 | /// Offset - The offset of this fragment in its section. This is ~0 until |
| 74 | /// initialized. |
| 75 | uint64_t Offset; |
| 76 | |
| 77 | /// @} |
| 78 | |
| 79 | protected: |
| 80 | MCFragment(FragmentType Kind, bool HasInstructions, |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 81 | MCSection *Parent = nullptr); |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 82 | |
| 83 | ~MCFragment(); |
| 84 | |
| 85 | public: |
| 86 | MCFragment() = delete; |
| 87 | MCFragment(const MCFragment &) = delete; |
| 88 | MCFragment &operator=(const MCFragment &) = delete; |
| 89 | |
| 90 | /// Destroys the current fragment. |
| 91 | /// |
| 92 | /// This must be used instead of delete as MCFragment is non-virtual. |
| 93 | /// This method will dispatch to the appropriate subclass. |
| 94 | void destroy(); |
| 95 | |
| 96 | FragmentType getKind() const { return Kind; } |
| 97 | |
| 98 | MCSection *getParent() const { return Parent; } |
| 99 | void setParent(MCSection *Value) { Parent = Value; } |
| 100 | |
| 101 | const MCSymbol *getAtom() const { return Atom; } |
| 102 | void setAtom(const MCSymbol *Value) { Atom = Value; } |
| 103 | |
| 104 | unsigned getLayoutOrder() const { return LayoutOrder; } |
| 105 | void setLayoutOrder(unsigned Value) { LayoutOrder = Value; } |
| 106 | |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 107 | /// Does this fragment have instructions emitted into it? By default |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 108 | /// this is false, but specific fragment types may set it to true. |
| 109 | bool hasInstructions() const { return HasInstructions; } |
| 110 | |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 111 | /// Return true if given frgment has FT_Dummy type. |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 112 | bool isDummy() const { return Kind == FT_Dummy; } |
| 113 | |
| 114 | void dump() const; |
| 115 | }; |
| 116 | |
| 117 | class MCDummyFragment : public MCFragment { |
| 118 | public: |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 119 | explicit MCDummyFragment(MCSection *Sec) : MCFragment(FT_Dummy, false, Sec) {} |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 120 | |
| 121 | static bool classof(const MCFragment *F) { return F->getKind() == FT_Dummy; } |
| 122 | }; |
| 123 | |
| 124 | /// Interface implemented by fragments that contain encoded instructions and/or |
| 125 | /// data. |
| 126 | /// |
| 127 | class MCEncodedFragment : public MCFragment { |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 128 | /// Should this fragment be aligned to the end of a bundle? |
| 129 | bool AlignToBundleEnd = false; |
| 130 | |
| 131 | uint8_t BundlePadding = 0; |
| 132 | |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 133 | protected: |
| 134 | MCEncodedFragment(MCFragment::FragmentType FType, bool HasInstructions, |
| 135 | MCSection *Sec) |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 136 | : MCFragment(FType, HasInstructions, Sec) {} |
| 137 | |
| 138 | /// STI - The MCSubtargetInfo in effect when the instruction was encoded. |
| 139 | /// must be non-null for instructions. |
| 140 | const MCSubtargetInfo *STI = nullptr; |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 141 | |
| 142 | public: |
| 143 | static bool classof(const MCFragment *F) { |
| 144 | MCFragment::FragmentType Kind = F->getKind(); |
| 145 | switch (Kind) { |
| 146 | default: |
| 147 | return false; |
| 148 | case MCFragment::FT_Relaxable: |
| 149 | case MCFragment::FT_CompactEncodedInst: |
| 150 | case MCFragment::FT_Data: |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 151 | case MCFragment::FT_Dwarf: |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 152 | return true; |
| 153 | } |
| 154 | } |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 155 | |
| 156 | /// Should this fragment be placed at the end of an aligned bundle? |
| 157 | bool alignToBundleEnd() const { return AlignToBundleEnd; } |
| 158 | void setAlignToBundleEnd(bool V) { AlignToBundleEnd = V; } |
| 159 | |
| 160 | /// Get the padding size that must be inserted before this fragment. |
| 161 | /// Used for bundling. By default, no padding is inserted. |
| 162 | /// Note that padding size is restricted to 8 bits. This is an optimization |
| 163 | /// to reduce the amount of space used for each fragment. In practice, larger |
| 164 | /// padding should never be required. |
| 165 | uint8_t getBundlePadding() const { return BundlePadding; } |
| 166 | |
| 167 | /// Set the padding size for this fragment. By default it's a no-op, |
| 168 | /// and only some fragments have a meaningful implementation. |
| 169 | void setBundlePadding(uint8_t N) { BundlePadding = N; } |
| 170 | |
| 171 | /// Retrieve the MCSubTargetInfo in effect when the instruction was encoded. |
| 172 | /// Guaranteed to be non-null if hasInstructions() == true |
| 173 | const MCSubtargetInfo *getSubtargetInfo() const { return STI; } |
| 174 | |
| 175 | /// Record that the fragment contains instructions with the MCSubtargetInfo in |
| 176 | /// effect when the instruction was encoded. |
| 177 | void setHasInstructions(const MCSubtargetInfo &STI) { |
| 178 | HasInstructions = true; |
| 179 | this->STI = &STI; |
| 180 | } |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 181 | }; |
| 182 | |
| 183 | /// Interface implemented by fragments that contain encoded instructions and/or |
| 184 | /// data. |
| 185 | /// |
| 186 | template<unsigned ContentsSize> |
| 187 | class MCEncodedFragmentWithContents : public MCEncodedFragment { |
| 188 | SmallVector<char, ContentsSize> Contents; |
| 189 | |
| 190 | protected: |
| 191 | MCEncodedFragmentWithContents(MCFragment::FragmentType FType, |
| 192 | bool HasInstructions, |
| 193 | MCSection *Sec) |
| 194 | : MCEncodedFragment(FType, HasInstructions, Sec) {} |
| 195 | |
| 196 | public: |
| 197 | SmallVectorImpl<char> &getContents() { return Contents; } |
| 198 | const SmallVectorImpl<char> &getContents() const { return Contents; } |
| 199 | }; |
| 200 | |
| 201 | /// Interface implemented by fragments that contain encoded instructions and/or |
| 202 | /// data and also have fixups registered. |
| 203 | /// |
| 204 | template<unsigned ContentsSize, unsigned FixupsSize> |
| 205 | class MCEncodedFragmentWithFixups : |
| 206 | public MCEncodedFragmentWithContents<ContentsSize> { |
| 207 | |
| 208 | /// Fixups - The list of fixups in this fragment. |
| 209 | SmallVector<MCFixup, FixupsSize> Fixups; |
| 210 | |
| 211 | protected: |
| 212 | MCEncodedFragmentWithFixups(MCFragment::FragmentType FType, |
| 213 | bool HasInstructions, |
| 214 | MCSection *Sec) |
| 215 | : MCEncodedFragmentWithContents<ContentsSize>(FType, HasInstructions, |
| 216 | Sec) {} |
| 217 | |
| 218 | public: |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 219 | |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 220 | using const_fixup_iterator = SmallVectorImpl<MCFixup>::const_iterator; |
| 221 | using fixup_iterator = SmallVectorImpl<MCFixup>::iterator; |
| 222 | |
| 223 | SmallVectorImpl<MCFixup> &getFixups() { return Fixups; } |
| 224 | const SmallVectorImpl<MCFixup> &getFixups() const { return Fixups; } |
| 225 | |
| 226 | fixup_iterator fixup_begin() { return Fixups.begin(); } |
| 227 | const_fixup_iterator fixup_begin() const { return Fixups.begin(); } |
| 228 | |
| 229 | fixup_iterator fixup_end() { return Fixups.end(); } |
| 230 | const_fixup_iterator fixup_end() const { return Fixups.end(); } |
| 231 | |
| 232 | static bool classof(const MCFragment *F) { |
| 233 | MCFragment::FragmentType Kind = F->getKind(); |
| 234 | return Kind == MCFragment::FT_Relaxable || Kind == MCFragment::FT_Data || |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 235 | Kind == MCFragment::FT_CVDefRange || Kind == MCFragment::FT_Dwarf;; |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 236 | } |
| 237 | }; |
| 238 | |
| 239 | /// Fragment for data and encoded instructions. |
| 240 | /// |
| 241 | class MCDataFragment : public MCEncodedFragmentWithFixups<32, 4> { |
| 242 | public: |
| 243 | MCDataFragment(MCSection *Sec = nullptr) |
| 244 | : MCEncodedFragmentWithFixups<32, 4>(FT_Data, false, Sec) {} |
| 245 | |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 246 | static bool classof(const MCFragment *F) { |
| 247 | return F->getKind() == MCFragment::FT_Data; |
| 248 | } |
| 249 | }; |
| 250 | |
| 251 | /// This is a compact (memory-size-wise) fragment for holding an encoded |
| 252 | /// instruction (non-relaxable) that has no fixups registered. When applicable, |
| 253 | /// it can be used instead of MCDataFragment and lead to lower memory |
| 254 | /// consumption. |
| 255 | /// |
| 256 | class MCCompactEncodedInstFragment : public MCEncodedFragmentWithContents<4> { |
| 257 | public: |
| 258 | MCCompactEncodedInstFragment(MCSection *Sec = nullptr) |
| 259 | : MCEncodedFragmentWithContents(FT_CompactEncodedInst, true, Sec) { |
| 260 | } |
| 261 | |
| 262 | static bool classof(const MCFragment *F) { |
| 263 | return F->getKind() == MCFragment::FT_CompactEncodedInst; |
| 264 | } |
| 265 | }; |
| 266 | |
| 267 | /// A relaxable fragment holds on to its MCInst, since it may need to be |
| 268 | /// relaxed during the assembler layout and relaxation stage. |
| 269 | /// |
| 270 | class MCRelaxableFragment : public MCEncodedFragmentWithFixups<8, 1> { |
| 271 | |
| 272 | /// Inst - The instruction this is a fragment for. |
| 273 | MCInst Inst; |
| 274 | |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 275 | public: |
| 276 | MCRelaxableFragment(const MCInst &Inst, const MCSubtargetInfo &STI, |
| 277 | MCSection *Sec = nullptr) |
| 278 | : MCEncodedFragmentWithFixups(FT_Relaxable, true, Sec), |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 279 | Inst(Inst) { this->STI = &STI; } |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 280 | |
| 281 | const MCInst &getInst() const { return Inst; } |
| 282 | void setInst(const MCInst &Value) { Inst = Value; } |
| 283 | |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 284 | static bool classof(const MCFragment *F) { |
| 285 | return F->getKind() == MCFragment::FT_Relaxable; |
| 286 | } |
| 287 | }; |
| 288 | |
| 289 | class MCAlignFragment : public MCFragment { |
| 290 | /// Alignment - The alignment to ensure, in bytes. |
| 291 | unsigned Alignment; |
| 292 | |
| 293 | /// EmitNops - Flag to indicate that (optimal) NOPs should be emitted instead |
| 294 | /// of using the provided value. The exact interpretation of this flag is |
| 295 | /// target dependent. |
| 296 | bool EmitNops : 1; |
| 297 | |
| 298 | /// Value - Value to use for filling padding bytes. |
| 299 | int64_t Value; |
| 300 | |
| 301 | /// ValueSize - The size of the integer (in bytes) of \p Value. |
| 302 | unsigned ValueSize; |
| 303 | |
| 304 | /// MaxBytesToEmit - The maximum number of bytes to emit; if the alignment |
| 305 | /// cannot be satisfied in this width then this fragment is ignored. |
| 306 | unsigned MaxBytesToEmit; |
| 307 | |
| 308 | public: |
| 309 | MCAlignFragment(unsigned Alignment, int64_t Value, unsigned ValueSize, |
| 310 | unsigned MaxBytesToEmit, MCSection *Sec = nullptr) |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 311 | : MCFragment(FT_Align, false, Sec), Alignment(Alignment), EmitNops(false), |
| 312 | Value(Value), ValueSize(ValueSize), MaxBytesToEmit(MaxBytesToEmit) {} |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 313 | |
| 314 | /// \name Accessors |
| 315 | /// @{ |
| 316 | |
| 317 | unsigned getAlignment() const { return Alignment; } |
| 318 | |
| 319 | int64_t getValue() const { return Value; } |
| 320 | |
| 321 | unsigned getValueSize() const { return ValueSize; } |
| 322 | |
| 323 | unsigned getMaxBytesToEmit() const { return MaxBytesToEmit; } |
| 324 | |
| 325 | bool hasEmitNops() const { return EmitNops; } |
| 326 | void setEmitNops(bool Value) { EmitNops = Value; } |
| 327 | |
| 328 | /// @} |
| 329 | |
| 330 | static bool classof(const MCFragment *F) { |
| 331 | return F->getKind() == MCFragment::FT_Align; |
| 332 | } |
| 333 | }; |
| 334 | |
| 335 | /// Fragment for adding required padding. |
| 336 | /// This fragment is always inserted before an instruction, and holds that |
| 337 | /// instruction as context information (as well as a mask of kinds) for |
| 338 | /// determining the padding size. |
| 339 | /// |
| 340 | class MCPaddingFragment : public MCFragment { |
| 341 | /// A mask containing all the kinds relevant to this fragment. i.e. the i'th |
| 342 | /// bit will be set iff kind i is relevant to this fragment. |
| 343 | uint64_t PaddingPoliciesMask; |
| 344 | /// A boolean indicating if this fragment will actually hold padding. If its |
| 345 | /// value is false, then this fragment serves only as a placeholder, |
| 346 | /// containing data to assist other insertion point in their decision making. |
| 347 | bool IsInsertionPoint; |
| 348 | |
| 349 | uint64_t Size; |
| 350 | |
| 351 | struct MCInstInfo { |
| 352 | bool IsInitialized; |
| 353 | MCInst Inst; |
| 354 | /// A boolean indicating whether the instruction pointed by this fragment is |
| 355 | /// a fixed size instruction or a relaxable instruction held by a |
| 356 | /// MCRelaxableFragment. |
| 357 | bool IsImmutableSizedInst; |
| 358 | union { |
| 359 | /// If the instruction is a fixed size instruction, hold its size. |
| 360 | size_t InstSize; |
| 361 | /// Otherwise, hold a pointer to the MCRelaxableFragment holding it. |
| 362 | MCRelaxableFragment *InstFragment; |
| 363 | }; |
| 364 | }; |
| 365 | MCInstInfo InstInfo; |
| 366 | |
| 367 | public: |
| 368 | static const uint64_t PFK_None = UINT64_C(0); |
| 369 | |
| 370 | enum MCPaddingFragmentKind { |
| 371 | // values 0-7 are reserved for future target independet values. |
| 372 | |
| 373 | FirstTargetPerfNopFragmentKind = 8, |
| 374 | |
| 375 | /// Limit range of target MCPerfNopFragment kinds to fit in uint64_t |
| 376 | MaxTargetPerfNopFragmentKind = 63 |
| 377 | }; |
| 378 | |
| 379 | MCPaddingFragment(MCSection *Sec = nullptr) |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 380 | : MCFragment(FT_Padding, false, Sec), PaddingPoliciesMask(PFK_None), |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 381 | IsInsertionPoint(false), Size(UINT64_C(0)), |
| 382 | InstInfo({false, MCInst(), false, {0}}) {} |
| 383 | |
| 384 | bool isInsertionPoint() const { return IsInsertionPoint; } |
| 385 | void setAsInsertionPoint() { IsInsertionPoint = true; } |
| 386 | uint64_t getPaddingPoliciesMask() const { return PaddingPoliciesMask; } |
| 387 | void setPaddingPoliciesMask(uint64_t Value) { PaddingPoliciesMask = Value; } |
| 388 | bool hasPaddingPolicy(uint64_t PolicyMask) const { |
| 389 | assert(isPowerOf2_64(PolicyMask) && |
| 390 | "Policy mask must contain exactly one policy"); |
| 391 | return (getPaddingPoliciesMask() & PolicyMask) != PFK_None; |
| 392 | } |
| 393 | const MCInst &getInst() const { |
| 394 | assert(isInstructionInitialized() && "Fragment has no instruction!"); |
| 395 | return InstInfo.Inst; |
| 396 | } |
| 397 | size_t getInstSize() const { |
| 398 | assert(isInstructionInitialized() && "Fragment has no instruction!"); |
| 399 | if (InstInfo.IsImmutableSizedInst) |
| 400 | return InstInfo.InstSize; |
| 401 | assert(InstInfo.InstFragment != nullptr && |
| 402 | "Must have a valid InstFragment to retrieve InstSize from"); |
| 403 | return InstInfo.InstFragment->getContents().size(); |
| 404 | } |
| 405 | void setInstAndInstSize(const MCInst &Inst, size_t InstSize) { |
| 406 | InstInfo.IsInitialized = true; |
| 407 | InstInfo.IsImmutableSizedInst = true; |
| 408 | InstInfo.Inst = Inst; |
| 409 | InstInfo.InstSize = InstSize; |
| 410 | } |
| 411 | void setInstAndInstFragment(const MCInst &Inst, |
| 412 | MCRelaxableFragment *InstFragment) { |
| 413 | InstInfo.IsInitialized = true; |
| 414 | InstInfo.IsImmutableSizedInst = false; |
| 415 | InstInfo.Inst = Inst; |
| 416 | InstInfo.InstFragment = InstFragment; |
| 417 | } |
| 418 | uint64_t getSize() const { return Size; } |
| 419 | void setSize(uint64_t Value) { Size = Value; } |
| 420 | bool isInstructionInitialized() const { return InstInfo.IsInitialized; } |
| 421 | |
| 422 | static bool classof(const MCFragment *F) { |
| 423 | return F->getKind() == MCFragment::FT_Padding; |
| 424 | } |
| 425 | }; |
| 426 | |
| 427 | class MCFillFragment : public MCFragment { |
| 428 | /// Value to use for filling bytes. |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 429 | uint64_t Value; |
| 430 | uint8_t ValueSize; |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 431 | /// The number of bytes to insert. |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 432 | const MCExpr &NumValues; |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 433 | |
| 434 | /// Source location of the directive that this fragment was created for. |
| 435 | SMLoc Loc; |
| 436 | |
| 437 | public: |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 438 | MCFillFragment(uint64_t Value, uint8_t VSize, const MCExpr &NumValues, |
| 439 | SMLoc Loc, MCSection *Sec = nullptr) |
| 440 | : MCFragment(FT_Fill, false, Sec), Value(Value), ValueSize(VSize), |
| 441 | NumValues(NumValues), Loc(Loc) {} |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 442 | |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 443 | uint64_t getValue() const { return Value; } |
| 444 | uint8_t getValueSize() const { return ValueSize; } |
| 445 | const MCExpr &getNumValues() const { return NumValues; } |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 446 | |
| 447 | SMLoc getLoc() const { return Loc; } |
| 448 | |
| 449 | static bool classof(const MCFragment *F) { |
| 450 | return F->getKind() == MCFragment::FT_Fill; |
| 451 | } |
| 452 | }; |
| 453 | |
| 454 | class MCOrgFragment : public MCFragment { |
| 455 | /// The offset this fragment should start at. |
| 456 | const MCExpr *Offset; |
| 457 | |
| 458 | /// Value to use for filling bytes. |
| 459 | int8_t Value; |
| 460 | |
| 461 | /// Source location of the directive that this fragment was created for. |
| 462 | SMLoc Loc; |
| 463 | |
| 464 | public: |
| 465 | MCOrgFragment(const MCExpr &Offset, int8_t Value, SMLoc Loc, |
| 466 | MCSection *Sec = nullptr) |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 467 | : MCFragment(FT_Org, false, Sec), Offset(&Offset), Value(Value), Loc(Loc) {} |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 468 | |
| 469 | /// \name Accessors |
| 470 | /// @{ |
| 471 | |
| 472 | const MCExpr &getOffset() const { return *Offset; } |
| 473 | |
| 474 | uint8_t getValue() const { return Value; } |
| 475 | |
| 476 | SMLoc getLoc() const { return Loc; } |
| 477 | |
| 478 | /// @} |
| 479 | |
| 480 | static bool classof(const MCFragment *F) { |
| 481 | return F->getKind() == MCFragment::FT_Org; |
| 482 | } |
| 483 | }; |
| 484 | |
| 485 | class MCLEBFragment : public MCFragment { |
| 486 | /// Value - The value this fragment should contain. |
| 487 | const MCExpr *Value; |
| 488 | |
| 489 | /// IsSigned - True if this is a sleb128, false if uleb128. |
| 490 | bool IsSigned; |
| 491 | |
| 492 | SmallString<8> Contents; |
| 493 | |
| 494 | public: |
| 495 | MCLEBFragment(const MCExpr &Value_, bool IsSigned_, MCSection *Sec = nullptr) |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 496 | : MCFragment(FT_LEB, false, Sec), Value(&Value_), IsSigned(IsSigned_) { |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 497 | Contents.push_back(0); |
| 498 | } |
| 499 | |
| 500 | /// \name Accessors |
| 501 | /// @{ |
| 502 | |
| 503 | const MCExpr &getValue() const { return *Value; } |
| 504 | |
| 505 | bool isSigned() const { return IsSigned; } |
| 506 | |
| 507 | SmallString<8> &getContents() { return Contents; } |
| 508 | const SmallString<8> &getContents() const { return Contents; } |
| 509 | |
| 510 | /// @} |
| 511 | |
| 512 | static bool classof(const MCFragment *F) { |
| 513 | return F->getKind() == MCFragment::FT_LEB; |
| 514 | } |
| 515 | }; |
| 516 | |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 517 | class MCDwarfLineAddrFragment : public MCEncodedFragmentWithFixups<8, 1> { |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 518 | /// LineDelta - the value of the difference between the two line numbers |
| 519 | /// between two .loc dwarf directives. |
| 520 | int64_t LineDelta; |
| 521 | |
| 522 | /// AddrDelta - The expression for the difference of the two symbols that |
| 523 | /// make up the address delta between two .loc dwarf directives. |
| 524 | const MCExpr *AddrDelta; |
| 525 | |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 526 | public: |
| 527 | MCDwarfLineAddrFragment(int64_t LineDelta, const MCExpr &AddrDelta, |
| 528 | MCSection *Sec = nullptr) |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 529 | : MCEncodedFragmentWithFixups<8, 1>(FT_Dwarf, false, Sec), |
| 530 | LineDelta(LineDelta), AddrDelta(&AddrDelta) {} |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 531 | |
| 532 | /// \name Accessors |
| 533 | /// @{ |
| 534 | |
| 535 | int64_t getLineDelta() const { return LineDelta; } |
| 536 | |
| 537 | const MCExpr &getAddrDelta() const { return *AddrDelta; } |
| 538 | |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 539 | /// @} |
| 540 | |
| 541 | static bool classof(const MCFragment *F) { |
| 542 | return F->getKind() == MCFragment::FT_Dwarf; |
| 543 | } |
| 544 | }; |
| 545 | |
| 546 | class MCDwarfCallFrameFragment : public MCFragment { |
| 547 | /// AddrDelta - The expression for the difference of the two symbols that |
| 548 | /// make up the address delta between two .cfi_* dwarf directives. |
| 549 | const MCExpr *AddrDelta; |
| 550 | |
| 551 | SmallString<8> Contents; |
| 552 | |
| 553 | public: |
| 554 | MCDwarfCallFrameFragment(const MCExpr &AddrDelta, MCSection *Sec = nullptr) |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 555 | : MCFragment(FT_DwarfFrame, false, Sec), AddrDelta(&AddrDelta) { |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 556 | Contents.push_back(0); |
| 557 | } |
| 558 | |
| 559 | /// \name Accessors |
| 560 | /// @{ |
| 561 | |
| 562 | const MCExpr &getAddrDelta() const { return *AddrDelta; } |
| 563 | |
| 564 | SmallString<8> &getContents() { return Contents; } |
| 565 | const SmallString<8> &getContents() const { return Contents; } |
| 566 | |
| 567 | /// @} |
| 568 | |
| 569 | static bool classof(const MCFragment *F) { |
| 570 | return F->getKind() == MCFragment::FT_DwarfFrame; |
| 571 | } |
| 572 | }; |
| 573 | |
| 574 | /// Represents a symbol table index fragment. |
| 575 | class MCSymbolIdFragment : public MCFragment { |
| 576 | const MCSymbol *Sym; |
| 577 | |
| 578 | public: |
| 579 | MCSymbolIdFragment(const MCSymbol *Sym, MCSection *Sec = nullptr) |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 580 | : MCFragment(FT_SymbolId, false, Sec), Sym(Sym) {} |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 581 | |
| 582 | /// \name Accessors |
| 583 | /// @{ |
| 584 | |
| 585 | const MCSymbol *getSymbol() { return Sym; } |
| 586 | const MCSymbol *getSymbol() const { return Sym; } |
| 587 | |
| 588 | /// @} |
| 589 | |
| 590 | static bool classof(const MCFragment *F) { |
| 591 | return F->getKind() == MCFragment::FT_SymbolId; |
| 592 | } |
| 593 | }; |
| 594 | |
| 595 | /// Fragment representing the binary annotations produced by the |
| 596 | /// .cv_inline_linetable directive. |
| 597 | class MCCVInlineLineTableFragment : public MCFragment { |
| 598 | unsigned SiteFuncId; |
| 599 | unsigned StartFileId; |
| 600 | unsigned StartLineNum; |
| 601 | const MCSymbol *FnStartSym; |
| 602 | const MCSymbol *FnEndSym; |
| 603 | SmallString<8> Contents; |
| 604 | |
| 605 | /// CodeViewContext has the real knowledge about this format, so let it access |
| 606 | /// our members. |
| 607 | friend class CodeViewContext; |
| 608 | |
| 609 | public: |
| 610 | MCCVInlineLineTableFragment(unsigned SiteFuncId, unsigned StartFileId, |
| 611 | unsigned StartLineNum, const MCSymbol *FnStartSym, |
| 612 | const MCSymbol *FnEndSym, |
| 613 | MCSection *Sec = nullptr) |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 614 | : MCFragment(FT_CVInlineLines, false, Sec), SiteFuncId(SiteFuncId), |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 615 | StartFileId(StartFileId), StartLineNum(StartLineNum), |
| 616 | FnStartSym(FnStartSym), FnEndSym(FnEndSym) {} |
| 617 | |
| 618 | /// \name Accessors |
| 619 | /// @{ |
| 620 | |
| 621 | const MCSymbol *getFnStartSym() const { return FnStartSym; } |
| 622 | const MCSymbol *getFnEndSym() const { return FnEndSym; } |
| 623 | |
| 624 | SmallString<8> &getContents() { return Contents; } |
| 625 | const SmallString<8> &getContents() const { return Contents; } |
| 626 | |
| 627 | /// @} |
| 628 | |
| 629 | static bool classof(const MCFragment *F) { |
| 630 | return F->getKind() == MCFragment::FT_CVInlineLines; |
| 631 | } |
| 632 | }; |
| 633 | |
| 634 | /// Fragment representing the .cv_def_range directive. |
| 635 | class MCCVDefRangeFragment : public MCEncodedFragmentWithFixups<32, 4> { |
| 636 | SmallVector<std::pair<const MCSymbol *, const MCSymbol *>, 2> Ranges; |
| 637 | SmallString<32> FixedSizePortion; |
| 638 | |
| 639 | /// CodeViewContext has the real knowledge about this format, so let it access |
| 640 | /// our members. |
| 641 | friend class CodeViewContext; |
| 642 | |
| 643 | public: |
| 644 | MCCVDefRangeFragment( |
| 645 | ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges, |
| 646 | StringRef FixedSizePortion, MCSection *Sec = nullptr) |
| 647 | : MCEncodedFragmentWithFixups<32, 4>(FT_CVDefRange, false, Sec), |
| 648 | Ranges(Ranges.begin(), Ranges.end()), |
| 649 | FixedSizePortion(FixedSizePortion) {} |
| 650 | |
| 651 | /// \name Accessors |
| 652 | /// @{ |
| 653 | ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> getRanges() const { |
| 654 | return Ranges; |
| 655 | } |
| 656 | |
| 657 | StringRef getFixedSizePortion() const { return FixedSizePortion; } |
| 658 | /// @} |
| 659 | |
| 660 | static bool classof(const MCFragment *F) { |
| 661 | return F->getKind() == MCFragment::FT_CVDefRange; |
| 662 | } |
| 663 | }; |
| 664 | |
| 665 | } // end namespace llvm |
| 666 | |
| 667 | #endif // LLVM_MC_MCFRAGMENT_H |