Fixed the comment. No functionality change.
[oota-llvm.git] / lib / CodeGen / SelectionDAG / SelectionDAGBuild.cpp
index 09e3bf6b3d29b50f47e3c16c7691d1b9e20c6579..0e8d9bee5ed1216dc0598201c9cf397e03099665 100644 (file)
@@ -335,8 +335,9 @@ void FunctionLoweringInfo::set(Function &fn, MachineFunction &mf,
 
             if (DW && DW->ValidDebugInfo(SPI->getContext())) {
               DICompileUnit CU(cast<GlobalVariable>(SPI->getContext()));
-              unsigned SrcFile = DW->RecordSource(CU.getDirectory(),
-                                                  CU.getFilename());
+              std::string Dir, FN;
+              unsigned SrcFile = DW->getOrCreateSourceID(CU.getDirectory(Dir),
+                                                         CU.getFilename(FN));
               unsigned idx = MF->getOrCreateDebugLocID(SrcFile,
                                                        SPI->getLine(),
                                                        SPI->getColumn());
@@ -354,8 +355,9 @@ void FunctionLoweringInfo::set(Function &fn, MachineFunction &mf,
               if (DW->ValidDebugInfo(SP)) {
                 DISubprogram Subprogram(cast<GlobalVariable>(SP));
                 DICompileUnit CU(Subprogram.getCompileUnit());
-                unsigned SrcFile = DW->RecordSource(CU.getDirectory(),
-                                                    CU.getFilename());
+                std::string Dir, FN;
+                unsigned SrcFile = DW->getOrCreateSourceID(CU.getDirectory(Dir),
+                                                           CU.getFilename(FN));
                 unsigned Line = Subprogram.getLineNumber();
                 DL = DebugLoc::get(MF->getOrCreateDebugLocID(SrcFile, Line, 0));
               }
@@ -576,6 +578,7 @@ static void getCopyToParts(SelectionDAG &DAG, DebugLoc dl, SDValue Val,
   MVT PtrVT = TLI.getPointerTy();
   MVT ValueVT = Val.getValueType();
   unsigned PartBits = PartVT.getSizeInBits();
+  unsigned OrigNumParts = NumParts;
   assert(TLI.isTypeLegal(PartVT) && "Copying to an illegal type!");
 
   if (!NumParts)
@@ -673,7 +676,7 @@ static void getCopyToParts(SelectionDAG &DAG, DebugLoc dl, SDValue Val,
     }
 
     if (TLI.isBigEndian())
-      std::reverse(Parts, Parts + NumParts);
+      std::reverse(Parts, Parts + OrigNumParts);
 
     return;
   }
@@ -976,15 +979,6 @@ void SelectionDAGLowering::visitRet(ReturnInst &I) {
     for (unsigned j = 0, f = NumValues; j != f; ++j) {
       MVT VT = ValueVTs[j];
 
-      // FIXME: C calling convention requires the return type to be promoted to
-      // at least 32-bit. But this is not necessary for non-C calling
-      // conventions.
-      if (VT.isInteger()) {
-        MVT MinVT = TLI.getRegisterType(MVT::i32);
-        if (VT.bitsLT(MinVT))
-          VT = MinVT;
-      }
-
       unsigned NumParts = TLI.getNumRegisters(VT);
       MVT PartVT = TLI.getRegisterType(VT);
       SmallVector<SDValue, 4> Parts(NumParts);
@@ -2760,6 +2754,13 @@ void SelectionDAGLowering::visitAlloca(AllocaInst &I) {
              I.getAlignment());
 
   SDValue AllocSize = getValue(I.getArraySize());
+  
+  AllocSize = DAG.getNode(ISD::MUL, getCurDebugLoc(), AllocSize.getValueType(),
+                          AllocSize,
+                          DAG.getConstant(TySize, AllocSize.getValueType()));
+  
+  
+  
   MVT IntPtr = TLI.getPointerTy();
   if (IntPtr.bitsLT(AllocSize.getValueType()))
     AllocSize = DAG.getNode(ISD::TRUNCATE, getCurDebugLoc(),
@@ -2768,9 +2769,6 @@ void SelectionDAGLowering::visitAlloca(AllocaInst &I) {
     AllocSize = DAG.getNode(ISD::ZERO_EXTEND, getCurDebugLoc(),
                             IntPtr, AllocSize);
 
-  AllocSize = DAG.getNode(ISD::MUL, getCurDebugLoc(), IntPtr, AllocSize,
-                          DAG.getIntPtrConstant(TySize));
-
   // Handle alignment.  If the requested alignment is less than or equal to
   // the stack alignment, ignore it.  If the size is greater than or equal to
   // the stack alignment, we note this in the DYNAMIC_STACKALLOC node.
@@ -3895,16 +3893,17 @@ SelectionDAGLowering::visitIntrinsicCall(CallInst &I, unsigned Intrinsic) {
     DwarfWriter *DW = DAG.getDwarfWriter();
     DbgStopPointInst &SPI = cast<DbgStopPointInst>(I);
     if (DW && DW->ValidDebugInfo(SPI.getContext())) {
+      MachineFunction &MF = DAG.getMachineFunction();
       DAG.setRoot(DAG.getDbgStopPoint(getRoot(),
                                       SPI.getLine(),
                                       SPI.getColumn(),
                                       SPI.getContext()));
       DICompileUnit CU(cast<GlobalVariable>(SPI.getContext()));
-      unsigned SrcFile = DW->RecordSource(CU.getDirectory(), CU.getFilename());
-      unsigned idx = DAG.getMachineFunction().
-                         getOrCreateDebugLocID(SrcFile,
-                                               SPI.getLine(),
-                                               SPI.getColumn());
+      std::string Dir, FN;
+      unsigned SrcFile = DW->getOrCreateSourceID(CU.getDirectory(Dir),
+                                                 CU.getFilename(FN));
+      unsigned idx = MF.getOrCreateDebugLocID(SrcFile,
+                                              SPI.getLine(), SPI.getColumn());
       setCurDebugLoc(DebugLoc::get(idx));
     }
     return 0;
@@ -3943,10 +3942,12 @@ SelectionDAGLowering::visitIntrinsicCall(CallInst &I, unsigned Intrinsic) {
     if (SP && DW->ValidDebugInfo(SP)) {
       // llvm.dbg.func.start implicitly defines a dbg_stoppoint which is
       // what (most?) gdb expects.
+      MachineFunction &MF = DAG.getMachineFunction();
       DISubprogram Subprogram(cast<GlobalVariable>(SP));
       DICompileUnit CompileUnit = Subprogram.getCompileUnit();
-      unsigned SrcFile = DW->RecordSource(CompileUnit.getDirectory(),
-                                          CompileUnit.getFilename());
+      std::string Dir, FN;
+      unsigned SrcFile = DW->getOrCreateSourceID(CompileUnit.getDirectory(Dir),
+                                                 CompileUnit.getFilename(FN));
 
       // Record the source line but does not create a label for the normal
       // function start. It will be emitted at asm emission time. However,
@@ -3960,15 +3961,13 @@ SelectionDAGLowering::visitIntrinsicCall(CallInst &I, unsigned Intrinsic) {
                                    getRoot(), LabelID));
       }
 
-      setCurDebugLoc(DebugLoc::get(DAG.getMachineFunction().
-                                   getOrCreateDebugLocID(SrcFile, Line, 0)));
+      setCurDebugLoc(DebugLoc::get(MF.getOrCreateDebugLocID(SrcFile, Line, 0)));
     }
 
     return 0;
   }
   case Intrinsic::dbg_declare: {
-    const Function *F = I.getParent()->getParent();
-    if (!F->hasFnAttr(Attribute::OptimizeForSize)) {
+    if (Fast) {
       DwarfWriter *DW = DAG.getDwarfWriter();
       DbgDeclareInst &DI = cast<DbgDeclareInst>(I);
       Value *Variable = DI.getVariable();
@@ -5421,6 +5420,16 @@ void SelectionDAGLowering::visitInlineAsm(CallSite CS) {
 void SelectionDAGLowering::visitMalloc(MallocInst &I) {
   SDValue Src = getValue(I.getOperand(0));
 
+  // Scale up by the type size in the original i32 type width.  Various
+  // mid-level optimizers may make assumptions about demanded bits etc from the
+  // i32-ness of the optimizer: we do not want to promote to i64 and then
+  // multiply on 64-bit targets.
+  // FIXME: Malloc inst should go away: PR715.
+  uint64_t ElementSize = TD->getTypePaddedSize(I.getType()->getElementType());
+  if (ElementSize != 1)
+    Src = DAG.getNode(ISD::MUL, getCurDebugLoc(), Src.getValueType(),
+                      Src, DAG.getConstant(ElementSize, Src.getValueType()));
+  
   MVT IntPtr = TLI.getPointerTy();
 
   if (IntPtr.bitsLT(Src.getValueType()))
@@ -5428,11 +5437,6 @@ void SelectionDAGLowering::visitMalloc(MallocInst &I) {
   else if (IntPtr.bitsGT(Src.getValueType()))
     Src = DAG.getNode(ISD::ZERO_EXTEND, getCurDebugLoc(), IntPtr, Src);
 
-  // Scale the source by the type size.
-  uint64_t ElementSize = TD->getTypePaddedSize(I.getType()->getElementType());
-  Src = DAG.getNode(ISD::MUL, getCurDebugLoc(), Src.getValueType(),
-                    Src, DAG.getIntPtrConstant(ElementSize));
-
   TargetLowering::ArgListTy Args;
   TargetLowering::ArgListEntry Entry;
   Entry.Node = Src;