[llvm-commits] CVS: llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp SelectionDAGCSEMap.cpp
Chris Lattner
lattner at cs.uiuc.edu
Fri Aug 11 14:01:36 PDT 2006
Changes in directory llvm/lib/CodeGen/SelectionDAG:
SelectionDAG.cpp updated: 1.323 -> 1.324
SelectionDAGCSEMap.cpp updated: 1.1 -> 1.2
---
Log message:
Move the BBNodes, GlobalValues, TargetGlobalValues, Constants, TargetConstants,
RegNodes, and ValueNodes maps into the CSEMap.
---
Diffs of the changes: (+83 -88)
SelectionDAG.cpp | 145 +++++++++++++++++++------------------------------
SelectionDAGCSEMap.cpp | 26 ++++++++
2 files changed, 83 insertions(+), 88 deletions(-)
Index: llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
diff -u llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:1.323 llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:1.324
--- llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:1.323 Fri Aug 11 13:38:11 2006
+++ llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp Fri Aug 11 16:01:22 2006
@@ -341,15 +341,6 @@
bool Erased = false;
switch (N->getOpcode()) {
case ISD::HANDLENODE: return; // noop.
- case ISD::Constant:
- Erased = Constants.erase(std::make_pair(cast<ConstantSDNode>(N)->getValue(),
- N->getValueType(0)));
- break;
- case ISD::TargetConstant:
- Erased = TargetConstants.erase(std::make_pair(
- cast<ConstantSDNode>(N)->getValue(),
- N->getValueType(0)));
- break;
case ISD::ConstantFP: {
uint64_t V = DoubleToBits(cast<ConstantFPSDNode>(N)->getValue());
Erased = ConstantFPs.erase(std::make_pair(V, N->getValueType(0)));
@@ -369,18 +360,6 @@
Erased = CondCodeNodes[cast<CondCodeSDNode>(N)->get()] != 0;
CondCodeNodes[cast<CondCodeSDNode>(N)->get()] = 0;
break;
- case ISD::GlobalAddress: {
- GlobalAddressSDNode *GN = cast<GlobalAddressSDNode>(N);
- Erased = GlobalValues.erase(std::make_pair(GN->getGlobal(),
- GN->getOffset()));
- break;
- }
- case ISD::TargetGlobalAddress: {
- GlobalAddressSDNode *GN = cast<GlobalAddressSDNode>(N);
- Erased =TargetGlobalValues.erase(std::make_pair(GN->getGlobal(),
- GN->getOffset()));
- break;
- }
case ISD::FrameIndex:
Erased = FrameIndices.erase(cast<FrameIndexSDNode>(N)->getIndex());
break;
@@ -406,9 +385,6 @@
std::make_pair(cast<ConstantPoolSDNode>(N)->getOffset(),
cast<ConstantPoolSDNode>(N)->getAlignment())));
break;
- case ISD::BasicBlock:
- Erased = BBNodes.erase(cast<BasicBlockSDNode>(N)->getBasicBlock());
- break;
case ISD::ExternalSymbol:
Erased = ExternalSymbols.erase(cast<ExternalSymbolSDNode>(N)->getSymbol());
break;
@@ -420,15 +396,6 @@
Erased = ValueTypeNodes[cast<VTSDNode>(N)->getVT()] != 0;
ValueTypeNodes[cast<VTSDNode>(N)->getVT()] = 0;
break;
- case ISD::Register:
- Erased = RegNodes.erase(std::make_pair(cast<RegisterSDNode>(N)->getReg(),
- N->getValueType(0)));
- break;
- case ISD::SRCVALUE: {
- SrcValueSDNode *SVN = cast<SrcValueSDNode>(N);
- Erased =ValueNodes.erase(std::make_pair(SVN->getValue(), SVN->getOffset()));
- break;
- }
default:
// Remove it from the CSE Map.
Erased = CSEMap.RemoveNode(N);
@@ -551,21 +518,6 @@
getConstant(Imm, Op.getValueType()));
}
-SDOperand SelectionDAG::getConstant(uint64_t Val, MVT::ValueType VT) {
- assert(MVT::isInteger(VT) && "Cannot create FP integer constant!");
- assert(!MVT::isVector(VT) && "Cannot create Vector ConstantSDNodes!");
-
- // Mask out any bits that are not valid for this constant.
- if (VT != MVT::i64)
- Val &= ((uint64_t)1 << MVT::getSizeInBits(VT)) - 1;
-
- SDNode *&N = Constants[std::make_pair(Val, VT)];
- if (N) return SDOperand(N, 0);
- N = new ConstantSDNode(false, Val, VT);
- AllNodes.push_back(N);
- return SDOperand(N, 0);
-}
-
SDOperand SelectionDAG::getString(const std::string &Val) {
StringSDNode *&N = StringNodes[Val];
if (!N) {
@@ -575,19 +527,26 @@
return SDOperand(N, 0);
}
-SDOperand SelectionDAG::getTargetConstant(uint64_t Val, MVT::ValueType VT) {
+SDOperand SelectionDAG::getConstant(uint64_t Val, MVT::ValueType VT, bool isT) {
assert(MVT::isInteger(VT) && "Cannot create FP integer constant!");
- // Mask out any bits that are not valid for this constant.
- if (VT != MVT::i64)
- Val &= ((uint64_t)1 << MVT::getSizeInBits(VT)) - 1;
+ assert(!MVT::isVector(VT) && "Cannot create Vector ConstantSDNodes!");
- SDNode *&N = TargetConstants[std::make_pair(Val, VT)];
- if (N) return SDOperand(N, 0);
- N = new ConstantSDNode(true, Val, VT);
+ // Mask out any bits that are not valid for this constant.
+ Val &= MVT::getIntVTBitMask(VT);
+
+ unsigned Opc = isT ? ISD::TargetConstant : ISD::Constant;
+ SelectionDAGCSEMap::NodeID ID(Opc, getNodeValueTypes(VT));
+ ID.AddInteger(Val);
+ void *IP = 0;
+ if (SDNode *E = CSEMap.FindNodeOrInsertPos(ID, IP))
+ return SDOperand(E, 0);
+ SDNode *N = new ConstantSDNode(isT, Val, VT);
+ CSEMap.InsertNode(N, IP);
AllNodes.push_back(N);
return SDOperand(N, 0);
}
+
SDOperand SelectionDAG::getConstantFP(double Val, MVT::ValueType VT) {
assert(MVT::isFloatingPoint(VT) && "Cannot create integer FP constant!");
if (VT == MVT::f32)
@@ -619,19 +578,17 @@
}
SDOperand SelectionDAG::getGlobalAddress(const GlobalValue *GV,
- MVT::ValueType VT, int offset) {
- SDNode *&N = GlobalValues[std::make_pair(GV, offset)];
- if (N) return SDOperand(N, 0);
- N = new GlobalAddressSDNode(false, GV, VT, offset);
- AllNodes.push_back(N);
- return SDOperand(N, 0);
-}
-
-SDOperand SelectionDAG::getTargetGlobalAddress(const GlobalValue *GV,
- MVT::ValueType VT, int offset) {
- SDNode *&N = TargetGlobalValues[std::make_pair(GV, offset)];
- if (N) return SDOperand(N, 0);
- N = new GlobalAddressSDNode(true, GV, VT, offset);
+ MVT::ValueType VT, int Offset,
+ bool isTargetGA) {
+ unsigned Opc = isTargetGA ? ISD::TargetGlobalAddress : ISD::GlobalAddress;
+ SelectionDAGCSEMap::NodeID ID(Opc, getNodeValueTypes(VT));
+ ID.AddPointer(GV);
+ ID.AddInteger(Offset);
+ void *IP = 0;
+ if (SDNode *E = CSEMap.FindNodeOrInsertPos(ID, IP))
+ return SDOperand(E, 0);
+ SDNode *N = new GlobalAddressSDNode(isTargetGA, GV, VT, Offset);
+ CSEMap.InsertNode(N, IP);
AllNodes.push_back(N);
return SDOperand(N, 0);
}
@@ -689,9 +646,13 @@
}
SDOperand SelectionDAG::getBasicBlock(MachineBasicBlock *MBB) {
- SDNode *&N = BBNodes[MBB];
- if (N) return SDOperand(N, 0);
- N = new BasicBlockSDNode(MBB);
+ SelectionDAGCSEMap::NodeID ID(ISD::BasicBlock, getNodeValueTypes(MVT::Other));
+ ID.AddPointer(MBB);
+ void *IP = 0;
+ if (SDNode *E = CSEMap.FindNodeOrInsertPos(ID, IP))
+ return SDOperand(E, 0);
+ SDNode *N = new BasicBlockSDNode(MBB);
+ CSEMap.InsertNode(N, IP);
AllNodes.push_back(N);
return SDOperand(N, 0);
}
@@ -736,12 +697,31 @@
}
SDOperand SelectionDAG::getRegister(unsigned RegNo, MVT::ValueType VT) {
- RegisterSDNode *&Reg = RegNodes[std::make_pair(RegNo, VT)];
- if (!Reg) {
- Reg = new RegisterSDNode(RegNo, VT);
- AllNodes.push_back(Reg);
- }
- return SDOperand(Reg, 0);
+ SelectionDAGCSEMap::NodeID ID(ISD::Register, getNodeValueTypes(VT));
+ ID.AddInteger(RegNo);
+ void *IP = 0;
+ if (SDNode *E = CSEMap.FindNodeOrInsertPos(ID, IP))
+ return SDOperand(E, 0);
+ SDNode *N = new RegisterSDNode(RegNo, VT);
+ CSEMap.InsertNode(N, IP);
+ AllNodes.push_back(N);
+ return SDOperand(N, 0);
+}
+
+SDOperand SelectionDAG::getSrcValue(const Value *V, int Offset) {
+ assert((!V || isa<PointerType>(V->getType())) &&
+ "SrcValue is not a pointer?");
+
+ SelectionDAGCSEMap::NodeID ID(ISD::SRCVALUE, getNodeValueTypes(MVT::Other));
+ ID.AddPointer(V);
+ ID.AddInteger(Offset);
+ void *IP = 0;
+ if (SDNode *E = CSEMap.FindNodeOrInsertPos(ID, IP))
+ return SDOperand(E, 0);
+ SDNode *N = new SrcValueSDNode(V, Offset);
+ CSEMap.InsertNode(N, IP);
+ AllNodes.push_back(N);
+ return SDOperand(N, 0);
}
SDOperand SelectionDAG::SimplifySetCC(MVT::ValueType VT, SDOperand N1,
@@ -1540,17 +1520,6 @@
return getNode(Opcode, VTs, Ops, 4);
}
-SDOperand SelectionDAG::getSrcValue(const Value *V, int Offset) {
- assert((!V || isa<PointerType>(V->getType())) &&
- "SrcValue is not a pointer?");
- SDNode *&N = ValueNodes[std::make_pair(V, Offset)];
- if (N) return SDOperand(N, 0);
-
- N = new SrcValueSDNode(V, Offset);
- AllNodes.push_back(N);
- return SDOperand(N, 0);
-}
-
SDOperand SelectionDAG::getVAArg(MVT::ValueType VT,
SDOperand Chain, SDOperand Ptr,
SDOperand SV) {
Index: llvm/lib/CodeGen/SelectionDAG/SelectionDAGCSEMap.cpp
diff -u llvm/lib/CodeGen/SelectionDAG/SelectionDAGCSEMap.cpp:1.1 llvm/lib/CodeGen/SelectionDAG/SelectionDAGCSEMap.cpp:1.2
--- llvm/lib/CodeGen/SelectionDAG/SelectionDAGCSEMap.cpp:1.1 Mon Aug 7 18:03:03 2006
+++ llvm/lib/CodeGen/SelectionDAG/SelectionDAGCSEMap.cpp Fri Aug 11 16:01:22 2006
@@ -23,6 +23,32 @@
SetValueTypes(N->value_begin());
// Add the operand info.
SetOperands(N->op_begin(), N->getNumOperands());
+
+ // Handle SDNode leafs with special info.
+ if (N->getNumOperands() == 0) {
+ switch (N->getOpcode()) {
+ default: break; // Normal nodes don't need extra info.
+ case ISD::TargetConstant:
+ case ISD::Constant:
+ AddInteger(cast<ConstantSDNode>(N)->getValue());
+ break;
+ case ISD::TargetGlobalAddress:
+ case ISD::GlobalAddress:
+ AddPointer(cast<GlobalAddressSDNode>(N)->getGlobal());
+ AddInteger(cast<GlobalAddressSDNode>(N)->getOffset());
+ break;
+ case ISD::BasicBlock:
+ AddPointer(cast<BasicBlockSDNode>(N)->getBasicBlock());
+ break;
+ case ISD::Register:
+ AddInteger(cast<RegisterSDNode>(N)->getReg());
+ break;
+ case ISD::SRCVALUE:
+ AddPointer(cast<SrcValueSDNode>(N)->getValue());
+ AddInteger(cast<SrcValueSDNode>(N)->getOffset());
+ break;
+ }
+ }
}
SelectionDAGCSEMap::NodeID::NodeID(unsigned short ID, const void *VTList) {
More information about the llvm-commits
mailing list