2 //***************************************************************************
4 // InstrSelectionSupport.h
7 // Target-independent instruction selection code.
8 // See SparcInstrSelection.cpp for usage.
11 // 10/10/01 - Vikram Adve - Created
12 //**************************************************************************/
14 #ifndef LLVM_CODEGEN_INSTR_SELECTION_SUPPORT_H
15 #define LLVM_CODEGEN_INSTR_SELECTION_SUPPORT_H
17 #include "llvm/Instruction.h"
18 #include "llvm/CodeGen/MachineInstr.h"
22 class InstructionNode;
27 //************************ Exported Functions ******************************/
30 //---------------------------------------------------------------------------
31 // Function GetConstantValueAsSignedInt
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
40 // isValidConstant is set to true if a valid constant was found.
41 //---------------------------------------------------------------------------
43 int64_t GetConstantValueAsSignedInt (const Value *V,
44 bool &isValidConstant);
47 //---------------------------------------------------------------------------
48 // Function: FoldGetElemChain
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 //---------------------------------------------------------------------------
56 Value* FoldGetElemChain (const InstructionNode* getElemInstrNode,
57 vector<ConstPoolVal*>& chainIdxVec);
60 //------------------------------------------------------------------------
61 // Function Set2OperandsFromInstr
62 // Function Set3OperandsFromInstr
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
70 // Check whether the second operand should use an immediate field or register.
71 // (First and third operands are never immediates for such instructions.)
74 // canDiscardResult: Specifies that the result operand can be discarded
75 // by using the dedicated "0"
77 // op1position, op2position and resultPosition: Specify in which position
78 // in the machine instruction the 3 operands (arg1, arg2
79 // and result) should go.
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 //------------------------------------------------------------------------
86 void Set2OperandsFromInstr (MachineInstr* minstr,
87 InstructionNode* vmInstrNode,
88 const TargetMachine& targetMachine,
89 bool canDiscardResult = false,
91 int resultPosition = 1);
93 void Set3OperandsFromInstr (MachineInstr* minstr,
94 InstructionNode* vmInstrNode,
95 const TargetMachine& targetMachine,
96 bool canDiscardResult = false,
99 int resultPosition = 2);
102 //---------------------------------------------------------------------------
103 // Function: ChooseRegOrImmed
107 //---------------------------------------------------------------------------
109 MachineOperand::MachineOperandType
110 ChooseRegOrImmed (Value* val,
111 MachineOpCode opCode,
112 const TargetMachine& targetMachine,
114 unsigned int& getMachineRegNum,
115 int64_t& getImmedValue);
118 //---------------------------------------------------------------------------
119 // Function: FixConstantOperandsForInstr
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.
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 //---------------------------------------------------------------------------
133 vector<MachineInstr*> FixConstantOperandsForInstr (Instruction* vmInstr,
134 MachineInstr* minstr,
135 TargetMachine& target);
138 //**************************************************************************/