LLVM  4.0.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)) {
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  : OSABI(osABI) {}
47 
48  // Override MCAsmBackend
49  unsigned getNumFixupKinds() const override {
51  }
52  const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const override;
53  void applyFixup(const MCFixup &Fixup, char *Data, unsigned DataSize,
54  uint64_t Value, bool IsPCRel) const override;
55  bool mayNeedRelaxation(const MCInst &Inst) const override {
56  return false;
57  }
58  bool fixupNeedsRelaxation(const MCFixup &Fixup, uint64_t Value,
59  const MCRelaxableFragment *Fragment,
60  const MCAsmLayout &Layout) const override {
61  return false;
62  }
63  void relaxInstruction(const MCInst &Inst, const MCSubtargetInfo &STI,
64  MCInst &Res) const override {
65  llvm_unreachable("SystemZ does do not have assembler relaxation");
66  }
67  bool writeNopData(uint64_t Count, MCObjectWriter *OW) const override;
68  MCObjectWriter *createObjectWriter(raw_pwrite_stream &OS) const override {
69  return createSystemZObjectWriter(OS, 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 MCFixup &Fixup, char *Data,
93  unsigned DataSize, uint64_t Value,
94  bool IsPCRel) const {
95  MCFixupKind Kind = Fixup.getKind();
96  unsigned Offset = Fixup.getOffset();
97  unsigned BitSize = getFixupKindInfo(Kind).TargetSize;
98  unsigned Size = (BitSize + 7) / 8;
99 
100  assert(Offset + Size <= DataSize && "Invalid fixup offset!");
101 
102  // Big-endian insertion of Size bytes.
103  Value = extractBitsForFixup(Kind, Value);
104  if (BitSize < 64)
105  Value &= ((uint64_t)1 << BitSize) - 1;
106  unsigned ShiftValue = (Size * 8) - 8;
107  for (unsigned I = 0; I != Size; ++I) {
108  Data[Offset + I] |= uint8_t(Value >> ShiftValue);
109  ShiftValue -= 8;
110  }
111 }
112 
113 bool SystemZMCAsmBackend::writeNopData(uint64_t Count,
114  MCObjectWriter *OW) const {
115  for (uint64_t I = 0; I != Count; ++I)
116  OW->write8(7);
117  return true;
118 }
119 
121  const MCRegisterInfo &MRI,
122  const Triple &TT, StringRef CPU,
123  const MCTargetOptions &Options) {
124  uint8_t OSABI = MCELFObjectTargetWriter::getOSABI(TT.getOS());
125  return new SystemZMCAsmBackend(OSABI);
126 }
OSType getOS() const
getOS - Get the parsed operating system type of this triple.
Definition: Triple.h:279
MCAsmBackend * createSystemZMCAsmBackend(const Target &T, const MCRegisterInfo &MRI, const Triple &TT, StringRef CPU, const MCTargetOptions &Options)
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:66
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
uint32_t getOffset() const
Definition: MCFixup.h:95
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: MCFragment.h:249
unsigned const MachineRegisterInfo * MRI
MCFixupKind
Extensible enumeration to represent the type of a fixup.
Definition: MCFixup.h:23
uint32_t Offset
MCObjectWriter * createSystemZObjectWriter(raw_pwrite_stream &OS, uint8_t OSABI)
MCFixupKind getKind() const
Definition: MCFixup.h:93
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
Target - Wrapper for Target specific information.
static uint64_t extractBitsForFixup(MCFixupKind Kind, uint64_t Value)
#define I(x, y, z)
Definition: MD5.cpp:54
MCSubtargetInfo - Generic base class for all target subtargets.
Target independent information on a fixup kind.
An abstract base class for streams implementations that also support a pwrite operation.
Definition: raw_ostream.h:333
const unsigned Kind
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
Definition: Value.h:71
Generic interface to target specific assembler backends.
Definition: MCAsmBackend.h:36
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:47
virtual const MCFixupKindInfo & getFixupKindInfo(MCFixupKind Kind) const
Get information on a fixup kind.