//===----------------------------------------------------------------------===//
#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);
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();
}
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";
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));
}
}
}
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
}
+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)
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;
case Type::ULongTyID: return MVT::i64;
case Type::FloatTyID: return MVT::f32;
case Type::DoubleTyID: return MVT::f64;
+ case Type::LabelTyID:
case Type::PointerTyID: return PointerType;
}
}
case ISD::ChainNode: std::cerr << "ChainNode"; break;
case ISD::BlockChainNode: std::cerr << "BlockChainNode"; break;
case ISD::ProtoNode: std::cerr << "ProtoNode"; break;
+
case ISD::Constant: std::cerr << "Constant"; break;
case ISD::FrameIndex: std::cerr << "FrameIndex"; break;
+ case ISD::BasicBlock: std::cerr << "BasicBlock"; break;
+
case ISD::Plus: std::cerr << "Plus"; break;
case ISD::Minus: std::cerr << "Minus"; break;
case ISD::Times: std::cerr << "Times"; break;
case ISD::And: std::cerr << "And"; break;
case ISD::Or: std::cerr << "Or"; 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::BrCond: std::cerr << "BrCond"; break;
case ISD::Switch: std::cerr << "Switch"; break;
case ISD::Ret: std::cerr << "Ret"; break;
case ISD::RetVoid: std::cerr << "RetVoid"; break;
case ISD::Store: std::cerr << "Store"; break;
case ISD::PHI: std::cerr << "PHI"; 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";