1*0fca6ea1SDimitry Andric //===- VarLenCodeEmitterGen.h - CEG for variable-length insts ---*- C++ -*-===// 2*0fca6ea1SDimitry Andric // 3*0fca6ea1SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*0fca6ea1SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 5*0fca6ea1SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*0fca6ea1SDimitry Andric // 7*0fca6ea1SDimitry Andric //===----------------------------------------------------------------------===// 8*0fca6ea1SDimitry Andric // 9*0fca6ea1SDimitry Andric // This file declare the CodeEmitterGen component for variable-length 10*0fca6ea1SDimitry Andric // instructions. See the .cpp file for more details. 11*0fca6ea1SDimitry Andric // 12*0fca6ea1SDimitry Andric //===----------------------------------------------------------------------===// 13*0fca6ea1SDimitry Andric 14*0fca6ea1SDimitry Andric #ifndef LLVM_UTILS_TABLEGEN_VARLENCODEEMITTERGEN_H 15*0fca6ea1SDimitry Andric #define LLVM_UTILS_TABLEGEN_VARLENCODEEMITTERGEN_H 16*0fca6ea1SDimitry Andric 17*0fca6ea1SDimitry Andric #include "llvm/TableGen/Record.h" 18*0fca6ea1SDimitry Andric 19*0fca6ea1SDimitry Andric namespace llvm { 20*0fca6ea1SDimitry Andric 21*0fca6ea1SDimitry Andric struct EncodingSegment { 22*0fca6ea1SDimitry Andric unsigned BitWidth; 23*0fca6ea1SDimitry Andric const Init *Value; 24*0fca6ea1SDimitry Andric StringRef CustomEncoder = ""; 25*0fca6ea1SDimitry Andric StringRef CustomDecoder = ""; 26*0fca6ea1SDimitry Andric }; 27*0fca6ea1SDimitry Andric 28*0fca6ea1SDimitry Andric class VarLenInst { 29*0fca6ea1SDimitry Andric const RecordVal *TheDef; 30*0fca6ea1SDimitry Andric size_t NumBits; 31*0fca6ea1SDimitry Andric 32*0fca6ea1SDimitry Andric // Set if any of the segment is not fixed value. 33*0fca6ea1SDimitry Andric bool HasDynamicSegment; 34*0fca6ea1SDimitry Andric 35*0fca6ea1SDimitry Andric SmallVector<EncodingSegment, 4> Segments; 36*0fca6ea1SDimitry Andric 37*0fca6ea1SDimitry Andric void buildRec(const DagInit *DI); 38*0fca6ea1SDimitry Andric 39*0fca6ea1SDimitry Andric public: VarLenInst()40*0fca6ea1SDimitry Andric VarLenInst() : TheDef(nullptr), NumBits(0U), HasDynamicSegment(false) {} 41*0fca6ea1SDimitry Andric 42*0fca6ea1SDimitry Andric explicit VarLenInst(const DagInit *DI, const RecordVal *TheDef); 43*0fca6ea1SDimitry Andric 44*0fca6ea1SDimitry Andric /// Number of bits size()45*0fca6ea1SDimitry Andric size_t size() const { return NumBits; } 46*0fca6ea1SDimitry Andric 47*0fca6ea1SDimitry Andric using const_iterator = decltype(Segments)::const_iterator; 48*0fca6ea1SDimitry Andric begin()49*0fca6ea1SDimitry Andric const_iterator begin() const { return Segments.begin(); } end()50*0fca6ea1SDimitry Andric const_iterator end() const { return Segments.end(); } getNumSegments()51*0fca6ea1SDimitry Andric size_t getNumSegments() const { return Segments.size(); } 52*0fca6ea1SDimitry Andric isFixedValueOnly()53*0fca6ea1SDimitry Andric bool isFixedValueOnly() const { return !HasDynamicSegment; } 54*0fca6ea1SDimitry Andric }; 55*0fca6ea1SDimitry Andric 56*0fca6ea1SDimitry Andric void emitVarLenCodeEmitter(RecordKeeper &R, raw_ostream &OS); 57*0fca6ea1SDimitry Andric 58*0fca6ea1SDimitry Andric } // end namespace llvm 59*0fca6ea1SDimitry Andric #endif 60