LLVM  13.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/ADT/StringSwitch.h"
12 #include "llvm/MC/MCAsmBackend.h"
15 #include "llvm/MC/MCInst.h"
16 #include "llvm/MC/MCObjectWriter.h"
18 
19 using namespace llvm;
20 
21 // Value is a fully-resolved relocation value: Symbol + Addend [- Pivot].
22 // Return the bits that should be installed in a relocation field for
23 // fixup kind Kind.
24 static uint64_t extractBitsForFixup(MCFixupKind Kind, uint64_t Value) {
26  return Value;
27 
28  switch (unsigned(Kind)) {
33  return (int64_t)Value / 2;
34 
36  return 0;
37  }
38 
39  llvm_unreachable("Unknown fixup kind!");
40 }
41 
42 namespace {
43 class SystemZMCAsmBackend : public MCAsmBackend {
44  uint8_t OSABI;
45 public:
46  SystemZMCAsmBackend(uint8_t osABI)
47  : MCAsmBackend(support::big), OSABI(osABI) {}
48 
49  // Override MCAsmBackend
50  unsigned getNumFixupKinds() const override {
52  }
53  Optional<MCFixupKind> getFixupKind(StringRef Name) const override;
54  const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const override;
55  bool shouldForceRelocation(const MCAssembler &Asm, const MCFixup &Fixup,
56  const MCValue &Target) override;
57  void applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,
59  uint64_t Value, bool IsResolved,
60  const MCSubtargetInfo *STI) const override;
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 Optional<MCFixupKind> SystemZMCAsmBackend::getFixupKind(StringRef Name) const {
76 #define ELF_RELOC(X, Y) .Case(#X, Y)
77 #include "llvm/BinaryFormat/ELFRelocs/SystemZ.def"
78 #undef ELF_RELOC
79  .Case("BFD_RELOC_NONE", ELF::R_390_NONE)
80  .Case("BFD_RELOC_8", ELF::R_390_8)
81  .Case("BFD_RELOC_16", ELF::R_390_16)
82  .Case("BFD_RELOC_32", ELF::R_390_32)
83  .Case("BFD_RELOC_64", ELF::R_390_64)
84  .Default(-1u);
85  if (Type != -1u)
86  return static_cast<MCFixupKind>(FirstLiteralRelocationKind + Type);
87  return None;
88 }
89 
90 const MCFixupKindInfo &
91 SystemZMCAsmBackend::getFixupKindInfo(MCFixupKind Kind) const {
92  const static MCFixupKindInfo Infos[SystemZ::NumTargetFixupKinds] = {
93  { "FK_390_PC12DBL", 4, 12, MCFixupKindInfo::FKF_IsPCRel },
94  { "FK_390_PC16DBL", 0, 16, MCFixupKindInfo::FKF_IsPCRel },
95  { "FK_390_PC24DBL", 0, 24, MCFixupKindInfo::FKF_IsPCRel },
96  { "FK_390_PC32DBL", 0, 32, MCFixupKindInfo::FKF_IsPCRel },
97  { "FK_390_TLS_CALL", 0, 0, 0 }
98  };
99 
100  // Fixup kinds from .reloc directive are like R_390_NONE. They
101  // do not require any extra processing.
104 
107 
108  assert(unsigned(Kind - FirstTargetFixupKind) < getNumFixupKinds() &&
109  "Invalid kind!");
110  return Infos[Kind - FirstTargetFixupKind];
111 }
112 
113 bool SystemZMCAsmBackend::shouldForceRelocation(const MCAssembler &,
114  const MCFixup &Fixup,
115  const MCValue &) {
116  return Fixup.getKind() >= FirstLiteralRelocationKind;
117 }
118 
120  const MCFixup &Fixup,
121  const MCValue &Target,
122  MutableArrayRef<char> Data, uint64_t Value,
123  bool IsResolved,
124  const MCSubtargetInfo *STI) const {
125  MCFixupKind Kind = Fixup.getKind();
127  return;
128  unsigned Offset = Fixup.getOffset();
129  unsigned BitSize = getFixupKindInfo(Kind).TargetSize;
130  unsigned Size = (BitSize + 7) / 8;
131 
132  assert(Offset + Size <= Data.size() && "Invalid fixup offset!");
133 
134  // Big-endian insertion of Size bytes.
136  if (BitSize < 64)
137  Value &= ((uint64_t)1 << BitSize) - 1;
138  unsigned ShiftValue = (Size * 8) - 8;
139  for (unsigned I = 0; I != Size; ++I) {
140  Data[Offset + I] |= uint8_t(Value >> ShiftValue);
141  ShiftValue -= 8;
142  }
143 }
144 
145 bool SystemZMCAsmBackend::writeNopData(raw_ostream &OS, uint64_t Count) const {
146  for (uint64_t I = 0; I != Count; ++I)
147  OS << '\x7';
148  return true;
149 }
150 
152  const MCSubtargetInfo &STI,
153  const MCRegisterInfo &MRI,
154  const MCTargetOptions &Options) {
155  uint8_t OSABI =
157  return new SystemZMCAsmBackend(OSABI);
158 }
llvm::Check::Size
@ Size
Definition: FileCheck.h:73
llvm::StringSwitch::Case
StringSwitch & Case(StringLiteral S, T Value)
Definition: StringSwitch.h:67
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::MCRelaxableFragment
A relaxable fragment holds on to its MCInst, since it may need to be relaxed during the assembler lay...
Definition: MCFragment.h:271
llvm::MCAsmBackend::getFixupKindInfo
virtual const MCFixupKindInfo & getFixupKindInfo(MCFixupKind Kind) const
Get information on a fixup kind.
Definition: MCAsmBackend.cpp:74
llvm::StringSwitch::Default
LLVM_NODISCARD R Default(T Value)
Definition: StringSwitch.h:181
llvm::Target
Target - Wrapper for Target specific information.
Definition: TargetRegistry.h:125
llvm::SystemZ::FK_390_PC16DBL
@ FK_390_PC16DBL
Definition: SystemZMCFixups.h:19
llvm::FirstTargetFixupKind
@ FirstTargetFixupKind
Definition: MCFixup.h:45
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
llvm::Optional
Definition: APInt.h:33
MCFixupKindInfo.h
SystemZMCTargetDesc.h
Offset
uint64_t Offset
Definition: ELFObjHandler.cpp:81
llvm::SystemZ::FK_390_PC12DBL
@ FK_390_PC12DBL
Definition: SystemZMCFixups.h:18
llvm::Data
@ Data
Definition: SIMachineScheduler.h:56
llvm::FirstLiteralRelocationKind
@ FirstLiteralRelocationKind
The range [FirstLiteralRelocationKind, MaxTargetFixupKind) is used for relocations coming from ....
Definition: MCFixup.h:50
llvm::MCAsmBackend
Generic interface to target specific assembler backends.
Definition: MCAsmBackend.h:36
MCAsmBackend.h
llvm::MutableArrayRef
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Definition: ArrayRef.h:307
llvm::SystemZ::FK_390_PC24DBL
@ FK_390_PC24DBL
Definition: SystemZMCFixups.h:20
llvm::MCSubtargetInfo::getTargetTriple
const Triple & getTargetTriple() const
Definition: MCSubtargetInfo.h:107
llvm::SystemZ::FK_390_TLS_CALL
@ FK_390_TLS_CALL
Definition: SystemZMCFixups.h:22
MCInst.h
MCSubtargetInfo.h
Options
const char LLVMTargetMachineRef LLVMPassBuilderOptionsRef Options
Definition: PassBuilderBindings.cpp:48
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
llvm::None
const NoneType None
Definition: None.h:23
llvm::lltok::Kind
Kind
Definition: LLToken.h:18
llvm::MCAssembler
Definition: MCAssembler.h:60
llvm::Triple::getOS
OSType getOS() const
getOS - Get the parsed operating system type of this triple.
Definition: Triple.h:316
MCELFObjectWriter.h
llvm::MCFixupKindInfo::FKF_IsPCRel
@ FKF_IsPCRel
Is this fixup kind PCrelative? This is used by the assembler backend to evaluate fixup values in a ta...
Definition: MCFixupKindInfo.h:19
I
#define I(x, y, z)
Definition: MD5.cpp:59
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::MCFixupKindInfo
Target independent information on a fixup kind.
Definition: MCFixupKindInfo.h:15
llvm::MCTargetOptions
Definition: MCTargetOptions.h:36
llvm::createSystemZObjectWriter
std::unique_ptr< MCObjectTargetWriter > createSystemZObjectWriter(uint8_t OSABI)
Definition: SystemZMCObjectWriter.cpp:166
llvm::SystemZ::FK_390_PC32DBL
@ FK_390_PC32DBL
Definition: SystemZMCFixups.h:21
llvm::FK_NONE
@ FK_NONE
A no-op fixup.
Definition: MCFixup.h:22
llvm::MCELFObjectTargetWriter::getOSABI
uint8_t getOSABI() const
Definition: MCELFObjectWriter.h:99
Fixup
PowerPC TLS Dynamic Call Fixup
Definition: PPCTLSDynamicCall.cpp:235
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:136
llvm::MCRegisterInfo
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
Definition: MCRegisterInfo.h:135
MRI
unsigned const MachineRegisterInfo * MRI
Definition: AArch64AdvSIMDScalarPass.cpp:105
MCObjectWriter.h
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:52
SystemZMCFixups.h
llvm::MCAsmLayout
Encapsulates the layout of an assembly file at a particular point in time.
Definition: MCAsmLayout.h:28
llvm::TargetStackID::Value
Value
Definition: TargetFrameLowering.h:27
StringSwitch.h
llvm::SystemZ::NumTargetFixupKinds
@ NumTargetFixupKinds
Definition: SystemZMCFixups.h:26
llvm::MCFixupKind
MCFixupKind
Extensible enumeration to represent the type of a fixup.
Definition: MCFixup.h:21
llvm::createSystemZMCAsmBackend
MCAsmBackend * createSystemZMCAsmBackend(const Target &T, const MCSubtargetInfo &STI, const MCRegisterInfo &MRI, const MCTargetOptions &Options)
Definition: SystemZMCAsmBackend.cpp:151
support
Reimplement select in terms of SEL *We would really like to support but we need to prove that the add doesn t need to overflow between the two bit chunks *Implement pre post increment support(e.g. PR935) *Implement smarter const ant generation for binops with large immediates. A few ARMv6T2 ops should be pattern matched
Definition: README.txt:10
llvm::StringSwitch
A switch()-like statement whose cases are string literals.
Definition: StringSwitch.h:42
llvm::HexStyle::Asm
@ Asm
0ffh
Definition: MCInstPrinter.h:34
llvm::MCValue
This represents an "assembler immediate".
Definition: MCValue.h:37
llvm::MCSubtargetInfo
Generic base class for all target subtargets.
Definition: MCSubtargetInfo.h:75
llvm::MCFixup
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
Definition: MCFixup.h:71
llvm::Value
LLVM Value Representation.
Definition: Value.h:75
extractBitsForFixup
static uint64_t extractBitsForFixup(MCFixupKind Kind, uint64_t Value)
Definition: SystemZMCAsmBackend.cpp:24
llvm::support::big
@ big
Definition: Endian.h:27