From e65fe1a3e103e3aa81b69704d20eb95f54097271 Mon Sep 17 00:00:00 2001 From: ed Date: Sun, 7 Jun 2009 09:21:09 +0000 Subject: Import LLVM r73021. --- tools/gold/gold-plugin.cpp | 10 ++ tools/llvmc/example/mcc16/Makefile | 24 +++++ tools/llvmc/example/mcc16/README | 75 +++++++++++++ tools/llvmc/example/mcc16/driver/Main.cpp | 14 +++ tools/llvmc/example/mcc16/driver/Makefile | 22 ++++ tools/llvmc/example/mcc16/plugins/Makefile | 18 ++++ .../llvmc/example/mcc16/plugins/PIC16Base/Makefile | 17 +++ .../example/mcc16/plugins/PIC16Base/PIC16Base.td | 116 +++++++++++++++++++++ .../example/mcc16/plugins/PIC16Base/PluginMain.cpp | 1 + 9 files changed, 297 insertions(+) create mode 100644 tools/llvmc/example/mcc16/Makefile create mode 100644 tools/llvmc/example/mcc16/README create mode 100644 tools/llvmc/example/mcc16/driver/Main.cpp create mode 100644 tools/llvmc/example/mcc16/driver/Makefile create mode 100644 tools/llvmc/example/mcc16/plugins/Makefile create mode 100644 tools/llvmc/example/mcc16/plugins/PIC16Base/Makefile create mode 100644 tools/llvmc/example/mcc16/plugins/PIC16Base/PIC16Base.td create mode 100644 tools/llvmc/example/mcc16/plugins/PIC16Base/PluginMain.cpp (limited to 'tools') diff --git a/tools/gold/gold-plugin.cpp b/tools/gold/gold-plugin.cpp index 86d3fd3..46b1717 100644 --- a/tools/gold/gold-plugin.cpp +++ b/tools/gold/gold-plugin.cpp @@ -45,6 +45,7 @@ namespace { bool generate_api_file = false; const char *gcc_path = NULL; + const char *as_path = NULL; struct claimed_file { lto_module_t M; @@ -109,6 +110,13 @@ ld_plugin_status onload(ld_plugin_tv *tv) { } else { gcc_path = strdup(tv->tv_u.tv_string + 4); } + } else if (strncmp("as=", tv->tv_u.tv_string, 3) == 0) { + if (as_path) { + (*message)(LDPL_WARNING, "Path to as specified twice. " + "Discarding %s", tv->tv_u.tv_string); + } else { + as_path = strdup(tv->tv_u.tv_string + 3); + } } else { (*message)(LDPL_WARNING, "Ignoring flag %s", tv->tv_u.tv_string); } @@ -346,6 +354,8 @@ ld_plugin_status all_symbols_read_hook(void) { lto_codegen_set_debug_model(cg, LTO_DEBUG_MODEL_DWARF); if (gcc_path) lto_codegen_set_gcc_path(cg, gcc_path); + if (as_path) + lto_codegen_set_assembler_path(cg, as_path); size_t bufsize = 0; const char *buffer = static_cast(lto_codegen_compile(cg, diff --git a/tools/llvmc/example/mcc16/Makefile b/tools/llvmc/example/mcc16/Makefile new file mode 100644 index 0000000..efc9d2d --- /dev/null +++ b/tools/llvmc/example/mcc16/Makefile @@ -0,0 +1,24 @@ +##===- llvmc/example/mcc16/Makefile ------------------------*- Makefile -*-===## +# +# The LLVM Compiler Infrastructure +# +# This file is distributed under the University of Illinois Open +# Source License. See LICENSE.TXT for details. +# +##===----------------------------------------------------------------------===## + +# Change this so that $(BASE_LEVEL)/Makefile.common refers to +# $LLVM_DIR/Makefile.common. +export LLVMC_BASE_LEVEL = ../../../.. + +# Change this to the name of your LLVMC-based driver. +export LLVMC_BASED_DRIVER_NAME = mcc16 + +# List your plugin names here +export LLVMC_BUILTIN_PLUGINS = PIC16Base + +LEVEL = $(LLVMC_BASE_LEVEL) + +DIRS = plugins driver + +include $(LEVEL)/Makefile.common diff --git a/tools/llvmc/example/mcc16/README b/tools/llvmc/example/mcc16/README new file mode 100644 index 0000000..eeef6a4 --- /dev/null +++ b/tools/llvmc/example/mcc16/README @@ -0,0 +1,75 @@ +This is a basic compiler driver for the PIC16 toolchain that shows how to create +your own llvmc-based drivers. It is based on the example/Skeleton template. + +The PIC16 toolchain looks like this: + +clang-cc (FE) -> llvm-ld (optimizer) -> llc (codegen) -> native-as -> native-ld + +Following features were requested by Sanjiv: + +From: Sanjiv Gupta microchip.com> +Subject: Re: llvmc for PIC16 +Newsgroups: gmane.comp.compilers.llvm.devel +Date: 2009-06-05 06:51:14 GMT + +The salient features that we want to have in the driver are: +1. llvm-ld will be used as "The Optimizer". +2. If the user has specified to generate the final executable, then +llvm-ld should run on all the .bc files generated by clang and create a +single optimized .bc file for further tools. +3. -Wo - pass optimizations to the llvm-ld +4. mcc16 -Wl - pass options to native linker. +5. mcc16 -Wa - pass options to native assembler. + +Here are some example command lines and sample command invocations as to +what should be done. + +$ mcc16 -S foo.c +// [clang-cc foo.c] -> foo.bc +// [llvm-ld foo.bc] -> foo.opt.bc +// [llc foo.opt.bc] -> foo.s + +$ mcc16 -S foo.c bar.c +// [clang-cc foo.c] -> foo.bc +// [llvm-ld foo.bc] -> foo.opt.bc +// [llc foo.opt.bc] -> foo.s +// [clang-cc bar.c] -> bar.bc +// [llvm-ld bar.bc] -> bar.opt.bc +// [llc bar.opt.bc] -> bar.s + +** Use of -g causes llvm-ld to run with -disable-opt +$ mcc16 -S -g foo.c +// [clang-cc foo.c] -> foo.bc +// [llvm-ld -disable-opt foo.bc] -> foo.opt.bc +// [llc foo.opt.bc] -> foo.s + +** -I is passed to clang-cc, -pre-RA-sched=list-burr to llc. +$ mcc16 -S -g -I ../include -pre-RA-sched=list-burr foo.c +// [clang-cc -I ../include foo.c] -> foo.bc +// [llvm-ld -disable-opt foo.bc] -> foo.opt.bc +// [llc -pre-RA-sched=list-burr foo.opt.bc] -> foo.s + +** -Wo passes options to llvm-ld +$ mcc16 -Wo=opt1,opt2 -S -I ../include -pre-RA-sched=list-burr foo.c +// [clang-cc -I ../include foo.c] -> foo.bc +// [llvm-ld -opt1 -opt2 foo.bc] -> foo.opt.bc +// [llc -pre-RA-sched=list-burr foo.opt.bc] -> foo.s + +** -Wa passes options to native as. +$ mcc16 -c foo.c -Wa=opt1 +// [clang-cc foo.c] -> foo.bc +// [llvm-ld foo.bc] -> foo.opt.bc +// [llc foo.opt.bc] -> foo.s +// [native-as -opt1 foo.s] -> foo.o + +$ mcc16 -Wo=opt1 -Wl=opt2 -Wa=opt3 foo.c bar.c +// [clang-cc foo.c] -> foo.bc +// [clang-cc bar.c] -> bar.bc +// [llvm-ld -opt1 foo.bc bar.bc] -> a.out.bc +// [llc a.out.bc] -> a.out.s +// [native-as -opt3 a.out.s] -> a.out.o +// [native-ld -opt2 a.out.o] -> a.out + +Is this achievable by a tablegen based driver ? + +- Sanjiv diff --git a/tools/llvmc/example/mcc16/driver/Main.cpp b/tools/llvmc/example/mcc16/driver/Main.cpp new file mode 100644 index 0000000..b1f5b67 --- /dev/null +++ b/tools/llvmc/example/mcc16/driver/Main.cpp @@ -0,0 +1,14 @@ +//===--- Main.cpp - The LLVM Compiler Driver -------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open +// Source License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// Just include CompilerDriver/Main.inc. +// +//===----------------------------------------------------------------------===// + +#include "llvm/CompilerDriver/Main.inc" diff --git a/tools/llvmc/example/mcc16/driver/Makefile b/tools/llvmc/example/mcc16/driver/Makefile new file mode 100644 index 0000000..ed9ebfd --- /dev/null +++ b/tools/llvmc/example/mcc16/driver/Makefile @@ -0,0 +1,22 @@ +##===- llvmc/example/mcc16/driver/Makefile -----------------*- Makefile -*-===## +# +# The LLVM Compiler Infrastructure +# +# This file is distributed under the University of Illinois Open +# Source License. See LICENSE.TXT for details. +# +##===----------------------------------------------------------------------===## + +LEVEL = $(LLVMC_BASE_LEVEL)/.. + +TOOLNAME = $(LLVMC_BASED_DRIVER_NAME) +LLVMLIBS = CompilerDriver + +ifneq ($(LLVMC_BUILTIN_PLUGINS),) +USEDLIBS += $(patsubst %,plugin_llvmc_%,$(LLVMC_BUILTIN_PLUGINS)) +endif + +LINK_COMPONENTS = support system +REQUIRES_EH := 1 + +include $(LEVEL)/Makefile.common diff --git a/tools/llvmc/example/mcc16/plugins/Makefile b/tools/llvmc/example/mcc16/plugins/Makefile new file mode 100644 index 0000000..fb07f23 --- /dev/null +++ b/tools/llvmc/example/mcc16/plugins/Makefile @@ -0,0 +1,18 @@ +##===- llvmc/example/Skeleton/plugins/Makefile -------------*- Makefile -*-===## +# +# The LLVM Compiler Infrastructure +# +# This file is distributed under the University of Illinois Open +# Source License. See LICENSE.TXT for details. +# +##===----------------------------------------------------------------------===## + +LEVEL = $(LLVMC_BASE_LEVEL)/.. + +ifneq ($(LLVMC_BUILTIN_PLUGINS),) +DIRS = $(LLVMC_BUILTIN_PLUGINS) +endif + +export LLVMC_BUILTIN_PLUGIN=1 + +include $(LEVEL)/Makefile.common diff --git a/tools/llvmc/example/mcc16/plugins/PIC16Base/Makefile b/tools/llvmc/example/mcc16/plugins/PIC16Base/Makefile new file mode 100644 index 0000000..5d785fd --- /dev/null +++ b/tools/llvmc/example/mcc16/plugins/PIC16Base/Makefile @@ -0,0 +1,17 @@ +##===- llvmc/example/Skeleton/plugins/Plugin/Makefile ------*- Makefile -*-===## +# +# The LLVM Compiler Infrastructure +# +# This file is distributed under the University of Illinois Open Source +# License. See LICENSE.TXT for details. +# +##===----------------------------------------------------------------------===## + +LEVEL = $(LLVMC_BASE_LEVEL)/../.. + +# Change this to the name of your plugin. +LLVMC_PLUGIN = PIC16Base + +BUILT_SOURCES = AutoGenerated.inc + +include $(LEVEL)/Makefile.common diff --git a/tools/llvmc/example/mcc16/plugins/PIC16Base/PIC16Base.td b/tools/llvmc/example/mcc16/plugins/PIC16Base/PIC16Base.td new file mode 100644 index 0000000..0b8a22b --- /dev/null +++ b/tools/llvmc/example/mcc16/plugins/PIC16Base/PIC16Base.td @@ -0,0 +1,116 @@ +//===- PIC16Base.td - PIC16 toolchain driver ---------------*- tablegen -*-===// +// +// A basic driver for the PIC16 toolchain. +// +//===----------------------------------------------------------------------===// + +include "llvm/CompilerDriver/Common.td" + +// Options + +def OptionList : OptionList<[ + (switch_option "g", + (help "Disable optimizations")), + (switch_option "S", + (help "Stop after compilation, do not assemble")), + (parameter_option "I", + (help "Add a directory to include path")), + (parameter_option "pre-RA-sched", + (help "Example of an option that is passed to llc")), + (prefix_list_option "Wa,", + (help "Pass options to native assembler")), + (prefix_list_option "Wl,", + (help "Pass options to native linker")), + (prefix_list_option "Wllc,", + (help "Pass options to llc")), + (prefix_list_option "Wo,", + (help "Pass options to llvm-ld")) +]>; + +// Tools + +def clang_cc : Tool<[ + (in_language "c"), + (out_language "llvm-bitcode"), + (output_suffix "bc"), + (cmd_line "clang-cc $INFILE -o $OUTFILE"), + (actions (case + (not_empty "I"), (forward "I"))), + (sink) +]>; + +def llvm_ld : Tool<[ + (in_language "llvm-bitcode"), + (out_language "llvm-bitcode"), + (output_suffix "bc"), + (cmd_line "llvm-ld $INFILE -o $OUTFILE"), + (actions (case + (switch_on "g"), (append_cmd "-disable-opt"), + (not_empty "Wo,"), (unpack_values "Wo,"))) +]>; + +def llvm_ld_lto : Tool<[ + (in_language "llvm-bitcode"), + (out_language "llvm-bitcode"), + (output_suffix "bc"), + (cmd_line "llvm-ld $INFILE -o $OUTFILE"), + (actions (case + (switch_on "g"), (append_cmd "-disable-opt"), + (not_empty "Wo,"), (unpack_values "Wo,"))), + (join) +]>; + +def llc : Tool<[ + (in_language "llvm-bitcode"), + (out_language "assembler"), + (output_suffix "s"), + (cmd_line "llc -f $INFILE -o $OUTFILE"), + (actions (case + (switch_on "S"), (stop_compilation), + (not_empty "Wllc,"), (unpack_values "Wllc,"), + (not_empty "pre-RA-sched"), (forward "pre-RA-sched"))) +]>; + +def native_as : Tool<[ + (in_language "assembler"), + (out_language "object-code"), + (output_suffix "o"), + (cmd_line "native-as $INFILE -o $OUTFILE"), + (actions (case + (not_empty "Wa,"), (unpack_values "Wa,"))) +]>; + +def native_ld : Tool<[ + (in_language "object-code"), + (out_language "executable"), + (output_suffix "out"), + (cmd_line "native-ld $INFILE -o $OUTFILE"), + (actions (case + (not_empty "Wl,"), (unpack_values "Wl,"))), + (join) +]>; + +// Language map + +def LanguageMap : LanguageMap<[ + LangToSuffixes<"c", ["c"]>, + LangToSuffixes<"c-cpp-output", ["i"]>, + LangToSuffixes<"assembler", ["s"]>, + LangToSuffixes<"assembler-with-cpp", ["S"]>, + LangToSuffixes<"llvm-assembler", ["ll"]>, + LangToSuffixes<"llvm-bitcode", ["bc"]>, + LangToSuffixes<"object-code", ["o"]>, + LangToSuffixes<"executable", ["out"]> +]>; + +// Compilation graph + +def CompilationGraph : CompilationGraph<[ + Edge<"root", "clang_cc">, + Edge<"clang_cc", "llvm_ld_lto">, + Edge<"llvm_ld_lto", "llc">, + OptionalEdge<"clang_cc", "llvm_ld", (case (switch_on "S"), (inc_weight))>, + Edge<"llvm_ld", "llc">, + Edge<"llc", "native_as">, + Edge<"native_as", "native_ld"> +]>; diff --git a/tools/llvmc/example/mcc16/plugins/PIC16Base/PluginMain.cpp b/tools/llvmc/example/mcc16/plugins/PIC16Base/PluginMain.cpp new file mode 100644 index 0000000..add8acb --- /dev/null +++ b/tools/llvmc/example/mcc16/plugins/PIC16Base/PluginMain.cpp @@ -0,0 +1 @@ +#include "AutoGenerated.inc" -- cgit v1.1