2 //***************************************************************************
7 // External interface to instruction selection.
10 // 7/02/01 - Vikram Adve - Created
11 //**************************************************************************/
13 #ifndef LLVM_CODEGEN_INSTR_SELECTION_H
14 #define LLVM_CODEGEN_INSTR_SELECTION_H
16 #include "llvm/Instruction.h"
20 class InstructionNode;
23 /************************* Required Functions *******************************
24 * Target-dependent functions that MUST be implemented for each target.
25 ***************************************************************************/
27 const unsigned MAX_INSTR_PER_VMINSTR = 8;
29 extern void GetInstructionsByRule (InstructionNode* subtreeRoot,
32 TargetMachine &Target,
33 vector<MachineInstr*>& mvec);
35 extern unsigned GetInstructionsForProlog(BasicBlock* entryBB,
36 TargetMachine &Target,
37 MachineInstr** minstrVec);
39 extern unsigned GetInstructionsForEpilog(BasicBlock* anExitBB,
40 TargetMachine &Target,
41 MachineInstr** minstrVec);
43 extern bool ThisIsAChainRule (int eruleno);
46 //************************ Exported Functions ******************************/
49 //---------------------------------------------------------------------------
50 // Function: SelectInstructionsForMethod
53 // Entry point for instruction selection using BURG.
54 // Returns true if instruction selection failed, false otherwise.
55 // Implemented in machine-specific instruction selection file.
56 //---------------------------------------------------------------------------
58 bool SelectInstructionsForMethod (Function* function,
59 TargetMachine &Target);
62 //************************ Exported Data Types *****************************/
65 //---------------------------------------------------------------------------
66 // class TmpInstruction
68 // This class represents temporary intermediate values
69 // used within the machine code for a VM instruction
70 //---------------------------------------------------------------------------
72 class TmpInstruction : public Instruction {
73 TmpInstruction(const TmpInstruction &TI)
74 : Instruction(TI.getType(), TI.getOpcode()) {
75 if (!TI.Operands.empty()) {
76 Operands.push_back(Use(TI.Operands[0], this));
77 if (TI.Operands.size() == 2)
78 Operands.push_back(Use(TI.Operands[1], this));
80 assert(0 && "Bad # operands to TmpInstruction!");
84 // Constructor that uses the type of S1 as the type of the temporary.
85 // s1 must be a valid value. s2 may be NULL.
86 TmpInstruction(Value *s1, Value *s2 = 0, const std::string &name = "")
87 : Instruction(s1->getType(), Instruction::UserOp1, name) {
88 Operands.push_back(Use(s1, this)); // s1 must be nonnull
90 Operands.push_back(Use(s2, this));
94 // Constructor that requires the type of the temporary to be specified.
95 // Both S1 and S2 may be NULL.
96 TmpInstruction(const Type *Ty, Value *s1 = 0, Value* s2 = 0,
97 const std::string &name = "")
98 : Instruction(Ty, Instruction::UserOp1, name) {
99 if (s1) { Operands.push_back(Use(s1, this)); }
100 if (s2) { Operands.push_back(Use(s2, this)); }
103 virtual Instruction *clone() const { return new TmpInstruction(*this); }
104 virtual const char *getOpcodeName() const {
105 return "TempValueForMachineInstr";
108 // Methods for support type inquiry through isa, cast, and dyn_cast:
109 static inline bool classof(const TmpInstruction *) { return true; }
110 static inline bool classof(const Instruction *I) {
111 return (I->getOpcode() == Instruction::UserOp1);
113 static inline bool classof(const Value *V) {
114 return isa<Instruction>(V) && classof(cast<Instruction>(V));