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;
24 /************************* Required Functions *******************************
25 * Target-dependent functions that MUST be implemented for each target.
26 ***************************************************************************/
28 const unsigned MAX_INSTR_PER_VMINSTR = 8;
30 extern unsigned GetInstructionsByRule (InstructionNode* subtreeRoot,
33 TargetMachine &Target,
34 MachineInstr** minstrVec);
36 extern unsigned GetInstructionsForProlog(BasicBlock* entryBB,
37 TargetMachine &Target,
38 MachineInstr** minstrVec);
40 extern unsigned GetInstructionsForEpilog(BasicBlock* anExitBB,
41 TargetMachine &Target,
42 MachineInstr** minstrVec);
44 extern bool ThisIsAChainRule (int eruleno);
47 //************************ Exported Functions ******************************/
50 //---------------------------------------------------------------------------
51 // Function: SelectInstructionsForMethod
54 // Entry point for instruction selection using BURG.
55 // Returns true if instruction selection failed, false otherwise.
56 // Implemented in machine-specific instruction selection file.
57 //---------------------------------------------------------------------------
59 bool SelectInstructionsForMethod (Method* method,
60 TargetMachine &Target);
63 //************************ Exported Data Types *****************************/
66 //---------------------------------------------------------------------------
67 // class TmpInstruction
69 // This class represents temporary intermediate values
70 // used within the machine code for a VM instruction
71 //---------------------------------------------------------------------------
73 class TmpInstruction : public Instruction {
74 TmpInstruction(const TmpInstruction &TI)
75 : Instruction(TI.getType(), TI.getOpcode()) {
76 if (!TI.Operands.empty()) {
77 Operands.push_back(Use(TI.Operands[0], this));
78 if (TI.Operands.size() == 2)
79 Operands.push_back(Use(TI.Operands[1], this));
81 assert(0 && "Bad # operands to TmpInstruction!");
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(Value *s1, Value *s2 = 0, const std::string &name = "")
88 : Instruction(s1->getType(), Instruction::UserOp1, name) {
89 Operands.push_back(Use(s1, this)); // s1 must be nonnull
91 Operands.push_back(Use(s2, this));
93 assert(s2->getType() == getType() &&
94 "TmpInstruction operand types do not match!");
99 // Constructor that requires the type of the temporary to be specified.
100 // Both S1 and S2 may be NULL.
101 TmpInstruction(const Type *Ty, Value *s1 = 0, Value* s2 = 0,
102 const std::string &name = "")
103 : Instruction(Ty, Instruction::UserOp1, name) {
104 if (s1) { Operands.push_back(Use(s1, this)); /*assert(s1->getType() == Ty);*/ }
105 if (s2) { Operands.push_back(Use(s2, this)); /*assert(s2->getType() == Ty);*/ }
108 virtual Instruction *clone() const { return new TmpInstruction(*this); }
109 virtual const char *getOpcodeName() const {
110 return "TemporaryInstruction";