fda0525617179def73a9db66c881f5997cfb765f
[oota-llvm.git] / include / llvm / CodeGen / InstrSelection.h
1 //===-- llvm/CodeGen/InstrSelection.h ---------------------------*- C++ -*-===//
2 //
3 // External interface to instruction selection.
4 //
5 //===----------------------------------------------------------------------===//
6
7 #ifndef LLVM_CODEGEN_INSTR_SELECTION_H
8 #define LLVM_CODEGEN_INSTR_SELECTION_H
9
10 #include "llvm/Instruction.h"
11
12 class Function;
13 class InstrForest;
14 class MachineInstr;
15 class InstructionNode;
16 class TargetMachine;
17 class MachineCodeForInstruction;
18 class FunctionPass;
19
20 //===--------------------- Required Functions ---------------------------------
21 // Target-dependent functions that MUST be implemented for each target.
22 //
23
24 extern void     GetInstructionsByRule   (InstructionNode* subtreeRoot,
25                                          int ruleForNode,
26                                          short* nts,
27                                          TargetMachine &Target,
28                                          std::vector<MachineInstr*>& mvec);
29
30 extern bool     ThisIsAChainRule        (int eruleno);
31
32
33 //************************ Exported Functions ******************************/
34
35
36 //---------------------------------------------------------------------------
37 // Function: createInstructionSelectionPass
38 // 
39 // Purpose:
40 //   Entry point for instruction selection using BURG.
41 //   Return a pass that performs machine dependent instruction selection.
42 //---------------------------------------------------------------------------
43
44 FunctionPass *createInstructionSelectionPass(TargetMachine &Target);
45
46
47 //************************ Exported Data Types *****************************/
48
49
50 //---------------------------------------------------------------------------
51 // class TmpInstruction
52 //
53 //   This class represents temporary intermediate values
54 //   used within the machine code for a VM instruction
55 //---------------------------------------------------------------------------
56
57 class TmpInstruction : public Instruction {
58   TmpInstruction(const TmpInstruction &TI)
59     : Instruction(TI.getType(), TI.getOpcode()) {
60     if (!TI.Operands.empty()) {
61       Operands.push_back(Use(TI.Operands[0], this));
62       if (TI.Operands.size() == 2)
63         Operands.push_back(Use(TI.Operands[1], this));
64       else
65         assert(0 && "Bad # operands to TmpInstruction!");
66     }
67   }
68 public:
69   // Constructor that uses the type of S1 as the type of the temporary.
70   // s1 must be a valid value.  s2 may be NULL.
71   TmpInstruction(MachineCodeForInstruction& mcfi,
72                  Value *s1, Value *s2 = 0, const std::string &name = "");
73   
74   // Constructor that requires the type of the temporary to be specified.
75   // Both S1 and S2 may be NULL.
76   TmpInstruction(MachineCodeForInstruction& mcfi,
77                  const Type *Ty, Value *s1 = 0, Value* s2 = 0,
78                  const std::string &name = "");
79   
80   virtual Instruction *clone() const {
81     assert(0 && "Cannot clone TmpInstructions!");
82     return 0;
83   }
84   virtual const char *getOpcodeName() const {
85     return "TempValueForMachineInstr";
86   }
87   
88   // Methods for support type inquiry through isa, cast, and dyn_cast:
89   static inline bool classof(const TmpInstruction *) { return true; }
90   static inline bool classof(const Instruction *I) {
91     return (I->getOpcode() == Instruction::UserOp1);
92   }
93   static inline bool classof(const Value *V) {
94     return isa<Instruction>(V) && classof(cast<Instruction>(V));
95   }
96 };
97
98 #endif