1 //===- Target/MInstructionInfo.h - Target Instruction Information -*-C++-*-===//
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.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_CODEGEN_MINSTRUCTIONINFO_H
11 #define LLVM_CODEGEN_MINSTRUCTIONINFO_H
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.
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
28 /// MIF namespace - This namespace contains flags that pertain to machine
34 LOAD = 1 << 0, // This instruction loads from memory
35 STORE = 1 << 1, // This instruction stores to memory
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
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.
50 class MInstructionInfo {
51 const MInstructionDesc *Desc; // Pointer to the descriptor array
52 unsigned NumInstructions; // Number of entries in the array
54 MInstructionInfo(const MInstructionDesc *D, unsigned NI)
55 : Desc(D), NumInstructions(NI) {}
58 enum { // Target independant constants
59 PHIOpcode = 0, /// Opcode for PHI instruction
60 NoOpOpcode = 1, /// Opcode for noop instruction
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).
67 virtual const MRegisterInfo &getRegisterInfo() const = 0;
69 const MInstructionDesc &operator[](unsigned Opcode) const {
70 assert(Opcode < NumInstructions &&
71 "Attempting to access record for invalid opcode!");
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);
81 virtual void print(const MInstruction *MI, std::ostream &O) const = 0;