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