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