コード例 #1
0
        [DebuggerNonUserCode] public BlockExpander(Block source, ExpansionContext ctx)
        {
            Source = source;
            Ctx    = ctx;

            Stmts     = new Block();
            ctx.Scope = Stmts;
            var cloned_locals = source.Locals.Select(l => l.DeepClone());

            cloned_locals.ForEach(local => ctx.Scope.Locals.Add(local));

            var is_root = Ctx.Parent == null || (Ctx.Parent.Stack.Count() != Ctx.Stack.Count());

            if (is_root)
            {
                RetLabel = new Label();
            }
            else
            {
                RetLabel.AssertNotNull();
            }

            source.ForEach(Expand);
            if (is_root && Stmts.LastOrDefault() is Goto)
            {
                Stmts.RemoveLast();
            }
            var gotos = Stmts.Family().OfType <Goto>().Where(@goto => @goto.LabelId == RetLabel.Id).ToReadOnly();

            if (is_root && gotos.IsNotEmpty())
            {
                Stmts.Add(RetLabel);
            }
        }
コード例 #2
0
ファイル: JitCompiler.cs プロジェクト: xeno-by/conflux
        // todo. cache jitted kernels
        public static JittedKernel DoCompile(CudaConfig cfg, Type t_kernel)
        {
            t_kernel = t_kernel.Hierarchy().AssertFirst(t => !t.Assembly.HasAttr<CompilerGeneratedAttribute>());
            using (var ctx = new JitContext(cfg, t_kernel))
            {
                var inliner_ctx = new ExpansionContext(Kernel);
                Hir = Hir.Expand(inliner_ctx);
                Log.EnsureBlankLine();
                Log.WriteLine("After inlining:");
                Log.WriteLine(Hir.DumpAsText());

                MemoryAllocator.InferAllocationScheme();
                Log.EnsureBlankLine();
                Log.WriteLine("Non-standard allocations:");
                var nonstandard_allocs = 0;
                Allocs.Fields.Where(kvp => kvp.Value != MemoryTier.Global).ForEach(kvp => { Log.WriteLine(kvp.Key.GetCSharpRef(ToCSharpOptions.Informative)); nonstandard_allocs++; });
                Allocs.Symbols.Where(kvp => kvp.Value != MemoryTier.Private).ForEach(kvp => { Log.WriteLine(kvp.Key); nonstandard_allocs++; });
                Log.WriteLine((nonstandard_allocs == 0 ? "None" : "") + Environment.NewLine);

                // todo. also implement the following:
                // 1) downgrade to SSA
                // 2) perform SCC from "Constant Propagation with Conditional Branches"
                //    when performing SCC don't forget to funcletize stuff e.g. Impl::Cfg and Impl::Device
                // 3) eliminate dead code

                Generator.Traverse(Hir);
                Log.EnsureBlankLine();
                Log.WriteLine("Generated PTX:");
                Log.WriteLine();
                Log.WriteLine(Ptx);

                return new JittedKernel(ctx);
            }
        }
コード例 #3
0
 [DebuggerNonUserCode] private ExpressionExpander(Expression source, ExpansionContext ctx)
 {
     Source = source;
     Ctx    = ctx;
     Stmts  = new List <Node>();
     Result = Expand(Source);
 }
コード例 #4
0
ファイル: ExpressionExpander.cs プロジェクト: xeno-by/conflux
 [DebuggerNonUserCode] private ExpressionExpander(Expression source, ExpansionContext ctx)
 {
     Source = source;
     Ctx = ctx;
     Stmts = new List<Node>();
     Result = Expand(Source);
 }
コード例 #5
0
ファイル: BlockExpander.cs プロジェクト: xeno-by/conflux
        [DebuggerNonUserCode] public BlockExpander(Block source, ExpansionContext ctx)
        {
            Source = source;
            Ctx = ctx;

            Stmts = new Block();
            ctx.Scope = Stmts;
            var cloned_locals = source.Locals.Select(l => l.DeepClone());
            cloned_locals.ForEach(local => ctx.Scope.Locals.Add(local));

            var is_root = Ctx.Parent == null || (Ctx.Parent.Stack.Count() != Ctx.Stack.Count());
            if (is_root) RetLabel = new Label();
            else RetLabel.AssertNotNull();

            source.ForEach(Expand);
            if (is_root && Stmts.LastOrDefault() is Goto) Stmts.RemoveLast();
            var gotos = Stmts.Family().OfType<Goto>().Where(@goto => @goto.LabelId == RetLabel.Id).ToReadOnly();
            if (is_root && gotos.IsNotEmpty()) Stmts.Add(RetLabel);
        }
コード例 #6
0
ファイル: BlockExpander.cs プロジェクト: xeno-by/conflux
 [DebuggerNonUserCode] public static Block ExpandBlock(Block source, ExpansionContext ctx) { return new BlockExpander(source, ctx).Stmts; }
コード例 #7
0
ファイル: Facade.cs プロジェクト: xeno-by/conflux
 public static Block Expand(this Block blk, ExpansionContext ctx)
 {
     return BlockExpander.ExpandBlock(blk, ctx);
 }
コード例 #8
0
ファイル: Facade.cs プロジェクト: xeno-by/conflux
 public static ExpandedExpression Expand(this Expression expr, ExpansionContext ctx)
 {
     return ExpressionExpander.ExpandExpression(expr, ctx);
 }
コード例 #9
0
ファイル: Facade.cs プロジェクト: avaranovich/conflux
 public static Block Expand(this Block blk, ExpansionContext ctx)
 {
     return(BlockExpander.ExpandBlock(blk, ctx));
 }
コード例 #10
0
ファイル: Facade.cs プロジェクト: avaranovich/conflux
 public static ExpandedExpression Expand(this Expression expr, ExpansionContext ctx)
 {
     return(ExpressionExpander.ExpandExpression(expr, ctx));
 }
コード例 #11
0
 [DebuggerNonUserCode] public static Block ExpandBlock(Block source, ExpansionContext ctx)
 {
     return(new BlockExpander(source, ctx).Stmts);
 }
コード例 #12
0
 [DebuggerNonUserCode] public static ExpandedExpression ExpandExpression(Expression source, ExpansionContext ctx)
 {
     var expander = new ExpressionExpander(source, ctx); return(new ExpandedExpression(expander.Stmts, expander.Result));
 }
コード例 #13
0
ファイル: ExpressionExpander.cs プロジェクト: xeno-by/conflux
 [DebuggerNonUserCode] public static ExpandedExpression ExpandExpression(Expression source, ExpansionContext ctx) { var expander = new ExpressionExpander(source, ctx); return new ExpandedExpression(expander.Stmts, expander.Result); }