diff options
author | Chris Lattner <sabre@nondot.org> | 2003-08-15 04:53:16 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2003-08-15 04:53:16 +0000 |
commit | 7dc97ff18023935880082d84a0004ac111859357 (patch) | |
tree | d8ed6d9baf51c19b3134c4cf07d96c25321dbad6 /lib/CodeGen/SelectionDAG/DAGBuilder.cpp | |
parent | f4f5f8bcaa388f663bdbd49b8ee4914f39a3a20a (diff) |
Add a bunch of new node types, etc
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@7875 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/SelectionDAG/DAGBuilder.cpp')
-rw-r--r-- | lib/CodeGen/SelectionDAG/DAGBuilder.cpp | 67 |
1 files changed, 55 insertions, 12 deletions
diff --git a/lib/CodeGen/SelectionDAG/DAGBuilder.cpp b/lib/CodeGen/SelectionDAG/DAGBuilder.cpp index aafde8ad66..03bf14bc28 100644 --- a/lib/CodeGen/SelectionDAG/DAGBuilder.cpp +++ b/lib/CodeGen/SelectionDAG/DAGBuilder.cpp @@ -6,25 +6,31 @@ //===----------------------------------------------------------------------===// #include "llvm/CodeGen/SelectionDAG.h" +#include "llvm/Constants.h" #include "llvm/Function.h" #include "llvm/Instructions.h" -#include "llvm/Support/InstVisitor.h" +#include "llvm/Type.h" #include "llvm/CodeGen/MachineFunction.h" #include "llvm/Target/TargetMachine.h" -#include "llvm/Type.h" -#include "llvm/Constants.h" +#include "llvm/Support/InstVisitor.h" struct SelectionDAGBuilder : public InstVisitor<SelectionDAGBuilder> { // DAG - the current dag we are building. 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. MachineBasicBlock *BB; // CurRoot - The root built for the current basic block. 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); @@ -33,14 +39,21 @@ struct SelectionDAGBuilder : public InstVisitor<SelectionDAGBuilder> { void visitAdd(BinaryOperator &BO); void visitSub(BinaryOperator &BO); void visitMul(BinaryOperator &BO); - void visitRet(ReturnInst &RI); void visitAnd(BinaryOperator &BO); void visitOr (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) { - std::cerr << "Instruction Selection cannot select: " << I; + std::cerr << "DAGBuilder: Cannot instruction select: " << I; abort(); } @@ -116,6 +129,10 @@ SelectionDAGNode *SelectionDAGBuilder::getNodeFor(Value *V) { Entry->addValue(new ReducedValue_Constant_f64(CFP->getValue())); } 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"; @@ -144,9 +161,9 @@ void SelectionDAGBuilder::visitBB(BasicBlock &bb) { else { // The previous basic block AND this basic block had roots, insert a // block chain node now... - CurRoot = DAG.addNode(new SelectionDAGNode(ISD::BlockChainNode, - MVT::isVoid, - BB, OldRoot, CurRoot)); + CurRoot = DAG.addNode(new SelectionDAGNode(ISD::BlockChainNode, + MVT::isVoid, + BB, OldRoot, CurRoot)); } } } @@ -180,6 +197,11 @@ void SelectionDAGBuilder::visitXor(BinaryOperator &BO) { getNodeFor(BO)->setNode(ISD::Xor, BB, getNodeFor(BO.getOperand(0)), 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) { 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)))); +} + + +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 SeelectionDAGBuilder to do all of the +// SelectionDAG constructor - Just use the SelectionDAGBuilder to do all of the // dirty work... SelectionDAG::SelectionDAG(MachineFunction &f, const TargetMachine &tm, 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) 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) SDB.visitBB(const_cast<BasicBlock&>(*I)); Root = SDB.CurRoot; |