LLVM  11.0.0git
SystemZMCAsmBackend.cpp
Go to the documentation of this file.
1 //===-- SystemZMCAsmBackend.cpp - SystemZ assembler backend ---------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 
11 #include "llvm/MC/MCAsmBackend.h"
14 #include "llvm/MC/MCInst.h"
15 #include "llvm/MC/MCObjectWriter.h"
17 
18 using namespace llvm;
19 
20 // Value is a fully-resolved relocation value: Symbol + Addend [- Pivot].
21 // Return the bits that should be installed in a relocation field for
22 // fixup kind Kind.
23 static uint64_t extractBitsForFixup(MCFixupKind Kind, uint64_t Value) {
24  if (Kind < FirstTargetFixupKind)
25  return Value;
26 
27  switch (unsigned(Kind)) {
32  return (int64_t)Value / 2;
33 
35  return 0;
36  }
37 
38  llvm_unreachable("Unknown fixup kind!");
39 }
40 
41 namespace {
42 class SystemZMCAsmBackend : public MCAsmBackend {
43  uint8_t OSABI;
44 public:
45  SystemZMCAsmBackend(uint8_t osABI)
46  : MCAsmBackend(support::big), OSABI(osABI) {}
47 
48  // Override MCAsmBackend
49  unsigned getNumFixupKinds() const override {
51  }
52  const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const override;
53  void applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,
55  uint64_t Value, bool IsResolved,
56  const MCSubtargetInfo *STI) const override;
57  bool mayNeedRelaxation(const MCInst &Inst,
58  const MCSubtargetInfo &STI) const override {
59  return false;
60  }
61  bool fixupNeedsRelaxation(const MCFixup &Fixup, uint64_t Value,
62  const MCRelaxableFragment *Fragment,
63  const MCAsmLayout &Layout) const override {
64  return false;
65  }
66  bool writeNopData(raw_ostream &OS, uint64_t Count) const override;
67  std::unique_ptr<MCObjectTargetWriter>
68  createObjectTargetWriter() const override {
69  return createSystemZObjectWriter(OSABI);
70  }
71 };
72 } // end anonymous namespace
73 
74 const MCFixupKindInfo &
75 SystemZMCAsmBackend::getFixupKindInfo(MCFixupKind Kind) const {
76  const static MCFixupKindInfo Infos[SystemZ::NumTargetFixupKinds] = {
77  { "FK_390_PC12DBL", 4, 12, MCFixupKindInfo::FKF_IsPCRel },
78  { "FK_390_PC16DBL", 0, 16, MCFixupKindInfo::FKF_IsPCRel },
79  { "FK_390_PC24DBL", 0, 24, MCFixupKindInfo::FKF_IsPCRel },
80  { "FK_390_PC32DBL", 0, 32, MCFixupKindInfo::FKF_IsPCRel },
81  { "FK_390_TLS_CALL", 0, 0, 0 }
82  };
83 
84  if (Kind < FirstTargetFixupKind)
85  return MCAsmBackend::getFixupKindInfo(Kind);
86 
87  assert(unsigned(Kind - FirstTargetFixupKind) < getNumFixupKinds() &&
88  "Invalid kind!");
89  return Infos[Kind - FirstTargetFixupKind];
90 }
91 
92 void SystemZMCAsmBackend::applyFixup(const MCAssembler &Asm,
93  const MCFixup &Fixup,
94  const MCValue &Target,
96  bool IsResolved,
97  const MCSubtargetInfo *STI) const {
98  MCFixupKind Kind = Fixup.getKind();
99  unsigned Offset = Fixup.getOffset();
100  unsigned BitSize = getFixupKindInfo(Kind).TargetSize;
101  unsigned Size = (BitSize + 7) / 8;
102 
103  assert(Offset + Size <= Data.size() && "Invalid fixup offset!");
104 
105  // Big-endian insertion of Size bytes.
106  Value = extractBitsForFixup(Kind, Value);
107  if (BitSize < 64)
108  Value &= ((uint64_t)1 << BitSize) - 1;
109  unsigned ShiftValue = (Size * 8) - 8;
110  for (unsigned I = 0; I != Size; ++I) {
111  Data[Offset + I] |= uint8_t(Value >> ShiftValue);
112  ShiftValue -= 8;
113  }
114 }
115 
116 bool SystemZMCAsmBackend::writeNopData(raw_ostream &OS, uint64_t Count) const {
117  for (uint64_t I = 0; I != Count; ++I)
118  OS << '\x7';
119  return true;
120 }
121 
123  const MCSubtargetInfo &STI,
124  const MCRegisterInfo &MRI,
125  const MCTargetOptions &Options) {
126  uint8_t OSABI =
128  return new SystemZMCAsmBackend(OSABI);
129 }
This class represents lattice values for constants.
Definition: AllocatorList.h:23
This represents an "assembler immediate".
Definition: MCValue.h:37
OSType getOS() const
getOS - Get the parsed operating system type of this triple.
Definition: Triple.h:309
virtual const MCFixupKindInfo & getFixupKindInfo(MCFixupKind Kind) const
Get information on a fixup kind.
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
Definition: MCFixup.h:82
const Triple & getTargetTriple() const
Is this fixup kind PCrelative? This is used by the assembler backend to evaluate fixup values in a ta...
Encapsulates the layout of an assembly file at a particular point in time.
Definition: MCAsmLayout.h:28
std::unique_ptr< MCObjectTargetWriter > createSystemZObjectWriter(uint8_t OSABI)
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:158
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
A relaxable fragment holds on to its MCInst, since it may need to be relaxed during the assembler lay...
Definition: MCFragment.h:261
unsigned const MachineRegisterInfo * MRI
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Definition: ArrayRef.h:298
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:156
MCFixupKind
Extensible enumeration to represent the type of a fixup.
Definition: MCFixup.h:22
uint32_t getOffset() const
Definition: MCFixup.h:135
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
PowerPC TLS Dynamic Call Fixup
Target - Wrapper for Target specific information.
static uint64_t extractBitsForFixup(MCFixupKind Kind, uint64_t Value)
MCAsmBackend * createSystemZMCAsmBackend(const Target &T, const MCSubtargetInfo &STI, const MCRegisterInfo &MRI, const MCTargetOptions &Options)
#define I(x, y, z)
Definition: MD5.cpp:59
Generic base class for all target subtargets.
uint32_t Size
Definition: Profile.cpp:46
Target independent information on a fixup kind.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
Definition: Value.h:74
Generic interface to target specific assembler backends.
Definition: MCAsmBackend.h:36
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:46
MCFixupKind getKind() const
Definition: MCFixup.h:131