[Beignet] [PATCH 02/18] Backend: Use CopyDebug when we add llvm instructions.

junyan.he at inbox.com junyan.he at inbox.com
Thu Dec 24 03:01:54 PST 2015


From: Junyan He <junyan.he at linux.intel.com>

Signed-off-by: Junyan He <junyan.he at linux.intel.com>
---
 backend/src/llvm/ExpandConstantExpr.cpp      |   6 +-
 backend/src/llvm/ExpandLargeIntegers.cpp     | 173 +++++++++++++--------------
 backend/src/llvm/llvm_intrinsic_lowering.cpp |   8 +-
 backend/src/llvm/llvm_passes.cpp             |  13 +-
 backend/src/llvm/llvm_sampler_fix.cpp        |   7 ++
 backend/src/llvm/llvm_scalarize.cpp          |   5 +-
 6 files changed, 111 insertions(+), 101 deletions(-)

diff --git a/backend/src/llvm/ExpandConstantExpr.cpp b/backend/src/llvm/ExpandConstantExpr.cpp
index c6f57b8..43f7a42 100644
--- a/backend/src/llvm/ExpandConstantExpr.cpp
+++ b/backend/src/llvm/ExpandConstantExpr.cpp
@@ -120,11 +120,11 @@ static Value *expandConstantVector(Instruction *InsertPt, ConstantVector *CV) {
   for (int i = 0; i < elemNum; i++) {
     Value *idx = ConstantInt::get(IntTy, i);
     if (dyn_cast<ConstantVector>(CV->getOperand(i)))
-      vec = IRB.CreateInsertElement(vec, expandConstantVector(InsertPt, dyn_cast<ConstantVector>(CV->getOperand(i))), idx);
+      vec = CopyDebug(IRB.CreateInsertElement(vec, expandConstantVector(InsertPt, dyn_cast<ConstantVector>(CV->getOperand(i))), idx), InsertPt);
     else if (dyn_cast<ConstantExpr>(CV->getOperand(i)))
-      vec = IRB.CreateInsertElement(vec, expandConstantExpr(InsertPt, dyn_cast<ConstantExpr>(CV->getOperand(i))), idx);
+      vec = CopyDebug(IRB.CreateInsertElement(vec, expandConstantExpr(InsertPt, dyn_cast<ConstantExpr>(CV->getOperand(i))), idx), InsertPt);
     else
-      vec = IRB.CreateInsertElement(vec, CV->getOperand(i), idx);
+      vec = CopyDebug(IRB.CreateInsertElement(vec, CV->getOperand(i), idx), InsertPt);
   }
   return vec;
 }
diff --git a/backend/src/llvm/ExpandLargeIntegers.cpp b/backend/src/llvm/ExpandLargeIntegers.cpp
index 20fdda9..94ae815 100644
--- a/backend/src/llvm/ExpandLargeIntegers.cpp
+++ b/backend/src/llvm/ExpandLargeIntegers.cpp
@@ -316,7 +316,7 @@ private:
 };
 } // Anonymous namespace
 
-static Value *buildVectorOrScalar(ConversionState &State, IRBuilder<> &IRB, SmallVector<Value *, 16> Elements) {
+static Value *buildVectorOrScalar(Instruction *Inst, ConversionState &State, IRBuilder<> &IRB, SmallVector<Value *, 16> Elements) {
   assert(!Elements.empty());
   Type *IntTy = IntegerType::get(IRB.getContext(), 32);
 
@@ -328,7 +328,7 @@ static Value *buildVectorOrScalar(ConversionState &State, IRBuilder<> &IRB, Smal
     for (unsigned i = 0; i < ElemNo; ++i) {
       Value *tmp = vec ? vec : UndefValue::get(VectorType::get(ElemTy, ElemNo));
       Value *idx = ConstantInt::get(IntTy, i);
-      vec = IRB.CreateInsertElement(tmp, Elements[i], idx);
+      vec = CopyDebug(IRB.CreateInsertElement(tmp, Elements[i], idx), Inst);
       if (!KeepInsert) {
         State.addEraseCandidate(cast<Instruction>(vec));
       }
@@ -349,7 +349,7 @@ static void getSplitedValue(ConversionState &State, Value *Val, SmallVector<Valu
 }
 
 // make all the elements in Src use the same llvm::Type, and return them in Dst
-static void unifyElementType(IRBuilder<> &IRB, SmallVector<Value *, 16> &Src, SmallVector<Value *, 16> &Dst) {
+static void unifyElementType(Instruction *Inst, IRBuilder<> &IRB, SmallVector<Value *, 16> &Src, SmallVector<Value *, 16> &Dst) {
   unsigned MinWidth = Src[0]->getType()->getPrimitiveSizeInBits();
   bool Unified = true;
   for (unsigned i = 0; i < Src.size(); i++) {
@@ -372,9 +372,9 @@ static void unifyElementType(IRBuilder<> &IRB, SmallVector<Value *, 16> &Src, Sm
 
       if (Size > MinWidth) {
         VectorType *VecTy = VectorType::get(ElemTy, Size/MinWidth);
-        Value *Casted = IRB.CreateBitCast(Src[i], VecTy);
+        Value *Casted = CopyDebug(IRB.CreateBitCast(Src[i], VecTy), Inst);
         for (unsigned j = 0; j < Size/MinWidth; j++)
-          Dst.push_back(IRB.CreateExtractElement(Casted, ConstantInt::get(IntTy, j)));
+          Dst.push_back(CopyDebug(IRB.CreateExtractElement(Casted, ConstantInt::get(IntTy, j)), Inst));
       } else {
         Dst.push_back(Src[i]);
       }
@@ -394,8 +394,8 @@ static void convertInstruction(Instruction *Inst, ConversionState &State,
   if (PHINode *Phi = dyn_cast<PHINode>(Inst)) {
     unsigned N = Phi->getNumIncomingValues();
     TypePair OpTys = getExpandedIntTypes(Phi->getIncomingValue(0)->getType());
-    PHINode *Lo = IRB.CreatePHI(OpTys.Lo, N, Twine(Name + ".lo"));
-    PHINode *Hi = IRB.CreatePHI(OpTys.Hi, N, Twine(Name + ".hi"));
+    PHINode *Lo = CopyDebug(IRB.CreatePHI(OpTys.Lo, N, Twine(Name + ".lo")), Inst);
+    PHINode *Hi = CopyDebug(IRB.CreatePHI(OpTys.Hi, N, Twine(Name + ".hi")), Inst);
     for (unsigned I = 0; I != N; ++I) {
       Value *InVal = Phi->getIncomingValue(I);
       BasicBlock *InBB = Phi->getIncomingBlock(I);
@@ -415,12 +415,12 @@ static void convertInstruction(Instruction *Inst, ConversionState &State,
     TypePair Tys = getExpandedIntTypes(Inst->getType());
     Value *Lo, *Hi;
     if (OpTy->getIntegerBitWidth() <= kChunkBits) {
-      Lo = IRB.CreateZExt(Operand, Tys.Lo, Twine(Name, ".lo"));
+      Lo = CopyDebug(IRB.CreateZExt(Operand, Tys.Lo, Twine(Name, ".lo")), Inst);
       Hi = ConstantInt::get(Tys.Hi, 0);
     } else {
       ValuePair Ops = State.getConverted(Operand);
       Lo = Ops.Lo;
-      Hi = IRB.CreateZExt(Ops.Hi, Tys.Hi, Twine(Name, ".hi"));
+      Hi = CopyDebug(IRB.CreateZExt(Ops.Hi, Tys.Hi, Twine(Name, ".hi")), Inst);
     }
     State.recordConverted(ZExt, ValuePair(Lo, Hi));
 
@@ -430,13 +430,13 @@ static void convertInstruction(Instruction *Inst, ConversionState &State,
     TypePair OpTys = getExpandedIntTypes(Operand->getType());
     ValuePair Ops = State.getConverted(Operand);
     if (!shouldConvert(Inst)) {
-      Value *NewInst = IRB.CreateTrunc(Ops.Lo, Trunc->getType(), Name);
+      Value *NewInst = CopyDebug(IRB.CreateTrunc(Ops.Lo, Trunc->getType(), Name), Inst);
       State.recordConverted(Trunc, NewInst);
     } else {
       TypePair Tys = getExpandedIntTypes(Trunc->getType());
       assert(Tys.Lo == OpTys.Lo);
       Value *Lo = Ops.Lo;
-      Value *Hi = IRB.CreateTrunc(Ops.Hi, Tys.Hi, Twine(Name, ".hi"));
+      Value *Hi = CopyDebug(IRB.CreateTrunc(Ops.Hi, Tys.Hi, Twine(Name, ".hi")), Inst);
       State.recordConverted(Trunc, ValuePair(Lo, Hi));
     }
 
@@ -451,7 +451,7 @@ static void convertInstruction(Instruction *Inst, ConversionState &State,
       SmallVector<Value *, 16> Unified;
       getSplitedValue(State, Operand, Split);
       // unify element type, this is required by insertelement
-      unifyElementType(IRB, Split, Unified);
+      unifyElementType(Inst, IRB, Split, Unified);
 
       Value *vec = NULL;
       unsigned ElemNo = Unified.size();
@@ -459,10 +459,10 @@ static void convertInstruction(Instruction *Inst, ConversionState &State,
       for (unsigned i = 0; i < ElemNo; ++i) {
         Value *tmp = vec ? vec : UndefValue::get(VectorType::get(ElemTy, ElemNo));
         Value *idx = ConstantInt::get(IntTy, i);
-        vec = IRB.CreateInsertElement(tmp, Unified[i], idx);
+        vec = CopyDebug(IRB.CreateInsertElement(tmp, Unified[i], idx), Inst);
       }
       if (vec->getType() != Cast->getType())
-        vec = IRB.CreateBitCast(vec, Cast->getType());
+        vec = CopyDebug(IRB.CreateBitCast(vec, Cast->getType()), Inst);
       State.recordConverted(Cast, vec);
     } else {
       // vector to integer
@@ -495,14 +495,14 @@ static void convertInstruction(Instruction *Inst, ConversionState &State,
       for (unsigned i = 0; i < LowNo; ++i)
         LoElems.push_back(State.getElement(VectorRoot, i+ChildIndex));
 
-      Lo = IRB.CreateBitCast(buildVectorOrScalar(State, IRB, LoElems), OpTys.Lo, Twine(Name, ".lo"));
+      Lo = CopyDebug(IRB.CreateBitCast(buildVectorOrScalar(Inst, State, IRB, LoElems), OpTys.Lo, Twine(Name, ".lo")), Inst);
 
       SmallVector<Value *, 16> HiElem;
       for (unsigned i = 0; i < HighNo; ++i)
         HiElem.push_back(State.getElement(VectorRoot, i+LowNo+ChildIndex));
 
-      Value *NewVec = buildVectorOrScalar(State, IRB, HiElem);
-      Hi = IRB.CreateBitCast(NewVec, OpTys.Hi);
+      Value *NewVec = buildVectorOrScalar(Inst, State, IRB, HiElem);
+      Hi = CopyDebug(IRB.CreateBitCast(NewVec, OpTys.Hi), Inst);
 
       State.recordVectorMap(NewVec, VectorElement(VectorRoot, LowNo + ChildIndex));
       State.recordConverted(Cast, ValuePair(Lo, Hi));
@@ -517,8 +517,8 @@ static void convertInstruction(Instruction *Inst, ConversionState &State,
     case Instruction::And:
     case Instruction::Or:
     case Instruction::Xor: {
-      Value *Lo = IRB.CreateBinOp(Op, Lhs.Lo, Rhs.Lo, Twine(Name, ".lo"));
-      Value *Hi = IRB.CreateBinOp(Op, Lhs.Hi, Rhs.Hi, Twine(Name, ".hi"));
+      Value *Lo = CopyDebug(IRB.CreateBinOp(Op, Lhs.Lo, Rhs.Lo, Twine(Name, ".lo")), Inst);
+      Value *Hi = CopyDebug(IRB.CreateBinOp(Op, Lhs.Hi, Rhs.Hi, Twine(Name, ".hi")), Inst);
       State.recordConverted(Binop, ValuePair(Lo, Hi));
       break;
     }
@@ -552,26 +552,22 @@ static void convertInstruction(Instruction *Inst, ConversionState &State,
       // |DEFGHIJKLMNOPQ000000000000|00000000000000000| Lo is 0, no Hi left.
       Value *Lo, *Hi;
       if (ShiftAmount < kChunkBits) {
-        Lo = IRB.CreateShl(Lhs.Lo, ShiftAmount, Twine(Name, ".lo"));
-        Hi = IRB.CreateZExtOrTrunc(IRB.CreateLShr(Lhs.Lo,
-                                                  kChunkBits - ShiftAmount,
-                                                  Twine(Name, ".lo.shr")),
-                                   Tys.Hi, Twine(Name, ".lo.ext"));
+        Lo = CopyDebug(IRB.CreateShl(Lhs.Lo, ShiftAmount, Twine(Name, ".lo")), Inst);
+        Hi = CopyDebug(IRB.CreateZExtOrTrunc(IRB.CreateLShr(Lhs.Lo, kChunkBits - ShiftAmount,
+                Twine(Name, ".lo.shr")), Tys.Hi, Twine(Name, ".lo.ext")), Inst);
       } else {
         Lo = ConstantInt::get(Tys.Lo, 0);
         if (ShiftAmount == kChunkBits) {
           // Hi will be from Lo
-          Hi = IRB.CreateZExtOrTrunc(Lhs.Lo, Tys.Hi, Twine(Name, ".lo.ext"));
+          Hi = CopyDebug(IRB.CreateZExtOrTrunc(Lhs.Lo, Tys.Hi, Twine(Name, ".lo.ext")), Inst);
         } else {
-          Hi = IRB.CreateShl(
-              IRB.CreateZExtOrTrunc(Lhs.Lo, Tys.Hi, Twine(Name, ".lo.ext")),
-              ShiftAmount - kChunkBits, Twine(Name, ".lo.shl"));
+          Hi = CopyDebug(IRB.CreateShl(CopyDebug(IRB.CreateZExtOrTrunc(Lhs.Lo, Tys.Hi, Twine(Name, ".lo.ext")), Inst),
+              ShiftAmount - kChunkBits, Twine(Name, ".lo.shl")), Inst);
         }
       }
       if (ShiftAmount < HiBits)
-        Hi = IRB.CreateOr(
-            Hi, IRB.CreateShl(Lhs.Hi, ShiftAmount, Twine(Name, ".hi.shl")),
-            Twine(Name, ".or"));
+        Hi = CopyDebug(IRB.CreateOr(Hi, CopyDebug(IRB.CreateShl(Lhs.Hi, ShiftAmount, Twine(Name, ".hi.shl")), Inst),
+            Twine(Name, ".or")), Inst);
       State.recordConverted(Binop, ValuePair(Lo, Hi));
       break;
     }
@@ -608,34 +604,33 @@ static void convertInstruction(Instruction *Inst, ConversionState &State,
         Lo = Lhs.Lo; Hi = Lhs.Hi;
       } else {
         if (ShiftAmount < kChunkBits) {
-          Lo = IRB.CreateShl(
-              IsArith
-                  ? IRB.CreateSExtOrTrunc(Lhs.Hi, Tys.Lo, Twine(Name, ".hi.ext"))
-                  : IRB.CreateZExtOrTrunc(Lhs.Hi, Tys.Lo, Twine(Name, ".hi.ext")),
-              kChunkBits - ShiftAmount, Twine(Name, ".hi.shl"));
-
-          Lo = IRB.CreateOr(
-              Lo, IRB.CreateLShr(Lhs.Lo, ShiftAmount, Twine(Name, ".lo.shr")),
-              Twine(Name, ".lo"));
+          Lo = CopyDebug(IRB.CreateShl(IsArith
+                  ? CopyDebug(IRB.CreateSExtOrTrunc(Lhs.Hi, Tys.Lo, Twine(Name, ".hi.ext")), Inst)
+                  : CopyDebug(IRB.CreateZExtOrTrunc(Lhs.Hi, Tys.Lo, Twine(Name, ".hi.ext")), Inst),
+              kChunkBits - ShiftAmount, Twine(Name, ".hi.shl")), Inst);
+
+          Lo = CopyDebug(IRB.CreateOr(Lo,
+              CopyDebug(IRB.CreateLShr(Lhs.Lo, ShiftAmount, Twine(Name, ".lo.shr")), Inst),
+              Twine(Name, ".lo")), Inst);
         } else if (ShiftAmount == kChunkBits) {
           Lo = IsArith
-                  ? IRB.CreateSExtOrTrunc(Lhs.Hi, Tys.Lo, Twine(Name, ".hi.ext"))
-                  : IRB.CreateZExtOrTrunc(Lhs.Hi, Tys.Lo, Twine(Name, ".hi.ext"));
+                  ? CopyDebug(IRB.CreateSExtOrTrunc(Lhs.Hi, Tys.Lo, Twine(Name, ".hi.ext")), Inst)
+                  : CopyDebug(IRB.CreateZExtOrTrunc(Lhs.Hi, Tys.Lo, Twine(Name, ".hi.ext")), Inst);
 
         } else {
-          Lo = IRB.CreateBinOp(Op, Lhs.Hi,
+          Lo = CopyDebug(IRB.CreateBinOp(Op, Lhs.Hi,
                                ConstantInt::get(Tys.Hi, ShiftAmount - kChunkBits),
-                               Twine(Name, ".hi.shr"));
+                               Twine(Name, ".hi.shr")), Inst);
           Lo = IsArith
-                   ? IRB.CreateSExtOrTrunc(Lo, Tys.Lo, Twine(Name, ".lo.ext"))
-                   : IRB.CreateZExtOrTrunc(Lo, Tys.Lo, Twine(Name, ".lo.ext"));
+                   ? CopyDebug(IRB.CreateSExtOrTrunc(Lo, Tys.Lo, Twine(Name, ".lo.ext")), Inst)
+                   : CopyDebug(IRB.CreateZExtOrTrunc(Lo, Tys.Lo, Twine(Name, ".lo.ext")), Inst);
         }
         if (ShiftAmount < HiBitWidth) {
-          Hi = IRB.CreateBinOp(Op, Lhs.Hi, ConstantInt::get(Tys.Hi, ShiftAmount),
-                               Twine(Name, ".hi"));
+          Hi = CopyDebug(IRB.CreateBinOp(Op, Lhs.Hi, ConstantInt::get(Tys.Hi, ShiftAmount),
+                               Twine(Name, ".hi")), Inst);
         } else {
           Hi = IsArith
-                   ? IRB.CreateAShr(Lhs.Hi, HiBitWidth - 1, Twine(Name, ".hi"))
+                   ? CopyDebug(IRB.CreateAShr(Lhs.Hi, HiBitWidth - 1, Twine(Name, ".hi")), Inst)
                    : ConstantInt::get(Tys.Hi, 0);
         }
       }
@@ -647,27 +642,27 @@ static void convertInstruction(Instruction *Inst, ConversionState &State,
     case Instruction::Sub: {
       Value *Lo, *Hi;
       if (Op == Instruction::Add) {
-        Value *Limit = IRB.CreateSelect(
-            IRB.CreateICmpULT(Lhs.Lo, Rhs.Lo, Twine(Name, ".cmp")), Rhs.Lo,
-            Lhs.Lo, Twine(Name, ".limit"));
+        Value *Limit = CopyDebug(IRB.CreateSelect(
+            CopyDebug(IRB.CreateICmpULT(Lhs.Lo, Rhs.Lo, Twine(Name, ".cmp")), Inst), Rhs.Lo,
+            Lhs.Lo, Twine(Name, ".limit")), Inst);
         // Don't propagate NUW/NSW to the lo operation: it can overflow.
-        Lo = IRB.CreateBinOp(Op, Lhs.Lo, Rhs.Lo, Twine(Name, ".lo"));
-        Value *Carry = IRB.CreateZExt(
-            IRB.CreateICmpULT(Lo, Limit, Twine(Name, ".overflowed")), Tys.Hi,
-            Twine(Name, ".carry"));
+        Lo = CopyDebug(IRB.CreateBinOp(Op, Lhs.Lo, Rhs.Lo, Twine(Name, ".lo")), Inst);
+        Value *Carry = CopyDebug(IRB.CreateZExt(
+            CopyDebug(IRB.CreateICmpULT(Lo, Limit, Twine(Name, ".overflowed")), Inst), Tys.Hi,
+            Twine(Name, ".carry")), Inst);
         // TODO(jfb) The hi operation could be tagged with NUW/NSW.
-        Hi = IRB.CreateBinOp(
-            Op, IRB.CreateBinOp(Op, Lhs.Hi, Rhs.Hi, Twine(Name, ".hi")), Carry,
-            Twine(Name, ".carried"));
+        Hi =  CopyDebug(IRB.CreateBinOp(
+            Op, CopyDebug(IRB.CreateBinOp(Op, Lhs.Hi, Rhs.Hi, Twine(Name, ".hi")), Inst), Carry,
+            Twine(Name, ".carried")), Inst);
       } else {
-        Value *Borrowed = IRB.CreateSExt(
-            IRB.CreateICmpULT(Lhs.Lo, Rhs.Lo, Twine(Name, ".borrow")), Tys.Hi,
-            Twine(Name, ".borrowing"));
-        Lo = IRB.CreateBinOp(Op, Lhs.Lo, Rhs.Lo, Twine(Name, ".lo"));
-        Hi = IRB.CreateBinOp(
+        Value *Borrowed = CopyDebug(IRB.CreateSExt(
+             CopyDebug(IRB.CreateICmpULT(Lhs.Lo, Rhs.Lo, Twine(Name, ".borrow")), Inst), Tys.Hi,
+             Twine(Name, ".borrowing")), Inst);
+        Lo = CopyDebug(IRB.CreateBinOp(Op, Lhs.Lo, Rhs.Lo, Twine(Name, ".lo")), Inst);
+        Hi = CopyDebug(IRB.CreateBinOp(
             Instruction::Add,
-            IRB.CreateBinOp(Op, Lhs.Hi, Rhs.Hi, Twine(Name, ".hi")), Borrowed,
-            Twine(Name, ".borrowed"));
+            CopyDebug(IRB.CreateBinOp(Op, Lhs.Hi, Rhs.Hi, Twine(Name, ".hi")), Inst), Borrowed,
+            Twine(Name, ".borrowed")), Inst);
       }
       State.recordConverted(Binop, ValuePair(Lo, Hi));
       break;
@@ -684,16 +679,13 @@ static void convertInstruction(Instruction *Inst, ConversionState &State,
     unsigned AddrSpace = Op->getType()->getPointerAddressSpace();
     TypePair Tys = getExpandedIntTypes(Load->getType());
     AlignPair Align = getAlign(DL, Load, Load->getType());
-    Value *Loty = IRB.CreateBitCast(Op, Tys.Lo->getPointerTo(AddrSpace),
-                                    Twine(Op->getName(), ".loty"));
-    Value *Lo =
-        IRB.CreateAlignedLoad(Loty, Align.Lo, Twine(Load->getName(), ".lo"));
-    Value *HiAddr =
-        IRB.CreateConstGEP1_32(Loty, 1, Twine(Op->getName(), ".hi.gep"));
-    Value *HiTy = IRB.CreateBitCast(HiAddr, Tys.Hi->getPointerTo(AddrSpace),
-                                    Twine(Op->getName(), ".hity"));
-    Value *Hi =
-        IRB.CreateAlignedLoad(HiTy, Align.Hi, Twine(Load->getName(), ".hi"));
+    Value *Loty = CopyDebug(IRB.CreateBitCast(Op, Tys.Lo->getPointerTo(AddrSpace),
+                                    Twine(Op->getName(), ".loty")), Inst);
+    Value *Lo = CopyDebug(IRB.CreateAlignedLoad(Loty, Align.Lo, Twine(Load->getName(), ".lo")), Inst);
+    Value *HiAddr = CopyDebug(IRB.CreateConstGEP1_32(Loty, 1, Twine(Op->getName(), ".hi.gep")), Inst);
+    Value *HiTy = CopyDebug(IRB.CreateBitCast(HiAddr, Tys.Hi->getPointerTo(AddrSpace),
+                                    Twine(Op->getName(), ".hity")), Inst);
+    Value *Hi = CopyDebug(IRB.CreateAlignedLoad(HiTy, Align.Hi, Twine(Load->getName(), ".hi")), Inst);
     State.recordConverted(Load, ValuePair(Lo, Hi));
 
   } else if (StoreInst *Store = dyn_cast<StoreInst>(Inst)) {
@@ -702,14 +694,13 @@ static void convertInstruction(Instruction *Inst, ConversionState &State,
     TypePair Tys = getExpandedIntTypes(Store->getValueOperand()->getType());
     ValuePair StoreVals = State.getConverted(Store->getValueOperand());
     AlignPair Align = getAlign(DL, Store, Store->getValueOperand()->getType());
-    Value *Loty = IRB.CreateBitCast(Ptr, Tys.Lo->getPointerTo(AddrSpace),
-                                    Twine(Ptr->getName(), ".loty"));
-    Value *Lo = IRB.CreateAlignedStore(StoreVals.Lo, Loty, Align.Lo);
-    Value *HiAddr =
-        IRB.CreateConstGEP1_32(Loty, 1, Twine(Ptr->getName(), ".hi.gep"));
-    Value *HiTy = IRB.CreateBitCast(HiAddr, Tys.Hi->getPointerTo(AddrSpace),
-                                    Twine(Ptr->getName(), ".hity"));
-    Value *Hi = IRB.CreateAlignedStore(StoreVals.Hi, HiTy, Align.Hi);
+    Value *Loty = CopyDebug(IRB.CreateBitCast(Ptr, Tys.Lo->getPointerTo(AddrSpace),
+                                    Twine(Ptr->getName(), ".loty")), Inst);
+    Value *Lo = CopyDebug(IRB.CreateAlignedStore(StoreVals.Lo, Loty, Align.Lo), Inst);
+    Value *HiAddr = CopyDebug(IRB.CreateConstGEP1_32(Loty, 1, Twine(Ptr->getName(), ".hi.gep")), Inst);
+    Value *HiTy = CopyDebug(IRB.CreateBitCast(HiAddr, Tys.Hi->getPointerTo(AddrSpace),
+                                    Twine(Ptr->getName(), ".hity")), Inst);
+    Value *Hi = CopyDebug(IRB.CreateAlignedStore(StoreVals.Hi, HiTy, Align.Hi), Inst);
     State.recordConverted(Store, ValuePair(Lo, Hi));
 
   } else if (ICmpInst *Icmp = dyn_cast<ICmpInst>(Inst)) {
@@ -718,12 +709,12 @@ static void convertInstruction(Instruction *Inst, ConversionState &State,
     switch (Icmp->getPredicate()) {
     case CmpInst::ICMP_EQ:
     case CmpInst::ICMP_NE: {
-      Value *Lo = IRB.CreateICmp(Icmp->getUnsignedPredicate(), Lhs.Lo, Rhs.Lo,
-                                 Twine(Name, ".lo"));
-      Value *Hi = IRB.CreateICmp(Icmp->getUnsignedPredicate(), Lhs.Hi, Rhs.Hi,
-                                 Twine(Name, ".hi"));
+      Value *Lo = CopyDebug(IRB.CreateICmp(Icmp->getUnsignedPredicate(), Lhs.Lo, Rhs.Lo,
+                                 Twine(Name, ".lo")), Inst);
+      Value *Hi = CopyDebug(IRB.CreateICmp(Icmp->getUnsignedPredicate(), Lhs.Hi, Rhs.Hi,
+                                 Twine(Name, ".hi")), Inst);
       Value *Result =
-          IRB.CreateBinOp(Instruction::And, Lo, Hi, Twine(Name, ".result"));
+          CopyDebug(IRB.CreateBinOp(Instruction::And, Lo, Hi, Twine(Name, ".result")), Inst);
       State.recordConverted(Icmp, Result);
       break;
     }
@@ -748,8 +739,8 @@ static void convertInstruction(Instruction *Inst, ConversionState &State,
     Value *Cond = Select->getCondition();
     ValuePair True = State.getConverted(Select->getTrueValue());
     ValuePair False = State.getConverted(Select->getFalseValue());
-    Value *Lo = IRB.CreateSelect(Cond, True.Lo, False.Lo, Twine(Name, ".lo"));
-    Value *Hi = IRB.CreateSelect(Cond, True.Hi, False.Hi, Twine(Name, ".hi"));
+    Value *Lo = CopyDebug(IRB.CreateSelect(Cond, True.Lo, False.Lo, Twine(Name, ".lo")), Inst);
+    Value *Hi = CopyDebug(IRB.CreateSelect(Cond, True.Hi, False.Hi, Twine(Name, ".hi")), Inst);
     State.recordConverted(Select, ValuePair(Lo, Hi));
 
   } else {
diff --git a/backend/src/llvm/llvm_intrinsic_lowering.cpp b/backend/src/llvm/llvm_intrinsic_lowering.cpp
index b35d1e6..12da864 100644
--- a/backend/src/llvm/llvm_intrinsic_lowering.cpp
+++ b/backend/src/llvm/llvm_intrinsic_lowering.cpp
@@ -77,8 +77,10 @@ namespace gbe {
         SmallVector<Value *, 8> Args(ArgBegin, ArgEnd);
         CallInst *NewCI = Builder.CreateCall(FCache, Args);
         NewCI->setName(CI->getName());
-        if (!CI->use_empty())
+        if (!CI->use_empty()) {
+          CopyDebug(NewCI, CI);
           CI->replaceAllUsesWith(NewCI);
+        }
         CI->eraseFromParent();
         return NewCI;
       }
@@ -106,8 +108,10 @@ namespace gbe {
                 Type *IntPtr = TD.getIntPtrType(Context);
                 Value *Size = Builder.CreateIntCast(CI->getArgOperand(2), IntPtr,
                                                     /* isSigned */ false);
+                CopyDebug(Size, CI);
                 Value *align = Builder.CreateIntCast(CI->getArgOperand(3), IntPtr,
                                                     /* isSigned */ false);
+                CopyDebug(align, CI);
                 ConstantInt *ci = dyn_cast<ConstantInt>(align);
                 Value *Ops[3];
                 Ops[0] = CI->getArgOperand(0);
@@ -128,8 +132,10 @@ namespace gbe {
                 Type *IntPtr = TD.getIntPtrType(Op0->getType());
                 Value *Size = Builder.CreateIntCast(CI->getArgOperand(2), IntPtr,
                                                     /* isSigned */ false);
+                CopyDebug(Size, CI);
                 Value *align = Builder.CreateIntCast(CI->getArgOperand(3), IntPtr,
                                                     /* isSigned */ false);
+                CopyDebug(align, CI);
                 ConstantInt *ci = dyn_cast<ConstantInt>(align);
                 Value *Ops[3];
                 Ops[0] = Op0;
diff --git a/backend/src/llvm/llvm_passes.cpp b/backend/src/llvm/llvm_passes.cpp
index d5d965b..d68c1a7 100644
--- a/backend/src/llvm/llvm_passes.cpp
+++ b/backend/src/llvm/llvm_passes.cpp
@@ -226,6 +226,7 @@ namespace gbe
 
     Value* currentAddrInst = 
       new PtrToIntInst(parentPointer, IntegerType::get(GEPInst->getContext(), ptrSize), "", GEPInst);
+    CopyDebug(currentAddrInst, GEPInst);
 
     int32_t constantOffset = 0;
 
@@ -270,11 +271,9 @@ namespace gbe
           else
           {
             //trunctate
-            operand = 
-              new TruncInst(operand, 
-                  IntegerType::get(GEPInst->getContext(), 
-                    ptrSize), 
-                  "", GEPInst);
+            operand = new TruncInst(operand,
+              IntegerType::get(GEPInst->getContext(), ptrSize), "", GEPInst);
+            CopyDebug(operand, GEPInst);
           }
         }
 
@@ -282,10 +281,12 @@ namespace gbe
         if (size != 1) {
           tmpMul = BinaryOperator::Create(Instruction::Mul, newConstSize, operand,
                                          "", GEPInst);
+          CopyDebug(tmpMul, GEPInst);
         }
         currentAddrInst = 
           BinaryOperator::Create(Instruction::Add, currentAddrInst, tmpMul,
               "", GEPInst);
+        CopyDebug(currentAddrInst, GEPInst);
       }
 
       //step down in type hirachy
@@ -301,11 +302,13 @@ namespace gbe
       currentAddrInst =
         BinaryOperator::Create(Instruction::Add, currentAddrInst,
             newConstOffset, "", GEPInst);
+      CopyDebug(currentAddrInst, GEPInst);
     }
 
     //convert offset to ptr type (nop)
     IntToPtrInst* intToPtrInst = 
       new IntToPtrInst(currentAddrInst,GEPInst->getType(),"", GEPInst);
+    CopyDebug(intToPtrInst, GEPInst);
 
     //replace uses of the GEP instruction with the newly calculated pointer
     GEPInst->replaceAllUsesWith(intToPtrInst);
diff --git a/backend/src/llvm/llvm_sampler_fix.cpp b/backend/src/llvm/llvm_sampler_fix.cpp
index 01db8fe..329f0f2 100644
--- a/backend/src/llvm/llvm_sampler_fix.cpp
+++ b/backend/src/llvm/llvm_sampler_fix.cpp
@@ -65,13 +65,18 @@ namespace gbe {
           Builder.SetInsertPoint(I);
           Value *addressMask = ConstantInt::get(i32Ty, __CLK_ADDRESS_MASK);
           Value *addressMode = Builder.CreateAnd(I->getOperand(0), addressMask);
+          CopyDebug(addressMode, I);
           Value *clampInt =  ConstantInt::get(i32Ty, CLK_ADDRESS_CLAMP);
           Value *isClampMode = Builder.CreateICmpEQ(addressMode, clampInt);
+          CopyDebug(isClampMode, I);
           Value *filterMask = ConstantInt::get(i32Ty, __CLK_FILTER_MASK);
           Value *filterMode = Builder.CreateAnd(I->getOperand(0), filterMask);
+          CopyDebug(filterMode, I);
           Value *nearestInt = ConstantInt::get(i32Ty, CLK_FILTER_NEAREST);
           Value *isNearestMode = Builder.CreateICmpEQ(filterMode, nearestInt);
+          CopyDebug(isNearestMode, I);
           needFixVal = Builder.CreateAnd(isClampMode, isNearestMode);
+          CopyDebug(needFixVal, I);
         }
 
         I->replaceAllUsesWith(needFixVal);
@@ -91,7 +96,9 @@ namespace gbe {
           Builder.SetInsertPoint(I);
           Value *normalizeMask = ConstantInt::get(i32Ty, CLK_NORMALIZED_COORDS_TRUE);
           Value *normalizeMode = Builder.CreateAnd(I->getOperand(0), normalizeMask);
+          CopyDebug(normalizeMode, I);
           needFixVal = Builder.CreateICmpEQ(normalizeMode, ConstantInt::get(i32Ty, 0));
+          CopyDebug(needFixVal, I);
         }
         I->replaceAllUsesWith(needFixVal);
         changed = true;
diff --git a/backend/src/llvm/llvm_scalarize.cpp b/backend/src/llvm/llvm_scalarize.cpp
index b48ff81..0ce71d8 100644
--- a/backend/src/llvm/llvm_scalarize.cpp
+++ b/backend/src/llvm/llvm_scalarize.cpp
@@ -464,7 +464,7 @@ namespace gbe {
       gatherComponents(i, args, callArgs);
 
       Instruction* res = createScalarInstruction(inst, callArgs);
-
+      CopyDebug(res, inst);
       setComponent(vVals, i, res);
       builder->Insert(res);
     }
@@ -608,6 +608,8 @@ namespace gbe {
     for (int i = 0; i < GetComponentCount(insn); ++i) {
       Value *cv = ConstantInt::get(intTy, i);
       Value *EI = builder->CreateExtractElement(insn, cv);
+
+      CopyDebug(EI, insn);
       setComponent(vVals, i, EI);
     }
   }
@@ -621,6 +623,7 @@ namespace gbe {
       Value *vec = II ? II : UndefValue::get(vecValue->getType());
       Value *cv = ConstantInt::get(intTy, i);
       II = builder->CreateInsertElement(vec, getComponent(i, vecValue), cv);
+      CopyDebug(II, insn);
     }
 
     return II;
-- 
1.9.1





More information about the Beignet mailing list