mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-08-19 04:29:21 +00:00
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
This commit is contained in:
parent
f4f5f8bcaa
commit
7dc97ff180
@ -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";
|
||||
@ -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))));
|
||||
}
|
||||
|
||||
|
||||
// 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...
|
||||
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;
|
||||
|
@ -37,6 +37,7 @@ MVT::ValueType SelectionDAG::getValueType(const Type *Ty) const {
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -79,8 +80,11 @@ void SelectionDAGNode::printit(unsigned Offset, unsigned &LastID,
|
||||
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;
|
||||
@ -91,7 +95,16 @@ void SelectionDAGNode::printit(unsigned Offset, unsigned &LastID,
|
||||
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;
|
||||
@ -99,6 +112,9 @@ void SelectionDAGNode::printit(unsigned Offset, unsigned &LastID,
|
||||
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";
|
||||
|
Loading…
Reference in New Issue
Block a user