| Joe Abbey | 8e72eb7 | 2014-09-16 09:18:23 +0000 | [diff] [blame] | 1 | //===-- ARMAsmBackend.h - ARM Assembler Backend -----------------*- C++ -*-===// |
| 2 | // |
| Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 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 |
| Joe Abbey | 8e72eb7 | 2014-09-16 09:18:23 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #ifndef LLVM_LIB_TARGET_ARM_ARMASMBACKEND_H |
| 10 | #define LLVM_LIB_TARGET_ARM_ARMASMBACKEND_H |
| 11 | |
| 12 | #include "MCTargetDesc/ARMFixupKinds.h" |
| Benjamin Kramer | b32a504 | 2016-01-27 19:29:42 +0000 | [diff] [blame] | 13 | #include "MCTargetDesc/ARMMCTargetDesc.h" |
| Joe Abbey | 8e72eb7 | 2014-09-16 09:18:23 +0000 | [diff] [blame] | 14 | #include "llvm/MC/MCAsmBackend.h" |
| 15 | #include "llvm/MC/MCSubtargetInfo.h" |
| Benjamin Kramer | b32a504 | 2016-01-27 19:29:42 +0000 | [diff] [blame] | 16 | #include "llvm/Support/TargetRegistry.h" |
| Joe Abbey | 8e72eb7 | 2014-09-16 09:18:23 +0000 | [diff] [blame] | 17 | |
| Benjamin Kramer | b32a504 | 2016-01-27 19:29:42 +0000 | [diff] [blame] | 18 | namespace llvm { |
| Joe Abbey | 8e72eb7 | 2014-09-16 09:18:23 +0000 | [diff] [blame] | 19 | |
| 20 | class ARMAsmBackend : public MCAsmBackend { |
| Peter Smith | 57f661b | 2018-06-06 09:40:06 +0000 | [diff] [blame] | 21 | // The STI from the target triple the MCAsmBackend was instantiated with |
| 22 | // note that MCFragments may have a different local STI that should be |
| 23 | // used in preference. |
| Alex Bradbury | 46db78b | 2018-01-03 13:46:21 +0000 | [diff] [blame] | 24 | const MCSubtargetInfo &STI; |
| Joe Abbey | 8e72eb7 | 2014-09-16 09:18:23 +0000 | [diff] [blame] | 25 | bool isThumbMode; // Currently emitting Thumb code. |
| Joe Abbey | 8e72eb7 | 2014-09-16 09:18:23 +0000 | [diff] [blame] | 26 | public: |
| Peter Collingbourne | 571a330 | 2018-05-21 17:57:19 +0000 | [diff] [blame] | 27 | ARMAsmBackend(const Target &T, const MCSubtargetInfo &STI, |
| 28 | support::endianness Endian) |
| 29 | : MCAsmBackend(Endian), STI(STI), |
| 30 | isThumbMode(STI.getTargetTriple().isThumb()) {} |
| Joe Abbey | 8e72eb7 | 2014-09-16 09:18:23 +0000 | [diff] [blame] | 31 | |
| Joe Abbey | 8e72eb7 | 2014-09-16 09:18:23 +0000 | [diff] [blame] | 32 | unsigned getNumFixupKinds() const override { |
| 33 | return ARM::NumTargetFixupKinds; |
| 34 | } |
| 35 | |
| Peter Smith | 57f661b | 2018-06-06 09:40:06 +0000 | [diff] [blame] | 36 | // FIXME: this should be calculated per fragment as the STI may be |
| 37 | // different. |
| Alex Bradbury | 46db78b | 2018-01-03 13:46:21 +0000 | [diff] [blame] | 38 | bool hasNOP() const { return STI.getFeatureBits()[ARM::HasV6T2Ops]; } |
| Joe Abbey | 8e72eb7 | 2014-09-16 09:18:23 +0000 | [diff] [blame] | 39 | |
| Fangrui Song | 43ca0e9 | 2019-05-17 02:51:54 +0000 | [diff] [blame] | 40 | Optional<MCFixupKind> getFixupKind(StringRef Name) const override; |
| 41 | |
| Joe Abbey | 8e72eb7 | 2014-09-16 09:18:23 +0000 | [diff] [blame] | 42 | const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const override; |
| 43 | |
| Rafael Espindola | 76287ab | 2017-06-30 22:47:27 +0000 | [diff] [blame] | 44 | bool shouldForceRelocation(const MCAssembler &Asm, const MCFixup &Fixup, |
| 45 | const MCValue &Target) override; |
| Joe Abbey | 8e72eb7 | 2014-09-16 09:18:23 +0000 | [diff] [blame] | 46 | |
| Rafael Espindola | 801b42d | 2017-06-23 22:52:36 +0000 | [diff] [blame] | 47 | unsigned adjustFixupValue(const MCAssembler &Asm, const MCFixup &Fixup, |
| Rafael Espindola | 1beb702 | 2017-07-11 23:18:25 +0000 | [diff] [blame] | 48 | const MCValue &Target, uint64_t Value, |
| Peter Smith | 57f661b | 2018-06-06 09:40:06 +0000 | [diff] [blame] | 49 | bool IsResolved, MCContext &Ctx, |
| 50 | const MCSubtargetInfo *STI) const; |
| Tim Northover | 8d67b8e | 2015-10-02 18:07:18 +0000 | [diff] [blame] | 51 | |
| Rafael Espindola | 801b42d | 2017-06-23 22:52:36 +0000 | [diff] [blame] | 52 | void applyFixup(const MCAssembler &Asm, const MCFixup &Fixup, |
| 53 | const MCValue &Target, MutableArrayRef<char> Data, |
| Peter Smith | 57f661b | 2018-06-06 09:40:06 +0000 | [diff] [blame] | 54 | uint64_t Value, bool IsResolved, |
| 55 | const MCSubtargetInfo *STI) const override; |
| Joe Abbey | 8e72eb7 | 2014-09-16 09:18:23 +0000 | [diff] [blame] | 56 | |
| Peter Smith | 57f661b | 2018-06-06 09:40:06 +0000 | [diff] [blame] | 57 | unsigned getRelaxedOpcode(unsigned Op, const MCSubtargetInfo &STI) const; |
| Tim Northover | 4233557 | 2015-04-06 18:44:42 +0000 | [diff] [blame] | 58 | |
| Peter Smith | 57f661b | 2018-06-06 09:40:06 +0000 | [diff] [blame] | 59 | bool mayNeedRelaxation(const MCInst &Inst, |
| 60 | const MCSubtargetInfo &STI) const override; |
| Joe Abbey | 8e72eb7 | 2014-09-16 09:18:23 +0000 | [diff] [blame] | 61 | |
| Tim Northover | 8d67b8e | 2015-10-02 18:07:18 +0000 | [diff] [blame] | 62 | const char *reasonForFixupRelaxation(const MCFixup &Fixup, |
| 63 | uint64_t Value) const; |
| 64 | |
| Joe Abbey | 8e72eb7 | 2014-09-16 09:18:23 +0000 | [diff] [blame] | 65 | bool fixupNeedsRelaxation(const MCFixup &Fixup, uint64_t Value, |
| 66 | const MCRelaxableFragment *DF, |
| 67 | const MCAsmLayout &Layout) const override; |
| 68 | |
| Nirav Dave | 8603062 | 2016-07-11 14:23:53 +0000 | [diff] [blame] | 69 | void relaxInstruction(const MCInst &Inst, const MCSubtargetInfo &STI, |
| 70 | MCInst &Res) const override; |
| Joe Abbey | 8e72eb7 | 2014-09-16 09:18:23 +0000 | [diff] [blame] | 71 | |
| Peter Collingbourne | 571a330 | 2018-05-21 17:57:19 +0000 | [diff] [blame] | 72 | bool writeNopData(raw_ostream &OS, uint64_t Count) const override; |
| Joe Abbey | 8e72eb7 | 2014-09-16 09:18:23 +0000 | [diff] [blame] | 73 | |
| 74 | void handleAssemblerFlag(MCAssemblerFlag Flag) override; |
| 75 | |
| 76 | unsigned getPointerSize() const { return 4; } |
| 77 | bool isThumb() const { return isThumbMode; } |
| 78 | void setIsThumb(bool it) { isThumbMode = it; } |
| Joe Abbey | 8e72eb7 | 2014-09-16 09:18:23 +0000 | [diff] [blame] | 79 | }; |
| Benjamin Kramer | b32a504 | 2016-01-27 19:29:42 +0000 | [diff] [blame] | 80 | } // end namespace llvm |
| Joe Abbey | 8e72eb7 | 2014-09-16 09:18:23 +0000 | [diff] [blame] | 81 | |
| 82 | #endif |