Changes to build successfully with GCC 3.02
[oota-llvm.git] / include / llvm / CodeGen / InstrSelectionSupport.h
1 // $Id$ -*-c++-*-
2 //***************************************************************************
3 // File:
4 //      InstrSelectionSupport.h
5 // 
6 // Purpose:
7 //      Target-independent instruction selection code.
8 //      See SparcInstrSelection.cpp for usage.
9 //      
10 // History:
11 //      10/10/01         -  Vikram Adve  -  Created
12 //**************************************************************************/
13
14 #ifndef LLVM_CODEGEN_INSTR_SELECTION_SUPPORT_H
15 #define LLVM_CODEGEN_INSTR_SELECTION_SUPPORT_H
16
17 #include "llvm/Instruction.h"
18 #include "llvm/CodeGen/MachineInstr.h"
19 class Method;
20 class InstrForest;
21 class MachineInstr;
22 class InstructionNode;
23 class TmpInstruction;
24 class Constant;
25 class TargetMachine;
26
27
28 //---------------------------------------------------------------------------
29 // Function GetConstantValueAsSignedInt
30 // 
31 // Convenience function to get the value of an integer constant, for an
32 // appropriate integer or non-integer type that can be held in an integer.
33 // The type of the argument must be the following:
34 //      Signed or unsigned integer
35 //      Boolean
36 //      Pointer
37 // 
38 // isValidConstant is set to true if a valid constant was found.
39 //---------------------------------------------------------------------------
40
41 int64_t         GetConstantValueAsSignedInt     (const Value *V,
42                                                  bool &isValidConstant);
43
44
45 //---------------------------------------------------------------------------
46 // Function: FoldGetElemChain
47 // 
48 // Purpose:
49 //   Fold a chain of GetElementPtr instructions into an equivalent
50 //   (Pointer, IndexVector) pair.  Returns the pointer Value, and
51 //   stores the resulting IndexVector in argument chainIdxVec.
52 //---------------------------------------------------------------------------
53
54 Value*          FoldGetElemChain    (const InstructionNode* getElemInstrNode,
55                                      std::vector<Value*>& chainIdxVec);
56
57
58 //------------------------------------------------------------------------ 
59 // Function Set2OperandsFromInstr
60 // Function Set3OperandsFromInstr
61 // 
62 // Purpose:
63 // 
64 // For the common case of 2- and 3-operand arithmetic/logical instructions,
65 // set the m/c instr. operands directly from the VM instruction's operands.
66 // Check whether the first or second operand is 0 and can use a dedicated
67 // "0" register.
68 // Check whether the second operand should use an immediate field or register.
69 // (First and third operands are never immediates for such instructions.)
70 // 
71 // Arguments:
72 // canDiscardResult: Specifies that the result operand can be discarded
73 //                   by using the dedicated "0"
74 // 
75 // op1position, op2position and resultPosition: Specify in which position
76 //                   in the machine instruction the 3 operands (arg1, arg2
77 //                   and result) should go.
78 // 
79 // RETURN VALUE: unsigned int flags, where
80 //      flags & 0x01    => operand 1 is constant and needs a register
81 //      flags & 0x02    => operand 2 is constant and needs a register
82 //------------------------------------------------------------------------ 
83
84 void            Set2OperandsFromInstr   (MachineInstr* minstr,
85                                          InstructionNode* vmInstrNode,
86                                          const TargetMachine& targetMachine,
87                                          bool canDiscardResult = false,
88                                          int op1Position = 0,
89                                          int resultPosition = 1);
90
91 void            Set3OperandsFromInstr   (MachineInstr* minstr,
92                                          InstructionNode* vmInstrNode,
93                                          const TargetMachine& targetMachine,
94                                          bool canDiscardResult = false,
95                                          int op1Position = 0,
96                                          int op2Position = 1,
97                                          int resultPosition = 2);
98
99
100 //---------------------------------------------------------------------------
101 // Function: ChooseRegOrImmed
102 // 
103 // Purpose:
104 // 
105 //---------------------------------------------------------------------------
106
107 MachineOperand::MachineOperandType
108                 ChooseRegOrImmed        (Value* val,
109                                          MachineOpCode opCode,
110                                          const TargetMachine& targetMachine,
111                                          bool canUseImmed,
112                                          unsigned int& getMachineRegNum,
113                                          int64_t& getImmedValue);
114
115
116 //---------------------------------------------------------------------------
117 // Function: FixConstantOperandsForInstr
118 // 
119 // Purpose:
120 // Special handling for constant operands of a machine instruction
121 // -- if the constant is 0, use the hardwired 0 register, if any;
122 // -- if the constant fits in the IMMEDIATE field, use that field;
123 // -- else create instructions to put the constant into a register, either
124 //    directly or by loading explicitly from the constant pool.
125 // 
126 // In the first 2 cases, the operand of `minstr' is modified in place.
127 // Returns a vector of machine instructions generated for operands that
128 // fall under case 3; these must be inserted before `minstr'.
129 //---------------------------------------------------------------------------
130
131 std::vector<MachineInstr*> FixConstantOperandsForInstr (Instruction* vmInstr,
132                                                         MachineInstr* minstr,
133                                                         TargetMachine& target);
134
135 #endif