Lexer doesn't create typehandle gross stuff now, parser does.
[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 Function;
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     (Function* function,
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     }
92   }
93   
94   // Constructor that requires the type of the temporary to be specified.
95   // Both S1 and S2 may be NULL.
96   TmpInstruction(const Type *Ty, Value *s1 = 0, Value* s2 = 0,
97                  const std::string &name = "")
98     : Instruction(Ty, Instruction::UserOp1, name) {
99     if (s1) { Operands.push_back(Use(s1, this)); }
100     if (s2) { Operands.push_back(Use(s2, this)); }
101   }
102   
103   virtual Instruction *clone() const { return new TmpInstruction(*this); }
104   virtual const char *getOpcodeName() const {
105     return "TempValueForMachineInstr";
106   }
107   
108   // Methods for support type inquiry through isa, cast, and dyn_cast:
109   static inline bool classof(const TmpInstruction *) { return true; }
110   static inline bool classof(const Instruction *I) {
111     return (I->getOpcode() == Instruction::UserOp1);
112   }
113   static inline bool classof(const Value *V) {
114     return isa<Instruction>(V) && classof(cast<Instruction>(V));
115   }
116 };
117
118 #endif