X86MCExpr.h 2.3 KB

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