aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2016-09-17 13:59:41 +0200
committerTristan Gingold <tgingold@free.fr>2016-09-17 13:59:41 +0200
commit295084718d1b9307d7adac59f6396b740807155a (patch)
tree8c0c2a02d771976fe45ec15789ce9c05c4c5057b
parent4b8917f8ddc7edb89143b81f6f91c96f9f4febf9 (diff)
downloadghdl-295084718d1b9307d7adac59f6396b740807155a.tar.gz
ghdl-295084718d1b9307d7adac59f6396b740807155a.tar.bz2
ghdl-295084718d1b9307d7adac59f6396b740807155a.zip
Add suport for llvm 3.6 - 3.9
-rw-r--r--BUILD.txt4
-rw-r--r--Makefile.in5
-rwxr-xr-xconfigure28
-rw-r--r--src/ortho/llvm-nodebug/Makefile10
-rw-r--r--src/ortho/llvm-nodebug/llvm-target.ads7
-rw-r--r--src/ortho/llvm-nodebug/ortho_code_main.adb314
6 files changed, 40 insertions, 328 deletions
diff --git a/BUILD.txt b/BUILD.txt
index 51c6d91d7..4bfebb7bc 100644
--- a/BUILD.txt
+++ b/BUILD.txt
@@ -96,8 +96,8 @@ $ make install
Building with the llvm backend
******************************
-You need to build and install
-llvm version 3.5 [do not modify this line as this is read by scripts].
+You need to build and install llvm. The supported versions are 3.5
+till 3.9, but only debugging is only supported with llvm 3.5
(Usually llvm also depends on libedit).
First configure ghdl with '--with-llvm-config'
diff --git a/Makefile.in b/Makefile.in
index ceb07217a..747b7a16a 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -31,6 +31,7 @@ LLVM_CONFIG=@llvm_config@
LDFLAGS=@LDFLAGS@
LIBBACKTRACE=@backtrace_lib@
llvm_be=@llvm_be@
+llvm_be_ver=@llvm_be_ver@
build_mode=@build_mode@
INSTALL_PROGRAM=install -m 755
@@ -230,14 +231,14 @@ ghdl1-llvm$(EXEEXT): force
$(MAKE) -f $(srcdir)/src/ortho/$(llvm_be)/Makefile \
ortho_srcdir=$(srcdir)/src/ortho ortho_exec=$@ \
GNAT_FLAGS="$(GHDL_LLVM_INCFLAGS) $(GNATFLAGS)" LDFLAGS="$(LDFLAGS)" \
- LLVM_CONFIG="$(LLVM_CONFIG)" all
+ LLVM_CONFIG="$(LLVM_CONFIG)" llvm_be_ver="$(llvm_be_ver)" all
oread-llvm$(EXEEXT): force
$(MAKE) -f $(srcdir)/src/ortho/$(llvm_be)/Makefile \
ortho_srcdir=$(srcdir)/src/ortho ortho_exec=$@ \
GNATMAKE="$(GNATMAKE)" \
GNAT_FLAGS="-aI$(srcdir)/src/ortho/oread $(GNATFLAGS)" \
- LLVM_CONFIG="$(LLVM_CONFIG)"
+ LLVM_CONFIG="$(LLVM_CONFIG)" llvm_be_ver="$(llvm_be_ver)"
install.llvm.program: install.dirs ghdl1-llvm$(EXEEXT) ghdl_llvm$(EXEEXT)
$(INSTALL_PROGRAM) ghdl_llvm$(EXEEXT) $(DESTDIR)$(bindir)/ghdl$(EXEEXT)
diff --git a/configure b/configure
index 49ce69380..fed905e2e 100755
--- a/configure
+++ b/configure
@@ -25,7 +25,7 @@ PIC_FLAGS=-fPIC
show_help=no
progname=$0
-subst_vars="CC GNATMAKE CFLAGS LDFLAGS build srcdir prefix backend libdirsuffix libdirreverse gcc_src_dir llvm_config llvm_be backtrace_lib build_mode EXEEXT SOEXT PIC_FLAGS"
+subst_vars="CC GNATMAKE CFLAGS LDFLAGS build srcdir prefix backend libdirsuffix libdirreverse gcc_src_dir llvm_config llvm_be llvm_be_ver backtrace_lib build_mode EXEEXT SOEXT PIC_FLAGS"
# Find srcdir
srcdir=`dirname $progname`
@@ -46,9 +46,6 @@ fi
gcc_version=`grep '^gcc version' $srcdir/BUILD.txt |
sed -e 's/gcc version \([0-9.]*\) \[.*\]\.$/\1/'`
-# Read required llvm version from BUILD.txt file
-llvm_version=`grep '^llvm version' $srcdir/BUILD.txt | cut -d ' ' -f 3`
-
# Check $1 is a prefix of $2
check_version()
{
@@ -94,7 +91,7 @@ Options [defaults in brackets]:
--prefix=PREFIX install in PREFIX [$prefix]
--srcdir=SRCDIR source code path [$srcdir]
--with-gcc=DIR use gcc backend from DIR (needs gcc $gcc_version)
- --with-llvm-config=PATH use llvm from PATH (needs llvm $llvm_version)
+ --with-llvm-config=PATH use llvm from PATH (needs llvm 3.5 - 3.9)
--with-backtrace-lib=LIB.a link with libbacktrace LIB.a to display a
backtrace on errors (only for llvm).
EOF
@@ -159,15 +156,28 @@ fi
# For llvm backend, check llvm-config
if test $backend = llvm; then
- llvm_ver=`"$llvm_config" --version 2>/dev/null`
+ llvm_version=`"$llvm_config" --version 2>/dev/null`
if [ $? != 0 ]; then
echo "cannot run $llvm_config"
exit 1
fi
- if ! check_version $llvm_version $llvm_ver; then
- echo "Mismatch llvm version $llvm_ver from $llvm_config"
- echo "Debugging is not enabled"
+ if check_version 3.5 $llvm_version; then
+ llvm_be=llvm
+ elif check_version 3.6 $llvm_version ||
+ check_version 3.7 $llvm_version ||
+ check_version 3.8 $llvm_version;
+ then
+ echo "Debugging is not enabled with llvm $llvm_version"
+ llvm_be=llvm-nodebug
+ # Tested with llvm 3.5, so assume 3.6, 3.7 and 3.8
+ llvm_be_ver=35
+ elif check_version 3.9 $llvm_version; then
+ echo "Debugging is not enabled with llvm $llvm_version"
llvm_be=llvm-nodebug
+ llvm_be_ver=39
+ else
+ echo "Unhandled version llvm $llvm_version"
+ exit 1
fi
# For llvm, the c++ compiler is used for linking so that the standard c++
# library is included. However, the linker needs the no_compact_unwind
diff --git a/src/ortho/llvm-nodebug/Makefile b/src/ortho/llvm-nodebug/Makefile
index 68aba29cf..3f9ab2099 100644
--- a/src/ortho/llvm-nodebug/Makefile
+++ b/src/ortho/llvm-nodebug/Makefile
@@ -8,7 +8,7 @@ BE=llvm-nodebug
all: $(ortho_exec)
-$(ortho_exec): $(ortho_srcdir)/llvm-nodebug/ortho_llvm.ads force llvm-cbindings.o
+$(ortho_exec): $(ortho_srcdir)/llvm-nodebug/ortho_llvm.ads force llvm-cbindings.o ortho_code_main.adb
$(GNATMAKE) -o $@ -aI$(ortho_srcdir)/llvm-nodebug -aI$(ortho_srcdir) \
$(GNAT_FLAGS) ortho_code_main -bargs -E \
-largs llvm-cbindings.o --LINK=$(CXX) \
@@ -17,6 +17,14 @@ $(ortho_exec): $(ortho_srcdir)/llvm-nodebug/ortho_llvm.ads force llvm-cbindings.
llvm-cbindings.o: $(ortho_srcdir)/llvm-nodebug/llvm-cbindings.cpp
$(CXX) -c `$(LLVM_CONFIG) --cxxflags` -o $@ $<
+ortho_code_main.adb:
+ echo "with Ortho_Code_Main$(llvm_be_ver);" > ortho_code_main.tmp
+ echo "procedure Ortho_Code_Main is" >> ortho_code_main.tmp
+ echo "begin" >> ortho_code_main.tmp
+ echo " Ortho_Code_Main$(llvm_be_ver);" >> ortho_code_main.tmp
+ echo "end Ortho_Code_Main;" >> ortho_code_main.tmp
+ mv ortho_code_main.tmp $@
+
clean:
$(RM) -f *.o *.ali ortho_code_main
$(RM) b~*.ad? *~
diff --git a/src/ortho/llvm-nodebug/llvm-target.ads b/src/ortho/llvm-nodebug/llvm-target.ads
index 17cd0427f..c5c89d84f 100644
--- a/src/ortho/llvm-nodebug/llvm-target.ads
+++ b/src/ortho/llvm-nodebug/llvm-target.ads
@@ -56,6 +56,13 @@ package LLVM.Target is
function CreateTargetData (StringRep : Cstring) return TargetDataRef;
pragma Import (C, CreateTargetData, "LLVMCreateTargetData");
+ -- Removed in LLVM 3.9 !!
+ -- Adds target data information to a pass manager. This does not take
+ -- ownership of the target data.
+ -- See the method llvm::PassManagerBase::add.
+ procedure AddTargetData(TD : TargetDataRef; PM : PassManagerRef);
+ pragma Import (C, AddTargetData, "LLVMAddTargetData");
+
-- Converts target data to a target layout string. The string must be
-- disposed with LLVMDisposeMessage.
-- See the constructor llvm::DataLayout::DataLayout. */
diff --git a/src/ortho/llvm-nodebug/ortho_code_main.adb b/src/ortho/llvm-nodebug/ortho_code_main.adb
deleted file mode 100644
index d5b11872a..000000000
--- a/src/ortho/llvm-nodebug/ortho_code_main.adb
+++ /dev/null
@@ -1,314 +0,0 @@
--- LLVM back-end for ortho - Main subprogram.
--- Copyright (C) 2014 Tristan Gingold
---
--- GHDL 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, or (at your option) any later
--- version.
---
--- GHDL 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 GCC; see the file COPYING. If not, write to the Free
--- Software Foundation, 59 Temple Place - Suite 330, Boston, MA
--- 02111-1307, USA.
-
-with Ada.Command_Line; use Ada.Command_Line;
-with Ada.Unchecked_Deallocation;
-with Ada.Unchecked_Conversion;
-with Ada.Text_IO; use Ada.Text_IO;
-
-with Ortho_Front; use Ortho_Front;
-with LLVM.BitWriter;
-with LLVM.Core; use LLVM.Core;
-with LLVM.Target; use LLVM.Target;
-with LLVM.TargetMachine; use LLVM.TargetMachine;
-with LLVM.Analysis;
-with LLVM.Transforms.Scalar;
-with Ortho_LLVM; use Ortho_LLVM;
-with Interfaces;
-with Interfaces.C; use Interfaces.C;
-
-procedure Ortho_Code_Main is
- -- Name of the output filename (given by option '-o').
- Output : String_Acc := null;
-
- type Output_Kind_Type is (Output_Llvm, Output_Bytecode,
- Output_Assembly, Output_Object);
- Output_Kind : Output_Kind_Type := Output_Llvm;
-
- -- True if the LLVM output must be displayed (set by '--dump-llvm')
- Flag_Dump_Llvm : Boolean := False;
-
- -- Index of the first file argument.
- First_File : Natural;
-
- -- Current option index.
- Optind : Natural;
-
- -- Number of arguments.
- Argc : constant Natural := Argument_Count;
-
- -- Name of the module.
- Module_Name : String := "ortho" & Ascii.Nul;
-
- -- Target triple.
- Triple : Cstring := Empty_Cstring;
-
- Target : aliased TargetRef;
-
- CPU : constant Cstring := Empty_Cstring;
- Features : constant Cstring := Empty_Cstring;
- Reloc : constant RelocMode := RelocDefault;
-
- function To_String (C : Cstring) return String is
- function Strlen (C : Cstring) return Natural;
- pragma Import (C, Strlen);
-
- subtype Fat_String is String (Positive);
- type Fat_String_Acc is access Fat_String;
-
- function To_Fat_String_Acc is new
- Ada.Unchecked_Conversion (Cstring, Fat_String_Acc);
- begin
- return To_Fat_String_Acc (C)(1 .. Strlen (C));
- end To_String;
-
- Codegen : CodeGenFileType := ObjectFile;
-
- Msg : aliased Cstring;
-begin
- Ortho_Front.Init;
-
- -- Decode options.
- First_File := Natural'Last;
- Optind := 1;
- while Optind <= Argc loop
- declare
- Arg : constant String := Argument (Optind);
- begin
- if Arg (1) = '-' then
- if Arg = "--dump-llvm" then
- Flag_Dump_Llvm := True;
- elsif Arg = "-o" then
- if Optind = Argc then
- Put_Line (Standard_Error, "error: missing filename to '-o'");
- return;
- end if;
- Output := new String'(Argument (Optind + 1) & ASCII.Nul);
- Optind := Optind + 1;
- elsif Arg = "-quiet" then
- -- Skip silently.
- null;
- elsif Arg = "-S" then
- Output_Kind := Output_Assembly;
- Codegen := AssemblyFile;
- elsif Arg = "-c" then
- Output_Kind := Output_Object;
- Codegen := ObjectFile;
- elsif Arg = "-O0" then
- Optimization := CodeGenLevelNone;
- elsif Arg = "-O1" or else Arg = "-O" then
- Optimization := CodeGenLevelLess;
- elsif Arg = "-O2" then
- Optimization := CodeGenLevelDefault;
- elsif Arg = "-O3" then
- Optimization := CodeGenLevelAggressive;
- elsif Arg = "--emit-llvm" then
- Output_Kind := Output_Llvm;
- elsif Arg = "--emit-bc" then
- Output_Kind := Output_Bytecode;
- elsif Arg = "-glines"
- or else Arg = "-gline-tables-only"
- then
- null;
- elsif Arg = "-g" then
- null;
- else
- -- This is really an argument.
- declare
- procedure Unchecked_Deallocation is
- new Ada.Unchecked_Deallocation
- (Name => String_Acc, Object => String);
-
- Opt : String_Acc := new String'(Arg);
- Opt_Arg : String_Acc;
- Res : Natural;
- begin
- Opt_Arg := null;
- if Optind < Argument_Count then
- declare
- Arg1 : constant String := Argument (Optind + 1);
- begin
- if Arg1 (Arg1'First) /= '-' then
- Opt_Arg := new String'(Arg1);
- end if;
- end;
- end if;
-
- Res := Ortho_Front.Decode_Option (Opt, Opt_Arg);
- case Res is
- when 0 =>
- Put_Line (Standard_Error,
- "unknown option '" & Arg & "'");
- return;
- when 1 =>
- null;
- when 2 =>
- Optind := Optind + 1;
- when others =>
- raise Program_Error;
- end case;
- Unchecked_Deallocation (Opt);
- Unchecked_Deallocation (Opt_Arg);
- end;
- end if;
- else
- First_File := Optind;
- exit;
- end if;
- end;
- Optind := Optind + 1;
- end loop;
-
- -- Link with LLVM libraries.
- InitializeNativeTarget;
- InitializeNativeAsmPrinter;
-
- -- LinkInJIT;
-
- Module := ModuleCreateWithName (Module_Name'Address);
-
- -- Extract target triple
- Triple := GetDefaultTargetTriple;
- SetTarget (Module, Triple);
-
- -- Get Target
- if GetTargetFromTriple (Triple, Target'Access, Msg'Access) /= 0 then
- raise Program_Error;
- end if;
-
- -- Create a target machine
- Target_Machine := CreateTargetMachine
- (Target, Triple, CPU, Features, Optimization, Reloc, CodeModelDefault);
-
- Target_Data := CreateTargetDataLayout (Target_Machine);
- SetModuleDataLayout (Module, Target_Data);
-
- Ortho_LLVM.Init;
-
- Set_Exit_Status (Failure);
-
- if First_File > Argument_Count then
- begin
- if not Parse (null) then
- return;
- end if;
- exception
- when others =>
- return;
- end;
- else
- for I in First_File .. Argument_Count loop
- declare
- Filename : constant String_Acc :=
- new String'(Argument (First_File));
- begin
- if not Parse (Filename) then
- return;
- end if;
- exception
- when others =>
- return;
- end;
- end loop;
- end if;
-
- if Flag_Dump_Llvm then
- DumpModule (Module);
- end if;
-
- -- Verify module.
- if False then
- if LLVM.Analysis.VerifyModule
- (Module, LLVM.Analysis.PrintMessageAction, Msg'Access) /= 0
- then
- DisposeMessage (Msg);
- raise Program_Error;
- end if;
- end if;
-
- if Optimization > CodeGenLevelNone then
- declare
- use LLVM.Transforms.Scalar;
- Global_Manager : constant Boolean := False;
- Pass_Manager : PassManagerRef;
- Res : Bool;
- pragma Unreferenced (Res);
- A_Func : ValueRef;
- begin
- if Global_Manager then
- Pass_Manager := CreatePassManager;
- else
- Pass_Manager := CreateFunctionPassManagerForModule (Module);
- end if;
-
- AddPromoteMemoryToRegisterPass (Pass_Manager);
- AddCFGSimplificationPass (Pass_Manager);
-
- if Global_Manager then
- Res := RunPassManager (Pass_Manager, Module);
- else
- A_Func := GetFirstFunction (Module);
- while A_Func /= Null_ValueRef loop
- Res := RunFunctionPassManager (Pass_Manager, A_Func);
- A_Func := GetNextFunction (A_Func);
- end loop;
- end if;
- end;
- end if;
-
- if Output /= null then
- declare
- Error : Boolean;
- begin
- Msg := Empty_Cstring;
-
- case Output_Kind is
- when Output_Assembly
- | Output_Object =>
- Error := LLVM.TargetMachine.TargetMachineEmitToFile
- (Target_Machine, Module,
- Output.all'Address, Codegen, Msg'Access) /= 0;
- when Output_Bytecode =>
- Error := LLVM.BitWriter.WriteBitcodeToFile
- (Module, Output.all'Address) /= 0;
- when Output_Llvm =>
- Error := PrintModuleToFile
- (Module, Output.all'Address, Msg'Access) /= 0;
- end case;
- if Error then
- Put_Line (Standard_Error,
- "error while writing to " & Output.all);
- if Msg /= Empty_Cstring then
- Put_Line (Standard_Error,
- "message: " & To_String (Msg));
- DisposeMessage (Msg);
- end if;
- Set_Exit_Status (2);
- return;
- end if;
- end;
- else
- DumpModule (Module);
- end if;
-
- Set_Exit_Status (Success);
-exception
- when others =>
- Set_Exit_Status (2);
- raise;
-end Ortho_Code_Main;