e8eb750f1c7b549c3e03fcc46fb2588b9926de3d
[oota-llvm.git] / include / llvm / Target / MInstructionInfo.h
1 //===- Target/MInstructionInfo.h - Target Instruction Information -*-C++-*-===//
2 //
3 // MInstruction's are completely generic instructions that provide very little
4 // interpretation upon their arguments and sementics.  This file defines an
5 // interface that should be used to get information about the semantics of the
6 // actual instructions.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef LLVM_CODEGEN_MINSTRUCTIONINFO_H
11 #define LLVM_CODEGEN_MINSTRUCTIONINFO_H
12
13 #include <assert.h>
14 #include <iosfwd>
15 class MInstruction;
16 class MRegisterInfo;
17
18 /// MInstructionDesc - This record contains all of the information known about a
19 /// particular instruction.  Note that several instructions with the same
20 /// mnemonic may be represented in the target machine as different instructions.
21 ///
22 struct MInstructionDesc {
23   const char *Name;     // Assembly language mnemonic for the instruction.
24   unsigned   Flags;    // Flags identifying inst properties (defined below)
25   unsigned TSFlags;    // Target Specific Flags
26 };
27
28 /// MIF namespace - This namespace contains flags that pertain to machine
29 /// instructions
30 ///
31 namespace MIF {
32   enum {
33     // Memory flags...
34     LOAD               = 1 << 0,   // This instruction loads from memory
35     STORE              = 1 << 1,   // This instruction stores to memory
36
37     // Control flow flags...
38     CALL               = 1 << 2,   // This instruction calls another function
39     RET                = 1 << 3,   // This instruction returns from function
40     BRANCH             = 1 << 4,   // This instruction is a branch
41   };
42 };
43
44 /// MInstructionInfo base class - We assume that the target defines a static
45 /// array of MInstructionDesc objects that represent all of the machine
46 /// instructions that the target has.  As such, we simply have to track a
47 /// pointer to this array so that we can turn an instruction opcode into an
48 /// instruction descriptor.
49 ///
50 class MInstructionInfo {
51   const MInstructionDesc *Desc;    // Pointer to the descriptor array
52   unsigned NumInstructions;        // Number of entries in the array
53 protected:
54   MInstructionInfo(const MInstructionDesc *D, unsigned NI)
55     : Desc(D), NumInstructions(NI) {}
56 public:
57
58   enum {                           // Target independant constants
59     PHIOpcode = 0,                 /// Opcode for PHI instruction
60     NoOpOpcode = 1,                /// Opcode for noop instruction
61   };
62
63   /// getRegisterInfo - MInstructionInfo is a superset of MRegister info.  As
64   /// such, whenever a client has an instance of instruction info, it should
65   /// always be able to get register info as well (through this method).
66   ///
67   virtual const MRegisterInfo &getRegisterInfo() const = 0;
68
69   const MInstructionDesc &operator[](unsigned Opcode) const {
70     assert(Opcode < NumInstructions &&
71            "Attempting to access record for invalid opcode!");
72     return Desc[Opcode];
73   }
74
75   /// Provide a get method, equivalent to [], but more useful if we have a
76   /// pointer to this object.
77   const MInstructionDesc &get(unsigned Opcode) const {
78     return operator[](Opcode);
79   }
80
81   virtual void print(const MInstruction *MI, std::ostream &O) const = 0;
82
83 };
84
85 #endif