public LoopUnrollingResults Unroll() { var unrolled = new DILOperationSet(); //if (IsClearanceLoop()) //{ // unrolled.Add(new AssignOp(0, 0)); // return new LoopUnrollingResults(unrolled, true); //} var withUnrolledNestLoops = new DILOperationSet(); foreach (var instruction in Instructions) { if (instruction is LoopOp) { var nestedLoop = instruction as LoopOp; var ur = nestedLoop.Unroll(); if (ur.WasLoopUnrolled) { withUnrolledNestLoops.AddRange(ur.UnrolledInstructions); } else { withUnrolledNestLoops.Add(new LoopOp(ur.UnrolledInstructions)); } } else { withUnrolledNestLoops.Add(instruction); } } if (IsSimple(withUnrolledNestLoops)) { var walk = new CodeWalker().Walk(withUnrolledNestLoops); if (walk.Domain.ContainsKey(0) && walk.Domain[0] == -1) { foreach (var cell in walk.Domain) { if (cell.Key == 0) { continue; } //// If the scalar value of the multiplication operation is 0, //// then simply assign 0 to the cell because n * 0 = 0. //if (cell.Value == 0) //{ // unrolled.Add(new AssignOp(cell.Key, 0)); //} //else //{ unrolled.Add(new MultiplicationMemoryOp(cell.Key, cell.Value)); //} } // If it's a simple loop, then the cell position of the loop should always be assigned a 0 since that's when the loop stops. if (walk.Domain.ContainsKey(0)) { unrolled.Add(new AssignOp(0, 0)); } return new LoopUnrollingResults(unrolled, true); } else { return new LoopUnrollingResults(withUnrolledNestLoops, false); } } return new LoopUnrollingResults(withUnrolledNestLoops, false); }
public LoopUnrollingResults Unroll() { var unrolled = new DILOperationSet(); //if (IsClearanceLoop()) //{ // unrolled.Add(new AssignOp(0, 0)); // return new LoopUnrollingResults(unrolled, true); //} var withUnrolledNestLoops = new DILOperationSet(); foreach (var instruction in Instructions) { if (instruction is LoopOp) { var nestedLoop = instruction as LoopOp; var ur = nestedLoop.Unroll(); if (ur.WasLoopUnrolled) { withUnrolledNestLoops.AddRange(ur.UnrolledInstructions); } else { withUnrolledNestLoops.Add(new LoopOp(ur.UnrolledInstructions)); } } else { withUnrolledNestLoops.Add(instruction); } } if (IsSimple(withUnrolledNestLoops)) { var walk = new CodeWalker().Walk(withUnrolledNestLoops); if (walk.Domain.ContainsKey(0) && walk.Domain[0] == -1) { foreach (var cell in walk.Domain) { if (cell.Key == 0) { continue; } //// If the scalar value of the multiplication operation is 0, //// then simply assign 0 to the cell because n * 0 = 0. //if (cell.Value == 0) //{ // unrolled.Add(new AssignOp(cell.Key, 0)); //} //else //{ unrolled.Add(new MultiplicationMemoryOp(cell.Key, cell.Value)); //} } // If it's a simple loop, then the cell position of the loop should always be assigned a 0 since that's when the loop stops. if (walk.Domain.ContainsKey(0)) { unrolled.Add(new AssignOp(0, 0)); } return(new LoopUnrollingResults(unrolled, true)); } else { return(new LoopUnrollingResults(withUnrolledNestLoops, false)); } } return(new LoopUnrollingResults(withUnrolledNestLoops, false)); }