VarLenCodeEmitterGen.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. //===- VarLenCodeEmitterGen.h - CEG for variable-length insts ---*- 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 declare the CodeEmitterGen component for variable-length
  10. // instructions. See the .cpp file for more details.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_UTILS_TABLEGEN_VARLENCODEEMITTERGEN_H
  14. #define LLVM_UTILS_TABLEGEN_VARLENCODEEMITTERGEN_H
  15. #include "llvm/TableGen/Record.h"
  16. namespace llvm {
  17. struct EncodingSegment {
  18. unsigned BitWidth;
  19. const Init *Value;
  20. StringRef CustomEncoder = "";
  21. StringRef CustomDecoder = "";
  22. };
  23. class VarLenInst {
  24. const RecordVal *TheDef;
  25. size_t NumBits;
  26. // Set if any of the segment is not fixed value.
  27. bool HasDynamicSegment;
  28. SmallVector<EncodingSegment, 4> Segments;
  29. void buildRec(const DagInit *DI);
  30. public:
  31. VarLenInst() : TheDef(nullptr), NumBits(0U), HasDynamicSegment(false) {}
  32. explicit VarLenInst(const DagInit *DI, const RecordVal *TheDef);
  33. /// Number of bits
  34. size_t size() const { return NumBits; }
  35. using const_iterator = decltype(Segments)::const_iterator;
  36. const_iterator begin() const { return Segments.begin(); }
  37. const_iterator end() const { return Segments.end(); }
  38. size_t getNumSegments() const { return Segments.size(); }
  39. bool isFixedValueOnly() const { return !HasDynamicSegment; }
  40. };
  41. void emitVarLenCodeEmitter(RecordKeeper &R, raw_ostream &OS);
  42. } // end namespace llvm
  43. #endif