2001-07-21 12:39:03 +00:00
|
|
|
// $Id$ -*-c++-*-
|
|
|
|
//***************************************************************************
|
|
|
|
// File:
|
|
|
|
// InstrSelection.h
|
|
|
|
//
|
|
|
|
// Purpose:
|
2001-10-10 20:50:20 +00:00
|
|
|
// External interface to instruction selection.
|
|
|
|
//
|
2001-07-21 12:39:03 +00:00
|
|
|
// History:
|
|
|
|
// 7/02/01 - Vikram Adve - Created
|
2001-10-10 20:50:20 +00:00
|
|
|
//**************************************************************************/
|
2001-07-21 12:39:03 +00:00
|
|
|
|
|
|
|
#ifndef LLVM_CODEGEN_INSTR_SELECTION_H
|
|
|
|
#define LLVM_CODEGEN_INSTR_SELECTION_H
|
|
|
|
|
|
|
|
#include "llvm/Instruction.h"
|
2002-03-23 22:51:58 +00:00
|
|
|
class Function;
|
2001-07-21 12:39:03 +00:00
|
|
|
class InstrForest;
|
2001-07-22 04:40:02 +00:00
|
|
|
class MachineInstr;
|
|
|
|
class InstructionNode;
|
2001-07-23 03:09:03 +00:00
|
|
|
class TargetMachine;
|
2001-07-21 12:39:03 +00:00
|
|
|
|
2001-10-10 20:50:20 +00:00
|
|
|
/************************* Required Functions *******************************
|
|
|
|
* Target-dependent functions that MUST be implemented for each target.
|
|
|
|
***************************************************************************/
|
2001-07-21 12:39:03 +00:00
|
|
|
|
|
|
|
const unsigned MAX_INSTR_PER_VMINSTR = 8;
|
|
|
|
|
2002-03-18 03:20:46 +00:00
|
|
|
extern void GetInstructionsByRule (InstructionNode* subtreeRoot,
|
2001-07-21 12:39:03 +00:00
|
|
|
int ruleForNode,
|
|
|
|
short* nts,
|
2001-07-23 03:09:03 +00:00
|
|
|
TargetMachine &Target,
|
2002-03-18 03:20:46 +00:00
|
|
|
vector<MachineInstr*>& mvec);
|
2001-07-21 12:39:03 +00:00
|
|
|
|
2001-10-22 13:56:33 +00:00
|
|
|
extern unsigned GetInstructionsForProlog(BasicBlock* entryBB,
|
|
|
|
TargetMachine &Target,
|
|
|
|
MachineInstr** minstrVec);
|
|
|
|
|
|
|
|
extern unsigned GetInstructionsForEpilog(BasicBlock* anExitBB,
|
|
|
|
TargetMachine &Target,
|
|
|
|
MachineInstr** minstrVec);
|
|
|
|
|
2001-07-21 12:39:03 +00:00
|
|
|
extern bool ThisIsAChainRule (int eruleno);
|
|
|
|
|
|
|
|
|
2001-10-10 20:50:20 +00:00
|
|
|
//************************ Exported Functions ******************************/
|
2001-07-21 12:39:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
// Function: SelectInstructionsForMethod
|
|
|
|
//
|
|
|
|
// Purpose:
|
|
|
|
// Entry point for instruction selection using BURG.
|
|
|
|
// Returns true if instruction selection failed, false otherwise.
|
|
|
|
// Implemented in machine-specific instruction selection file.
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2002-03-23 22:51:58 +00:00
|
|
|
bool SelectInstructionsForMethod (Function* function,
|
2001-07-23 03:09:03 +00:00
|
|
|
TargetMachine &Target);
|
2001-07-21 12:39:03 +00:00
|
|
|
|
|
|
|
|
2001-10-10 20:50:20 +00:00
|
|
|
//************************ Exported Data Types *****************************/
|
2001-07-21 12:39:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
// class TmpInstruction
|
|
|
|
//
|
|
|
|
// This class represents temporary intermediate values
|
|
|
|
// used within the machine code for a VM instruction
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class TmpInstruction : public Instruction {
|
2002-02-03 07:07:16 +00:00
|
|
|
TmpInstruction(const TmpInstruction &TI)
|
|
|
|
: Instruction(TI.getType(), TI.getOpcode()) {
|
|
|
|
if (!TI.Operands.empty()) {
|
|
|
|
Operands.push_back(Use(TI.Operands[0], this));
|
|
|
|
if (TI.Operands.size() == 2)
|
|
|
|
Operands.push_back(Use(TI.Operands[1], this));
|
|
|
|
else
|
|
|
|
assert(0 && "Bad # operands to TmpInstruction!");
|
|
|
|
}
|
2001-07-21 12:39:03 +00:00
|
|
|
}
|
|
|
|
public:
|
2001-11-08 04:50:33 +00:00
|
|
|
// Constructor that uses the type of S1 as the type of the temporary.
|
|
|
|
// s1 must be a valid value. s2 may be NULL.
|
2002-02-03 07:07:16 +00:00
|
|
|
TmpInstruction(Value *s1, Value *s2 = 0, const std::string &name = "")
|
|
|
|
: Instruction(s1->getType(), Instruction::UserOp1, name) {
|
|
|
|
Operands.push_back(Use(s1, this)); // s1 must be nonnull
|
|
|
|
if (s2) {
|
|
|
|
Operands.push_back(Use(s2, this));
|
|
|
|
#if 0
|
|
|
|
assert(s2->getType() == getType() &&
|
|
|
|
"TmpInstruction operand types do not match!");
|
|
|
|
#endif
|
|
|
|
}
|
2001-11-08 04:50:33 +00:00
|
|
|
}
|
|
|
|
|
2002-02-03 07:07:16 +00:00
|
|
|
// Constructor that requires the type of the temporary to be specified.
|
2001-11-08 04:50:33 +00:00
|
|
|
// Both S1 and S2 may be NULL.
|
2002-02-03 07:07:16 +00:00
|
|
|
TmpInstruction(const Type *Ty, Value *s1 = 0, Value* s2 = 0,
|
|
|
|
const std::string &name = "")
|
|
|
|
: Instruction(Ty, Instruction::UserOp1, name) {
|
|
|
|
if (s1) { Operands.push_back(Use(s1, this)); /*assert(s1->getType() == Ty);*/ }
|
|
|
|
if (s2) { Operands.push_back(Use(s2, this)); /*assert(s2->getType() == Ty);*/ }
|
2001-07-21 12:39:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual Instruction *clone() const { return new TmpInstruction(*this); }
|
|
|
|
virtual const char *getOpcodeName() const {
|
2002-02-03 07:07:16 +00:00
|
|
|
return "TemporaryInstruction";
|
2001-11-08 04:50:33 +00:00
|
|
|
}
|
2001-07-21 12:39:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|