X86MCExpr.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. //=--- X86MCExpr.h - X86 specific MC expression classes ---*- 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. //
  9. // This file describes X86-specific MCExprs, i.e, registers used for
  10. // extended variable assignments.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_LIB_TARGET_X86_MCTARGETDESC_X86MCEXPR_H
  14. #define LLVM_LIB_TARGET_X86_MCTARGETDESC_X86MCEXPR_H
  15. #include "X86ATTInstPrinter.h"
  16. #include "llvm/MC/MCAsmInfo.h"
  17. #include "llvm/MC/MCContext.h"
  18. #include "llvm/MC/MCExpr.h"
  19. #include "llvm/Support/ErrorHandling.h"
  20. namespace llvm {
  21. class X86MCExpr : public MCTargetExpr {
  22. private:
  23. const int64_t RegNo; // All
  24. explicit X86MCExpr(int64_t R) : RegNo(R) {}
  25. public:
  26. /// @name Construction
  27. /// @{
  28. static const X86MCExpr *create(int64_t RegNo, MCContext &Ctx) {
  29. return new (Ctx) X86MCExpr(RegNo);
  30. }
  31. /// @}
  32. /// @name Accessors
  33. /// @{
  34. /// getSubExpr - Get the child of this expression.
  35. int64_t getRegNo() const { return RegNo; }
  36. /// @}
  37. void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override {
  38. if (!MAI || MAI->getAssemblerDialect() == 0)
  39. OS << '%';
  40. OS << X86ATTInstPrinter::getRegisterName(RegNo);
  41. }
  42. bool evaluateAsRelocatableImpl(MCValue &Res, const MCAsmLayout *Layout,
  43. const MCFixup *Fixup) const override {
  44. return false;
  45. }
  46. // Register values should be inlined as they are not valid .set expressions.
  47. bool inlineAssignedExpr() const override { return true; }
  48. bool isEqualTo(const MCExpr *X) const override {
  49. if (auto *E = dyn_cast<X86MCExpr>(X))
  50. return getRegNo() == E->getRegNo();
  51. return false;
  52. }
  53. void visitUsedExpr(MCStreamer &Streamer) const override{};
  54. MCFragment *findAssociatedFragment() const override { return nullptr; }
  55. // There are no TLS X86MCExprs at the moment.
  56. void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override {}
  57. static bool classof(const MCExpr *E) {
  58. return E->getKind() == MCExpr::Target;
  59. }
  60. };
  61. } // end namespace llvm
  62. #endif