Add a new codegen pass that normalizes dwarf exception handling
[oota-llvm.git] / lib / CodeGen / SelectionDAG / SelectionDAGBuild.cpp
index 6fe56578b2065cee451a1ce224f29d33a6bc323b..889d7f5dd93444fe43af80560f4c2354cff291c2 100644 (file)
@@ -45,7 +45,6 @@
 #include "llvm/Target/TargetInstrInfo.h"
 #include "llvm/Target/TargetIntrinsicInfo.h"
 #include "llvm/Target/TargetLowering.h"
-#include "llvm/Target/TargetMachine.h"
 #include "llvm/Target/TargetOptions.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/CommandLine.h"
@@ -129,7 +128,7 @@ static void ComputeValueVTs(const TargetLowering &TLI, const Type *Ty,
   // Given an array type, recursively traverse the elements.
   if (const ArrayType *ATy = dyn_cast<ArrayType>(Ty)) {
     const Type *EltTy = ATy->getElementType();
-    uint64_t EltSize = TLI.getTargetData()->getTypePaddedSize(EltTy);
+    uint64_t EltSize = TLI.getTargetData()->getTypeAllocSize(EltTy);
     for (unsigned i = 0, e = ATy->getNumElements(); i != e; ++i)
       ComputeValueVTs(TLI, EltTy, ValueVTs, Offsets,
                       StartingOffset + i * EltSize);
@@ -295,7 +294,7 @@ void FunctionLoweringInfo::set(Function &fn, MachineFunction &mf,
     if (AllocaInst *AI = dyn_cast<AllocaInst>(I))
       if (ConstantInt *CUI = dyn_cast<ConstantInt>(AI->getArraySize())) {
         const Type *Ty = AI->getAllocatedType();
-        uint64_t TySize = TLI.getTargetData()->getTypePaddedSize(Ty);
+        uint64_t TySize = TLI.getTargetData()->getTypeAllocSize(Ty);
         unsigned Align =
           std::max((unsigned)TLI.getTargetData()->getPrefTypeAlignment(Ty),
                    AI->getAlignment());
@@ -332,15 +331,12 @@ void FunctionLoweringInfo::set(Function &fn, MachineFunction &mf,
           switch (F->getIntrinsicID()) {
           default: break;
           case Intrinsic::dbg_stoppoint: {
-            DwarfWriter *DW = DAG.getDwarfWriter();
             DbgStopPointInst *SPI = cast<DbgStopPointInst>(I);
 
-            if (DW && DW->ValidDebugInfo(SPI->getContext(), false)) {
+            if (DIDescriptor::ValidDebugInfo(SPI->getContext(),
+                                             CodeGenOpt::Default)) {
               DICompileUnit CU(cast<GlobalVariable>(SPI->getContext()));
-              std::string Dir, FN;
-              unsigned SrcFile = DW->getOrCreateSourceID(CU.getDirectory(Dir),
-                                                         CU.getFilename(FN));
-              unsigned idx = MF->getOrCreateDebugLocID(SrcFile,
+              unsigned idx = MF->getOrCreateDebugLocID(CU.getGV(),
                                                        SPI->getLine(),
                                                        SPI->getColumn());
               DL = DebugLoc::get(idx);
@@ -349,20 +345,15 @@ void FunctionLoweringInfo::set(Function &fn, MachineFunction &mf,
             break;
           }
           case Intrinsic::dbg_func_start: {
-            DwarfWriter *DW = DAG.getDwarfWriter();
-            if (DW) {
-              DbgFuncStartInst *FSI = cast<DbgFuncStartInst>(I);
-              Value *SP = FSI->getSubprogram();
-
-              if (DW->ValidDebugInfo(SP, false)) {
-                DISubprogram Subprogram(cast<GlobalVariable>(SP));
-                DICompileUnit CU(Subprogram.getCompileUnit());
-                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));
-              }
+            DbgFuncStartInst *FSI = cast<DbgFuncStartInst>(I);
+            Value *SP = FSI->getSubprogram();
+
+            if (DIDescriptor::ValidDebugInfo(SP, CodeGenOpt::Default)) {
+              DISubprogram Subprogram(cast<GlobalVariable>(SP));
+              DICompileUnit CU(Subprogram.getCompileUnit());
+              unsigned Line = Subprogram.getLineNumber();
+              DL = DebugLoc::get(MF->getOrCreateDebugLocID(CU.getGV(),
+                                                           Line, 0));
             }
 
             break;
@@ -435,7 +426,7 @@ static SDValue getCopyFromParts(SelectionDAG &DAG, DebugLoc dl,
 
   if (NumParts > 1) {
     // Assemble the value from multiple parts.
-    if (!ValueVT.isVector()) {
+    if (!ValueVT.isVector() && ValueVT.isInteger()) {
       unsigned PartBits = PartVT.getSizeInBits();
       unsigned ValueBits = ValueVT.getSizeInBits();
 
@@ -447,9 +438,7 @@ static SDValue getCopyFromParts(SelectionDAG &DAG, DebugLoc dl,
         ValueVT : MVT::getIntegerVT(RoundBits);
       SDValue Lo, Hi;
 
-      MVT HalfVT = ValueVT.isInteger() ?
-        MVT::getIntegerVT(RoundBits/2) :
-        MVT::getFloatingPointVT(RoundBits/2);
+      MVT HalfVT = MVT::getIntegerVT(RoundBits/2);
 
       if (RoundParts > 2) {
         Lo = getCopyFromParts(DAG, dl, Parts, RoundParts/2, PartVT, HalfVT);
@@ -482,7 +471,7 @@ static SDValue getCopyFromParts(SelectionDAG &DAG, DebugLoc dl,
         Lo = DAG.getNode(ISD::ZERO_EXTEND, dl, TotalVT, Lo);
         Val = DAG.getNode(ISD::OR, dl, TotalVT, Lo, Hi);
       }
-    } else {
+    } else if (ValueVT.isVector()) {
       // Handle a multi-element vector.
       MVT IntermediateVT, RegisterVT;
       unsigned NumIntermediates;
@@ -519,6 +508,22 @@ static SDValue getCopyFromParts(SelectionDAG &DAG, DebugLoc dl,
       Val = DAG.getNode(IntermediateVT.isVector() ?
                         ISD::CONCAT_VECTORS : ISD::BUILD_VECTOR, dl,
                         ValueVT, &Ops[0], NumIntermediates);
+    } else if (PartVT.isFloatingPoint()) {
+      // FP split into multiple FP parts (for ppcf128)
+      assert(ValueVT == MVT(MVT::ppcf128) && PartVT == MVT(MVT::f64) &&
+             "Unexpected split");
+      SDValue Lo, Hi;
+      Lo = DAG.getNode(ISD::BIT_CONVERT, dl, MVT(MVT::f64), Parts[0]);
+      Hi = DAG.getNode(ISD::BIT_CONVERT, dl, MVT(MVT::f64), Parts[1]);
+      if (TLI.isBigEndian())
+        std::swap(Lo, Hi);
+      Val = DAG.getNode(ISD::BUILD_PAIR, dl, ValueVT, Lo, Hi);
+    } else {
+      // FP split into integer parts (soft fp)
+      assert(ValueVT.isFloatingPoint() && PartVT.isInteger() &&
+             !PartVT.isVector() && "Unexpected split");
+      MVT IntVT = MVT::getIntegerVT(ValueVT.getSizeInBits());
+      Val = getCopyFromParts(DAG, dl, Parts, NumParts, PartVT, IntVT);
     }
   }
 
@@ -1932,6 +1937,10 @@ bool SelectionDAGLowering::handleBitTestsSwitchCase(CaseRec& CR,
   // inserting any additional MBBs necessary to represent the switch.
   MachineFunction *CurMF = CurMBB->getParent();
 
+  // If target does not have legal shift left, do not emit bit tests at all.
+  if (!TLI.isOperationLegal(ISD::SHL, TLI.getPointerTy()))
+    return false;
+
   size_t numCmps = 0;
   for (CaseItr I = CR.Range.first, E = CR.Range.second;
        I!=E; ++I) {
@@ -2431,10 +2440,10 @@ void SelectionDAGLowering::visitExtractElement(User &I) {
 
 // Utility for visitShuffleVector - Returns true if the mask is mask starting
 // from SIndx and increasing to the element length (undefs are allowed).
-static bool SequentialMask(SmallVectorImpl<int> &Mask, int SIndx) {
-  int MaskNumElts = Mask.size();
-  for (int i = 0; i != MaskNumElts; ++i)
-    if ((Mask[i] >= 0) && (Mask[i] != i + SIndx))
+static bool SequentialMask(SmallVectorImpl<int> &Mask, unsigned SIndx) {
+  unsigned MaskNumElts = Mask.size();
+  for (unsigned i = 0; i != MaskNumElts; ++i)
+    if ((Mask[i] >= 0) && (Mask[i] != (int)(i + SIndx)))
       return false;
   return true;
 }
@@ -2448,8 +2457,8 @@ void SelectionDAGLowering::visitShuffleVector(User &I) {
   // representing undef values.
   SmallVector<Constant*, 8> MaskElts;
   cast<Constant>(I.getOperand(2))->getVectorElements(MaskElts);
-  int MaskNumElts = MaskElts.size();
-  for (int i = 0; i != MaskNumElts; ++i) {
+  unsigned MaskNumElts = MaskElts.size();
+  for (unsigned i = 0; i != MaskNumElts; ++i) {
     if (isa<UndefValue>(MaskElts[i]))
       Mask.push_back(-1);
     else
@@ -2458,7 +2467,7 @@ void SelectionDAGLowering::visitShuffleVector(User &I) {
   
   MVT VT = TLI.getValueType(I.getType());
   MVT SrcVT = Src1.getValueType();
-  int SrcNumElts = SrcVT.getVectorNumElements();
+  unsigned SrcNumElts = SrcVT.getVectorNumElements();
 
   if (SrcNumElts == MaskNumElts) {
     setValue(&I, DAG.getVectorShuffle(VT, getCurDebugLoc(), Src1, Src2,
@@ -2498,9 +2507,9 @@ void SelectionDAGLowering::visitShuffleVector(User &I) {
 
     // Readjust mask for new input vector length.
     SmallVector<int, 8> MappedOps;
-    for (int i = 0; i != MaskNumElts; ++i) {
+    for (unsigned i = 0; i != MaskNumElts; ++i) {
       int Idx = Mask[i];
-      if (Idx < SrcNumElts)
+      if (Idx < (int)SrcNumElts)
         MappedOps.push_back(Idx);
       else
         MappedOps.push_back(Idx + MaskNumElts - SrcNumElts);
@@ -2511,32 +2520,19 @@ void SelectionDAGLowering::visitShuffleVector(User &I) {
   }
 
   if (SrcNumElts > MaskNumElts) {
-    // Resulting vector is shorter than the incoming vector.
-    if (SrcNumElts == MaskNumElts && SequentialMask(Mask,0)) {
-      // Shuffle extracts 1st vector.
-      setValue(&I, Src1);
-      return;
-    }
-
-    if (SrcNumElts == MaskNumElts && SequentialMask(Mask,MaskNumElts)) {
-      // Shuffle extracts 2nd vector.
-      setValue(&I, Src2);
-      return;
-    }
-
     // Analyze the access pattern of the vector to see if we can extract
     // two subvectors and do the shuffle. The analysis is done by calculating
     // the range of elements the mask access on both vectors.
     int MinRange[2] = { SrcNumElts+1, SrcNumElts+1};
     int MaxRange[2] = {-1, -1};
 
-    for (int i = 0; i != MaskNumElts; ++i) {
+    for (unsigned i = 0; i != MaskNumElts; ++i) {
       int Idx = Mask[i];
       int Input = 0;
       if (Idx < 0)
         continue;
       
-      if (Idx >= SrcNumElts) {
+      if (Idx >= (int)SrcNumElts) {
         Input = 1;
         Idx -= SrcNumElts;
       }
@@ -2551,18 +2547,18 @@ void SelectionDAGLowering::visitShuffleVector(User &I) {
     int RangeUse[2] = { 2, 2 };  // 0 = Unused, 1 = Extract, 2 = Can not Extract.
     int StartIdx[2];  // StartIdx to extract from
     for (int Input=0; Input < 2; ++Input) {
-      if (MinRange[Input] == SrcNumElts+1 && MaxRange[Input] == -1) {
+      if (MinRange[Input] == (int)(SrcNumElts+1) && MaxRange[Input] == -1) {
         RangeUse[Input] = 0; // Unused
         StartIdx[Input] = 0;
-      } else if (MaxRange[Input] - MinRange[Input] < MaskNumElts) {
+      } else if (MaxRange[Input] - MinRange[Input] < (int)MaskNumElts) {
         // Fits within range but we should see if we can find a good
         // start index that is a multiple of the mask length.
-        if (MaxRange[Input] < MaskNumElts) {
+        if (MaxRange[Input] < (int)MaskNumElts) {
           RangeUse[Input] = 1; // Extract from beginning of the vector
           StartIdx[Input] = 0;
         } else {
           StartIdx[Input] = (MinRange[Input]/MaskNumElts)*MaskNumElts;
-          if (MaxRange[Input] - StartIdx[Input] < MaskNumElts &&
+          if (MaxRange[Input] - StartIdx[Input] < (int)MaskNumElts &&
               StartIdx[Input] + MaskNumElts < SrcNumElts)
             RangeUse[Input] = 1; // Extract from a multiple of the mask length.
         }
@@ -2586,11 +2582,11 @@ void SelectionDAGLowering::visitShuffleVector(User &I) {
       }
       // Calculate new mask.
       SmallVector<int, 8> MappedOps;
-      for (int i = 0; i != MaskNumElts; ++i) {
+      for (unsigned i = 0; i != MaskNumElts; ++i) {
         int Idx = Mask[i];
         if (Idx < 0)
           MappedOps.push_back(Idx);
-        else if (Idx < SrcNumElts)
+        else if (Idx < (int)SrcNumElts)
           MappedOps.push_back(Idx - StartIdx[0]);
         else
           MappedOps.push_back(Idx - SrcNumElts - StartIdx[1] + MaskNumElts);
@@ -2607,12 +2603,12 @@ void SelectionDAGLowering::visitShuffleVector(User &I) {
   MVT EltVT = VT.getVectorElementType();
   MVT PtrVT = TLI.getPointerTy();
   SmallVector<SDValue,8> Ops;
-  for (int i = 0; i != MaskNumElts; ++i) {
+  for (unsigned i = 0; i != MaskNumElts; ++i) {
     if (Mask[i] < 0) {
       Ops.push_back(DAG.getUNDEF(EltVT));
     } else {
       int Idx = Mask[i];
-      if (Idx < SrcNumElts)
+      if (Idx < (int)SrcNumElts)
         Ops.push_back(DAG.getNode(ISD::EXTRACT_VECTOR_ELT, getCurDebugLoc(),
                                   EltVT, Src1, DAG.getConstant(Idx, PtrVT)));
       else
@@ -2718,7 +2714,7 @@ void SelectionDAGLowering::visitGetElementPtr(User &I) {
       if (ConstantInt *CI = dyn_cast<ConstantInt>(Idx)) {
         if (CI->getZExtValue() == 0) continue;
         uint64_t Offs =
-            TD->getTypePaddedSize(Ty)*cast<ConstantInt>(CI)->getSExtValue();
+            TD->getTypeAllocSize(Ty)*cast<ConstantInt>(CI)->getSExtValue();
         SDValue OffsVal;
         unsigned PtrBits = TLI.getPointerTy().getSizeInBits();
         if (PtrBits < 64) {
@@ -2733,7 +2729,7 @@ void SelectionDAGLowering::visitGetElementPtr(User &I) {
       }
 
       // N = N + Idx * ElementSize;
-      uint64_t ElementSize = TD->getTypePaddedSize(Ty);
+      uint64_t ElementSize = TD->getTypeAllocSize(Ty);
       SDValue IdxN = getValue(Idx);
 
       // If the index is smaller or larger than intptr_t, truncate or extend
@@ -2774,7 +2770,7 @@ void SelectionDAGLowering::visitAlloca(AllocaInst &I) {
     return;   // getValue will auto-populate this.
 
   const Type *Ty = I.getAllocatedType();
-  uint64_t TySize = TLI.getTargetData()->getTypePaddedSize(Ty);
+  uint64_t TySize = TLI.getTargetData()->getTypeAllocSize(Ty);
   unsigned Align =
     std::max((unsigned)TLI.getTargetData()->getPrefTypeAlignment(Ty),
              I.getAlignment());
@@ -3908,22 +3904,19 @@ SelectionDAGLowering::visitIntrinsicCall(CallInst &I, unsigned Intrinsic) {
     return 0;
   }
   case Intrinsic::dbg_stoppoint: {
-    DwarfWriter *DW = DAG.getDwarfWriter();
     DbgStopPointInst &SPI = cast<DbgStopPointInst>(I);
-    if (DW && DW->ValidDebugInfo(SPI.getContext(), OptLevel)) {
+    if (DIDescriptor::ValidDebugInfo(SPI.getContext(), OptLevel)) {
       MachineFunction &MF = DAG.getMachineFunction();
-      if (OptLevel == 0)
-        DAG.setRoot(DAG.getDbgStopPoint(getRoot(),
+      DICompileUnit CU(cast<GlobalVariable>(SPI.getContext()));
+      DebugLoc Loc = DebugLoc::get(MF.getOrCreateDebugLocID(CU.getGV(),
+                                              SPI.getLine(), SPI.getColumn()));
+      setCurDebugLoc(Loc);
+      
+      if (OptLevel == CodeGenOpt::None)
+        DAG.setRoot(DAG.getDbgStopPoint(Loc, getRoot(),
                                         SPI.getLine(),
                                         SPI.getColumn(),
                                         SPI.getContext()));
-      DICompileUnit CU(cast<GlobalVariable>(SPI.getContext()));
-      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;
   }
@@ -3931,7 +3924,8 @@ SelectionDAGLowering::visitIntrinsicCall(CallInst &I, unsigned Intrinsic) {
     DwarfWriter *DW = DAG.getDwarfWriter();
     DbgRegionStartInst &RSI = cast<DbgRegionStartInst>(I);
 
-    if (DW && DW->ValidDebugInfo(RSI.getContext(), OptLevel)) {
+    if (DIDescriptor::ValidDebugInfo(RSI.getContext(), OptLevel) &&
+        DW && DW->ShouldEmitDwarfDebug()) {
       unsigned LabelID =
         DW->RecordRegionStart(cast<GlobalVariable>(RSI.getContext()));
       DAG.setRoot(DAG.getLabel(ISD::DBG_LABEL, getCurDebugLoc(),
@@ -3944,119 +3938,115 @@ SelectionDAGLowering::visitIntrinsicCall(CallInst &I, unsigned Intrinsic) {
     DwarfWriter *DW = DAG.getDwarfWriter();
     DbgRegionEndInst &REI = cast<DbgRegionEndInst>(I);
 
-    if (DW && DW->ValidDebugInfo(REI.getContext(), OptLevel)) {
+    if (DIDescriptor::ValidDebugInfo(REI.getContext(), OptLevel) &&
+        DW && DW->ShouldEmitDwarfDebug()) {
       MachineFunction &MF = DAG.getMachineFunction();
       DISubprogram Subprogram(cast<GlobalVariable>(REI.getContext()));
-      std::string SPName;
-      Subprogram.getLinkageName(SPName);
-      if (!SPName.empty() 
-          && strcmp(SPName.c_str(), MF.getFunction()->getNameStart())) {
-          // This is end of inlined function. Debugging information for
-          // inlined function is not handled yet (only supported by FastISel).
-        if (OptLevel == 0) {
+
+      if (Subprogram.isNull() || Subprogram.describes(MF.getFunction())) {
+        unsigned LabelID =
+          DW->RecordRegionEnd(cast<GlobalVariable>(REI.getContext()));
+        DAG.setRoot(DAG.getLabel(ISD::DBG_LABEL, getCurDebugLoc(),
+                                 getRoot(), LabelID));
+      } else {
+        // This is end of inlined function. Debugging information for inlined
+        // function is not handled yet (only supported by FastISel).
+        if (OptLevel == CodeGenOpt::None) {
           unsigned ID = DW->RecordInlinedFnEnd(Subprogram);
           if (ID != 0)
             // Returned ID is 0 if this is unbalanced "end of inlined
-            // scope". This could happen if optimizer eats dbg intrinsics
-            // or "beginning of inlined scope" is not recoginized due to
-            // missing location info. In such cases, do ignore this region.end.
+            // scope". This could happen if optimizer eats dbg intrinsics or
+            // "beginning of inlined scope" is not recoginized due to missing
+            // location info. In such cases, do ignore this region.end.
             DAG.setRoot(DAG.getLabel(ISD::DBG_LABEL, getCurDebugLoc(), 
                                      getRoot(), ID));
         }
-        return 0;
       }
-
-      unsigned LabelID =
-        DW->RecordRegionEnd(cast<GlobalVariable>(REI.getContext()));
-      DAG.setRoot(DAG.getLabel(ISD::DBG_LABEL, getCurDebugLoc(),
-                               getRoot(), LabelID));
     }
 
     return 0;
   }
   case Intrinsic::dbg_func_start: {
     DwarfWriter *DW = DAG.getDwarfWriter();
-    if (!DW) return 0;
     DbgFuncStartInst &FSI = cast<DbgFuncStartInst>(I);
     Value *SP = FSI.getSubprogram();
-    if (SP && DW->ValidDebugInfo(SP, OptLevel)) {
-      MachineFunction &MF = DAG.getMachineFunction();
-      if (OptLevel == 0) {
-        // llvm.dbg.func.start implicitly defines a dbg_stoppoint which is what
-        // (most?) gdb expects.
-        DebugLoc PrevLoc = CurDebugLoc;
-        DISubprogram Subprogram(cast<GlobalVariable>(SP));
-        DICompileUnit CompileUnit = Subprogram.getCompileUnit();
-        std::string Dir, FN;
-        unsigned SrcFile = DW->getOrCreateSourceID(CompileUnit.getDirectory(Dir),
-                                                   CompileUnit.getFilename(FN));
-        
-        if (!Subprogram.describes(MF.getFunction())) {
-          // This is a beginning of an inlined function.
-
-          // If llvm.dbg.func.start is seen in a new block before any
-          // llvm.dbg.stoppoint intrinsic then the location info is unknown.
-          // FIXME : Why DebugLoc is reset at the beginning of each block ?
-          if (PrevLoc.isUnknown())
-            return 0;
-
-          // Record the source line.
-          unsigned Line = Subprogram.getLineNumber();
-          unsigned LabelID = DW->RecordSourceLine(Line, 0, SrcFile);
-          setCurDebugLoc(DebugLoc::get(MF.getOrCreateDebugLocID(SrcFile, Line, 0)));
+    if (!DIDescriptor::ValidDebugInfo(SP, OptLevel))
+      return 0;
+
+    MachineFunction &MF = DAG.getMachineFunction();
+    if (OptLevel == CodeGenOpt::None) {
+      // llvm.dbg.func.start implicitly defines a dbg_stoppoint which is what
+      // (most?) gdb expects.
+      DebugLoc PrevLoc = CurDebugLoc;
+      DISubprogram Subprogram(cast<GlobalVariable>(SP));
+      DICompileUnit CompileUnit = Subprogram.getCompileUnit();
+
+      if (!Subprogram.describes(MF.getFunction())) {
+        // This is a beginning of an inlined function.
+
+        // If llvm.dbg.func.start is seen in a new block before any
+        // llvm.dbg.stoppoint intrinsic then the location info is unknown.
+        // FIXME : Why DebugLoc is reset at the beginning of each block ?
+        if (PrevLoc.isUnknown())
+          return 0;
 
+        // Record the source line.
+        unsigned Line = Subprogram.getLineNumber();
+        setCurDebugLoc(DebugLoc::get(
+                     MF.getOrCreateDebugLocID(CompileUnit.getGV(), Line, 0)));
+
+        if (DW && DW->ShouldEmitDwarfDebug()) {
+          DebugLocTuple PrevLocTpl = MF.getDebugLocTuple(PrevLoc);
+          unsigned LabelID = DW->RecordInlinedFnStart(Subprogram,
+                                          DICompileUnit(PrevLocTpl.CompileUnit),
+                                          PrevLocTpl.Line,
+                                          PrevLocTpl.Col);
           DAG.setRoot(DAG.getLabel(ISD::DBG_LABEL, getCurDebugLoc(),
                                    getRoot(), LabelID));
-          DebugLocTuple PrevLocTpl = MF.getDebugLocTuple(PrevLoc);
-          DW->RecordInlinedFnStart(&FSI, Subprogram, LabelID, 
-                                   PrevLocTpl.Src,
-                                   PrevLocTpl.Line,
-                                   PrevLocTpl.Col);
-        } else {
-          // Record the source line.
-          unsigned Line = Subprogram.getLineNumber();
-          setCurDebugLoc(DebugLoc::get(MF.getOrCreateDebugLocID(SrcFile, Line, 0)));
-          DW->RecordSourceLine(Line, 0, SrcFile);
-          // llvm.dbg.func_start also defines beginning of function scope.
-          DW->RecordRegionStart(cast<GlobalVariable>(FSI.getSubprogram()));
         }
       } else {
-        DISubprogram Subprogram(cast<GlobalVariable>(SP));
-        
-        std::string SPName;
-        Subprogram.getLinkageName(SPName);
-        if (!SPName.empty() 
-            && strcmp(SPName.c_str(), MF.getFunction()->getNameStart())) {
-          // This is beginning of inlined function. Debugging information for
-          // inlined function is not handled yet (only supported by FastISel).
-          return 0;
+        // Record the source line.
+        unsigned Line = Subprogram.getLineNumber();
+        MF.setDefaultDebugLoc(DebugLoc::get(
+                     MF.getOrCreateDebugLocID(CompileUnit.getGV(), Line, 0)));
+        if (DW && DW->ShouldEmitDwarfDebug()) {
+          // llvm.dbg.func_start also defines beginning of function scope.
+          DW->RecordRegionStart(cast<GlobalVariable>(FSI.getSubprogram()));
         }
+      }
+    } else {
+      DISubprogram Subprogram(cast<GlobalVariable>(SP));
 
-        // llvm.dbg.func.start implicitly defines a dbg_stoppoint which is
-        // what (most?) gdb expects.
-        DICompileUnit CompileUnit = Subprogram.getCompileUnit();
-        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,
-        // create a label if this is a beginning of inlined function.
-        unsigned Line = Subprogram.getLineNumber();
-        setCurDebugLoc(DebugLoc::get(MF.getOrCreateDebugLocID(SrcFile, Line, 0)));
-        // FIXME -  Start new region because llvm.dbg.func_start also defines 
-        // beginning of function scope.
+      std::string SPName;
+      Subprogram.getLinkageName(SPName);
+      if (!SPName.empty()
+          && strcmp(SPName.c_str(), MF.getFunction()->getNameStart())) {
+        // This is beginning of inlined function. Debugging information for
+        // inlined function is not handled yet (only supported by FastISel).
+        return 0;
       }
+
+      // llvm.dbg.func.start implicitly defines a dbg_stoppoint which is
+      // what (most?) gdb expects.
+      DICompileUnit CompileUnit = Subprogram.getCompileUnit();
+
+      // Record the source line but does not create a label for the normal
+      // function start. It will be emitted at asm emission time. However,
+      // create a label if this is a beginning of inlined function.
+      unsigned Line = Subprogram.getLineNumber();
+      setCurDebugLoc(DebugLoc::get(
+                     MF.getOrCreateDebugLocID(CompileUnit.getGV(), Line, 0)));
+      // FIXME -  Start new region because llvm.dbg.func_start also defines
+      // beginning of function scope.
     }
 
     return 0;
   }
   case Intrinsic::dbg_declare: {
-    if (OptLevel == 0) {
-      DwarfWriter *DW = DAG.getDwarfWriter();
+    if (OptLevel == CodeGenOpt::None) {
       DbgDeclareInst &DI = cast<DbgDeclareInst>(I);
       Value *Variable = DI.getVariable();
-      if (DW && DW->ValidDebugInfo(Variable, OptLevel))
+      if (DIDescriptor::ValidDebugInfo(Variable, OptLevel))
         DAG.setRoot(DAG.getNode(ISD::DECLARE, dl, MVT::Other, getRoot(),
                                 getValue(DI.getAddress()), getValue(Variable)));
     } else {
@@ -4065,12 +4055,8 @@ SelectionDAGLowering::visitIntrinsicCall(CallInst &I, unsigned Intrinsic) {
     return 0;
   }
   case Intrinsic::eh_exception: {
-    if (!CurMBB->isLandingPad()) {
-      // FIXME: Mark exception register as live in.  Hack for PR1508.
-      unsigned Reg = TLI.getExceptionAddressRegister();
-      if (Reg) CurMBB->addLiveIn(Reg);
-    }
     // Insert the EXCEPTIONADDR instruction.
+    assert(CurMBB->isLandingPad() &&"Call to eh.exception not in landing pad!");
     SDVTList VTs = DAG.getVTList(TLI.getPointerTy(), MVT::Other);
     SDValue Ops[1];
     Ops[0] = DAG.getRoot();
@@ -5088,6 +5074,10 @@ hasInlineAsmMemConstraint(std::vector<InlineAsm::ConstraintInfo> &CInfos,
       if (CType == TargetLowering::C_Memory)
         return true;
     }
+    
+    // Indirect operand accesses access memory.
+    if (CI.isIndirect)
+      return true;
   }
 
   return false;
@@ -5101,11 +5091,6 @@ void SelectionDAGLowering::visitInlineAsm(CallSite CS) {
   /// ConstraintOperands - Information about all of the constraints.
   std::vector<SDISelAsmOperandInfo> ConstraintOperands;
 
-  // We won't need to flush pending loads if this asm doesn't touch
-  // memory and is nonvolatile.
-  SDValue Chain = IA->hasSideEffects() ? getRoot() : DAG.getRoot();
-  SDValue Flag;
-
   std::set<unsigned> OutputRegs, InputRegs;
 
   // Do a prepass over the constraints, canonicalizing them, and building up the
@@ -5114,10 +5099,15 @@ void SelectionDAGLowering::visitInlineAsm(CallSite CS) {
     ConstraintInfos = IA->ParseConstraints();
 
   bool hasMemory = hasInlineAsmMemConstraint(ConstraintInfos, TLI);
-  // Flush pending loads if this touches memory (includes clobbering it).
-  // It's possible this is overly conservative.
-  if (hasMemory)
+  
+  SDValue Chain, Flag;
+  
+  // We won't need to flush pending loads if this asm doesn't touch
+  // memory and is nonvolatile.
+  if (hasMemory || IA->hasSideEffects())
     Chain = getRoot();
+  else
+    Chain = DAG.getRoot();
 
   unsigned ArgNo = 0;   // ArgNo - The argument of the CallInst.
   unsigned ResNo = 0;   // ResNo - The result number of the next output.
@@ -5219,7 +5209,7 @@ void SelectionDAGLowering::visitInlineAsm(CallSite CS) {
         // Otherwise, create a stack slot and emit a store to it before the
         // asm.
         const Type *Ty = OpVal->getType();
-        uint64_t TySize = TLI.getTargetData()->getTypePaddedSize(Ty);
+        uint64_t TySize = TLI.getTargetData()->getTypeAllocSize(Ty);
         unsigned Align  = TLI.getTargetData()->getPrefTypeAlignment(Ty);
         MachineFunction &MF = DAG.getMachineFunction();
         int SSFI = MF.getFrameInfo()->CreateStackObject(TySize, Align);
@@ -5345,6 +5335,8 @@ void SelectionDAGLowering::visitInlineAsm(CallSite CS) {
         if ((OpFlag & 7) == 2 /*REGDEF*/
             || (OpFlag & 7) == 6 /* EARLYCLOBBER REGDEF */) {
           // Add (OpFlag&0xffff)>>3 registers to MatchedRegs.
+          assert(!OpInfo.isIndirect &&
+                 "Don't know how to handle tied indirect register inputs yet!");
           RegsForValue MatchedRegs;
           MatchedRegs.TLI = &TLI;
           MatchedRegs.ValueVTs.push_back(InOperandVal.getValueType());
@@ -5495,6 +5487,7 @@ void SelectionDAGLowering::visitInlineAsm(CallSite CS) {
     SDValue OutVal = OutRegs.getCopyFromRegs(DAG, getCurDebugLoc(),
                                              Chain, &Flag);
     StoresToEmit.push_back(std::make_pair(OutVal, Ptr));
+
   }
 
   // Emit the non-flagged stores from the physregs.
@@ -5519,7 +5512,7 @@ void SelectionDAGLowering::visitMalloc(MallocInst &I) {
   // 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());
+  uint64_t ElementSize = TD->getTypeAllocSize(I.getType()->getElementType());
   if (ElementSize != 1)
     Src = DAG.getNode(ISD::MUL, getCurDebugLoc(), Src.getValueType(),
                       Src, DAG.getConstant(ElementSize, Src.getValueType()));
@@ -5633,7 +5626,7 @@ void TargetLowering::LowerArguments(Function &F, SelectionDAG &DAG,
         const PointerType *Ty = cast<PointerType>(I->getType());
         const Type *ElementTy = Ty->getElementType();
         unsigned FrameAlign = getByValTypeAlignment(ElementTy);
-        unsigned FrameSize  = getTargetData()->getTypePaddedSize(ElementTy);
+        unsigned FrameSize  = getTargetData()->getTypeAllocSize(ElementTy);
         // For ByVal, alignment should be passed from FE.  BE will guess if
         // this info is not there but there are cases it cannot get right.
         if (F.getParamAlignment(j))
@@ -5766,7 +5759,7 @@ TargetLowering::LowerCallTo(SDValue Chain, const Type *RetTy,
         const PointerType *Ty = cast<PointerType>(Args[i].Ty);
         const Type *ElementTy = Ty->getElementType();
         unsigned FrameAlign = getByValTypeAlignment(ElementTy);
-        unsigned FrameSize  = getTargetData()->getTypePaddedSize(ElementTy);
+        unsigned FrameSize  = getTargetData()->getTypeAllocSize(ElementTy);
         // For ByVal, alignment should come from FE.  BE will guess if this
         // info is not there but there are cases it cannot get right.
         if (Args[i].Alignment)