From 9dcc26b6a0413b042142017c22d847676b41bac5 Mon Sep 17 00:00:00 2001 From: Mikhail Glushenkov Date: Sun, 7 Jun 2009 07:08:01 +0000 Subject: [PATCH] A basic PIC16 toolchain driver. Nice addition to the examples and also a starting point for Sanjiv to work on. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@73013 91177308-0d34-0410-b5e6-96231b3b80d8 --- 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 +++ .../example/mcc16/plugins/PIC16Base/Makefile | 17 +++ .../mcc16/plugins/PIC16Base/PIC16Base.td | 116 ++++++++++++++++++ .../mcc16/plugins/PIC16Base/PluginMain.cpp | 1 + 8 files changed, 287 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 diff --git a/tools/llvmc/example/mcc16/Makefile b/tools/llvmc/example/mcc16/Makefile new file mode 100644 index 00000000000..efc9d2dc7ba --- /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 00000000000..eeef6a4f8f1 --- /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 00000000000..b1f5b6798ae --- /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 00000000000..ed9ebfdca92 --- /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 00000000000..fb07f23d58e --- /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 00000000000..5d785fd4821 --- /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 00000000000..0b8a22b8070 --- /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 00000000000..add8acb4a57 --- /dev/null +++ b/tools/llvmc/example/mcc16/plugins/PIC16Base/PluginMain.cpp @@ -0,0 +1 @@ +#include "AutoGenerated.inc" -- 2.34.1