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