Rename ConstPoolVal -> Constant
[oota-llvm.git] / include / llvm / CodeGen / InstrSelection.h
1 // $Id$ -*-c++-*-
2 //***************************************************************************
3 // File:
4 //      InstrSelection.h
5 // 
6 // Purpose:
7 //      External interface to instruction selection.
8 // 
9 // History:
10 //      7/02/01  -  Vikram Adve  -  Created
11 //**************************************************************************/
12
13 #ifndef LLVM_CODEGEN_INSTR_SELECTION_H
14 #define LLVM_CODEGEN_INSTR_SELECTION_H
15
16 #include "llvm/Instruction.h"
17 class Method;
18 class InstrForest;
19 class MachineInstr;
20 class InstructionNode;
21 class TmpInstruction;
22 class TargetMachine;
23
24
25 /************************* Required Functions *******************************
26  * Target-dependent functions that MUST be implemented for each target.
27  ***************************************************************************/
28
29 const unsigned MAX_INSTR_PER_VMINSTR = 8;
30
31 const Instruction::OtherOps TMP_INSTRUCTION_OPCODE = Instruction::UserOp1;
32
33 extern unsigned GetInstructionsByRule   (InstructionNode* subtreeRoot,
34                                          int ruleForNode,
35                                          short* nts,
36                                          TargetMachine &Target,
37                                          MachineInstr** minstrVec);
38
39 extern unsigned GetInstructionsForProlog(BasicBlock* entryBB,
40                                          TargetMachine &Target,
41                                          MachineInstr** minstrVec);
42
43 extern unsigned GetInstructionsForEpilog(BasicBlock* anExitBB,
44                                          TargetMachine &Target,
45                                          MachineInstr** minstrVec);
46
47 extern bool     ThisIsAChainRule        (int eruleno);
48
49
50 //************************ Exported Functions ******************************/
51
52
53 //---------------------------------------------------------------------------
54 // Function: SelectInstructionsForMethod
55 // 
56 // Purpose:
57 //   Entry point for instruction selection using BURG.
58 //   Returns true if instruction selection failed, false otherwise.
59 //   Implemented in machine-specific instruction selection file.
60 //---------------------------------------------------------------------------
61
62 bool            SelectInstructionsForMethod     (Method* method,
63                                                  TargetMachine &Target);
64
65
66 //************************ Exported Data Types *****************************/
67
68
69 //---------------------------------------------------------------------------
70 // class TmpInstruction
71 //
72 //   This class represents temporary intermediate values
73 //   used within the machine code for a VM instruction
74 //---------------------------------------------------------------------------
75
76 class TmpInstruction : public Instruction {
77   TmpInstruction (const TmpInstruction  &ci)
78     : Instruction(ci.getType(), ci.getOpcode())
79   {
80     Operands.reserve(2);
81     Operands.push_back(Use(Operands[0], this));
82     Operands.push_back(Use(Operands[1], this));
83   }
84 public:
85   // Constructor that uses the type of S1 as the type of the temporary.
86   // s1 must be a valid value.  s2 may be NULL.
87   TmpInstruction(OtherOps opcode, Value *s1, Value* s2, const string &name="")
88     : Instruction(s1->getType(), opcode, name)
89   {
90     assert(s1 != NULL && "Use different constructor if both operands are 0");
91     Initialize(opcode, s1, s2);
92   }
93   
94   // Constructor that allows the type of the temporary to be specified.
95   // Both S1 and S2 may be NULL.
96   TmpInstruction(OtherOps opcode, const Type* tmpType,
97                  Value *s1, Value* s2, const string &name = "")
98     : Instruction(tmpType, opcode, name)
99   {
100     Initialize(opcode, s1, s2);
101   }
102   
103   virtual Instruction *clone() const { return new TmpInstruction(*this); }
104   virtual const char *getOpcodeName() const {
105     return "userOp1";
106   }
107   
108 private:
109   void Initialize(OtherOps opcode, Value *s1, Value* s2) {
110     assert(opcode==TMP_INSTRUCTION_OPCODE && "Tmp instruction opcode invalid");
111     Operands.reserve(s1 && s2? 2 : ((s1 || s2)? 1 : 0));
112     if (s1)
113       Operands.push_back(Use(s1, this));
114     if (s2)
115       Operands.push_back(Use(s2, this));
116   }
117 };
118
119 //**************************************************************************/
120
121 #endif