2002-07-30 03:57:36 +00:00
|
|
|
//===- InstrSelection.cpp - Machine Independant Inst Selection Driver -----===//
|
|
|
|
//
|
|
|
|
// Machine-independent driver file for instruction selection. This file
|
|
|
|
// constructs a forest of BURG instruction trees and then uses the
|
|
|
|
// BURG-generated tree grammar (BURM) to find the optimal instruction sequences
|
|
|
|
// for a given machine.
|
2001-07-21 12:41:50 +00:00
|
|
|
//
|
2002-07-30 03:57:36 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2001-07-21 12:41:50 +00:00
|
|
|
|
2001-09-07 17:15:18 +00:00
|
|
|
#include "llvm/CodeGen/InstrSelection.h"
|
2001-10-17 23:57:50 +00:00
|
|
|
#include "llvm/CodeGen/InstrSelectionSupport.h"
|
2002-02-03 07:33:46 +00:00
|
|
|
#include "llvm/CodeGen/InstrForest.h"
|
|
|
|
#include "llvm/CodeGen/MachineCodeForInstruction.h"
|
2002-10-28 00:28:31 +00:00
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
2002-12-29 03:13:05 +00:00
|
|
|
#include "llvm/Target/TargetRegInfo.h"
|
2002-02-03 07:33:46 +00:00
|
|
|
#include "llvm/Target/TargetMachine.h"
|
2002-04-07 20:49:59 +00:00
|
|
|
#include "llvm/Function.h"
|
2001-12-03 18:02:31 +00:00
|
|
|
#include "llvm/iPHINode.h"
|
2002-07-30 03:57:36 +00:00
|
|
|
#include "llvm/Pass.h"
|
2001-11-27 00:03:19 +00:00
|
|
|
#include "Support/CommandLine.h"
|
2002-09-08 21:08:43 +00:00
|
|
|
#include "Support/LeakDetector.h"
|
2002-06-25 20:55:50 +00:00
|
|
|
using std::vector;
|
2001-07-21 12:41:50 +00:00
|
|
|
|
2003-01-15 19:47:53 +00:00
|
|
|
std::vector<MachineInstr*>
|
|
|
|
FixConstantOperandsForInstr(Instruction* vmInstr, MachineInstr* minstr,
|
|
|
|
TargetMachine& target);
|
|
|
|
|
2002-07-30 03:57:36 +00:00
|
|
|
namespace {
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// SelectDebugLevel - Allow command line control over debugging.
|
|
|
|
//
|
|
|
|
enum SelectDebugLevel_t {
|
|
|
|
Select_NoDebugInfo,
|
|
|
|
Select_PrintMachineCode,
|
|
|
|
Select_DebugInstTrees,
|
|
|
|
Select_DebugBurgTrees,
|
|
|
|
};
|
|
|
|
|
|
|
|
// Enable Debug Options to be specified on the command line
|
|
|
|
cl::opt<SelectDebugLevel_t>
|
|
|
|
SelectDebugLevel("dselect", cl::Hidden,
|
|
|
|
cl::desc("enable instruction selection debug information"),
|
|
|
|
cl::values(
|
|
|
|
clEnumValN(Select_NoDebugInfo, "n", "disable debug output"),
|
|
|
|
clEnumValN(Select_PrintMachineCode, "y", "print generated machine code"),
|
|
|
|
clEnumValN(Select_DebugInstTrees, "i",
|
|
|
|
"print debugging info for instruction selection"),
|
|
|
|
clEnumValN(Select_DebugBurgTrees, "b", "print burg trees"),
|
|
|
|
0));
|
|
|
|
|
|
|
|
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// InstructionSelection Pass
|
|
|
|
//
|
|
|
|
// This is the actual pass object that drives the instruction selection
|
|
|
|
// process.
|
|
|
|
//
|
|
|
|
class InstructionSelection : public FunctionPass {
|
|
|
|
TargetMachine &Target;
|
|
|
|
void InsertCodeForPhis(Function &F);
|
|
|
|
void InsertPhiElimInstructions(BasicBlock *BB,
|
2002-08-09 20:05:34 +00:00
|
|
|
const vector<MachineInstr*>& CpVec);
|
2002-07-30 03:57:36 +00:00
|
|
|
void SelectInstructionsForTree(InstrTreeNode* treeRoot, int goalnt);
|
|
|
|
void PostprocessMachineCodeForTree(InstructionNode* instrNode,
|
|
|
|
int ruleForNode, short* nts);
|
|
|
|
public:
|
|
|
|
InstructionSelection(TargetMachine &T) : Target(T) {}
|
2002-10-23 03:30:47 +00:00
|
|
|
|
|
|
|
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
|
|
|
AU.setPreservesCFG();
|
|
|
|
}
|
2002-07-30 03:57:36 +00:00
|
|
|
|
|
|
|
bool runOnFunction(Function &F);
|
|
|
|
};
|
|
|
|
}
|
2001-10-22 13:51:09 +00:00
|
|
|
|
2002-07-30 03:57:36 +00:00
|
|
|
// Register the pass...
|
|
|
|
static RegisterLLC<InstructionSelection>
|
|
|
|
X("instselect", "Instruction Selection", createInstructionSelectionPass);
|
2001-07-21 12:41:50 +00:00
|
|
|
|
2003-05-31 07:41:24 +00:00
|
|
|
TmpInstruction::TmpInstruction(MachineCodeForInstruction& mcfi,
|
|
|
|
Value *s1, Value *s2, const std::string &name)
|
|
|
|
: Instruction(s1->getType(), Instruction::UserOp1, name)
|
|
|
|
{
|
|
|
|
mcfi.addTemp(this);
|
|
|
|
|
2002-09-08 21:08:43 +00:00
|
|
|
Operands.push_back(Use(s1, this)); // s1 must be nonnull
|
|
|
|
if (s2) {
|
|
|
|
Operands.push_back(Use(s2, this));
|
|
|
|
}
|
|
|
|
|
|
|
|
// TmpInstructions should not be garbage checked.
|
|
|
|
LeakDetector::removeGarbageObject(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Constructor that requires the type of the temporary to be specified.
|
|
|
|
// Both S1 and S2 may be NULL.(
|
2003-05-31 07:41:24 +00:00
|
|
|
TmpInstruction::TmpInstruction(MachineCodeForInstruction& mcfi,
|
|
|
|
const Type *Ty, Value *s1, Value* s2,
|
2002-09-08 21:08:43 +00:00
|
|
|
const std::string &name)
|
2003-05-31 07:41:24 +00:00
|
|
|
: Instruction(Ty, Instruction::UserOp1, name)
|
|
|
|
{
|
|
|
|
mcfi.addTemp(this);
|
|
|
|
|
2002-09-08 21:08:43 +00:00
|
|
|
if (s1) { Operands.push_back(Use(s1, this)); }
|
|
|
|
if (s2) { Operands.push_back(Use(s2, this)); }
|
|
|
|
|
|
|
|
// TmpInstructions should not be garbage checked.
|
|
|
|
LeakDetector::removeGarbageObject(this);
|
|
|
|
}
|
|
|
|
|
2001-07-21 12:41:50 +00:00
|
|
|
|
2002-07-30 03:57:36 +00:00
|
|
|
bool InstructionSelection::runOnFunction(Function &F)
|
2001-09-18 12:56:28 +00:00
|
|
|
{
|
2001-08-28 23:04:38 +00:00
|
|
|
//
|
|
|
|
// Build the instruction trees to be given as inputs to BURG.
|
|
|
|
//
|
2002-07-30 03:57:36 +00:00
|
|
|
InstrForest instrForest(&F);
|
2001-08-28 23:04:38 +00:00
|
|
|
|
|
|
|
if (SelectDebugLevel >= Select_DebugInstTrees)
|
|
|
|
{
|
2003-01-15 19:47:53 +00:00
|
|
|
std::cerr << "\n\n*** Input to instruction selection for function "
|
|
|
|
<< F.getName() << "\n\n" << F
|
|
|
|
<< "\n\n*** Instruction trees for function "
|
|
|
|
<< F.getName() << "\n\n";
|
2001-08-28 23:04:38 +00:00
|
|
|
instrForest.dump();
|
|
|
|
}
|
2001-07-21 12:41:50 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Invoke BURG instruction selection for each tree
|
|
|
|
//
|
2002-03-24 03:36:52 +00:00
|
|
|
for (InstrForest::const_root_iterator RI = instrForest.roots_begin();
|
|
|
|
RI != instrForest.roots_end(); ++RI)
|
2001-09-18 12:56:28 +00:00
|
|
|
{
|
2002-03-24 03:36:52 +00:00
|
|
|
InstructionNode* basicNode = *RI;
|
|
|
|
assert(basicNode->parent() == NULL && "A `root' node has a parent?");
|
2001-07-21 12:41:50 +00:00
|
|
|
|
2001-09-18 12:56:28 +00:00
|
|
|
// Invoke BURM to label each tree node with a state
|
|
|
|
burm_label(basicNode);
|
2001-07-21 12:41:50 +00:00
|
|
|
|
2001-09-18 12:56:28 +00:00
|
|
|
if (SelectDebugLevel >= Select_DebugBurgTrees)
|
|
|
|
{
|
|
|
|
printcover(basicNode, 1, 0);
|
2003-01-15 19:47:53 +00:00
|
|
|
std::cerr << "\nCover cost == " << treecost(basicNode, 1, 0) <<"\n\n";
|
2001-09-18 12:56:28 +00:00
|
|
|
printMatches(basicNode);
|
|
|
|
}
|
2001-07-21 12:41:50 +00:00
|
|
|
|
2001-09-18 12:56:28 +00:00
|
|
|
// Then recursively walk the tree to select instructions
|
2002-07-30 03:57:36 +00:00
|
|
|
SelectInstructionsForTree(basicNode, /*goalnt*/1);
|
2001-07-21 12:41:50 +00:00
|
|
|
}
|
|
|
|
|
2001-07-30 18:48:43 +00:00
|
|
|
//
|
2002-10-28 05:30:46 +00:00
|
|
|
// Create the MachineBasicBlock records and add all of the MachineInstrs
|
|
|
|
// defined in the MachineCodeForInstruction objects to also live in the
|
|
|
|
// MachineBasicBlock objects.
|
2001-07-30 18:48:43 +00:00
|
|
|
//
|
2002-10-28 05:30:46 +00:00
|
|
|
MachineFunction &MF = MachineFunction::get(&F);
|
|
|
|
for (Function::iterator BI = F.begin(), BE = F.end(); BI != BE; ++BI) {
|
|
|
|
MachineBasicBlock *MCBB = new MachineBasicBlock(BI);
|
|
|
|
MF.getBasicBlockList().push_back(MCBB);
|
|
|
|
|
2002-06-25 16:13:21 +00:00
|
|
|
for (BasicBlock::iterator II = BI->begin(); II != BI->end(); ++II) {
|
2002-07-30 03:57:36 +00:00
|
|
|
MachineCodeForInstruction &mvec = MachineCodeForInstruction::get(II);
|
2002-10-28 05:30:46 +00:00
|
|
|
MCBB->insert(MCBB->end(), mvec.begin(), mvec.end());
|
2001-07-30 18:48:43 +00:00
|
|
|
}
|
2002-10-28 05:30:46 +00:00
|
|
|
}
|
2001-11-12 14:44:50 +00:00
|
|
|
|
2002-07-30 03:57:36 +00:00
|
|
|
// Insert phi elimination code
|
|
|
|
InsertCodeForPhis(F);
|
2001-07-30 18:48:43 +00:00
|
|
|
|
2001-09-18 12:56:28 +00:00
|
|
|
if (SelectDebugLevel >= Select_PrintMachineCode)
|
|
|
|
{
|
2003-01-15 19:47:53 +00:00
|
|
|
std::cerr << "\n*** Machine instructions after INSTRUCTION SELECTION\n";
|
2002-10-28 00:28:31 +00:00
|
|
|
MachineFunction::get(&F).dump();
|
2001-09-18 12:56:28 +00:00
|
|
|
}
|
2001-08-28 23:04:38 +00:00
|
|
|
|
2002-07-30 03:57:36 +00:00
|
|
|
return true;
|
2001-11-12 14:44:50 +00:00
|
|
|
}
|
|
|
|
|
2001-11-15 00:27:14 +00:00
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
// This method inserts phi elimination code for all BBs in a method
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
2002-03-18 03:31:54 +00:00
|
|
|
void
|
2002-07-30 03:57:36 +00:00
|
|
|
InstructionSelection::InsertCodeForPhis(Function &F)
|
2002-03-18 03:31:54 +00:00
|
|
|
{
|
2002-04-07 20:49:59 +00:00
|
|
|
// for all basic blocks in function
|
2001-11-15 00:27:14 +00:00
|
|
|
//
|
2002-10-28 19:01:16 +00:00
|
|
|
MachineFunction &MF = MachineFunction::get(&F);
|
|
|
|
for (MachineFunction::iterator BB = MF.begin(); BB != MF.end(); ++BB) {
|
2003-07-26 23:29:51 +00:00
|
|
|
for (BasicBlock::const_iterator IIt = BB->getBasicBlock()->begin();
|
|
|
|
const PHINode *PN = dyn_cast<PHINode>(IIt); ++IIt) {
|
2002-06-25 16:13:21 +00:00
|
|
|
// FIXME: This is probably wrong...
|
|
|
|
Value *PhiCpRes = new PHINode(PN->getType(), "PhiCp:");
|
2002-09-08 21:19:29 +00:00
|
|
|
|
|
|
|
// The leak detector shouldn't track these nodes. They are not garbage,
|
|
|
|
// even though their parent field is never filled in.
|
|
|
|
//
|
|
|
|
LeakDetector::removeGarbageObject(PhiCpRes);
|
|
|
|
|
2002-06-25 16:13:21 +00:00
|
|
|
// for each incoming value of the phi, insert phi elimination
|
|
|
|
//
|
|
|
|
for (unsigned i = 0; i < PN->getNumIncomingValues(); ++i) {
|
|
|
|
// insert the copy instruction to the predecessor BB
|
|
|
|
vector<MachineInstr*> mvec, CpVec;
|
2002-07-30 03:57:36 +00:00
|
|
|
Target.getRegInfo().cpValue2Value(PN->getIncomingValue(i), PhiCpRes,
|
2002-06-25 16:13:21 +00:00
|
|
|
mvec);
|
|
|
|
for (vector<MachineInstr*>::iterator MI=mvec.begin();
|
|
|
|
MI != mvec.end(); ++MI) {
|
|
|
|
vector<MachineInstr*> CpVec2 =
|
2003-07-26 23:29:51 +00:00
|
|
|
FixConstantOperandsForInstr(const_cast<PHINode*>(PN), *MI, Target);
|
2002-06-25 16:13:21 +00:00
|
|
|
CpVec2.push_back(*MI);
|
|
|
|
CpVec.insert(CpVec.end(), CpVec2.begin(), CpVec2.end());
|
|
|
|
}
|
2002-03-18 03:31:54 +00:00
|
|
|
|
2002-06-25 16:13:21 +00:00
|
|
|
InsertPhiElimInstructions(PN->getIncomingBlock(i), CpVec);
|
2001-11-15 00:27:14 +00:00
|
|
|
}
|
|
|
|
|
2002-06-25 16:13:21 +00:00
|
|
|
vector<MachineInstr*> mvec;
|
2003-07-26 23:29:51 +00:00
|
|
|
Target.getRegInfo().cpValue2Value(PhiCpRes, const_cast<PHINode*>(PN),
|
|
|
|
mvec);
|
2002-10-28 19:01:16 +00:00
|
|
|
BB->insert(BB->begin(), mvec.begin(), mvec.end());
|
2001-11-15 00:27:14 +00:00
|
|
|
} // for each Phi Instr in BB
|
2002-04-07 20:49:59 +00:00
|
|
|
} // for all BBs in function
|
2001-11-15 00:27:14 +00:00
|
|
|
}
|
|
|
|
|
2002-07-30 03:57:36 +00:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
// Thid method inserts a copy instruction to a predecessor BB as a result
|
|
|
|
// of phi elimination.
|
|
|
|
//-------------------------------------------------------------------------
|
2001-11-15 00:27:14 +00:00
|
|
|
|
2002-07-30 03:57:36 +00:00
|
|
|
void
|
|
|
|
InstructionSelection::InsertPhiElimInstructions(BasicBlock *BB,
|
2002-11-09 00:49:43 +00:00
|
|
|
const vector<MachineInstr*>& CpVec)
|
2002-07-30 03:57:36 +00:00
|
|
|
{
|
|
|
|
Instruction *TermInst = (Instruction*)BB->getTerminator();
|
|
|
|
MachineCodeForInstruction &MC4Term = MachineCodeForInstruction::get(TermInst);
|
|
|
|
MachineInstr *FirstMIOfTerm = MC4Term.front();
|
|
|
|
assert (FirstMIOfTerm && "No Machine Instrs for terminator");
|
2002-10-28 19:01:16 +00:00
|
|
|
|
|
|
|
MachineFunction &MF = MachineFunction::get(BB->getParent());
|
|
|
|
|
|
|
|
// FIXME: if PHI instructions existed in the machine code, this would be
|
|
|
|
// unnecesary.
|
2002-11-09 00:49:43 +00:00
|
|
|
MachineBasicBlock *MBB = 0;
|
2002-10-28 19:01:16 +00:00
|
|
|
for (MachineFunction::iterator I = MF.begin(), E = MF.end(); I != E; ++I)
|
|
|
|
if (I->getBasicBlock() == BB) {
|
|
|
|
MBB = I;
|
|
|
|
break;
|
|
|
|
}
|
2001-10-17 23:57:50 +00:00
|
|
|
|
2002-07-30 03:57:36 +00:00
|
|
|
// find the position of first machine instruction generated by the
|
|
|
|
// terminator of this BB
|
2002-10-28 01:41:47 +00:00
|
|
|
MachineBasicBlock::iterator MCIt =
|
2002-10-28 19:01:16 +00:00
|
|
|
std::find(MBB->begin(), MBB->end(), FirstMIOfTerm);
|
2002-07-30 03:57:36 +00:00
|
|
|
|
2002-10-28 19:01:16 +00:00
|
|
|
assert(MCIt != MBB->end() && "Start inst of terminator not found");
|
2002-07-30 03:57:36 +00:00
|
|
|
|
|
|
|
// insert the copy instructions just before the first machine instruction
|
|
|
|
// generated for the terminator
|
2002-10-28 19:01:16 +00:00
|
|
|
MBB->insert(MCIt, CpVec.begin(), CpVec.end());
|
2001-10-17 23:57:50 +00:00
|
|
|
}
|
|
|
|
|
2002-07-30 03:57:36 +00:00
|
|
|
|
2001-07-21 12:41:50 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
// Function SelectInstructionsForTree
|
|
|
|
//
|
|
|
|
// Recursively walk the tree to select instructions.
|
|
|
|
// Do this top-down so that child instructions can exploit decisions
|
|
|
|
// made at the child instructions.
|
|
|
|
//
|
|
|
|
// E.g., if br(setle(reg,const)) decides the constant is 0 and uses
|
|
|
|
// a branch-on-integer-register instruction, then the setle node
|
|
|
|
// can use that information to avoid generating the SUBcc instruction.
|
|
|
|
//
|
|
|
|
// Note that this cannot be done bottom-up because setle must do this
|
|
|
|
// only if it is a child of the branch (otherwise, the result of setle
|
|
|
|
// may be used by multiple instructions).
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2002-07-30 03:57:36 +00:00
|
|
|
void
|
|
|
|
InstructionSelection::SelectInstructionsForTree(InstrTreeNode* treeRoot,
|
|
|
|
int goalnt)
|
2001-09-18 12:56:28 +00:00
|
|
|
{
|
2001-07-21 12:41:50 +00:00
|
|
|
// Get the rule that matches this node.
|
|
|
|
//
|
|
|
|
int ruleForNode = burm_rule(treeRoot->state, goalnt);
|
|
|
|
|
2002-07-30 03:57:36 +00:00
|
|
|
if (ruleForNode == 0) {
|
2003-01-15 19:47:53 +00:00
|
|
|
std::cerr << "Could not match instruction tree for instr selection\n";
|
2002-07-30 03:57:36 +00:00
|
|
|
abort();
|
|
|
|
}
|
2001-07-21 12:41:50 +00:00
|
|
|
|
|
|
|
// Get this rule's non-terminals and the corresponding child nodes (if any)
|
|
|
|
//
|
|
|
|
short *nts = burm_nts[ruleForNode];
|
|
|
|
|
|
|
|
// First, select instructions for the current node and rule.
|
|
|
|
// (If this is a list node, not an instruction, then skip this step).
|
|
|
|
// This function is specific to the target architecture.
|
|
|
|
//
|
2001-09-18 12:56:28 +00:00
|
|
|
if (treeRoot->opLabel != VRegListOp)
|
|
|
|
{
|
2002-08-09 20:05:34 +00:00
|
|
|
vector<MachineInstr*> minstrVec;
|
2002-03-18 03:31:54 +00:00
|
|
|
|
2001-09-18 12:56:28 +00:00
|
|
|
InstructionNode* instrNode = (InstructionNode*)treeRoot;
|
|
|
|
assert(instrNode->getNodeType() == InstrTreeNode::NTInstructionNode);
|
2001-10-22 13:51:09 +00:00
|
|
|
|
2002-07-30 03:57:36 +00:00
|
|
|
GetInstructionsByRule(instrNode, ruleForNode, nts, Target, minstrVec);
|
2002-03-18 03:31:54 +00:00
|
|
|
|
2002-02-03 07:33:46 +00:00
|
|
|
MachineCodeForInstruction &mvec =
|
|
|
|
MachineCodeForInstruction::get(instrNode->getInstruction());
|
2002-03-18 03:31:54 +00:00
|
|
|
mvec.insert(mvec.end(), minstrVec.begin(), minstrVec.end());
|
2001-07-21 12:41:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Then, recursively compile the child nodes, if any.
|
|
|
|
//
|
2001-09-18 12:56:28 +00:00
|
|
|
if (nts[0])
|
|
|
|
{ // i.e., there is at least one kid
|
|
|
|
InstrTreeNode* kids[2];
|
|
|
|
int currentRule = ruleForNode;
|
2001-07-21 12:41:50 +00:00
|
|
|
burm_kids(treeRoot, currentRule, kids);
|
2001-09-18 12:56:28 +00:00
|
|
|
|
|
|
|
// First skip over any chain rules so that we don't visit
|
|
|
|
// the current node again.
|
|
|
|
//
|
|
|
|
while (ThisIsAChainRule(currentRule))
|
|
|
|
{
|
|
|
|
currentRule = burm_rule(treeRoot->state, nts[0]);
|
|
|
|
nts = burm_nts[currentRule];
|
|
|
|
burm_kids(treeRoot, currentRule, kids);
|
|
|
|
}
|
2001-07-21 12:41:50 +00:00
|
|
|
|
2001-09-18 12:56:28 +00:00
|
|
|
// Now we have the first non-chain rule so we have found
|
|
|
|
// the actual child nodes. Recursively compile them.
|
|
|
|
//
|
2002-07-30 03:57:36 +00:00
|
|
|
for (unsigned i = 0; nts[i]; i++)
|
2001-09-18 12:56:28 +00:00
|
|
|
{
|
|
|
|
assert(i < 2);
|
|
|
|
InstrTreeNode::InstrTreeNodeType nodeType = kids[i]->getNodeType();
|
|
|
|
if (nodeType == InstrTreeNode::NTVRegListNode ||
|
|
|
|
nodeType == InstrTreeNode::NTInstructionNode)
|
2002-07-30 03:57:36 +00:00
|
|
|
SelectInstructionsForTree(kids[i], nts[i]);
|
2001-09-18 12:56:28 +00:00
|
|
|
}
|
2001-07-21 12:41:50 +00:00
|
|
|
}
|
|
|
|
|
2001-10-17 23:57:50 +00:00
|
|
|
// Finally, do any postprocessing on this node after its children
|
|
|
|
// have been translated
|
|
|
|
//
|
|
|
|
if (treeRoot->opLabel != VRegListOp)
|
2002-07-30 03:57:36 +00:00
|
|
|
PostprocessMachineCodeForTree((InstructionNode*)treeRoot, ruleForNode, nts);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
// Function PostprocessMachineCodeForTree
|
|
|
|
//
|
|
|
|
// Apply any final cleanups to machine code for the root of a subtree
|
|
|
|
// after selection for all its children has been completed.
|
|
|
|
//
|
|
|
|
void
|
|
|
|
InstructionSelection::PostprocessMachineCodeForTree(InstructionNode* instrNode,
|
|
|
|
int ruleForNode,
|
|
|
|
short* nts)
|
|
|
|
{
|
|
|
|
// Fix up any constant operands in the machine instructions to either
|
|
|
|
// use an immediate field or to load the constant into a register
|
|
|
|
// Walk backwards and use direct indexes to allow insertion before current
|
|
|
|
//
|
|
|
|
Instruction* vmInstr = instrNode->getInstruction();
|
|
|
|
MachineCodeForInstruction &mvec = MachineCodeForInstruction::get(vmInstr);
|
2002-08-09 20:05:34 +00:00
|
|
|
for (unsigned i = mvec.size(); i != 0; --i)
|
2001-10-17 23:57:50 +00:00
|
|
|
{
|
2002-08-09 20:05:34 +00:00
|
|
|
vector<MachineInstr*> loadConstVec =
|
|
|
|
FixConstantOperandsForInstr(vmInstr, mvec[i-1], Target);
|
2002-07-30 03:57:36 +00:00
|
|
|
|
2002-08-09 20:05:34 +00:00
|
|
|
mvec.insert(mvec.begin()+i-1, loadConstVec.begin(), loadConstVec.end());
|
2001-10-17 23:57:50 +00:00
|
|
|
}
|
2002-07-30 03:57:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// createInstructionSelectionPass - Public entrypoint for instruction selection
|
|
|
|
// and this file as a whole...
|
|
|
|
//
|
|
|
|
Pass *createInstructionSelectionPass(TargetMachine &T) {
|
|
|
|
return new InstructionSelection(T);
|
2001-07-21 12:41:50 +00:00
|
|
|
}
|