FastISel.h revision 74af88a6661ad5185924bf39164fb4aa144d32cf
1b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman//===-- FastISel.h - Definition of the FastISel class ---------------------===// 2b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman// 3b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman// The LLVM Compiler Infrastructure 4b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman// 5b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman// This file is distributed under the University of Illinois Open Source 6b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman// License. See LICENSE.TXT for details. 7b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman// 8b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman//===----------------------------------------------------------------------===// 9b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman// 10b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman// This file defines the FastISel class. 112ce5bf188dfa4329eb246df6011dd1edde5a5979Owen Anderson// 12b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman//===----------------------------------------------------------------------===// 132ce5bf188dfa4329eb246df6011dd1edde5a5979Owen Anderson 14b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman#ifndef LLVM_CODEGEN_FASTISEL_H 15b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman#define LLVM_CODEGEN_FASTISEL_H 16b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman 17b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman#include "llvm/ADT/DenseMap.h" 18833ec1deed4568410e4fdfa0de9021d32c1479ffDan Gohman#include "llvm/CodeGen/ValueTypes.h" 1984023e0fbefc406a4c611d3d64a10df5d3a97dd7Dan Gohman#include "llvm/CodeGen/MachineBasicBlock.h" 20b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman 21b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohmannamespace llvm { 22b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman 230586d91bb3e516d5826826522d9a90ed6ef74d86Dan Gohmanclass AllocaInst; 2410df0fa73e396bbc93a8940e8b53827390c54d10Dan Gohmanclass ConstantFP; 25a4160c3434b08288d1f79f1acbe453d1b9610b22Dan Gohmanclass FunctionLoweringInfo; 26dd5b58ad7be78be90390074f0df138778af5c895Dan Gohmanclass Instruction; 27b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohmanclass MachineBasicBlock; 2895267a1e671efc3c14e916b6978bbb15973b4cdcOwen Andersonclass MachineConstantPool; 29b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohmanclass MachineFunction; 30f81eca0ab908fdcf98ae0efaa75acccc8ba40dc2Dan Gohmanclass MachineInstr; 310586d91bb3e516d5826826522d9a90ed6ef74d86Dan Gohmanclass MachineFrameInfo; 32bb466331e7e50d03497ce40ee344870236fd9c32Dan Gohmanclass MachineRegisterInfo; 3383785c80968165b30fcdd111ceb2c28d38bcff86Evan Chengclass TargetData; 34b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohmanclass TargetInstrInfo; 3583785c80968165b30fcdd111ceb2c28d38bcff86Evan Chengclass TargetLowering; 3622bb31103de3337f0bb74c7bee16d1817d4dca14Dan Gohmanclass TargetMachine; 37b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohmanclass TargetRegisterClass; 38db4971259ce94cea26e555e9ade82672a3581f5cDan Gohmanclass TargetRegisterInfo; 39beac75da3784929aee9f0357fc5cd76d49d6c3d7Chris Lattnerclass LoadInst; 40b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman 4140610241d00e219341ff4b7106c5baff08ad407bDan Gohman/// FastISel - This is a fast-path instruction selection class that 4240610241d00e219341ff4b7106c5baff08ad407bDan Gohman/// generates poor code and doesn't support illegal types or non-trivial 4340610241d00e219341ff4b7106c5baff08ad407bDan Gohman/// lowering, but runs quickly. 44b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohmanclass FastISel { 4522bb31103de3337f0bb74c7bee16d1817d4dca14Dan Gohmanprotected: 46104e4ce1629ea84736691bd1ee7867bdf90e8a2eDan Gohman DenseMap<const Value *, unsigned> LocalValueMap; 47a4160c3434b08288d1f79f1acbe453d1b9610b22Dan Gohman FunctionLoweringInfo &FuncInfo; 48bb466331e7e50d03497ce40ee344870236fd9c32Dan Gohman MachineRegisterInfo &MRI; 490586d91bb3e516d5826826522d9a90ed6ef74d86Dan Gohman MachineFrameInfo &MFI; 500586d91bb3e516d5826826522d9a90ed6ef74d86Dan Gohman MachineConstantPool &MCP; 519bc96a57206cbebaa9b0ba9979f949eb10c1592cBill Wendling DebugLoc DL; 5222bb31103de3337f0bb74c7bee16d1817d4dca14Dan Gohman const TargetMachine &TM; 5383785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng const TargetData &TD; 54bb466331e7e50d03497ce40ee344870236fd9c32Dan Gohman const TargetInstrInfo &TII; 5522bb31103de3337f0bb74c7bee16d1817d4dca14Dan Gohman const TargetLowering &TLI; 56db4971259ce94cea26e555e9ade82672a3581f5cDan Gohman const TargetRegisterInfo &TRI; 5774af88a6661ad5185924bf39164fb4aa144d32cfIvan Krasin 5874af88a6661ad5185924bf39164fb4aa144d32cfIvan Krasin /// The position of the last instruction for materializing constants 5974af88a6661ad5185924bf39164fb4aa144d32cfIvan Krasin /// for use in the current block. It resets to EmitStartPt when it 6074af88a6661ad5185924bf39164fb4aa144d32cfIvan Krasin /// makes sense (for example, it's usually profitable to avoid function 6174af88a6661ad5185924bf39164fb4aa144d32cfIvan Krasin /// calls between the definition and the use) 6284023e0fbefc406a4c611d3d64a10df5d3a97dd7Dan Gohman MachineInstr *LastLocalValue; 63b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman 6474af88a6661ad5185924bf39164fb4aa144d32cfIvan Krasin /// The top most instruction in the current block that is allowed for 6574af88a6661ad5185924bf39164fb4aa144d32cfIvan Krasin /// emitting local variables. LastLocalValue resets to EmitStartPt when 6674af88a6661ad5185924bf39164fb4aa144d32cfIvan Krasin /// it makes sense (for example, on function calls) 6774af88a6661ad5185924bf39164fb4aa144d32cfIvan Krasin MachineInstr *EmitStartPt; 6874af88a6661ad5185924bf39164fb4aa144d32cfIvan Krasin 69b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohmanpublic: 7084023e0fbefc406a4c611d3d64a10df5d3a97dd7Dan Gohman /// getLastLocalValue - Return the position of the last instruction 7184023e0fbefc406a4c611d3d64a10df5d3a97dd7Dan Gohman /// emitted for materializing constants for use in the current block. 7284023e0fbefc406a4c611d3d64a10df5d3a97dd7Dan Gohman MachineInstr *getLastLocalValue() { return LastLocalValue; } 7384023e0fbefc406a4c611d3d64a10df5d3a97dd7Dan Gohman 7484023e0fbefc406a4c611d3d64a10df5d3a97dd7Dan Gohman /// setLastLocalValue - Update the position of the last instruction 7584023e0fbefc406a4c611d3d64a10df5d3a97dd7Dan Gohman /// emitted for materializing constants for use in the current block. 7674af88a6661ad5185924bf39164fb4aa144d32cfIvan Krasin void setLastLocalValue(MachineInstr *I) { 7774af88a6661ad5185924bf39164fb4aa144d32cfIvan Krasin EmitStartPt = I; 7874af88a6661ad5185924bf39164fb4aa144d32cfIvan Krasin LastLocalValue = I; 7974af88a6661ad5185924bf39164fb4aa144d32cfIvan Krasin } 8084023e0fbefc406a4c611d3d64a10df5d3a97dd7Dan Gohman 819bc96a57206cbebaa9b0ba9979f949eb10c1592cBill Wendling /// startNewBlock - Set the current block to which generated machine 829bc96a57206cbebaa9b0ba9979f949eb10c1592cBill Wendling /// instructions will be appended, and clear the local CSE map. 83241f464d24a6c22721607841069bbeb17b3f71e6Dan Gohman /// 8484023e0fbefc406a4c611d3d64a10df5d3a97dd7Dan Gohman void startNewBlock(); 85241f464d24a6c22721607841069bbeb17b3f71e6Dan Gohman 86390f3ace34855a3d4c9e0adf468976375f8c6dc1Devang Patel /// getCurDebugLoc() - Return current debug location information. 87390f3ace34855a3d4c9e0adf468976375f8c6dc1Devang Patel DebugLoc getCurDebugLoc() const { return DL; } 88390f3ace34855a3d4c9e0adf468976375f8c6dc1Devang Patel 893df24e667f04a7003342b534310919abc9c87418Dan Gohman /// SelectInstruction - Do "fast" instruction selection for the given 903df24e667f04a7003342b534310919abc9c87418Dan Gohman /// LLVM IR instruction, and append generated machine instructions to 913df24e667f04a7003342b534310919abc9c87418Dan Gohman /// the current block. Return true if selection was successful. 923df24e667f04a7003342b534310919abc9c87418Dan Gohman /// 9346510a73e977273ec67747eb34cbdb43f815e451Dan Gohman bool SelectInstruction(const Instruction *I); 94b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman 95e2d0af4d7802a36e183897cc061747ba88819226Dan Gohman /// SelectOperator - Do "fast" instruction selection for the given 9640b189e4e257924d90aaf63bf2e12bc7bbca961aDan Gohman /// LLVM IR operator (Instruction or ConstantExpr), and append 9740b189e4e257924d90aaf63bf2e12bc7bbca961aDan Gohman /// generated machine instructions to the current block. Return true 9840b189e4e257924d90aaf63bf2e12bc7bbca961aDan Gohman /// if selection was successful. 9940b189e4e257924d90aaf63bf2e12bc7bbca961aDan Gohman /// 10046510a73e977273ec67747eb34cbdb43f815e451Dan Gohman bool SelectOperator(const User *I, unsigned Opcode); 10140b189e4e257924d90aaf63bf2e12bc7bbca961aDan Gohman 1023df24e667f04a7003342b534310919abc9c87418Dan Gohman /// getRegForValue - Create a virtual register and arrange for it to 1033df24e667f04a7003342b534310919abc9c87418Dan Gohman /// be assigned the value for the given LLVM value. 10446510a73e977273ec67747eb34cbdb43f815e451Dan Gohman unsigned getRegForValue(const Value *V); 10599b218218c0ca3ebfdd568ddfeafa07842e9d69dDan Gohman 10659fbc80f6b3b5c71dfb84149f589625f7ed510e3Evan Cheng /// lookUpRegForValue - Look up the value to see if its value is already 10759fbc80f6b3b5c71dfb84149f589625f7ed510e3Evan Cheng /// cached in a register. It may be defined by instructions across blocks or 10859fbc80f6b3b5c71dfb84149f589625f7ed510e3Evan Cheng /// defined locally. 10946510a73e977273ec67747eb34cbdb43f815e451Dan Gohman unsigned lookUpRegForValue(const Value *V); 11059fbc80f6b3b5c71dfb84149f589625f7ed510e3Evan Cheng 111c8a1a3c426209e9c7b35e279e1578a89edc40af6Dan Gohman /// getRegForGEPIndex - This is a wrapper around getRegForValue that also 112c8a1a3c426209e9c7b35e279e1578a89edc40af6Dan Gohman /// takes care of truncating or sign-extending the given getelementptr 113c8a1a3c426209e9c7b35e279e1578a89edc40af6Dan Gohman /// index value. 114a6cb641f48df20f6f79018569b519e5a32e897a2Dan Gohman std::pair<unsigned, bool> getRegForGEPIndex(const Value *V); 115c8a1a3c426209e9c7b35e279e1578a89edc40af6Dan Gohman 116beac75da3784929aee9f0357fc5cd76d49d6c3d7Chris Lattner /// TryToFoldLoad - The specified machine instr operand is a vreg, and that 117beac75da3784929aee9f0357fc5cd76d49d6c3d7Chris Lattner /// vreg is being provided by the specified load instruction. If possible, 118beac75da3784929aee9f0357fc5cd76d49d6c3d7Chris Lattner /// try to fold the load as an operand to the instruction, returning true if 119beac75da3784929aee9f0357fc5cd76d49d6c3d7Chris Lattner /// possible. 120beac75da3784929aee9f0357fc5cd76d49d6c3d7Chris Lattner virtual bool TryToFoldLoad(MachineInstr * /*MI*/, unsigned /*OpNo*/, 121beac75da3784929aee9f0357fc5cd76d49d6c3d7Chris Lattner const LoadInst * /*LI*/) { 122beac75da3784929aee9f0357fc5cd76d49d6c3d7Chris Lattner return false; 123beac75da3784929aee9f0357fc5cd76d49d6c3d7Chris Lattner } 1242ce5bf188dfa4329eb246df6011dd1edde5a5979Owen Anderson 125beac75da3784929aee9f0357fc5cd76d49d6c3d7Chris Lattner /// recomputeInsertPt - Reset InsertPt to prepare for inserting instructions 12684023e0fbefc406a4c611d3d64a10df5d3a97dd7Dan Gohman /// into the current block. 12784023e0fbefc406a4c611d3d64a10df5d3a97dd7Dan Gohman void recomputeInsertPt(); 12884023e0fbefc406a4c611d3d64a10df5d3a97dd7Dan Gohman 129a10b8494a50108482302f6f077d72fbc76d776edDan Gohman struct SavePoint { 130a10b8494a50108482302f6f077d72fbc76d776edDan Gohman MachineBasicBlock::iterator InsertPt; 131a10b8494a50108482302f6f077d72fbc76d776edDan Gohman DebugLoc DL; 132a10b8494a50108482302f6f077d72fbc76d776edDan Gohman }; 133a10b8494a50108482302f6f077d72fbc76d776edDan Gohman 13484023e0fbefc406a4c611d3d64a10df5d3a97dd7Dan Gohman /// enterLocalValueArea - Prepare InsertPt to begin inserting instructions 13584023e0fbefc406a4c611d3d64a10df5d3a97dd7Dan Gohman /// into the local value area and return the old insert position. 136a10b8494a50108482302f6f077d72fbc76d776edDan Gohman SavePoint enterLocalValueArea(); 13784023e0fbefc406a4c611d3d64a10df5d3a97dd7Dan Gohman 138a10b8494a50108482302f6f077d72fbc76d776edDan Gohman /// leaveLocalValueArea - Reset InsertPt to the given old insert position. 139a10b8494a50108482302f6f077d72fbc76d776edDan Gohman void leaveLocalValueArea(SavePoint Old); 14084023e0fbefc406a4c611d3d64a10df5d3a97dd7Dan Gohman 141cc8430f742b0f1e567292c8a776e94fc1c930b2aDan Gohman virtual ~FastISel(); 142cc8430f742b0f1e567292c8a776e94fc1c930b2aDan Gohman 143b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohmanprotected: 144a4160c3434b08288d1f79f1acbe453d1b9610b22Dan Gohman explicit FastISel(FunctionLoweringInfo &funcInfo); 145e285a74f7cf9dd3ccf4fe758576cf83301f8a43eDan Gohman 1466e3ff375474c4fd78feb0b8463eb273a23cb4404Dan Gohman /// TargetSelectInstruction - This method is called by target-independent 1476e3ff375474c4fd78feb0b8463eb273a23cb4404Dan Gohman /// code when the normal FastISel process fails to select an instruction. 1486e3ff375474c4fd78feb0b8463eb273a23cb4404Dan Gohman /// This gives targets a chance to emit code for anything that doesn't 1496e3ff375474c4fd78feb0b8463eb273a23cb4404Dan Gohman /// fit into FastISel's framework. It returns true if it was successful. 1506e3ff375474c4fd78feb0b8463eb273a23cb4404Dan Gohman /// 1516e3ff375474c4fd78feb0b8463eb273a23cb4404Dan Gohman virtual bool 15246510a73e977273ec67747eb34cbdb43f815e451Dan Gohman TargetSelectInstruction(const Instruction *I) = 0; 1536e3ff375474c4fd78feb0b8463eb273a23cb4404Dan Gohman 154bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman /// FastEmit_r - This method is called by target-independent code 155bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman /// to request that an instruction with the given type and opcode 156bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman /// be emitted. 157825b72b0571821bf2d378749f69d6c4cfb52d2f9Owen Anderson virtual unsigned FastEmit_(MVT VT, 158825b72b0571821bf2d378749f69d6c4cfb52d2f9Owen Anderson MVT RetVT, 1597c3ecb6838ef7a2ca306c0f3cd68022f0855ae71Dan Gohman unsigned Opcode); 160bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman 161bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman /// FastEmit_r - This method is called by target-independent code 162bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman /// to request that an instruction with the given type, opcode, and 163bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman /// register operand be emitted. 164bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman /// 165825b72b0571821bf2d378749f69d6c4cfb52d2f9Owen Anderson virtual unsigned FastEmit_r(MVT VT, 166825b72b0571821bf2d378749f69d6c4cfb52d2f9Owen Anderson MVT RetVT, 167a6cb641f48df20f6f79018569b519e5a32e897a2Dan Gohman unsigned Opcode, 168a6cb641f48df20f6f79018569b519e5a32e897a2Dan Gohman unsigned Op0, bool Op0IsKill); 169bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman 170bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman /// FastEmit_rr - This method is called by target-independent code 171bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman /// to request that an instruction with the given type, opcode, and 172bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman /// register operands be emitted. 173bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman /// 174825b72b0571821bf2d378749f69d6c4cfb52d2f9Owen Anderson virtual unsigned FastEmit_rr(MVT VT, 175825b72b0571821bf2d378749f69d6c4cfb52d2f9Owen Anderson MVT RetVT, 1767c3ecb6838ef7a2ca306c0f3cd68022f0855ae71Dan Gohman unsigned Opcode, 177a6cb641f48df20f6f79018569b519e5a32e897a2Dan Gohman unsigned Op0, bool Op0IsKill, 178a6cb641f48df20f6f79018569b519e5a32e897a2Dan Gohman unsigned Op1, bool Op1IsKill); 179b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman 18083785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng /// FastEmit_ri - This method is called by target-independent code 18183785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng /// to request that an instruction with the given type, opcode, and 18283785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng /// register and immediate operands be emitted. 18383785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng /// 184825b72b0571821bf2d378749f69d6c4cfb52d2f9Owen Anderson virtual unsigned FastEmit_ri(MVT VT, 185825b72b0571821bf2d378749f69d6c4cfb52d2f9Owen Anderson MVT RetVT, 1867c3ecb6838ef7a2ca306c0f3cd68022f0855ae71Dan Gohman unsigned Opcode, 187a6cb641f48df20f6f79018569b519e5a32e897a2Dan Gohman unsigned Op0, bool Op0IsKill, 188a6cb641f48df20f6f79018569b519e5a32e897a2Dan Gohman uint64_t Imm); 189d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman 19010df0fa73e396bbc93a8940e8b53827390c54d10Dan Gohman /// FastEmit_rf - This method is called by target-independent code 19110df0fa73e396bbc93a8940e8b53827390c54d10Dan Gohman /// to request that an instruction with the given type, opcode, and 19210df0fa73e396bbc93a8940e8b53827390c54d10Dan Gohman /// register and floating-point immediate operands be emitted. 19310df0fa73e396bbc93a8940e8b53827390c54d10Dan Gohman /// 194825b72b0571821bf2d378749f69d6c4cfb52d2f9Owen Anderson virtual unsigned FastEmit_rf(MVT VT, 195825b72b0571821bf2d378749f69d6c4cfb52d2f9Owen Anderson MVT RetVT, 1967c3ecb6838ef7a2ca306c0f3cd68022f0855ae71Dan Gohman unsigned Opcode, 197a6cb641f48df20f6f79018569b519e5a32e897a2Dan Gohman unsigned Op0, bool Op0IsKill, 198a6cb641f48df20f6f79018569b519e5a32e897a2Dan Gohman const ConstantFP *FPImm); 19910df0fa73e396bbc93a8940e8b53827390c54d10Dan Gohman 200d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman /// FastEmit_rri - This method is called by target-independent code 201d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman /// to request that an instruction with the given type, opcode, and 202d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman /// register and immediate operands be emitted. 203d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman /// 204825b72b0571821bf2d378749f69d6c4cfb52d2f9Owen Anderson virtual unsigned FastEmit_rri(MVT VT, 205825b72b0571821bf2d378749f69d6c4cfb52d2f9Owen Anderson MVT RetVT, 2067c3ecb6838ef7a2ca306c0f3cd68022f0855ae71Dan Gohman unsigned Opcode, 207a6cb641f48df20f6f79018569b519e5a32e897a2Dan Gohman unsigned Op0, bool Op0IsKill, 208a6cb641f48df20f6f79018569b519e5a32e897a2Dan Gohman unsigned Op1, bool Op1IsKill, 209a6cb641f48df20f6f79018569b519e5a32e897a2Dan Gohman uint64_t Imm); 21083785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng 21183785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng /// FastEmit_ri_ - This method is a wrapper of FastEmit_ri. It first tries 21283785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng /// to emit an instruction with an immediate operand using FastEmit_ri. 21383785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng /// If that fails, it materializes the immediate into a register and try 21483785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng /// FastEmit_rr instead. 215825b72b0571821bf2d378749f69d6c4cfb52d2f9Owen Anderson unsigned FastEmit_ri_(MVT VT, 2167c3ecb6838ef7a2ca306c0f3cd68022f0855ae71Dan Gohman unsigned Opcode, 217a6cb641f48df20f6f79018569b519e5a32e897a2Dan Gohman unsigned Op0, bool Op0IsKill, 218a6cb641f48df20f6f79018569b519e5a32e897a2Dan Gohman uint64_t Imm, MVT ImmType); 2192ce5bf188dfa4329eb246df6011dd1edde5a5979Owen Anderson 2206d0c25ec3a7ca822e68f73a4481eee43eb5c9485Owen Anderson /// FastEmit_i - This method is called by target-independent code 2216d0c25ec3a7ca822e68f73a4481eee43eb5c9485Owen Anderson /// to request that an instruction with the given type, opcode, and 2226d0c25ec3a7ca822e68f73a4481eee43eb5c9485Owen Anderson /// immediate operand be emitted. 223825b72b0571821bf2d378749f69d6c4cfb52d2f9Owen Anderson virtual unsigned FastEmit_i(MVT VT, 224825b72b0571821bf2d378749f69d6c4cfb52d2f9Owen Anderson MVT RetVT, 2257c3ecb6838ef7a2ca306c0f3cd68022f0855ae71Dan Gohman unsigned Opcode, 2266d0c25ec3a7ca822e68f73a4481eee43eb5c9485Owen Anderson uint64_t Imm); 22783785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng 22810df0fa73e396bbc93a8940e8b53827390c54d10Dan Gohman /// FastEmit_f - This method is called by target-independent code 22910df0fa73e396bbc93a8940e8b53827390c54d10Dan Gohman /// to request that an instruction with the given type, opcode, and 23010df0fa73e396bbc93a8940e8b53827390c54d10Dan Gohman /// floating-point immediate operand be emitted. 231825b72b0571821bf2d378749f69d6c4cfb52d2f9Owen Anderson virtual unsigned FastEmit_f(MVT VT, 232825b72b0571821bf2d378749f69d6c4cfb52d2f9Owen Anderson MVT RetVT, 2337c3ecb6838ef7a2ca306c0f3cd68022f0855ae71Dan Gohman unsigned Opcode, 23446510a73e977273ec67747eb34cbdb43f815e451Dan Gohman const ConstantFP *FPImm); 23510df0fa73e396bbc93a8940e8b53827390c54d10Dan Gohman 236bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman /// FastEmitInst_ - Emit a MachineInstr with no operands and a 237bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman /// result register in the given register class. 238bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman /// 239b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman unsigned FastEmitInst_(unsigned MachineInstOpcode, 240b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman const TargetRegisterClass *RC); 241bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman 242d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman /// FastEmitInst_r - Emit a MachineInstr with one register operand 243bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman /// and a result register in the given register class. 244bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman /// 245b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman unsigned FastEmitInst_r(unsigned MachineInstOpcode, 246b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman const TargetRegisterClass *RC, 247a6cb641f48df20f6f79018569b519e5a32e897a2Dan Gohman unsigned Op0, bool Op0IsKill); 248bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman 249d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman /// FastEmitInst_rr - Emit a MachineInstr with two register operands 250bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman /// and a result register in the given register class. 251bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman /// 252b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman unsigned FastEmitInst_rr(unsigned MachineInstOpcode, 253b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman const TargetRegisterClass *RC, 254a6cb641f48df20f6f79018569b519e5a32e897a2Dan Gohman unsigned Op0, bool Op0IsKill, 255a6cb641f48df20f6f79018569b519e5a32e897a2Dan Gohman unsigned Op1, bool Op1IsKill); 256bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman 257d71867a8f4b1ab6ab8cc8f5b1a732184ec5bad1bOwen Anderson /// FastEmitInst_rrr - Emit a MachineInstr with three register operands 258d71867a8f4b1ab6ab8cc8f5b1a732184ec5bad1bOwen Anderson /// and a result register in the given register class. 259d71867a8f4b1ab6ab8cc8f5b1a732184ec5bad1bOwen Anderson /// 260d71867a8f4b1ab6ab8cc8f5b1a732184ec5bad1bOwen Anderson unsigned FastEmitInst_rrr(unsigned MachineInstOpcode, 261d71867a8f4b1ab6ab8cc8f5b1a732184ec5bad1bOwen Anderson const TargetRegisterClass *RC, 262d71867a8f4b1ab6ab8cc8f5b1a732184ec5bad1bOwen Anderson unsigned Op0, bool Op0IsKill, 263d71867a8f4b1ab6ab8cc8f5b1a732184ec5bad1bOwen Anderson unsigned Op1, bool Op1IsKill, 264d71867a8f4b1ab6ab8cc8f5b1a732184ec5bad1bOwen Anderson unsigned Op2, bool Op2IsKill); 265d71867a8f4b1ab6ab8cc8f5b1a732184ec5bad1bOwen Anderson 2663728b4ad8bfb42171cc04bb01bc95302fa66810bEric Christopher /// FastEmitInst_ri - Emit a MachineInstr with a register operand, 2673728b4ad8bfb42171cc04bb01bc95302fa66810bEric Christopher /// an immediate, and a result register in the given register class. 268d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman /// 269d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman unsigned FastEmitInst_ri(unsigned MachineInstOpcode, 270d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman const TargetRegisterClass *RC, 271a6cb641f48df20f6f79018569b519e5a32e897a2Dan Gohman unsigned Op0, bool Op0IsKill, 272a6cb641f48df20f6f79018569b519e5a32e897a2Dan Gohman uint64_t Imm); 273d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman 2742ce5bf188dfa4329eb246df6011dd1edde5a5979Owen Anderson /// FastEmitInst_rii - Emit a MachineInstr with one register operand 2752ce5bf188dfa4329eb246df6011dd1edde5a5979Owen Anderson /// and two immediate operands. 2762ce5bf188dfa4329eb246df6011dd1edde5a5979Owen Anderson /// 2772ce5bf188dfa4329eb246df6011dd1edde5a5979Owen Anderson unsigned FastEmitInst_rii(unsigned MachineInstOpcode, 2782ce5bf188dfa4329eb246df6011dd1edde5a5979Owen Anderson const TargetRegisterClass *RC, 2792ce5bf188dfa4329eb246df6011dd1edde5a5979Owen Anderson unsigned Op0, bool Op0IsKill, 2802ce5bf188dfa4329eb246df6011dd1edde5a5979Owen Anderson uint64_t Imm1, uint64_t Imm2); 2812ce5bf188dfa4329eb246df6011dd1edde5a5979Owen Anderson 28210df0fa73e396bbc93a8940e8b53827390c54d10Dan Gohman /// FastEmitInst_rf - Emit a MachineInstr with two register operands 28310df0fa73e396bbc93a8940e8b53827390c54d10Dan Gohman /// and a result register in the given register class. 28410df0fa73e396bbc93a8940e8b53827390c54d10Dan Gohman /// 28510df0fa73e396bbc93a8940e8b53827390c54d10Dan Gohman unsigned FastEmitInst_rf(unsigned MachineInstOpcode, 28610df0fa73e396bbc93a8940e8b53827390c54d10Dan Gohman const TargetRegisterClass *RC, 287a6cb641f48df20f6f79018569b519e5a32e897a2Dan Gohman unsigned Op0, bool Op0IsKill, 288a6cb641f48df20f6f79018569b519e5a32e897a2Dan Gohman const ConstantFP *FPImm); 28910df0fa73e396bbc93a8940e8b53827390c54d10Dan Gohman 290d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman /// FastEmitInst_rri - Emit a MachineInstr with two register operands, 291d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman /// an immediate, and a result register in the given register class. 292d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman /// 293d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman unsigned FastEmitInst_rri(unsigned MachineInstOpcode, 294d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman const TargetRegisterClass *RC, 295a6cb641f48df20f6f79018569b519e5a32e897a2Dan Gohman unsigned Op0, bool Op0IsKill, 296a6cb641f48df20f6f79018569b519e5a32e897a2Dan Gohman unsigned Op1, bool Op1IsKill, 297a6cb641f48df20f6f79018569b519e5a32e897a2Dan Gohman uint64_t Imm); 2982ce5bf188dfa4329eb246df6011dd1edde5a5979Owen Anderson 2996d0c25ec3a7ca822e68f73a4481eee43eb5c9485Owen Anderson /// FastEmitInst_i - Emit a MachineInstr with a single immediate 3006d0c25ec3a7ca822e68f73a4481eee43eb5c9485Owen Anderson /// operand, and a result register in the given register class. 3016d0c25ec3a7ca822e68f73a4481eee43eb5c9485Owen Anderson unsigned FastEmitInst_i(unsigned MachineInstrOpcode, 3026d0c25ec3a7ca822e68f73a4481eee43eb5c9485Owen Anderson const TargetRegisterClass *RC, 3036d0c25ec3a7ca822e68f73a4481eee43eb5c9485Owen Anderson uint64_t Imm); 304d74ea775af55782e3b0d5b10fa7602f8822a2f72Owen Anderson 305d74ea775af55782e3b0d5b10fa7602f8822a2f72Owen Anderson /// FastEmitInst_ii - Emit a MachineInstr with a two immediate operands. 306d74ea775af55782e3b0d5b10fa7602f8822a2f72Owen Anderson unsigned FastEmitInst_ii(unsigned MachineInstrOpcode, 307d74ea775af55782e3b0d5b10fa7602f8822a2f72Owen Anderson const TargetRegisterClass *RC, 308d74ea775af55782e3b0d5b10fa7602f8822a2f72Owen Anderson uint64_t Imm1, uint64_t Imm2); 309d74ea775af55782e3b0d5b10fa7602f8822a2f72Owen Anderson 3108970f00deff00ffce1f35cf00883357e1582daa1Owen Anderson /// FastEmitInst_extractsubreg - Emit a MachineInstr for an extract_subreg 311536ab130ec95cbb7bf30530251dafa7dfecc8471Evan Cheng /// from a specified index of a superregister to a specified type. 312825b72b0571821bf2d378749f69d6c4cfb52d2f9Owen Anderson unsigned FastEmitInst_extractsubreg(MVT RetVT, 313a6cb641f48df20f6f79018569b519e5a32e897a2Dan Gohman unsigned Op0, bool Op0IsKill, 314a6cb641f48df20f6f79018569b519e5a32e897a2Dan Gohman uint32_t Idx); 3158970f00deff00ffce1f35cf00883357e1582daa1Owen Anderson 31614ea1ec2324cb595f2e035bbf54ddcd483f17c11Dan Gohman /// FastEmitZExtFromI1 - Emit MachineInstrs to compute the value of Op 31714ea1ec2324cb595f2e035bbf54ddcd483f17c11Dan Gohman /// with all but the least significant bit set to zero. 318825b72b0571821bf2d378749f69d6c4cfb52d2f9Owen Anderson unsigned FastEmitZExtFromI1(MVT VT, 319a6cb641f48df20f6f79018569b519e5a32e897a2Dan Gohman unsigned Op0, bool Op0IsKill); 32014ea1ec2324cb595f2e035bbf54ddcd483f17c11Dan Gohman 321d98d6203e429b2d7208b6687931e9079e85e95ecDan Gohman /// FastEmitBranch - Emit an unconditional branch to the given block, 322d98d6203e429b2d7208b6687931e9079e85e95ecDan Gohman /// unless it is the immediate (fall-through) successor, and update 323d98d6203e429b2d7208b6687931e9079e85e95ecDan Gohman /// the CFG. 3243bf912593301152b65accb9d9c37a95172f1df5aStuart Hastings void FastEmitBranch(MachineBasicBlock *MBB, DebugLoc DL); 325d98d6203e429b2d7208b6687931e9079e85e95ecDan Gohman 326482feb33b2bba677d47bab859d9e1e95d67016bdEli Friedman void UpdateValueMap(const Value* I, unsigned Reg, unsigned NumRegs = 1); 327ea09f4f4691a0db65772b54fe8163a48c9dce01dEvan Cheng 328c7f72de3b4ef21828ea4780f0693bf0acd04e1c5Dan Gohman unsigned createResultReg(const TargetRegisterClass *RC); 3292ce5bf188dfa4329eb246df6011dd1edde5a5979Owen Anderson 3302ce5bf188dfa4329eb246df6011dd1edde5a5979Owen Anderson /// TargetMaterializeConstant - Emit a constant in a register using 3319c7216f984111eb8f1716741bc9039ed86ec4a9bOwen Anderson /// target-specific logic, such as constant pool loads. 33246510a73e977273ec67747eb34cbdb43f815e451Dan Gohman virtual unsigned TargetMaterializeConstant(const Constant* C) { 3330586d91bb3e516d5826826522d9a90ed6ef74d86Dan Gohman return 0; 3340586d91bb3e516d5826826522d9a90ed6ef74d86Dan Gohman } 3350586d91bb3e516d5826826522d9a90ed6ef74d86Dan Gohman 3360586d91bb3e516d5826826522d9a90ed6ef74d86Dan Gohman /// TargetMaterializeAlloca - Emit an alloca address in a register using 3370586d91bb3e516d5826826522d9a90ed6ef74d86Dan Gohman /// target-specific logic. 33846510a73e977273ec67747eb34cbdb43f815e451Dan Gohman virtual unsigned TargetMaterializeAlloca(const AllocaInst* C) { 33995267a1e671efc3c14e916b6978bbb15973b4cdcOwen Anderson return 0; 34095267a1e671efc3c14e916b6978bbb15973b4cdcOwen Anderson } 341c7f72de3b4ef21828ea4780f0693bf0acd04e1c5Dan Gohman 3422790ba8e5a7bb6e00fdac9997d840598fb60271cEli Friedman virtual unsigned TargetMaterializeFloatZero(const ConstantFP* CF) { 3432790ba8e5a7bb6e00fdac9997d840598fb60271cEli Friedman return 0; 3442790ba8e5a7bb6e00fdac9997d840598fb60271cEli Friedman } 3452790ba8e5a7bb6e00fdac9997d840598fb60271cEli Friedman 346ea09f4f4691a0db65772b54fe8163a48c9dce01dEvan Chengprivate: 34746510a73e977273ec67747eb34cbdb43f815e451Dan Gohman bool SelectBinaryOp(const User *I, unsigned ISDOpcode); 348bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman 34946510a73e977273ec67747eb34cbdb43f815e451Dan Gohman bool SelectFNeg(const User *I); 3503d45a853db014fdddcdb79424e663dfed5eccbc7Dan Gohman 35146510a73e977273ec67747eb34cbdb43f815e451Dan Gohman bool SelectGetElementPtr(const User *I); 352763d89343be210eb62a13318ca0cc9321ce46bfbDan Gohman 35346510a73e977273ec67747eb34cbdb43f815e451Dan Gohman bool SelectCall(const User *I); 35433134c4a75558288d663267c8991f6bd37a530afDan Gohman 35546510a73e977273ec67747eb34cbdb43f815e451Dan Gohman bool SelectBitCast(const User *I); 3562ce5bf188dfa4329eb246df6011dd1edde5a5979Owen Anderson 35746510a73e977273ec67747eb34cbdb43f815e451Dan Gohman bool SelectCast(const User *I, unsigned Opcode); 358e8c92dd439581bec7e3516cbdbea74e2e60fe7f0Dan Gohman 3592586b8f9366aed5a1efa44d3f18d095511601642Eli Friedman bool SelectExtractValue(const User *I); 3602586b8f9366aed5a1efa44d3f18d095511601642Eli Friedman 361e8c92dd439581bec7e3516cbdbea74e2e60fe7f0Dan Gohman /// HandlePHINodesInSuccessorBlocks - Handle PHI nodes in successor blocks. 362e8c92dd439581bec7e3516cbdbea74e2e60fe7f0Dan Gohman /// Emit code to ensure constants are copied into registers when needed. 363e8c92dd439581bec7e3516cbdbea74e2e60fe7f0Dan Gohman /// Remember the virtual registers that need to be added to the Machine PHI 364e8c92dd439581bec7e3516cbdbea74e2e60fe7f0Dan Gohman /// nodes as input. We cannot just directly add them, because expansion 365e8c92dd439581bec7e3516cbdbea74e2e60fe7f0Dan Gohman /// might result in multiple MBB's for one BB. As such, the start of the 366e8c92dd439581bec7e3516cbdbea74e2e60fe7f0Dan Gohman /// BB might correspond to a different MBB than the end. 367e8c92dd439581bec7e3516cbdbea74e2e60fe7f0Dan Gohman bool HandlePHINodesInSuccessorBlocks(const BasicBlock *LLVMBB); 3681fdc614bee2a324fcc210d1e46d9b6fca3ca324bDan Gohman 3691fdc614bee2a324fcc210d1e46d9b6fca3ca324bDan Gohman /// materializeRegForValue - Helper for getRegForVale. This function is 3701fdc614bee2a324fcc210d1e46d9b6fca3ca324bDan Gohman /// called when the value isn't already available in a register and must 3711fdc614bee2a324fcc210d1e46d9b6fca3ca324bDan Gohman /// be materialized with new instructions. 3721fdc614bee2a324fcc210d1e46d9b6fca3ca324bDan Gohman unsigned materializeRegForValue(const Value *V, MVT VT); 373a6cb641f48df20f6f79018569b519e5a32e897a2Dan Gohman 37474af88a6661ad5185924bf39164fb4aa144d32cfIvan Krasin /// flushLocalValueMap - clears LocalValueMap and moves the area for the 37574af88a6661ad5185924bf39164fb4aa144d32cfIvan Krasin /// new local variables to the beginning of the block. It helps to avoid 37674af88a6661ad5185924bf39164fb4aa144d32cfIvan Krasin /// spilling cached variables across heavy instructions like calls. 37774af88a6661ad5185924bf39164fb4aa144d32cfIvan Krasin void flushLocalValueMap(); 37874af88a6661ad5185924bf39164fb4aa144d32cfIvan Krasin 379a6cb641f48df20f6f79018569b519e5a32e897a2Dan Gohman /// hasTrivialKill - Test whether the given value has exactly one use. 380a6cb641f48df20f6f79018569b519e5a32e897a2Dan Gohman bool hasTrivialKill(const Value *V) const; 381b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman}; 382b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman 383b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman} 384b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman 385b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman#endif 386