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;
25 /************************* Required Functions *******************************
26 * Target-dependent functions that MUST be implemented for each target.
27 ***************************************************************************/
29 const unsigned MAX_INSTR_PER_VMINSTR = 8;
31 const Instruction::OtherOps TMP_INSTRUCTION_OPCODE = Instruction::UserOp1;
33 extern unsigned GetInstructionsByRule (InstructionNode* subtreeRoot,
36 TargetMachine &Target,
37 MachineInstr** minstrVec);
39 extern unsigned GetInstructionsForProlog(BasicBlock* entryBB,
40 TargetMachine &Target,
41 MachineInstr** minstrVec);
43 extern unsigned GetInstructionsForEpilog(BasicBlock* anExitBB,
44 TargetMachine &Target,
45 MachineInstr** minstrVec);
47 extern bool ThisIsAChainRule (int eruleno);
50 //************************ Exported Functions ******************************/
53 //---------------------------------------------------------------------------
54 // Function: SelectInstructionsForMethod
57 // Entry point for instruction selection using BURG.
58 // Returns true if instruction selection failed, false otherwise.
59 // Implemented in machine-specific instruction selection file.
60 //---------------------------------------------------------------------------
62 bool SelectInstructionsForMethod (Method* method,
63 TargetMachine &Target);
66 //************************ Exported Data Types *****************************/
69 //---------------------------------------------------------------------------
70 // class TmpInstruction
72 // This class represents temporary intermediate values
73 // used within the machine code for a VM instruction
74 //---------------------------------------------------------------------------
76 class TmpInstruction : public Instruction {
77 TmpInstruction (const TmpInstruction &ci)
78 : Instruction(ci.getType(), ci.getOpcode())
81 Operands.push_back(Use(Operands[0], this));
82 Operands.push_back(Use(Operands[1], this));
85 // Constructor that uses the type of S1 as the type of the temporary.
86 // s1 must be a valid value. s2 may be NULL.
87 TmpInstruction(OtherOps opcode, Value *s1, Value* s2, const string &name="")
88 : Instruction(s1->getType(), opcode, name)
90 assert(s1 != NULL && "Use different constructor if both operands are 0");
91 Initialize(opcode, s1, s2);
94 // Constructor that allows the type of the temporary to be specified.
95 // Both S1 and S2 may be NULL.
96 TmpInstruction(OtherOps opcode, const Type* tmpType,
97 Value *s1, Value* s2, const string &name = "")
98 : Instruction(tmpType, opcode, name)
100 Initialize(opcode, s1, s2);
103 virtual Instruction *clone() const { return new TmpInstruction(*this); }
104 virtual const char *getOpcodeName() const {
109 void Initialize(OtherOps opcode, Value *s1, Value* s2) {
110 assert(opcode==TMP_INSTRUCTION_OPCODE && "Tmp instruction opcode invalid");
111 Operands.reserve(s1 && s2? 2 : ((s1 || s2)? 1 : 0));
113 Operands.push_back(Use(s1, this));
115 Operands.push_back(Use(s2, this));
119 //**************************************************************************/