/* * yosys -- Yosys Open SYnthesis Suite * * Copyright (C) 2012 Claire Xenia Wolf * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * */ #include "kernel/register.h" #include "kernel/celltypes.h" #include "kernel/rtlil.h" #include "kernel/log.h" USING_YOSYS_NAMESPACE PRIVATE_NAMESPACE_BEGIN struct SynthEasicPass : public ScriptPass { SynthEasicPass() : ScriptPass("synth_easic", "synthesis for eASIC platform") { } void help() override { // |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---| log("\n"); log(" synth_easic [options]\n"); log("\n"); log("This command runs synthesis for eASIC platform.\n"); log("\n"); log(" -top \n"); log(" use the specified module as top module\n"); log("\n"); log(" -vlog \n"); log(" write the design to the specified structural Verilog file. writing of\n"); log(" an output file is omitted if this parameter is not specified.\n"); log("\n"); log(" -etools \n"); log(" set path to the eTools installation. (default=/opt/eTools)\n"); log("\n"); log(" -run :\n"); log(" only run the commands between the labels (see below). an empty\n"); log(" from label is synonymous to 'begin', and empty to label is\n"); log(" synonymous to the end of the command list.\n"); log("\n"); log(" -noflatten\n"); log(" do not flatten design before synthesis\n"); log("\n"); log(" -retime\n"); log(" run 'abc' with '-dff -D 1' options\n"); log("\n"); log("\n"); log("The following commands are executed by this synthesis command:\n"); help_script(); log("\n"); } string top_opt, vlog_file, etools_path; bool flatten, retime; void clear_flags() override { top_opt = "-auto-top"; vlog_file = ""; etools_path = "/opt/eTools"; flatten = true; retime = false; } void execute(std::vector args, RTLIL::Design *design) override { string run_from, run_to; clear_flags(); size_t argidx; for (argidx = 1; argidx < args.size(); argidx++) { if (args[argidx] == "-top" && argidx+1 < args.size()) { top_opt = "-top " + args[++argidx]; continue; } if (args[argidx] == "-vlog" && argidx+1 < args.size()) { vlog_file = args[++argidx]; continue; } if (args[argidx] == "-etools" && argidx+1 < args.size()) { etools_path = args[++argidx]; continue; } if (args[argidx] == "-run" && argidx+1 < args.size()) { size_t pos = args[argidx+1].find(':'); if (pos == std::string::npos) break; run_from = args[++argidx].substr(0, pos); run_to = args[argidx].substr(pos+1); continue; } if (args[argidx] == "-noflatten") { flatten = false; continue; } if (args[argidx] == "-retime") { retime = true; continue; } break; } extra_args(args, argidx, design); if (!design->full_selection()) log_cmd_error("This command only operates on fully selected designs!\n"); log_header(design, "Executing SYNTH_EASIC pass.\n"); log_push(); run_script(design, run_from, run_to); log_pop(); } void script() override { string phys_clk_lib = stringf("%s/data_ruby28/design_libs/logical/timing/gp/n3x_phys_clk_0v893ff125c.lib", etools_path.c_str()); string logic_lut_lib = stringf("%s/data_ruby28/design_libs/logical/timing/gp/n3x_logic_lut_0v893ff125c.lib", etools_path.c_str()); if (check_label("begin")) { run(stringf("read_liberty -lib %s", help_mode ? "" : phys_clk_lib.c_str())); run(stringf("read_liberty -lib %s", help_mode ? "" : logic_lut_lib.c_str())); run(stringf("hierarchy -check %s", help_mode ? "-top " : top_opt.c_str())); } if (flatten && check_label("flatten", "(unless -noflatten)")) { run("proc"); run("flatten"); } if (check_label("coarse")) { run("synth -run coarse"); } if (check_label("fine")) { run("opt -fast -mux_undef -undriven -fine"); run("memory_map"); run("opt -undriven -fine"); run("techmap"); run("opt -fast"); if (retime || help_mode) { run("abc -dff -D 1", " (only if -retime)"); run("opt_clean", "(only if -retime)"); } } if (check_label("map")) { run(stringf("dfflibmap -liberty %s", help_mode ? "" : phys_clk_lib.c_str())); run(stringf("abc -liberty %s", help_mode ? "" : logic_lut_lib.c_str())); run("opt_clean"); } if (check_label("check")) { run("hierarchy -check"); run("stat"); run("check -noinit"); run("blackbox =A:whitebox"); } if (check_label("vlog")) { if (!vlog_file.empty() || help_mode) run(stringf("write_verilog -noexpr -attr2comment %s", help_mode ? "" : vlog_file.c_str())); } } } SynthEasicPass; PRIVATE_NAMESPACE_END f='#n73'>73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312
--  LLVM back-end for ortho.
--  Copyright (C) 2014 Tristan Gingold
--
--  This program is free software: you can redistribute it and/or modify
--  it under the terms of the GNU General Public License as published by
--  the Free Software Foundation, either version 2 of the License, or
--  (at your option) any later version.
--
--  This program is distributed in the hope that it will be useful,
--  but WITHOUT ANY WARRANTY; without even the implied warranty of
--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
--  GNU General Public License for more details.
--
--  You should have received a copy of the GNU General Public License
--  along with this program.  If not, see <gnu.org/licenses>.

with Interfaces; use Interfaces;
with Interfaces.C; use Interfaces.C;
with Ortho_Ident; use Ortho_Ident;
with LLVM.Core; use LLVM.Core;
with LLVM.TargetMachine;
with LLVM.Target;

--  Interface to create nodes.
package Ortho_LLVM is
   procedure Init;

   --  LLVM specific: the module.
   Module : ModuleRef;

   --  Descriptor for the layout.
   Target_Data : LLVM.Target.TargetDataRef;

   Target_Machine : LLVM.TargetMachine.TargetMachineRef;

   --  Optimization level
   Optimization : LLVM.TargetMachine.CodeGenOptLevel :=
     LLVM.TargetMachine.CodeGenLevelDefault;

private
   --  No support for nested subprograms in LLVM.
   Has_Nested_Subprograms : constant Boolean := False;

   type O_Tnode_Type (<>);
   type O_Tnode is access O_Tnode_Type;
   O_Tnode_Null : constant O_Tnode := null;

   type ON_Type_Kind is
     (ON_No_Type,
      ON_Unsigned_Type, ON_Signed_Type, ON_Enum_Type, ON_Boolean_Type,
      ON_Float_Type,
      ON_Array_Type, ON_Array_Sub_Type,
      ON_Incomplete_Record_Type,
      ON_Record_Type, ON_Union_Type,
      ON_Incomplete_Access_Type, ON_Access_Type);

   subtype ON_Scalar_Types is ON_Type_Kind range
     ON_Unsigned_Type .. ON_Float_Type;

   subtype ON_Integer_Types is ON_Type_Kind range
     ON_Unsigned_Type .. ON_Boolean_Type;

   type O_Tnode_Type (Kind : ON_Type_Kind := ON_No_Type) is record
      LLVM : TypeRef;
      Dbg : ValueRef;
      case Kind is
         when ON_No_Type =>
            null;
         when ON_Union_Type =>
            Un_Size : unsigned;
            Un_Main_Field : TypeRef;
         when ON_Access_Type
           | ON_Incomplete_Access_Type =>
            Acc_Type : O_Tnode;
         when ON_Scalar_Types =>
            Scal_Size : Natural;
         when ON_Array_Type
           | ON_Array_Sub_Type =>
            --  Type of the element
            Arr_El_Type : O_Tnode;
         when ON_Record_Type
           | ON_Incomplete_Record_Type =>
            null;
      end case;
   end record;

   type O_Inter;
   type O_Inter_Acc is access O_Inter;
   type O_Inter is record
      Itype : O_Tnode;
      Ival : ValueRef;
      Ident : O_Ident;
      Next : O_Inter_Acc;
   end record;

   type On_Decl_Kind is
     (ON_Type_Decl, ON_Completed_Type_Decl,
      ON_Const_Decl,
      ON_Var_Decl, ON_Local_Decl, ON_Interface_Decl,
      ON_Subprg_Decl,
      ON_No_Decl);

   type O_Dnode (Kind : On_Decl_Kind := ON_No_Decl) is record
      Dtype : O_Tnode;
      LLVM : ValueRef;
      case Kind is
         when ON_Var_Decl
           | ON_Const_Decl
           | ON_Local_Decl =>
            null;
         when ON_Subprg_Decl =>
            Subprg_Id : O_Ident;
            Nbr_Args : unsigned;
            Subprg_Inters : O_Inter_Acc;
         when ON_Interface_Decl =>
            Inter : O_Inter_Acc;
         when others =>
            null;
      end case;
   end record;

   O_Dnode_Null : constant O_Dnode := (Kind => ON_No_Decl,
                                       Dtype => O_Tnode_Null,
                                       LLVM => Null_ValueRef);

   type OF_Kind is (OF_None, OF_Record, OF_Union);
   type O_Fnode (Kind : OF_Kind := OF_None) is record
      --  Type of the field.
      Ftype : O_Tnode;
      case Kind is
         when OF_None =>
            null;
         when OF_Record =>
            --  Field index (starting from 0).
            Index : Natural;
         when OF_Union =>
            Utype : TypeRef;
            Ptr_Type : TypeRef;
      end case;
   end record;

   O_Fnode_Null : constant O_Fnode := (Kind => OF_None,
                                       Ftype => O_Tnode_Null);

   type O_Anode_Type;
   type O_Anode is access O_Anode_Type;
   type O_Anode_Type is record
      Next : O_Anode;
      Formal : O_Dnode;
      Actual : O_Enode;
   end record;

   type O_Cnode is record
      LLVM : ValueRef;
      Ctype : O_Tnode;
   end record;
   O_Cnode_Null : constant O_Cnode := (LLVM => Null_ValueRef,
                                       Ctype => O_Tnode_Null);

   type O_Enode is record
      LLVM : ValueRef;
      Etype : O_Tnode;
   end record;
   O_Enode_Null : constant O_Enode := (LLVM => Null_ValueRef,
                                       Etype => O_Tnode_Null);


   type O_Lnode is record
      --  If True, the LLVM component is the value (used for arguments).
      --  If False, the LLVM component is the address of the value (used
      --   for everything else).
      Direct : Boolean;
      LLVM : ValueRef;
      Ltype : O_Tnode;
   end record;

   O_Lnode_Null : constant O_Lnode := (False, Null_ValueRef, O_Tnode_Null);

   type O_Gnode is record
      LLVM : ValueRef;
      Ltype : O_Tnode;
   end record;

   O_Gnode_Null : constant O_Gnode := (Null_ValueRef, O_Tnode_Null);

   type O_Snode is record
      --  First BB in the loop body.
      Bb_Entry : BasicBlockRef;

      --  BB after the loop.
      Bb_Exit : BasicBlockRef;
   end record;

   O_Snode_Null : constant O_Snode := (Null_BasicBlockRef,
                                       Null_BasicBlockRef);

   type O_Inter_List is record
      Ident : O_Ident;
      Storage : O_Storage;
      Res_Type : O_Tnode;
      Nbr_Inter : Natural;
      First_Inter, Last_Inter : O_Inter_Acc;
   end record;

   type O_Element;
   type O_Element_Acc is access O_Element;
   type O_Element is record
      --  Identifier for the element
      Ident : O_Ident;

      --  Type of the element
      Etype : O_Tnode;

      --  Next element (in the linked list)
      Next : O_Element_Acc;
   end record;

   --  Record and union builder.
   type O_Element_List is record
      Kind : OF_Kind;

      --  Number of fields.
      Nbr_Elements : Natural;

      --  For record: the access to the incomplete (but named) type.
      Rec_Type : O_Tnode;

      --  For unions: biggest for size and alignment
      Size : unsigned;
      Align : Unsigned_32;
      Align_Type : TypeRef;

      First_Elem, Last_Elem : O_Element_Acc;
   end record;

   type ValueRefArray_Acc is access ValueRefArray;

   type O_Record_Aggr_List is record
      --  Current number of elements in Vals.
      Len : unsigned;

      --  Value of elements.
      Vals : ValueRefArray_Acc;

      --  Type of the aggregate.
      Atype : O_Tnode;
   end record;

   type O_Array_Aggr_List is record
      --  Current number of elements in Vals.
      Len : unsigned;

      --  Value of elements.
      Vals : ValueRefArray_Acc;
      El_Type : TypeRef;

      --  Type of the aggregate.
      Atype : O_Tnode;
   end record;

   type O_Assoc_List is record
      Subprg : O_Dnode;
      Idx : unsigned;
      Vals : ValueRefArray_Acc;
   end record;

   type O_Enum_List is record
      LLVM : TypeRef;
      Num : Natural;
      Etype : O_Tnode;
   end record;

   type O_Choice_Type is record
      Low, High : ValueRef;
      Bb : BasicBlockRef;
   end record;

   type O_Choice_Array is array (Natural range <>) of O_Choice_Type;
   type O_Choice_Array_Acc is access O_Choice_Array;

   type O_Case_Block is record
      --  BB before the case.
      BB_Prev : BasicBlockRef;

      --  Select expression
      Value : ValueRef;
      Vtype : O_Tnode;

      --  BB after the case statement.
      BB_Next : BasicBlockRef;

      --  BB for others
      BB_Others : BasicBlockRef;

      --  BB for the current choice
      BB_Choice : BasicBlockRef;

      --  List of choices.
      Nbr_Choices : Natural;
      Choices : O_Choice_Array_Acc;
   end record;

   type O_If_Block is record
      --  The next basic block.
      --  After the 'If', this is the BB for the else part.  If there is no
      --   else part, this is the BB for statements after the if.
      --  After the 'else', this is the BB for statements after the if.
      Bb : BasicBlockRef;
   end record;

   function Get_LLVM_Type (Atype : O_Tnode) return TypeRef;
end Ortho_LLVM;