#include "llvm/Type.h"
#include "llvm/iMemory.h"
#include "llvm/Instruction.h"
-#include "llvm/LLC/CompileContext.h"
#include "llvm/CodeGen/MachineInstr.h"
#include "llvm/Tools/CommandLine.h"
//************************* Forward Declarations ***************************/
static bool SelectInstructionsForTree(BasicTreeNode* treeRoot, int goalnt,
- CompileContext& ccontext);
+ TargetMachine &Target);
//******************* Externally Visible Functions *************************/
// Returns true if instruction selection failed, false otherwise.
//---------------------------------------------------------------------------
-bool SelectInstructionsForMethod(Method* method, CompileContext& ccontext) {
+bool SelectInstructionsForMethod(Method* method, TargetMachine &Target) {
bool failed = false;
InstrForest instrForest;
}
// Then recursively walk the tree to select instructions
- if (SelectInstructionsForTree(basicNode, /*goalnt*/1, ccontext))
+ if (SelectInstructionsForTree(basicNode, /*goalnt*/1, Target))
{
failed = true;
break;
bool
SelectInstructionsForTree(BasicTreeNode* treeRoot,
int goalnt,
- CompileContext& ccontext)
+ TargetMachine &Target)
{
// Use a static vector to avoid allocating a new one per VM instruction
static MachineInstr* minstrVec[MAX_INSTR_PER_VMINSTR];
InstructionNode* instrNode = (InstructionNode*) MainTreeNode(treeRoot);
assert(instrNode->getNodeType() == InstrTreeNode::NTInstructionNode);
- unsigned N = GetInstructionsByRule(instrNode, ruleForNode, nts, ccontext,
+ unsigned N = GetInstructionsByRule(instrNode, ruleForNode, nts, Target,
minstrVec);
assert(N <= MAX_INSTR_PER_VMINSTR);
for (unsigned i=0; i < N; i++)
if (nodeType == InstrTreeNode::NTVRegListNode ||
nodeType == InstrTreeNode::NTInstructionNode)
{
- bool failed= SelectInstructionsForTree(kids[i], nts[i],ccontext);
- if (failed)
+ if (SelectInstructionsForTree(kids[i], nts[i], Target))
return true; // failure
}
}
// 7/02/01 - Vikram Adve - Created
//***************************************************************************
-//*************************** User Include Files ***************************/
-
#include "llvm/Type.h"
#include "llvm/DerivedTypes.h"
#include "llvm/SymbolTable.h"
#include "llvm/BasicBlock.h"
#include "llvm/Method.h"
#include "llvm/ConstPoolVals.h"
-#include "llvm/LLC/CompileContext.h"
#include "llvm/CodeGen/Sparc.h"
#include "llvm/CodeGen/MachineInstr.h"
#include "llvm/CodeGen/InstrForest.h"
GetInstructionsByRule(InstructionNode* subtreeRoot,
int ruleForNode,
short* nts,
- CompileContext& ccontext,
+ TargetMachine &Target,
MachineInstr** mvec)
{
int numInstr = 1; // initialize for common case
case 3: // stmt: Store(reg,reg)
case 4: // stmt: Store(reg,ptrreg)
mvec[0] = new MachineInstr(ChooseStoreInstruction(subtreeRoot->leftChild()->getValue()->getType()));
- SetOperandsForMemInstr(mvec[0], subtreeRoot, ccontext.getTarget());
+ SetOperandsForMemInstr(mvec[0], subtreeRoot, Target);
break;
case 5: // stmt: BrUncond
else
{
mvec[0] =new MachineInstr(ChooseConvertToIntInstr(subtreeRoot,opType));
- Set2OperandsFromInstr(mvec[0], subtreeRoot, ccontext.getTarget());
+ Set2OperandsFromInstr(mvec[0], subtreeRoot, Target);
}
break;
{
opType = subtreeRoot->leftChild()->getValue()->getType();
mvec[0] = new MachineInstr(ChooseConvertToFloatInstr(subtreeRoot, opType));
- Set2OperandsFromInstr(mvec[0], subtreeRoot, ccontext.getTarget());
+ Set2OperandsFromInstr(mvec[0], subtreeRoot, Target);
}
break;
case 33: // reg: Add(reg, reg)
mvec[0] = new MachineInstr(ChooseAddInstruction(subtreeRoot));
- Set3OperandsFromInstr(mvec[0], subtreeRoot, ccontext.getTarget());
+ Set3OperandsFromInstr(mvec[0], subtreeRoot, Target);
break;
case 34: // reg: Sub(reg, reg)
mvec[0] = new MachineInstr(ChooseSubInstruction(subtreeRoot));
- Set3OperandsFromInstr(mvec[0], subtreeRoot, ccontext.getTarget());
+ Set3OperandsFromInstr(mvec[0], subtreeRoot, Target);
break;
case 135: // reg: Mul(todouble, todouble)
case 35: // reg: Mul(reg, reg)
mvec[0] = new MachineInstr(ChooseMulInstruction(subtreeRoot, checkCast));
- Set3OperandsFromInstr(mvec[0], subtreeRoot, ccontext.getTarget());
+ Set3OperandsFromInstr(mvec[0], subtreeRoot, Target);
break;
case 36: // reg: Div(reg, reg)
mvec[0] = new MachineInstr(ChooseDivInstruction(subtreeRoot));
- Set3OperandsFromInstr(mvec[0], subtreeRoot, ccontext.getTarget());
+ Set3OperandsFromInstr(mvec[0], subtreeRoot, Target);
break;
case 37: // reg: Rem(reg, reg)
case 38: // reg: And(reg, reg)
mvec[0] = new MachineInstr(AND);
- Set3OperandsFromInstr(mvec[0], subtreeRoot, ccontext.getTarget());
+ Set3OperandsFromInstr(mvec[0], subtreeRoot, Target);
break;
case 138: // reg: And(reg, not)
mvec[0] = new MachineInstr(ANDN);
- Set3OperandsFromInstr(mvec[0], subtreeRoot, ccontext.getTarget());
+ Set3OperandsFromInstr(mvec[0], subtreeRoot, Target);
break;
case 39: // reg: Or(reg, reg)
mvec[0] = new MachineInstr(ORN);
- Set3OperandsFromInstr(mvec[0], subtreeRoot, ccontext.getTarget());
+ Set3OperandsFromInstr(mvec[0], subtreeRoot, Target);
break;
case 139: // reg: Or(reg, not)
mvec[0] = new MachineInstr(ORN);
- Set3OperandsFromInstr(mvec[0], subtreeRoot, ccontext.getTarget());
+ Set3OperandsFromInstr(mvec[0], subtreeRoot, Target);
break;
case 40: // reg: Xor(reg, reg)
mvec[0] = new MachineInstr(XOR);
- Set3OperandsFromInstr(mvec[0], subtreeRoot, ccontext.getTarget());
+ Set3OperandsFromInstr(mvec[0], subtreeRoot, Target);
break;
case 140: // reg: Xor(reg, not)
mvec[0] = new MachineInstr(XNOR);
- Set3OperandsFromInstr(mvec[0], subtreeRoot, ccontext.getTarget());
+ Set3OperandsFromInstr(mvec[0], subtreeRoot, Target);
break;
case 41: // boolconst: SetCC(reg, Constant)
{
// integer condition: destination should be %g0
mvec[0] = new MachineInstr(SUBcc);
- Set3OperandsFromInstr(mvec[0], subtreeRoot, ccontext.getTarget(),
+ Set3OperandsFromInstr(mvec[0], subtreeRoot, Target,
/*canDiscardResult*/ true);
}
else
case 53: // reg: LoadIdx(reg,reg)
case 54: // reg: LoadIdx(ptrreg,reg)
mvec[0] = new MachineInstr(ChooseLoadInstruction(subtreeRoot->getValue()->getType()));
- SetOperandsForMemInstr(mvec[0], subtreeRoot, ccontext.getTarget());
+ SetOperandsForMemInstr(mvec[0], subtreeRoot, Target);
break;
case 55: // reg: GetElemPtr(reg)
}
// else in all other cases we need to a separate ADD instruction
mvec[0] = new MachineInstr(ADD);
- SetOperandsForMemInstr(mvec[0], subtreeRoot, ccontext.getTarget());
+ SetOperandsForMemInstr(mvec[0], subtreeRoot, Target);
break;
case 57: // reg: Alloca: Implement as 2 instructions:
Instruction* instr = subtreeRoot->getInstruction();
const PointerType* instrType = (const PointerType*) instr->getType();
assert(instrType->isPointerType());
- int tsize = (int) ccontext.getTarget().findOptimalStorageSize(
- instrType->getValueType());
+ int tsize = (int) Target.findOptimalStorageSize(instrType->getValueType());
if (tsize == 0)
{
numInstr = 0;
instrType->getValueType()->isArrayType());
const Type* eltType =
((ArrayType*) instrType->getValueType())->getElementType();
- int tsize = (int) ccontext.getTarget().findOptimalStorageSize(eltType);
+ int tsize = (int) Target.findOptimalStorageSize(eltType);
if (tsize == 0)
{
opType = subtreeRoot->leftChild()->getValue()->getType();
assert(opType->isIntegral() || opType == Type::BoolTy);
mvec[0] = new MachineInstr((opType == Type::LongTy)? SLLX : SLL);
- Set3OperandsFromInstr(mvec[0], subtreeRoot, ccontext.getTarget());
+ Set3OperandsFromInstr(mvec[0], subtreeRoot, Target);
break;
case 63: // reg: Shr(reg, reg)
mvec[0] = new MachineInstr((opType->isSigned()
? ((opType == Type::LongTy)? SRAX : SRA)
: ((opType == Type::LongTy)? SRLX : SRL)));
- Set3OperandsFromInstr(mvec[0], subtreeRoot, ccontext.getTarget());
+ Set3OperandsFromInstr(mvec[0], subtreeRoot, Target);
break;
case 71: // reg: VReg
&& "A chain rule should have only one RHS non-terminal!");
nextRule = burm_rule(subtreeRoot->getBasicNode()->state, nts[0]);
nts = burm_nts[nextRule];
- numInstr = GetInstructionsByRule(subtreeRoot, nextRule, nts,ccontext,mvec);
+ numInstr = GetInstructionsByRule(subtreeRoot, nextRule, nts,Target,mvec);
break;
default:
}
numInstr =
- FixConstantOperands(subtreeRoot, mvec, numInstr, ccontext.getTarget());
+ FixConstantOperands(subtreeRoot, mvec, numInstr, Target);
return numInstr;
}
#include "llvm/Type.h"
#include "llvm/iMemory.h"
#include "llvm/Instruction.h"
-#include "llvm/LLC/CompileContext.h"
#include "llvm/CodeGen/MachineInstr.h"
#include "llvm/Tools/CommandLine.h"
//************************* Forward Declarations ***************************/
static bool SelectInstructionsForTree(BasicTreeNode* treeRoot, int goalnt,
- CompileContext& ccontext);
+ TargetMachine &Target);
//******************* Externally Visible Functions *************************/
// Returns true if instruction selection failed, false otherwise.
//---------------------------------------------------------------------------
-bool SelectInstructionsForMethod(Method* method, CompileContext& ccontext) {
+bool SelectInstructionsForMethod(Method* method, TargetMachine &Target) {
bool failed = false;
InstrForest instrForest;
}
// Then recursively walk the tree to select instructions
- if (SelectInstructionsForTree(basicNode, /*goalnt*/1, ccontext))
+ if (SelectInstructionsForTree(basicNode, /*goalnt*/1, Target))
{
failed = true;
break;
bool
SelectInstructionsForTree(BasicTreeNode* treeRoot,
int goalnt,
- CompileContext& ccontext)
+ TargetMachine &Target)
{
// Use a static vector to avoid allocating a new one per VM instruction
static MachineInstr* minstrVec[MAX_INSTR_PER_VMINSTR];
InstructionNode* instrNode = (InstructionNode*) MainTreeNode(treeRoot);
assert(instrNode->getNodeType() == InstrTreeNode::NTInstructionNode);
- unsigned N = GetInstructionsByRule(instrNode, ruleForNode, nts, ccontext,
+ unsigned N = GetInstructionsByRule(instrNode, ruleForNode, nts, Target,
minstrVec);
assert(N <= MAX_INSTR_PER_VMINSTR);
for (unsigned i=0; i < N; i++)
if (nodeType == InstrTreeNode::NTVRegListNode ||
nodeType == InstrTreeNode::NTInstructionNode)
{
- bool failed= SelectInstructionsForTree(kids[i], nts[i],ccontext);
- if (failed)
+ if (SelectInstructionsForTree(kids[i], nts[i], Target))
return true; // failure
}
}