fa4f21a1751a17ab94e4dbeceb9703e78f34885b
[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 TargetMachine;
22
23 /************************* Required Functions *******************************
24  * Target-dependent functions that MUST be implemented for each target.
25  ***************************************************************************/
26
27 const unsigned MAX_INSTR_PER_VMINSTR = 8;
28
29 extern void     GetInstructionsByRule   (InstructionNode* subtreeRoot,
30                                          int ruleForNode,
31                                          short* nts,
32                                          TargetMachine &Target,
33                                          vector<MachineInstr*>& mvec);
34
35 extern unsigned GetInstructionsForProlog(BasicBlock* entryBB,
36                                          TargetMachine &Target,
37                                          MachineInstr** minstrVec);
38
39 extern unsigned GetInstructionsForEpilog(BasicBlock* anExitBB,
40                                          TargetMachine &Target,
41                                          MachineInstr** minstrVec);
42
43 extern bool     ThisIsAChainRule        (int eruleno);
44
45
46 //************************ Exported Functions ******************************/
47
48
49 //---------------------------------------------------------------------------
50 // Function: SelectInstructionsForMethod
51 // 
52 // Purpose:
53 //   Entry point for instruction selection using BURG.
54 //   Returns true if instruction selection failed, false otherwise.
55 //   Implemented in machine-specific instruction selection file.
56 //---------------------------------------------------------------------------
57
58 bool            SelectInstructionsForMethod     (Method* method,
59                                                  TargetMachine &Target);
60
61
62 //************************ Exported Data Types *****************************/
63
64
65 //---------------------------------------------------------------------------
66 // class TmpInstruction
67 //
68 //   This class represents temporary intermediate values
69 //   used within the machine code for a VM instruction
70 //---------------------------------------------------------------------------
71
72 class TmpInstruction : public Instruction {
73   TmpInstruction(const TmpInstruction &TI)
74     : Instruction(TI.getType(), TI.getOpcode()) {
75     if (!TI.Operands.empty()) {
76       Operands.push_back(Use(TI.Operands[0], this));
77       if (TI.Operands.size() == 2)
78         Operands.push_back(Use(TI.Operands[1], this));
79       else
80         assert(0 && "Bad # operands to TmpInstruction!");
81     }
82   }
83 public:
84   // Constructor that uses the type of S1 as the type of the temporary.
85   // s1 must be a valid value.  s2 may be NULL.
86   TmpInstruction(Value *s1, Value *s2 = 0, const std::string &name = "")
87     : Instruction(s1->getType(), Instruction::UserOp1, name) {
88     Operands.push_back(Use(s1, this));  // s1 must be nonnull
89     if (s2) {
90       Operands.push_back(Use(s2, this));
91 #if 0
92       assert(s2->getType() == getType() &&
93              "TmpInstruction operand types do not match!");
94 #endif
95     }
96   }
97   
98   // Constructor that requires the type of the temporary to be specified.
99   // Both S1 and S2 may be NULL.
100   TmpInstruction(const Type *Ty, Value *s1 = 0, Value* s2 = 0,
101                  const std::string &name = "")
102     : Instruction(Ty, Instruction::UserOp1, name) {
103     if (s1) { Operands.push_back(Use(s1, this)); /*assert(s1->getType() == Ty);*/ }
104     if (s2) { Operands.push_back(Use(s2, this)); /*assert(s2->getType() == Ty);*/ }
105   }
106   
107   virtual Instruction *clone() const { return new TmpInstruction(*this); }
108   virtual const char *getOpcodeName() const {
109     return "TemporaryInstruction";
110   }
111 };
112
113 #endif