blob: 8406d2328630f294b30db7a9954d6fcd437f504c [file] [log] [blame]
Eugene Zelenko3d8b0eb2017-02-08 22:23:19 +00001//===- MCAsmBackend.cpp - Target MC Assembly Backend ----------------------===//
Daniel Dunbar3bea9bf2010-02-21 21:53:53 +00002//
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
Chandler Carruth6bda14b2017-06-06 11:49:48 +000010#include "llvm/MC/MCAsmBackend.h"
Eugene Zelenko3d8b0eb2017-02-08 22:23:19 +000011#include "llvm/ADT/None.h"
Craig Topper58713212013-07-15 04:27:47 +000012#include "llvm/ADT/STLExtras.h"
Omer Paparo Bivas2251c792017-10-24 06:16:03 +000013#include "llvm/MC/MCCodePadder.h"
Craig Topper6e80c282012-03-26 06:58:25 +000014#include "llvm/MC/MCFixupKindInfo.h"
Eugene Zelenko3d8b0eb2017-02-08 22:23:19 +000015#include <cassert>
16#include <cstddef>
17#include <cstdint>
18
Daniel Dunbar3bea9bf2010-02-21 21:53:53 +000019using namespace llvm;
20
Peter Collingbourne571a3302018-05-21 17:57:19 +000021MCAsmBackend::MCAsmBackend(support::endianness Endian)
22 : CodePadder(new MCCodePadder()), Endian(Endian) {}
Daniel Dunbar3bea9bf2010-02-21 21:53:53 +000023
Eugene Zelenko3d8b0eb2017-02-08 22:23:19 +000024MCAsmBackend::~MCAsmBackend() = default;
Daniel Dunbar0c9d9fd2010-12-16 03:20:06 +000025
David Majnemerce108422016-01-19 23:05:27 +000026Optional<MCFixupKind> MCAsmBackend::getFixupKind(StringRef Name) const {
27 return None;
Daniel Sanders9f6ad492015-11-12 13:33:00 +000028}
29
Colin LeMahieua01780f2015-05-30 18:42:22 +000030const MCFixupKindInfo &MCAsmBackend::getFixupKindInfo(MCFixupKind Kind) const {
Daniel Dunbar0c9d9fd2010-12-16 03:20:06 +000031 static const MCFixupKindInfo Builtins[] = {
Colin LeMahieua01780f2015-05-30 18:42:22 +000032 {"FK_Data_1", 0, 8, 0},
33 {"FK_Data_2", 0, 16, 0},
34 {"FK_Data_4", 0, 32, 0},
35 {"FK_Data_8", 0, 64, 0},
36 {"FK_PCRel_1", 0, 8, MCFixupKindInfo::FKF_IsPCRel},
37 {"FK_PCRel_2", 0, 16, MCFixupKindInfo::FKF_IsPCRel},
38 {"FK_PCRel_4", 0, 32, MCFixupKindInfo::FKF_IsPCRel},
39 {"FK_PCRel_8", 0, 64, MCFixupKindInfo::FKF_IsPCRel},
40 {"FK_GPRel_1", 0, 8, 0},
41 {"FK_GPRel_2", 0, 16, 0},
42 {"FK_GPRel_4", 0, 32, 0},
43 {"FK_GPRel_8", 0, 64, 0},
Simon Atanasyaneb9ed612016-08-22 16:18:42 +000044 {"FK_DTPRel_4", 0, 32, 0},
45 {"FK_DTPRel_8", 0, 64, 0},
46 {"FK_TPRel_4", 0, 32, 0},
47 {"FK_TPRel_8", 0, 64, 0},
Colin LeMahieua01780f2015-05-30 18:42:22 +000048 {"FK_SecRel_1", 0, 8, 0},
49 {"FK_SecRel_2", 0, 16, 0},
50 {"FK_SecRel_4", 0, 32, 0},
51 {"FK_SecRel_8", 0, 64, 0}};
Jim Grosbachdc1e36e2012-05-11 01:41:30 +000052
Craig Topper58713212013-07-15 04:27:47 +000053 assert((size_t)Kind <= array_lengthof(Builtins) && "Unknown fixup kind");
Daniel Dunbar0c9d9fd2010-12-16 03:20:06 +000054 return Builtins[Kind];
55}
Colin LeMahieua01780f2015-05-30 18:42:22 +000056
57bool MCAsmBackend::fixupNeedsRelaxationAdvanced(
58 const MCFixup &Fixup, bool Resolved, uint64_t Value,
Shiva Chen6e07dfb2018-05-18 06:42:21 +000059 const MCRelaxableFragment *DF, const MCAsmLayout &Layout,
60 const bool WasForced) const {
Colin LeMahieua01780f2015-05-30 18:42:22 +000061 if (!Resolved)
62 return true;
63 return fixupNeedsRelaxation(Fixup, Value, DF, Layout);
64}
Omer Paparo Bivas2251c792017-10-24 06:16:03 +000065
66void MCAsmBackend::handleCodePaddingBasicBlockStart(
67 MCObjectStreamer *OS, const MCCodePaddingContext &Context) {
68 CodePadder->handleBasicBlockStart(OS, Context);
69}
70
71void MCAsmBackend::handleCodePaddingBasicBlockEnd(
72 const MCCodePaddingContext &Context) {
73 CodePadder->handleBasicBlockEnd(Context);
74}
75
76void MCAsmBackend::handleCodePaddingInstructionBegin(const MCInst &Inst) {
77 CodePadder->handleInstructionBegin(Inst);
78}
79
80void MCAsmBackend::handleCodePaddingInstructionEnd(const MCInst &Inst) {
81 CodePadder->handleInstructionEnd(Inst);
82}
83
84bool MCAsmBackend::relaxFragment(MCPaddingFragment *PF, MCAsmLayout &Layout) {
85 return CodePadder->relaxFragment(PF, Layout);
Shiva Chen6e07dfb2018-05-18 06:42:21 +000086}