1 //===-- llvm/CodeGen/InstrSelectionSupport.h --------------------*- C++ -*-===//
3 // Target-independent instruction selection code. See SparcInstrSelection.cpp
6 //===----------------------------------------------------------------------===//
8 #ifndef LLVM_CODEGEN_INSTR_SELECTION_SUPPORT_H
9 #define LLVM_CODEGEN_INSTR_SELECTION_SUPPORT_H
11 #include "llvm/CodeGen/MachineInstr.h"
12 #include "Support/DataTypes.h"
13 class InstructionNode;
17 //---------------------------------------------------------------------------
18 // Function GetConstantValueAsUnsignedInt
19 // Function GetConstantValueAsSignedInt
21 // Convenience functions to get the value of an integer constant, for an
22 // appropriate integer or non-integer type that can be held in a signed
23 // or unsigned integer respectively. The type of the argument must be
25 // Signed or unsigned integer
29 // isValidConstant is set to true if a valid constant was found.
30 //---------------------------------------------------------------------------
32 uint64_t GetConstantValueAsUnsignedInt (const Value *V,
33 bool &isValidConstant);
35 int64_t GetConstantValueAsSignedInt (const Value *V,
36 bool &isValidConstant);
39 //---------------------------------------------------------------------------
40 // Function: GetMemInstArgs
43 // Get the pointer value and the index vector for a memory operation
44 // (GetElementPtr, Load, or Store). If all indices of the given memory
45 // operation are constant, fold in constant indices in a chain of
46 // preceding GetElementPtr instructions (if any), and return the
47 // pointer value of the first instruction in the chain.
48 // All folded instructions are marked so no code is generated for them.
51 // Returns the pointer Value to use.
52 // Returns the resulting IndexVector in idxVec.
53 // Returns true/false in allConstantIndices if all indices are/aren't const.
54 //---------------------------------------------------------------------------
56 Value* GetMemInstArgs (InstructionNode* memInstrNode,
57 std::vector<Value*>& idxVec,
58 bool& allConstantIndices);
61 //---------------------------------------------------------------------------
62 // Function: ChooseRegOrImmed
66 //---------------------------------------------------------------------------
68 MachineOperand::MachineOperandType ChooseRegOrImmed(
71 const TargetMachine& targetMachine,
73 unsigned& getMachineRegNum,
74 int64_t& getImmedValue);
76 MachineOperand::MachineOperandType ChooseRegOrImmed(int64_t intValue,
79 const TargetMachine& target,
81 unsigned& getMachineRegNum,
82 int64_t& getImmedValue);
85 //---------------------------------------------------------------------------
86 // Function: FixConstantOperandsForInstr
89 // Special handling for constant operands of a machine instruction
90 // -- if the constant is 0, use the hardwired 0 register, if any;
91 // -- if the constant fits in the IMMEDIATE field, use that field;
92 // -- else create instructions to put the constant into a register, either
93 // directly or by loading explicitly from the constant pool.
95 // In the first 2 cases, the operand of `minstr' is modified in place.
96 // Returns a vector of machine instructions generated for operands that
97 // fall under case 3; these must be inserted before `minstr'.
98 //---------------------------------------------------------------------------
100 std::vector<MachineInstr*> FixConstantOperandsForInstr (Instruction* vmInstr,
101 MachineInstr* minstr,
102 TargetMachine& target);