LLVM  3.7.0
SystemZMCAsmBackend.cpp
Go to the documentation of this file.
1 //===-- SystemZMCAsmBackend.cpp - SystemZ assembler backend ---------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
12 #include "llvm/MC/MCAsmBackend.h"
15 #include "llvm/MC/MCInst.h"
16 #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)) {
30  return (int64_t)Value / 2;
31 
33  return 0;
34  }
35 
36  llvm_unreachable("Unknown fixup kind!");
37 }
38 
39 namespace {
40 class SystemZMCAsmBackend : public MCAsmBackend {
41  uint8_t OSABI;
42 public:
43  SystemZMCAsmBackend(uint8_t osABI)
44  : OSABI(osABI) {}
45 
46  // Override MCAsmBackend
47  unsigned getNumFixupKinds() const override {
49  }
50  const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const override;
51  void applyFixup(const MCFixup &Fixup, char *Data, unsigned DataSize,
52  uint64_t Value, bool IsPCRel) const override;
53  bool mayNeedRelaxation(const MCInst &Inst) const override {
54  return false;
55  }
56  bool fixupNeedsRelaxation(const MCFixup &Fixup, uint64_t Value,
57  const MCRelaxableFragment *Fragment,
58  const MCAsmLayout &Layout) const override {
59  return false;
60  }
61  void relaxInstruction(const MCInst &Inst, MCInst &Res) const override {
62  llvm_unreachable("SystemZ does do not have assembler relaxation");
63  }
64  bool writeNopData(uint64_t Count, MCObjectWriter *OW) const override;
65  MCObjectWriter *createObjectWriter(raw_pwrite_stream &OS) const override {
66  return createSystemZObjectWriter(OS, OSABI);
67  }
68 };
69 } // end anonymous namespace
70 
71 const MCFixupKindInfo &
72 SystemZMCAsmBackend::getFixupKindInfo(MCFixupKind Kind) const {
73  const static MCFixupKindInfo Infos[SystemZ::NumTargetFixupKinds] = {
74  { "FK_390_PC16DBL", 0, 16, MCFixupKindInfo::FKF_IsPCRel },
75  { "FK_390_PC32DBL", 0, 32, MCFixupKindInfo::FKF_IsPCRel },
76  { "FK_390_TLS_CALL", 0, 0, 0 }
77  };
78 
79  if (Kind < FirstTargetFixupKind)
80  return MCAsmBackend::getFixupKindInfo(Kind);
81 
82  assert(unsigned(Kind - FirstTargetFixupKind) < getNumFixupKinds() &&
83  "Invalid kind!");
84  return Infos[Kind - FirstTargetFixupKind];
85 }
86 
87 void SystemZMCAsmBackend::applyFixup(const MCFixup &Fixup, char *Data,
88  unsigned DataSize, uint64_t Value,
89  bool IsPCRel) const {
90  MCFixupKind Kind = Fixup.getKind();
91  unsigned Offset = Fixup.getOffset();
92  unsigned Size = (getFixupKindInfo(Kind).TargetSize + 7) / 8;
93 
94  assert(Offset + Size <= DataSize && "Invalid fixup offset!");
95 
96  // Big-endian insertion of Size bytes.
97  Value = extractBitsForFixup(Kind, Value);
98  unsigned ShiftValue = (Size * 8) - 8;
99  for (unsigned I = 0; I != Size; ++I) {
100  Data[Offset + I] |= uint8_t(Value >> ShiftValue);
101  ShiftValue -= 8;
102  }
103 }
104 
105 bool SystemZMCAsmBackend::writeNopData(uint64_t Count,
106  MCObjectWriter *OW) const {
107  for (uint64_t I = 0; I != Count; ++I)
108  OW->write8(7);
109  return true;
110 }
111 
113  const MCRegisterInfo &MRI,
114  const Triple &TT, StringRef CPU) {
115  uint8_t OSABI = MCELFObjectTargetWriter::getOSABI(TT.getOS());
116  return new SystemZMCAsmBackend(OSABI);
117 }
OSType getOS() const
getOS - Get the parsed operating system type of this triple.
Definition: Triple.h:251
Defines the object file and target independent interfaces used by the assembler backend to write nati...
void write8(uint8_t Value)
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
Definition: MCFixup.h:62
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:29
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:98
MCAsmBackend * createSystemZMCAsmBackend(const Target &T, const MCRegisterInfo &MRI, const Triple &TT, StringRef CPU)
uint32_t getOffset() const
Definition: MCFixup.h:91
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:150
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: MCAssembler.h:259
MCFixupKind
Extensible enumeration to represent the type of a fixup.
Definition: MCFixup.h:23
MCObjectWriter * createSystemZObjectWriter(raw_pwrite_stream &OS, uint8_t OSABI)
MCFixupKind getKind() const
Definition: MCFixup.h:89
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
PowerPC TLS Dynamic Call Fixup
Target - Wrapper for Target specific information.
static uint64_t extractBitsForFixup(MCFixupKind Kind, uint64_t Value)
#define I(x, y, z)
Definition: MD5.cpp:54
Target independent information on a fixup kind.
An abstract base class for streams implementations that also support a pwrite operation.
Definition: raw_ostream.h:321
const ARM::ArchExtKind Kind
LLVM Value Representation.
Definition: Value.h:69
Generic interface to target specific assembler backends.
Definition: MCAsmBackend.h:34
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:40
virtual const MCFixupKindInfo & getFixupKindInfo(MCFixupKind Kind) const
Get information on a fixup kind.