Rename ConstPoolVal -> Constant
[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 //************************ Exported Functions ******************************/
28
29
30 //---------------------------------------------------------------------------
31 // Function GetConstantValueAsSignedInt
32 // 
33 // Convenience function to get the value of an integer constant, for an
34 // appropriate integer or non-integer type that can be held in an integer.
35 // The type of the argument must be the following:
36 //      Signed or unsigned integer
37 //      Boolean
38 //      Pointer
39 // 
40 // isValidConstant is set to true if a valid constant was found.
41 //---------------------------------------------------------------------------
42
43 int64_t         GetConstantValueAsSignedInt     (const Value *V,
44                                                  bool &isValidConstant);
45
46
47 //---------------------------------------------------------------------------
48 // Function: FoldGetElemChain
49 // 
50 // Purpose:
51 //   Fold a chain of GetElementPtr instructions into an equivalent
52 //   (Pointer, IndexVector) pair.  Returns the pointer Value, and
53 //   stores the resulting IndexVector in argument chainIdxVec.
54 //---------------------------------------------------------------------------
55
56 Value*          FoldGetElemChain    (const InstructionNode* getElemInstrNode,
57                                      vector<Constant*>& chainIdxVec);
58
59
60 //------------------------------------------------------------------------ 
61 // Function Set2OperandsFromInstr
62 // Function Set3OperandsFromInstr
63 // 
64 // Purpose:
65 // 
66 // For the common case of 2- and 3-operand arithmetic/logical instructions,
67 // set the m/c instr. operands directly from the VM instruction's operands.
68 // Check whether the first or second operand is 0 and can use a dedicated
69 // "0" register.
70 // Check whether the second operand should use an immediate field or register.
71 // (First and third operands are never immediates for such instructions.)
72 // 
73 // Arguments:
74 // canDiscardResult: Specifies that the result operand can be discarded
75 //                   by using the dedicated "0"
76 // 
77 // op1position, op2position and resultPosition: Specify in which position
78 //                   in the machine instruction the 3 operands (arg1, arg2
79 //                   and result) should go.
80 // 
81 // RETURN VALUE: unsigned int flags, where
82 //      flags & 0x01    => operand 1 is constant and needs a register
83 //      flags & 0x02    => operand 2 is constant and needs a register
84 //------------------------------------------------------------------------ 
85
86 void            Set2OperandsFromInstr   (MachineInstr* minstr,
87                                          InstructionNode* vmInstrNode,
88                                          const TargetMachine& targetMachine,
89                                          bool canDiscardResult = false,
90                                          int op1Position = 0,
91                                          int resultPosition = 1);
92
93 void            Set3OperandsFromInstr   (MachineInstr* minstr,
94                                          InstructionNode* vmInstrNode,
95                                          const TargetMachine& targetMachine,
96                                          bool canDiscardResult = false,
97                                          int op1Position = 0,
98                                          int op2Position = 1,
99                                          int resultPosition = 2);
100
101
102 //---------------------------------------------------------------------------
103 // Function: ChooseRegOrImmed
104 // 
105 // Purpose:
106 // 
107 //---------------------------------------------------------------------------
108
109 MachineOperand::MachineOperandType
110                 ChooseRegOrImmed        (Value* val,
111                                          MachineOpCode opCode,
112                                          const TargetMachine& targetMachine,
113                                          bool canUseImmed,
114                                          unsigned int& getMachineRegNum,
115                                          int64_t& getImmedValue);
116
117
118 //---------------------------------------------------------------------------
119 // Function: FixConstantOperandsForInstr
120 // 
121 // Purpose:
122 // Special handling for constant operands of a machine instruction
123 // -- if the constant is 0, use the hardwired 0 register, if any;
124 // -- if the constant fits in the IMMEDIATE field, use that field;
125 // -- else create instructions to put the constant into a register, either
126 //    directly or by loading explicitly from the constant pool.
127 // 
128 // In the first 2 cases, the operand of `minstr' is modified in place.
129 // Returns a vector of machine instructions generated for operands that
130 // fall under case 3; these must be inserted before `minstr'.
131 //---------------------------------------------------------------------------
132
133 vector<MachineInstr*> FixConstantOperandsForInstr (Instruction* vmInstr,
134                                                    MachineInstr* minstr,
135                                                    TargetMachine& target);
136
137
138 //**************************************************************************/
139
140 #endif