1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-24 19:52:54 +01:00

Add a bunch of new node types, etc

llvm-svn: 7875
This commit is contained in:
Chris Lattner 2003-08-15 04:53:16 +00:00
parent d929db2450
commit d76432ee48
2 changed files with 71 additions and 12 deletions

View File

@ -6,25 +6,31 @@
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#include "llvm/CodeGen/SelectionDAG.h" #include "llvm/CodeGen/SelectionDAG.h"
#include "llvm/Constants.h"
#include "llvm/Function.h" #include "llvm/Function.h"
#include "llvm/Instructions.h" #include "llvm/Instructions.h"
#include "llvm/Support/InstVisitor.h" #include "llvm/Type.h"
#include "llvm/CodeGen/MachineFunction.h" #include "llvm/CodeGen/MachineFunction.h"
#include "llvm/Target/TargetMachine.h" #include "llvm/Target/TargetMachine.h"
#include "llvm/Type.h" #include "llvm/Support/InstVisitor.h"
#include "llvm/Constants.h"
struct SelectionDAGBuilder : public InstVisitor<SelectionDAGBuilder> { struct SelectionDAGBuilder : public InstVisitor<SelectionDAGBuilder> {
// DAG - the current dag we are building. // DAG - the current dag we are building.
SelectionDAG &DAG; SelectionDAG &DAG;
// SDTB - The target-specific builder interface, which indicates how to expand
// extremely target-specific aspects of the representation, such as function
// calls and arguments.
SelectionDAGTargetBuilder &SDTB;
// BB - The current machine basic block we are working on. // BB - The current machine basic block we are working on.
MachineBasicBlock *BB; MachineBasicBlock *BB;
// CurRoot - The root built for the current basic block. // CurRoot - The root built for the current basic block.
SelectionDAGNode *CurRoot; SelectionDAGNode *CurRoot;
SelectionDAGBuilder(SelectionDAG &dag) : DAG(dag), BB(0), CurRoot(0) {} SelectionDAGBuilder(SelectionDAG &dag, SelectionDAGTargetBuilder &sdtb)
: DAG(dag), SDTB(sdtb), BB(0), CurRoot(0) {}
void visitBB(BasicBlock &bb); void visitBB(BasicBlock &bb);
@ -33,14 +39,21 @@ struct SelectionDAGBuilder : public InstVisitor<SelectionDAGBuilder> {
void visitAdd(BinaryOperator &BO); void visitAdd(BinaryOperator &BO);
void visitSub(BinaryOperator &BO); void visitSub(BinaryOperator &BO);
void visitMul(BinaryOperator &BO); void visitMul(BinaryOperator &BO);
void visitRet(ReturnInst &RI);
void visitAnd(BinaryOperator &BO); void visitAnd(BinaryOperator &BO);
void visitOr (BinaryOperator &BO); void visitOr (BinaryOperator &BO);
void visitXor(BinaryOperator &BO); void visitXor(BinaryOperator &BO);
void visitSetEQ(BinaryOperator &BO);
void visitLoad(LoadInst &LI);
void visitCall(CallInst &CI);
void visitBr(BranchInst &BI);
void visitRet(ReturnInst &RI);
void visitInstruction(Instruction &I) { void visitInstruction(Instruction &I) {
std::cerr << "Instruction Selection cannot select: " << I; std::cerr << "DAGBuilder: Cannot instruction select: " << I;
abort(); abort();
} }
@ -116,6 +129,10 @@ SelectionDAGNode *SelectionDAGBuilder::getNodeFor(Value *V) {
Entry->addValue(new ReducedValue_Constant_f64(CFP->getValue())); Entry->addValue(new ReducedValue_Constant_f64(CFP->getValue()));
} }
if (Entry) return Entry; if (Entry) return Entry;
} else if (BasicBlock *BB = dyn_cast<BasicBlock>(V)) {
Entry = new SelectionDAGNode(ISD::BasicBlock, ValueType);
Entry->addValue(new ReducedValue_BasicBlock_i32(DAG.BlockMap[BB]));
return Entry;
} }
std::cerr << "Unhandled LLVM value in DAG Builder!: " << *V << "\n"; std::cerr << "Unhandled LLVM value in DAG Builder!: " << *V << "\n";
@ -144,9 +161,9 @@ void SelectionDAGBuilder::visitBB(BasicBlock &bb) {
else { else {
// The previous basic block AND this basic block had roots, insert a // The previous basic block AND this basic block had roots, insert a
// block chain node now... // block chain node now...
CurRoot = DAG.addNode(new SelectionDAGNode(ISD::BlockChainNode, CurRoot = DAG.addNode(new SelectionDAGNode(ISD::BlockChainNode,
MVT::isVoid, MVT::isVoid,
BB, OldRoot, CurRoot)); BB, OldRoot, CurRoot));
} }
} }
} }
@ -180,6 +197,11 @@ void SelectionDAGBuilder::visitXor(BinaryOperator &BO) {
getNodeFor(BO)->setNode(ISD::Xor, BB, getNodeFor(BO.getOperand(0)), getNodeFor(BO)->setNode(ISD::Xor, BB, getNodeFor(BO.getOperand(0)),
getNodeFor(BO.getOperand(1))); getNodeFor(BO.getOperand(1)));
} }
void SelectionDAGBuilder::visitSetEQ(BinaryOperator &BO) {
getNodeFor(BO)->setNode(ISD::SetEQ, BB, getNodeFor(BO.getOperand(0)),
getNodeFor(BO.getOperand(1)));
}
void SelectionDAGBuilder::visitRet(ReturnInst &RI) { void SelectionDAGBuilder::visitRet(ReturnInst &RI) {
if (RI.getNumOperands()) { // Value return if (RI.getNumOperands()) { // Value return
@ -191,9 +213,30 @@ void SelectionDAGBuilder::visitRet(ReturnInst &RI) {
} }
void SelectionDAGBuilder::visitBr(BranchInst &BI) {
if (BI.isUnconditional())
addSeqNode(new SelectionDAGNode(ISD::Br, MVT::isVoid, BB,
getNodeFor(BI.getOperand(0))));
else
addSeqNode(new SelectionDAGNode(ISD::BrCond, MVT::isVoid, BB,
getNodeFor(BI.getCondition()),
getNodeFor(BI.getSuccessor(0)),
getNodeFor(BI.getSuccessor(1))));
}
// SelectionDAG constructor - Just use the SeelectionDAGBuilder to do all of the void SelectionDAGBuilder::visitLoad(LoadInst &LI) {
// FIXME: this won't prevent reordering of loads!
getNodeFor(LI)->setNode(ISD::Load, BB, getNodeFor(LI.getOperand(0)));
}
void SelectionDAGBuilder::visitCall(CallInst &CI) {
SDTB.expandCall(DAG, CI);
}
// SelectionDAG constructor - Just use the SelectionDAGBuilder to do all of the
// dirty work... // dirty work...
SelectionDAG::SelectionDAG(MachineFunction &f, const TargetMachine &tm, SelectionDAG::SelectionDAG(MachineFunction &f, const TargetMachine &tm,
SelectionDAGTargetBuilder &SDTB) SelectionDAGTargetBuilder &SDTB)
@ -213,9 +256,9 @@ SelectionDAG::SelectionDAG(MachineFunction &f, const TargetMachine &tm,
for (Function::const_iterator I = Fn.begin(), E = Fn.end(); I != E; ++I) for (Function::const_iterator I = Fn.begin(), E = Fn.end(); I != E; ++I)
F.getBasicBlockList().push_back(BlockMap[I] = new MachineBasicBlock(I)); F.getBasicBlockList().push_back(BlockMap[I] = new MachineBasicBlock(I));
SDTB.expandArguments(*this, f); SDTB.expandArguments(*this);
SelectionDAGBuilder SDB(*this); SelectionDAGBuilder SDB(*this, SDTB);
for (Function::const_iterator I = Fn.begin(), E = Fn.end(); I != E; ++I) for (Function::const_iterator I = Fn.begin(), E = Fn.end(); I != E; ++I)
SDB.visitBB(const_cast<BasicBlock&>(*I)); SDB.visitBB(const_cast<BasicBlock&>(*I));
Root = SDB.CurRoot; Root = SDB.CurRoot;

View File

@ -37,6 +37,7 @@ MVT::ValueType SelectionDAG::getValueType(const Type *Ty) const {
case Type::ULongTyID: return MVT::i64; case Type::ULongTyID: return MVT::i64;
case Type::FloatTyID: return MVT::f32; case Type::FloatTyID: return MVT::f32;
case Type::DoubleTyID: return MVT::f64; case Type::DoubleTyID: return MVT::f64;
case Type::LabelTyID:
case Type::PointerTyID: return PointerType; case Type::PointerTyID: return PointerType;
} }
} }
@ -79,8 +80,11 @@ void SelectionDAGNode::printit(unsigned Offset, unsigned &LastID,
case ISD::ChainNode: std::cerr << "ChainNode"; break; case ISD::ChainNode: std::cerr << "ChainNode"; break;
case ISD::BlockChainNode: std::cerr << "BlockChainNode"; break; case ISD::BlockChainNode: std::cerr << "BlockChainNode"; break;
case ISD::ProtoNode: std::cerr << "ProtoNode"; break; case ISD::ProtoNode: std::cerr << "ProtoNode"; break;
case ISD::Constant: std::cerr << "Constant"; break; case ISD::Constant: std::cerr << "Constant"; break;
case ISD::FrameIndex: std::cerr << "FrameIndex"; break; case ISD::FrameIndex: std::cerr << "FrameIndex"; break;
case ISD::BasicBlock: std::cerr << "BasicBlock"; break;
case ISD::Plus: std::cerr << "Plus"; break; case ISD::Plus: std::cerr << "Plus"; break;
case ISD::Minus: std::cerr << "Minus"; break; case ISD::Minus: std::cerr << "Minus"; break;
case ISD::Times: std::cerr << "Times"; break; case ISD::Times: std::cerr << "Times"; break;
@ -91,7 +95,16 @@ void SelectionDAGNode::printit(unsigned Offset, unsigned &LastID,
case ISD::And: std::cerr << "And"; break; case ISD::And: std::cerr << "And"; break;
case ISD::Or: std::cerr << "Or"; break; case ISD::Or: std::cerr << "Or"; break;
case ISD::Xor: std::cerr << "Xor"; break; case ISD::Xor: std::cerr << "Xor"; break;
case ISD::SetEQ: std::cerr << "SetEQ"; break;
case ISD::SetNE: std::cerr << "SetNE"; break;
case ISD::SetLT: std::cerr << "SetLT"; break;
case ISD::SetLE: std::cerr << "SetLE"; break;
case ISD::SetGT: std::cerr << "SetGT"; break;
case ISD::SetGE: std::cerr << "SetGE"; break;
case ISD::Br: std::cerr << "Br"; break; case ISD::Br: std::cerr << "Br"; break;
case ISD::BrCond: std::cerr << "BrCond"; break;
case ISD::Switch: std::cerr << "Switch"; break; case ISD::Switch: std::cerr << "Switch"; break;
case ISD::Ret: std::cerr << "Ret"; break; case ISD::Ret: std::cerr << "Ret"; break;
case ISD::RetVoid: std::cerr << "RetVoid"; break; case ISD::RetVoid: std::cerr << "RetVoid"; break;
@ -99,6 +112,9 @@ void SelectionDAGNode::printit(unsigned Offset, unsigned &LastID,
case ISD::Store: std::cerr << "Store"; break; case ISD::Store: std::cerr << "Store"; break;
case ISD::PHI: std::cerr << "PHI"; break; case ISD::PHI: std::cerr << "PHI"; break;
case ISD::Call: std::cerr << "Call"; break; case ISD::Call: std::cerr << "Call"; break;
case ISD::Unspec1: std::cerr << "Unspec1"; break;
case ISD::Unspec2: std::cerr << "Unspec2"; break;
} }
std::cerr << "\n"; std::cerr << "\n";