llvm.org GIT mirror llvm / 4fbd796
Change ConstantSDNode and ConstantFPSDNode to use ConstantInt* and ConstantFP* instead of APInt and APFloat directly. This reduces the amount of time to create ConstantSDNode and ConstantFPSDNode nodes when ConstantInt* and ConstantFP* respectively are already available, as is the case in SelectionDAGBuild.cpp. Also, it reduces the amount of time to legalize constants into constant pools, and the amount of time to add ConstantFP operands to MachineInstrs, due to eliminating ConstantInt::get and ConstantFP::get calls. It increases the amount of work needed to create new constants in cases where the client doesn't already have a ConstantInt* or ConstantFP*, such as legalize expanding 64-bit integer constants to 32-bit constants. And it adds a layer of indirection for the accessor methods. But these appear to be outweight by the benefits in most cases. It will also make it easier to make ConstantSDNode and ConstantFPNode more consistent with ConstantInt and ConstantFP. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@56162 91177308-0d34-0410-b5e6-96231b3b80d8 Dan Gohman 11 years ago
10 changed file(s) with 55 addition(s) and 39 deletion(s). Raw diff Collapse all Expand all
5151 return *this;
5252 }
5353
54 const MachineInstrBuilder &addFPImm(ConstantFP *Val) const {
54 const MachineInstrBuilder &addFPImm(const ConstantFP *Val) const {
5555 MI->addOperand(MachineOperand::CreateFPImm(Val));
5656 return *this;
5757 }
8585 /// Contents union - This contains the payload for the various operand types.
8686 union {
8787 MachineBasicBlock *MBB; // For MO_MachineBasicBlock.
88 ConstantFP *CFP; // For MO_FPImmediate.
88 const ConstantFP *CFP; // For MO_FPImmediate.
8989 int64_t ImmVal; // For MO_Immediate.
9090
9191 struct { // For MO_Register.
251251 return Contents.ImmVal;
252252 }
253253
254 ConstantFP *getFPImm() const {
254 const ConstantFP *getFPImm() const {
255255 assert(isFPImmediate() && "Wrong MachineOperand accessor");
256256 return Contents.CFP;
257257 }
339339 return Op;
340340 }
341341
342 static MachineOperand CreateFPImm(ConstantFP *CFP) {
342 static MachineOperand CreateFPImm(const ConstantFP *CFP) {
343343 MachineOperand Op(MachineOperand::MO_FPImmediate);
344344 Op.Contents.CFP = CFP;
345345 return Op;
230230 //
231231 SDValue getConstant(uint64_t Val, MVT VT, bool isTarget = false);
232232 SDValue getConstant(const APInt &Val, MVT VT, bool isTarget = false);
233 SDValue getConstant(const ConstantInt &Val, MVT VT, bool isTarget = false);
233234 SDValue getIntPtrConstant(uint64_t Val, bool isTarget = false);
234235 SDValue getTargetConstant(uint64_t Val, MVT VT) {
235236 return getConstant(Val, VT, true);
237238 SDValue getTargetConstant(const APInt &Val, MVT VT) {
238239 return getConstant(Val, VT, true);
239240 }
241 SDValue getTargetConstant(const ConstantInt &Val, MVT VT) {
242 return getConstant(Val, VT, true);
243 }
240244 SDValue getConstantFP(double Val, MVT VT, bool isTarget = false);
241245 SDValue getConstantFP(const APFloat& Val, MVT VT, bool isTarget = false);
246 SDValue getConstantFP(const ConstantFP &CF, MVT VT, bool isTarget = false);
242247 SDValue getTargetConstantFP(double Val, MVT VT) {
243248 return getConstantFP(Val, VT, true);
244249 }
245250 SDValue getTargetConstantFP(const APFloat& Val, MVT VT) {
251 return getConstantFP(Val, VT, true);
252 }
253 SDValue getTargetConstantFP(const ConstantFP &Val, MVT VT) {
246254 return getConstantFP(Val, VT, true);
247255 }
248256 SDValue getGlobalAddress(const GlobalValue *GV, MVT VT,
1919 #define LLVM_CODEGEN_SELECTIONDAGNODES_H
2020
2121 #include "llvm/Value.h"
22 #include "llvm/Constants.h"
2223 #include "llvm/ADT/FoldingSet.h"
2324 #include "llvm/ADT/GraphTraits.h"
2425 #include "llvm/ADT/iterator.h"
25 #include "llvm/ADT/APFloat.h"
26 #include "llvm/ADT/APInt.h"
2726 #include "llvm/ADT/ilist_node.h"
2827 #include "llvm/ADT/STLExtras.h"
2928 #include "llvm/CodeGen/ValueTypes.h"
17031702 };
17041703
17051704 class ConstantSDNode : public SDNode {
1706 APInt Value;
1705 const ConstantInt *Value;
17071706 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
17081707 protected:
17091708 friend class SelectionDAG;
1710 ConstantSDNode(bool isTarget, const APInt &val, MVT VT)
1709 ConstantSDNode(bool isTarget, const ConstantInt *val, MVT VT)
17111710 : SDNode(isTarget ? ISD::TargetConstant : ISD::Constant, getSDVTList(VT)),
17121711 Value(val) {
17131712 }
17141713 public:
17151714
1716 const APInt &getAPIntValue() const { return Value; }
1717 uint64_t getZExtValue() const { return Value.getZExtValue(); }
1715 const ConstantInt *getConstantIntValue() const { return Value; }
1716 const APInt &getAPIntValue() const { return Value->getValue(); }
1717 uint64_t getZExtValue() const { return Value->getZExtValue(); }
17181718
17191719 int64_t getSignExtended() const {
17201720 unsigned Bits = getValueType(0).getSizeInBits();
1721 return ((int64_t)Value.getZExtValue() << (64-Bits)) >> (64-Bits);
1722 }
1723
1724 bool isNullValue() const { return Value == 0; }
1725 bool isAllOnesValue() const {
1726 return Value == getValueType(0).getIntegerVTBitMask();
1727 }
1721 return ((int64_t)getZExtValue() << (64-Bits)) >> (64-Bits);
1722 }
1723
1724 bool isNullValue() const { return Value->isNullValue(); }
1725 bool isAllOnesValue() const { return Value->isAllOnesValue(); }
17281726
17291727 static bool classof(const ConstantSDNode *) { return true; }
17301728 static bool classof(const SDNode *N) {
17341732 };
17351733
17361734 class ConstantFPSDNode : public SDNode {
1737 APFloat Value;
1735 const ConstantFP *Value;
17381736 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
17391737 protected:
17401738 friend class SelectionDAG;
1741 ConstantFPSDNode(bool isTarget, const APFloat& val, MVT VT)
1739 ConstantFPSDNode(bool isTarget, const ConstantFP *val, MVT VT)
17421740 : SDNode(isTarget ? ISD::TargetConstantFP : ISD::ConstantFP,
17431741 getSDVTList(VT)), Value(val) {
17441742 }
17451743 public:
17461744
1747 const APFloat& getValueAPF() const { return Value; }
1745 const APFloat& getValueAPF() const { return Value->getValueAPF(); }
1746 const ConstantFP *getConstantFPValue() const { return Value; }
17481747
17491748 /// isExactlyValue - We don't rely on operator== working on double values, as
17501749 /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
17561755 /// have to duplicate its logic everywhere it's called.
17571756 bool isExactlyValue(double V) const {
17581757 // convert is not supported on this type
1759 if (&Value.getSemantics() == &APFloat::PPCDoubleDouble)
1758 if (&Value->getValueAPF().getSemantics() == &APFloat::PPCDoubleDouble)
17601759 return false;
17611760 APFloat Tmp(V);
1762 Tmp.convert(Value.getSemantics(), APFloat::rmNearestTiesToEven);
1761 Tmp.convert(Value->getValueAPF().getSemantics(),
1762 APFloat::rmNearestTiesToEven);
17631763 return isExactlyValue(Tmp);
17641764 }
17651765 bool isExactlyValue(const APFloat& V) const;
40204020
40214021 // fold (fp_round_inreg c1fp) -> c1fp
40224022 if (N0CFP) {
4023 SDValue Round = DAG.getConstantFP(N0CFP->getValueAPF(), EVT);
4023 SDValue Round = DAG.getConstantFP(*N0CFP->getConstantFPValue(), EVT);
40244024 return DAG.getNode(ISD::FP_EXTEND, VT, Round);
40254025 }
40264026 return SDValue();
441441 // an FP extending load is the same cost as a normal load (such as on the x87
442442 // fp stack or PPC FP unit).
443443 MVT VT = CFP->getValueType(0);
444 ConstantFP *LLVMC = ConstantFP::get(CFP->getValueAPF());
444 ConstantFP *LLVMC = const_cast(CFP->getConstantFPValue());
445445 if (!UseCP) {
446446 if (VT!=MVT::f64 && VT!=MVT::f32)
447447 assert(0 && "Invalid type expansion");
49834983 for (unsigned i = 0, e = NumElems; i != e; ++i) {
49844984 if (ConstantFPSDNode *V =
49854985 dyn_cast(Node->getOperand(i))) {
4986 CV.push_back(ConstantFP::get(V->getValueAPF()));
4986 CV.push_back(const_cast(V->getConstantFPValue()));
49874987 } else if (ConstantSDNode *V =
49884988 dyn_cast(Node->getOperand(i))) {
4989 CV.push_back(ConstantInt::get(V->getAPIntValue()));
4989 CV.push_back(const_cast(V->getConstantIntValue()));
49904990 } else {
49914991 assert(Node->getOperand(i).getOpcode() == ISD::UNDEF);
49924992 const Type *OpNTy =
255255 } else if (ConstantSDNode *C = dyn_cast(Op)) {
256256 MI->addOperand(MachineOperand::CreateImm(C->getZExtValue()));
257257 } else if (ConstantFPSDNode *F = dyn_cast(Op)) {
258 ConstantFP *CFP = ConstantFP::get(F->getValueAPF());
258 const ConstantFP *CFP = F->getConstantFPValue();
259259 MI->addOperand(MachineOperand::CreateFPImm(CFP));
260260 } else if (RegisterSDNode *R = dyn_cast(Op)) {
261261 MI->addOperand(MachineOperand::CreateReg(R->getReg(), false));
6868 /// As such, this method can be used to do an exact bit-for-bit comparison of
6969 /// two floating point values.
7070 bool ConstantFPSDNode::isExactlyValue(const APFloat& V) const {
71 return Value.bitwiseIsEqual(V);
71 return getValueAPF().bitwiseIsEqual(V);
7272 }
7373
7474 bool ConstantFPSDNode::isValueValidForType(MVT VT,
366366 break;
367367 case ISD::TargetConstant:
368368 case ISD::Constant:
369 ID.Add(cast(N)->getAPIntValue());
369 ID.AddPointer(cast(N)->getConstantIntValue());
370370 break;
371371 case ISD::TargetConstantFP:
372372 case ISD::ConstantFP: {
373 ID.Add(cast(N)->getValueAPF());
373 ID.AddPointer(cast(N)->getConstantFPValue());
374374 break;
375375 }
376376 case ISD::TargetGlobalAddress:
860860 }
861861
862862 SDValue SelectionDAG::getConstant(const APInt &Val, MVT VT, bool isT) {
863 return getConstant(*ConstantInt::get(Val), VT, isT);
864 }
865
866 SDValue SelectionDAG::getConstant(const ConstantInt &Val, MVT VT, bool isT) {
863867 assert(VT.isInteger() && "Cannot create FP integer constant!");
864868
865869 MVT EltVT = VT.isVector() ? VT.getVectorElementType() : VT;
869873 unsigned Opc = isT ? ISD::TargetConstant : ISD::Constant;
870874 FoldingSetNodeID ID;
871875 AddNodeIDNode(ID, Opc, getVTList(EltVT), 0, 0);
872 ID.Add(Val);
876 ID.AddPointer(&Val);
873877 void *IP = 0;
874878 SDNode *N = NULL;
875879 if ((N = CSEMap.FindNodeOrInsertPos(ID, IP)))
877881 return SDValue(N, 0);
878882 if (!N) {
879883 N = NodeAllocator.Allocate();
880 new (N) ConstantSDNode(isT, Val, EltVT);
884 new (N) ConstantSDNode(isT, &Val, EltVT);
881885 CSEMap.InsertNode(N, IP);
882886 AllNodes.push_back(N);
883887 }
897901
898902
899903 SDValue SelectionDAG::getConstantFP(const APFloat& V, MVT VT, bool isTarget) {
904 return getConstantFP(*ConstantFP::get(V), VT, isTarget);
905 }
906
907 SDValue SelectionDAG::getConstantFP(const ConstantFP& V, MVT VT, bool isTarget){
900908 assert(VT.isFloatingPoint() && "Cannot create integer FP constant!");
901909
902910 MVT EltVT =
908916 unsigned Opc = isTarget ? ISD::TargetConstantFP : ISD::ConstantFP;
909917 FoldingSetNodeID ID;
910918 AddNodeIDNode(ID, Opc, getVTList(EltVT), 0, 0);
911 ID.Add(V);
919 ID.AddPointer(&V);
912920 void *IP = 0;
913921 SDNode *N = NULL;
914922 if ((N = CSEMap.FindNodeOrInsertPos(ID, IP)))
916924 return SDValue(N, 0);
917925 if (!N) {
918926 N = NodeAllocator.Allocate();
919 new (N) ConstantFPSDNode(isTarget, V, EltVT);
927 new (N) ConstantFPSDNode(isTarget, &V, EltVT);
920928 CSEMap.InsertNode(N, IP);
921929 AllNodes.push_back(N);
922930 }
793793 MVT VT = TLI.getValueType(V->getType(), true);
794794
795795 if (ConstantInt *CI = dyn_cast(C))
796 return N = DAG.getConstant(CI->getValue(), VT);
796 return N = DAG.getConstant(*CI, VT);
797797
798798 if (GlobalValue *GV = dyn_cast(C))
799799 return N = DAG.getGlobalAddress(GV, VT);
802802 return N = DAG.getConstant(0, TLI.getPointerTy());
803803
804804 if (ConstantFP *CFP = dyn_cast(C))
805 return N = DAG.getConstantFP(CFP->getValueAPF(), VT);
805 return N = DAG.getConstantFP(*CFP, VT);
806806
807807 if (isa(C) && !isa(V->getType()) &&
808808 !V->getType()->isAggregateType())
791791 assert(N->getExtTypes().size() == 1 && "Multiple types not handled!");
792792 std::string TmpVar = "Tmp" + utostr(ResNo);
793793 emitCode("SDValue " + TmpVar +
794 " = CurDAG->getTargetConstantFP(cast(" +
795 Val + ")->getValueAPF(), cast(" + Val +
796 ")->getValueType(0));");
794 " = CurDAG->getTargetConstantFP(*cast(" +
795 Val + ")->getConstantFPValue(), cast(" +
796 Val + ")->getValueType(0));");
797797 // Add Tmp to VariableMap, so that we don't multiply select this
798798 // value if used multiple times by this pattern result.
799799 Val = TmpVar;