1d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma//===- HexagonMCInst.h - Hexagon sub-class of MCInst ----------------------===//
2d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma//
3d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma//                     The LLVM Compiler Infrastructure
4d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma//
5d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma// This file is distributed under the University of Illinois Open Source
6d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma// License. See LICENSE.TXT for details.
7d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma//
8d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma//===----------------------------------------------------------------------===//
9d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma//
10d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma// This class extends MCInst to allow some VLIW annotations.
11d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma//
12d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma//===----------------------------------------------------------------------===//
13d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma
14d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma#ifndef HEXAGONMCINST_H
15d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma#define HEXAGONMCINST_H
16d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma
17d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma#include "HexagonTargetMachine.h"
18d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma#include "llvm/MC/MCInst.h"
19d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma
20d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Vermanamespace llvm {
21d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma  class MCOperand;
22d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma
23d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma  class HexagonMCInst: public MCInst {
24d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma    // MCID is set during instruction lowering.
25d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma    // It is needed in order to access TSFlags for
26d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma    // use in checking MC instruction properties.
27d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma    const MCInstrDesc *MCID;
28d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma
29d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma    // Packet start and end markers
30d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma    unsigned packetStart: 1, packetEnd: 1;
31d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma
32d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma  public:
33d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma    explicit HexagonMCInst():
34d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma      MCInst(), MCID(0), packetStart(0), packetEnd(0) {};
35d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma    HexagonMCInst(const MCInstrDesc& mcid):
36d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma      MCInst(), MCID(&mcid), packetStart(0), packetEnd(0) {};
37d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma
38d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma    bool isPacketStart() const { return (packetStart); };
39d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma    bool isPacketEnd() const { return (packetEnd); };
40d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma    void setPacketStart(bool Y) { packetStart = Y; };
41d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma    void setPacketEnd(bool Y) { packetEnd = Y; };
42d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma    void resetPacket() { setPacketStart(false); setPacketEnd(false); };
43d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma
44d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma    // Return the slots used by the insn.
45d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma    unsigned getUnits(const HexagonTargetMachine* TM) const;
46d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma
47d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma    // Return the Hexagon ISA class for the insn.
48d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma    unsigned getType() const;
49d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma
50d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma    void setDesc(const MCInstrDesc& mcid) { MCID = &mcid; };
51d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma    const MCInstrDesc& getDesc(void) const { return *MCID; };
52d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma
53d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma    // Return whether the insn is an actual insn.
54d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma    bool isCanon() const;
55d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma
56d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma    // Return whether the insn is a prefix.
57d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma    bool isPrefix() const;
58d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma
59d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma    // Return whether the insn is solo, i.e., cannot be in a packet.
60d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma    bool isSolo() const;
61d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma
62d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma    // Return whether the instruction needs to be constant extended.
63d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma    bool isConstExtended() const;
64d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma
65d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma    // Return constant extended operand number.
66d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma    unsigned short getCExtOpNum(void) const;
67d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma
68d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma    // Return whether the insn is a new-value consumer.
69d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma    bool isNewValue() const;
70d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma
71d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma    // Return whether the instruction is a legal new-value producer.
72d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma    bool hasNewValue() const;
73d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma
74d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma    // Return the operand that consumes or produces a new value.
75d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma    const MCOperand& getNewValue() const;
76d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma
77d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma    // Return number of bits in the constant extended operand.
78d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma    unsigned getBitCount(void) const;
79d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma
80d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma  private:
81d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma    // Return whether the instruction must be always extended.
82d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma    bool isExtended() const;
83d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma
84d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma    // Return true if the insn may be extended based on the operand value.
85d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma    bool isExtendable() const;
86d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma
87d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma    // Return true if the operand can be constant extended.
88d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma    bool isOperandExtended(const unsigned short OperandNum) const;
89d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma
90d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma    // Return the min value that a constant extendable operand can have
91d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma    // without being extended.
92d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma    int getMinValue() const;
93d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma
94d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma    // Return the max value that a constant extendable operand can have
95d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma    // without being extended.
96d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma    int getMaxValue() const;
97d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma  };
98d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma}
99d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma
100d6c98ae63824854ea2175b362a10985cac7cfb32Jyotsna Verma#endif
101