Eugene Zelenko | 3d8b0eb | 2017-02-08 22:23:19 +0000 | [diff] [blame] | 1 | //===- MCAsmBackend.cpp - Target MC Assembly Backend ----------------------===// |
Daniel Dunbar | 3bea9bf | 2010-02-21 21:53:53 +0000 | [diff] [blame] | 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 | |
Chandler Carruth | 6bda14b | 2017-06-06 11:49:48 +0000 | [diff] [blame] | 10 | #include "llvm/MC/MCAsmBackend.h" |
Eugene Zelenko | 3d8b0eb | 2017-02-08 22:23:19 +0000 | [diff] [blame] | 11 | #include "llvm/ADT/None.h" |
Craig Topper | 5871321 | 2013-07-15 04:27:47 +0000 | [diff] [blame] | 12 | #include "llvm/ADT/STLExtras.h" |
Omer Paparo Bivas | 2251c79 | 2017-10-24 06:16:03 +0000 | [diff] [blame^] | 13 | #include "llvm/MC/MCCodePadder.h" |
Craig Topper | 6e80c28 | 2012-03-26 06:58:25 +0000 | [diff] [blame] | 14 | #include "llvm/MC/MCFixupKindInfo.h" |
Eugene Zelenko | 3d8b0eb | 2017-02-08 22:23:19 +0000 | [diff] [blame] | 15 | #include <cassert> |
| 16 | #include <cstddef> |
| 17 | #include <cstdint> |
| 18 | |
Daniel Dunbar | 3bea9bf | 2010-02-21 21:53:53 +0000 | [diff] [blame] | 19 | using namespace llvm; |
| 20 | |
Omer Paparo Bivas | 2251c79 | 2017-10-24 06:16:03 +0000 | [diff] [blame^] | 21 | MCAsmBackend::MCAsmBackend() : CodePadder(new MCCodePadder()) {} |
| 22 | |
| 23 | MCAsmBackend::MCAsmBackend(std::unique_ptr<MCCodePadder> TargetCodePadder) |
| 24 | : CodePadder(std::move(TargetCodePadder)) {} |
Daniel Dunbar | 3bea9bf | 2010-02-21 21:53:53 +0000 | [diff] [blame] | 25 | |
Eugene Zelenko | 3d8b0eb | 2017-02-08 22:23:19 +0000 | [diff] [blame] | 26 | MCAsmBackend::~MCAsmBackend() = default; |
Daniel Dunbar | 0c9d9fd | 2010-12-16 03:20:06 +0000 | [diff] [blame] | 27 | |
David Majnemer | ce10842 | 2016-01-19 23:05:27 +0000 | [diff] [blame] | 28 | Optional<MCFixupKind> MCAsmBackend::getFixupKind(StringRef Name) const { |
| 29 | return None; |
Daniel Sanders | 9f6ad49 | 2015-11-12 13:33:00 +0000 | [diff] [blame] | 30 | } |
| 31 | |
Colin LeMahieu | a01780f | 2015-05-30 18:42:22 +0000 | [diff] [blame] | 32 | const MCFixupKindInfo &MCAsmBackend::getFixupKindInfo(MCFixupKind Kind) const { |
Daniel Dunbar | 0c9d9fd | 2010-12-16 03:20:06 +0000 | [diff] [blame] | 33 | static const MCFixupKindInfo Builtins[] = { |
Colin LeMahieu | a01780f | 2015-05-30 18:42:22 +0000 | [diff] [blame] | 34 | {"FK_Data_1", 0, 8, 0}, |
| 35 | {"FK_Data_2", 0, 16, 0}, |
| 36 | {"FK_Data_4", 0, 32, 0}, |
| 37 | {"FK_Data_8", 0, 64, 0}, |
| 38 | {"FK_PCRel_1", 0, 8, MCFixupKindInfo::FKF_IsPCRel}, |
| 39 | {"FK_PCRel_2", 0, 16, MCFixupKindInfo::FKF_IsPCRel}, |
| 40 | {"FK_PCRel_4", 0, 32, MCFixupKindInfo::FKF_IsPCRel}, |
| 41 | {"FK_PCRel_8", 0, 64, MCFixupKindInfo::FKF_IsPCRel}, |
| 42 | {"FK_GPRel_1", 0, 8, 0}, |
| 43 | {"FK_GPRel_2", 0, 16, 0}, |
| 44 | {"FK_GPRel_4", 0, 32, 0}, |
| 45 | {"FK_GPRel_8", 0, 64, 0}, |
Simon Atanasyan | eb9ed61 | 2016-08-22 16:18:42 +0000 | [diff] [blame] | 46 | {"FK_DTPRel_4", 0, 32, 0}, |
| 47 | {"FK_DTPRel_8", 0, 64, 0}, |
| 48 | {"FK_TPRel_4", 0, 32, 0}, |
| 49 | {"FK_TPRel_8", 0, 64, 0}, |
Colin LeMahieu | a01780f | 2015-05-30 18:42:22 +0000 | [diff] [blame] | 50 | {"FK_SecRel_1", 0, 8, 0}, |
| 51 | {"FK_SecRel_2", 0, 16, 0}, |
| 52 | {"FK_SecRel_4", 0, 32, 0}, |
| 53 | {"FK_SecRel_8", 0, 64, 0}}; |
Jim Grosbach | dc1e36e | 2012-05-11 01:41:30 +0000 | [diff] [blame] | 54 | |
Craig Topper | 5871321 | 2013-07-15 04:27:47 +0000 | [diff] [blame] | 55 | assert((size_t)Kind <= array_lengthof(Builtins) && "Unknown fixup kind"); |
Daniel Dunbar | 0c9d9fd | 2010-12-16 03:20:06 +0000 | [diff] [blame] | 56 | return Builtins[Kind]; |
| 57 | } |
Colin LeMahieu | a01780f | 2015-05-30 18:42:22 +0000 | [diff] [blame] | 58 | |
| 59 | bool MCAsmBackend::fixupNeedsRelaxationAdvanced( |
| 60 | const MCFixup &Fixup, bool Resolved, uint64_t Value, |
| 61 | const MCRelaxableFragment *DF, const MCAsmLayout &Layout) const { |
| 62 | if (!Resolved) |
| 63 | return true; |
| 64 | return fixupNeedsRelaxation(Fixup, Value, DF, Layout); |
| 65 | } |
Omer Paparo Bivas | 2251c79 | 2017-10-24 06:16:03 +0000 | [diff] [blame^] | 66 | |
| 67 | void MCAsmBackend::handleCodePaddingBasicBlockStart( |
| 68 | MCObjectStreamer *OS, const MCCodePaddingContext &Context) { |
| 69 | CodePadder->handleBasicBlockStart(OS, Context); |
| 70 | } |
| 71 | |
| 72 | void MCAsmBackend::handleCodePaddingBasicBlockEnd( |
| 73 | const MCCodePaddingContext &Context) { |
| 74 | CodePadder->handleBasicBlockEnd(Context); |
| 75 | } |
| 76 | |
| 77 | void MCAsmBackend::handleCodePaddingInstructionBegin(const MCInst &Inst) { |
| 78 | CodePadder->handleInstructionBegin(Inst); |
| 79 | } |
| 80 | |
| 81 | void MCAsmBackend::handleCodePaddingInstructionEnd(const MCInst &Inst) { |
| 82 | CodePadder->handleInstructionEnd(Inst); |
| 83 | } |
| 84 | |
| 85 | bool MCAsmBackend::relaxFragment(MCPaddingFragment *PF, MCAsmLayout &Layout) { |
| 86 | return CodePadder->relaxFragment(PF, Layout); |
| 87 | } |