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 (Method* method,
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));
92 assert(s2->getType() == getType() &&
93 "TmpInstruction operand types do not match!");
98 // Constructor that requires the type of the temporary to be specified.
99 // Both S1 and S2 may be NULL.
100 TmpInstruction(const Type *Ty, Value *s1 = 0, Value* s2 = 0,
101 const std::string &name = "")
102 : Instruction(Ty, Instruction::UserOp1, name) {
103 if (s1) { Operands.push_back(Use(s1, this)); /*assert(s1->getType() == Ty);*/ }
104 if (s2) { Operands.push_back(Use(s2, this)); /*assert(s2->getType() == Ty);*/ }
107 virtual Instruction *clone() const { return new TmpInstruction(*this); }
108 virtual const char *getOpcodeName() const {
109 return "TemporaryInstruction";