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;
28 //---------------------------------------------------------------------------
29 // Function GetConstantValueAsSignedInt
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
38 // isValidConstant is set to true if a valid constant was found.
39 //---------------------------------------------------------------------------
41 int64_t GetConstantValueAsSignedInt (const Value *V,
42 bool &isValidConstant);
45 //---------------------------------------------------------------------------
46 // Function: FoldGetElemChain
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 //---------------------------------------------------------------------------
54 Value* FoldGetElemChain (const InstructionNode* getElemInstrNode,
55 std::vector<Value*>& chainIdxVec);
58 //------------------------------------------------------------------------
59 // Function Set2OperandsFromInstr
60 // Function Set3OperandsFromInstr
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
68 // Check whether the second operand should use an immediate field or register.
69 // (First and third operands are never immediates for such instructions.)
72 // canDiscardResult: Specifies that the result operand can be discarded
73 // by using the dedicated "0"
75 // op1position, op2position and resultPosition: Specify in which position
76 // in the machine instruction the 3 operands (arg1, arg2
77 // and result) should go.
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 //------------------------------------------------------------------------
84 void Set2OperandsFromInstr (MachineInstr* minstr,
85 InstructionNode* vmInstrNode,
86 const TargetMachine& targetMachine,
87 bool canDiscardResult = false,
89 int resultPosition = 1);
91 void Set3OperandsFromInstr (MachineInstr* minstr,
92 InstructionNode* vmInstrNode,
93 const TargetMachine& targetMachine,
94 bool canDiscardResult = false,
97 int resultPosition = 2);
100 //---------------------------------------------------------------------------
101 // Function: ChooseRegOrImmed
105 //---------------------------------------------------------------------------
107 MachineOperand::MachineOperandType
108 ChooseRegOrImmed (Value* val,
109 MachineOpCode opCode,
110 const TargetMachine& targetMachine,
112 unsigned int& getMachineRegNum,
113 int64_t& getImmedValue);
116 //---------------------------------------------------------------------------
117 // Function: FixConstantOperandsForInstr
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.
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 //---------------------------------------------------------------------------
131 std::vector<MachineInstr*> FixConstantOperandsForInstr (Instruction* vmInstr,
132 MachineInstr* minstr,
133 TargetMachine& target);