Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Annotation of /branches/vis15/src/compiler/codegen/target-spec.sml
ViewVC logotype

Annotation of /branches/vis15/src/compiler/codegen/target-spec.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3906 - (view) (download)

1 : jhr 3812 (* target-spec.sml
2 :     *
3 : jhr 3864 * Properties, including the target description, that affect code generation.
4 :     *
5 : jhr 3812 * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)
6 :     *
7 :     * COPYRIGHT (c) 2016 The University of Chicago
8 :     * All rights reserved.
9 :     *)
10 :    
11 :     structure TargetSpec =
12 :     struct
13 :    
14 :     datatype platform = datatype TargetOptions.platform
15 :    
16 :     type t = {
17 :     (* properties from the command line *)
18 :     diderotc : string, (* the diderotc command used to invoke this compiler *)
19 :     argv : string list, (* command-line arguments used to invoke this compiler *)
20 :     version : string, (* version message string for this compiler *)
21 : jhr 3864 (* properties from the target options *)
22 : jhr 3812 srcFile : string, (* source filename *)
23 :     outDir : string, (* directory to put output *)
24 :     outBase : string, (* basename for output or name of executable *)
25 :     exec : bool, (* generate standalone executable? *)
26 :     snapshot : bool, (* generate functions to get snapshots? *)
27 :     platform : platform, (* target platform *)
28 :     namespace : string, (* optional namespace prefix *)
29 :     double : bool, (* true for double-precision candidates *)
30 :     longint : bool, (* true for 64-bit integers (not currently used) *)
31 : jhr 3864 scalar : bool, (* true if scalar code (not SSE) should be generated *)
32 : jhr 3812 debug : bool, (* true if debugging of the target is enabled *)
33 :     bsp : bool, (* true if BSP style execution should always be used *)
34 :     (* properties from analysing the program *)
35 :     hasGlobals : bool, (* true if the program has global variables *)
36 :     hasInputs : bool, (* true if the program has input variables *)
37 :     isArray : bool, (* true for programs that use a fixed array of strands *)
38 :     hasDynSeq : bool, (* true for programs that have create dynamic sequences;
39 :     * this does not include programs that just load sequences
40 :     * from nrrd files. *)
41 :     hasStabilize : bool, (* true for programs with user-defined stabilize methods *)
42 :     hasDie : bool, (* true for programs that have "die" *)
43 :     hasNew : bool, (* true for programs that have "new" *)
44 :     hasCom : bool, (* true for programs that have strand communication *)
45 :     hasReduce : bool (* true for programs that have global reduce *)
46 :     }
47 :    
48 :     (* create the property record from the target description and program properties *)
49 :     fun mk (tgt : TargetOptions.t, props : Properties.t list) : t = {
50 :     diderotc = CommandLine.name(),
51 :     argv = CommandLine.arguments(),
52 :     version = Version.message,
53 :     srcFile = #srcFile tgt,
54 :     outDir = #outDir tgt,
55 :     outBase = #outBase tgt,
56 :     exec = #exec tgt,
57 :     snapshot = #snapshot tgt,
58 :     platform = #platform tgt,
59 :     namespace = #namespace tgt,
60 :     double = #double tgt,
61 :     longint = #longint tgt,
62 : jhr 3864 scalar = #scalar tgt,
63 : jhr 3812 debug = #debug tgt,
64 :     bsp = #bsp tgt,
65 : jhr 3866 hasGlobals = Properties.hasProp Properties.HasGlobals props,
66 :     hasInputs = Properties.hasProp Properties.HasInputs props,
67 :     isArray = Properties.hasProp Properties.StrandArray props,
68 :     hasDynSeq = Properties.hasProp Properties.DynamicSeq props,
69 :     hasStabilize = Properties.hasProp Properties.HasStabilizeMethod props,
70 :     hasDie = Properties.hasProp Properties.StrandsMayDie props,
71 :     hasNew = Properties.hasProp Properties.NewStrands props,
72 :     hasCom = Properties.hasProp Properties.StrandCommunication props,
73 :     hasReduce = Properties.hasProp Properties.GlobalReduce props
74 : jhr 3812 }
75 :    
76 : jhr 3906 (* return true if the target is parallel *)
77 :     fun isParallel (p : t) = (case #platform p of PARALLEL => true | _ => false)
78 :    
79 : jhr 3812 (* returns false if BSP style execution should always be used;
80 :     * this property can be set on the command line, but
81 :     * also holds when the program has communication, etc.
82 :     *)
83 :     fun noBSP (p : t) = not(#bsp p orelse #hasCom p orelse #hasReduce p)
84 :    
85 :     (* returns true if the program does not use inter-strand communication *)
86 :     fun noComm (p : t) = not(#hasCom p)
87 :    
88 :     (* return true if we need to keep two copies of the state: in and out. *)
89 :     fun dualState (p : t) = (#hasCom p)
90 :    
91 :     (* convert a target specification to the name of the runtime library *)
92 : jhr 3899 fun runtimeLibName (spec : t) = let
93 : jhr 3812 val l = if #debug spec then ["-debug.o"] else [".o"]
94 :     val t = (case #platform spec
95 :     of SEQUENTIAL => "-seq"
96 :     | PARALLEL => "-par"
97 :     | OPENCL => "-cl"
98 :     | CUDA => "-cuda"
99 :     (* end case *))
100 :     in
101 :     OS.Path.concat(
102 :     Paths.diderotLib(),
103 : jhr 3866 String.concat("diderot-rt" :: t :: l))
104 : jhr 3812 end
105 :    
106 :     (* return the CPP floating-point precision definition for the target *)
107 :     fun floatPrecisionDef (p : t) = if #double p
108 :     then "DIDEROT_DOUBLE_PRECISION"
109 :     else "DIDEROT_SINGLE_PRECISION"
110 :    
111 :     (* return the CPP integer precision definition for the target *)
112 :     fun intPrecisionDef (p : t) = if #longint p
113 :     then "DIDEROT_LONGINT"
114 :     else "DIDEROT_INT"
115 :    
116 :     (* return the CPP target definition for the target *)
117 :     fun targetDef (p : t) = "DIDEROT_TARGET_" ^ TargetOptions.platformToString (#platform p)
118 :    
119 : jhr 3899 (* qualify a C function or type name by the target namespace *)
120 :     fun qualifyCId name (spec : t) = #namespace spec ^ name
121 :     fun qualifyCId' base (spec : t, name) = concat[#namespace spec, base, "_", name]
122 :    
123 : jhr 3812 end

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0