ARMAsmBackend.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. //===-- ARMAsmBackend.h - ARM Assembler Backend -----------------*- C++ -*-===//
  2. //
  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
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #ifndef LLVM_LIB_TARGET_ARM_ARMASMBACKEND_H
  9. #define LLVM_LIB_TARGET_ARM_ARMASMBACKEND_H
  10. #include "MCTargetDesc/ARMFixupKinds.h"
  11. #include "MCTargetDesc/ARMMCTargetDesc.h"
  12. #include "llvm/MC/MCAsmBackend.h"
  13. #include "llvm/MC/MCSubtargetInfo.h"
  14. #include "llvm/Support/TargetRegistry.h"
  15. namespace llvm {
  16. class ARMAsmBackend : public MCAsmBackend {
  17. // The STI from the target triple the MCAsmBackend was instantiated with
  18. // note that MCFragments may have a different local STI that should be
  19. // used in preference.
  20. const MCSubtargetInfo &STI;
  21. bool isThumbMode; // Currently emitting Thumb code.
  22. public:
  23. ARMAsmBackend(const Target &T, const MCSubtargetInfo &STI,
  24. support::endianness Endian)
  25. : MCAsmBackend(Endian), STI(STI),
  26. isThumbMode(STI.getTargetTriple().isThumb()) {}
  27. unsigned getNumFixupKinds() const override {
  28. return ARM::NumTargetFixupKinds;
  29. }
  30. // FIXME: this should be calculated per fragment as the STI may be
  31. // different.
  32. bool hasNOP() const { return STI.getFeatureBits()[ARM::HasV6T2Ops]; }
  33. Optional<MCFixupKind> getFixupKind(StringRef Name) const override;
  34. const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const override;
  35. bool shouldForceRelocation(const MCAssembler &Asm, const MCFixup &Fixup,
  36. const MCValue &Target) override;
  37. unsigned adjustFixupValue(const MCAssembler &Asm, const MCFixup &Fixup,
  38. const MCValue &Target, uint64_t Value,
  39. bool IsResolved, MCContext &Ctx,
  40. const MCSubtargetInfo *STI) const;
  41. void applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,
  42. const MCValue &Target, MutableArrayRef<char> Data,
  43. uint64_t Value, bool IsResolved,
  44. const MCSubtargetInfo *STI) const override;
  45. unsigned getRelaxedOpcode(unsigned Op, const MCSubtargetInfo &STI) const;
  46. bool mayNeedRelaxation(const MCInst &Inst,
  47. const MCSubtargetInfo &STI) const override;
  48. const char *reasonForFixupRelaxation(const MCFixup &Fixup,
  49. uint64_t Value) const;
  50. bool fixupNeedsRelaxation(const MCFixup &Fixup, uint64_t Value,
  51. const MCRelaxableFragment *DF,
  52. const MCAsmLayout &Layout) const override;
  53. void relaxInstruction(MCInst &Inst,
  54. const MCSubtargetInfo &STI) const override;
  55. bool writeNopData(raw_ostream &OS, uint64_t Count) const override;
  56. void handleAssemblerFlag(MCAssemblerFlag Flag) override;
  57. unsigned getPointerSize() const { return 4; }
  58. bool isThumb() const { return isThumbMode; }
  59. void setIsThumb(bool it) { isThumbMode = it; }
  60. };
  61. } // end namespace llvm
  62. #endif