llvm.org GIT mirror llvm / b3d3629
llvmc: remove dynamic plugins. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@111094 91177308-0d34-0410-b5e6-96231b3b80d8 Mikhail Glushenkov 9 years ago
32 changed file(s) with 676 addition(s) and 1167 deletion(s). Raw diff Collapse all Expand all
169169 include/llvm/Config/AsmParsers.def \
170170 include/llvm/Config/Disassemblers.def \
171171 include/llvm/System/DataTypes.h \
172 tools/llvmc/plugins/Base/Base.td
172 tools/llvmc/src/Base.td
173173 FilesToConfigPATH := $(addprefix $(LLVM_OBJ_ROOT)/,$(FilesToConfig))
174174
175175 all-local:: $(FilesToConfigPATH)
195195 install-bytecode:: install-bytecode-local
196196
197197 ###############################################################################
198 # LLVMC: Provide rules for compiling llvmc plugins
199 ###############################################################################
200
201 ifdef LLVMC_PLUGIN
202
203 LIBRARYNAME := $(patsubst %,plugin_llvmc_%,$(LLVMC_PLUGIN))
204 CPP.Flags += -DLLVMC_PLUGIN_NAME=$(LLVMC_PLUGIN)
205
206 ifeq ($(ENABLE_LLVMC_DYNAMIC),1)
207 LD.Flags += -lCompilerDriver
208 endif
209
210 # Build a dynamic library if the user runs `make` directly from the plugin
211 # directory.
212 ifndef LLVMC_BUILTIN_PLUGIN
213 LOADABLE_MODULE = 1
214 endif
215
216 # TableGen stuff...
217 ifneq ($(BUILT_SOURCES),)
218 LLVMC_BUILD_AUTOGENERATED_INC=1
219 endif
220
221 endif # LLVMC_PLUGIN
198 # LLVMC: Provide rules for compiling llvmc-based driver
199 ###############################################################################
222200
223201 ifdef LLVMC_BASED_DRIVER
224202
225203 TOOLNAME = $(LLVMC_BASED_DRIVER)
226204
227 ifeq ($(ENABLE_LLVMC_DYNAMIC),1)
228 LD.Flags += -lCompilerDriver
229 else
230 LLVMLIBS = CompilerDriver.a
231 LINK_COMPONENTS = support system
232 endif
233
234 # Preprocessor magic that generates references to static variables in built-in
235 # plugins.
236 ifneq ($(LLVMC_BUILTIN_PLUGINS),)
237
238 USEDLIBS += $(patsubst %,plugin_llvmc_%.a,$(LLVMC_BUILTIN_PLUGINS))
239
240 LLVMC_BUILTIN_PLUGINS.pre := \
241 $(patsubst %,-DLLVMC_BUILTIN_PLUGIN_%=, \
242 1 2 3 4 5 6 7 8 9 10)
243
244 CPP.Flags += \
245 $(filter-out $(LLVMC_BUILTIN_PLUGINS.pre) $(LLVMC_BUILTIN_PLUGINS), \
246 $(join $(LLVMC_BUILTIN_PLUGINS.pre), $(LLVMC_BUILTIN_PLUGINS)))
247
248 endif
205 LLVMLIBS = CompilerDriver.a
206 LINK_COMPONENTS = support system
249207
250208 endif # LLVMC_BASED_DRIVER
251209
16001558 TABLEGEN_INC_FILES_COMMON = 1
16011559 endif
16021560
1603 ifdef LLVMC_BUILD_AUTOGENERATED_INC
1561 ifdef LLVMC_BASED_DRIVER
16041562 TABLEGEN_INC_FILES_COMMON = 1
16051563 endif
16061564
17241682
17251683 endif # TARGET
17261684
1727 ifdef LLVMC_BUILD_AUTOGENERATED_INC
1728
1729 LLVMCPluginSrc := $(sort $(strip $(wildcard $(PROJ_SRC_DIR)/*.td)) \
1730 $(strip $(wildcard $(PROJ_OBJ_DIR)/*.td)))
1731
1732 TDFiles := $(LLVMCPluginSrc) \
1733 $(strip $(wildcard $(LLVM_SRC_ROOT)/include/llvm/CompilerDriver/*.td))
1734
1735 $(ObjDir)/AutoGenerated.inc.tmp: $(LLVMCPluginSrc) $(ObjDir)/.dir \
1736 $(TBLGEN) $(TD_COMMON)
1737 $(Echo) "Building LLVMC configuration library with tblgen"
1685 ifdef LLVMC_BASED_DRIVER
1686
1687 TDSrc := $(sort $(strip $(wildcard $(PROJ_SRC_DIR)/*.td)) \
1688 $(strip $(wildcard $(PROJ_OBJ_DIR)/*.td)))
1689
1690 TDCommon := $(strip $(wildcard \
1691 $(LLVM_SRC_ROOT)/include/llvm/CompilerDriver/*.td))
1692
1693 TDFiles := $(TDSrc) $(TDCommon)
1694
1695 $(INCTMPFiles) : $(TBLGEN) $(TDFiles)
1696
1697 $(ObjDir)/%.inc.tmp: %.td $(ObjDir)/.dir
1698 $(Echo) "Building LLVMC compilation graph description with tblgen"
17381699 $(Verb) $(TableGen) -gen-llvmc -o $(call SYSPATH, $@) $<
17391700
1740 endif # LLVMC_BUILD_AUTOGENERATED_INC
1701 clean-local::
1702 -$(Verb) $(RM) -f $(INCFiles)
1703
1704 endif # LLVMC_BASED_DRIVER
17411705
17421706 ###############################################################################
17431707 # OTHER RULES: Other rules needed
857857 esac],
858858 llvm_cv_enable_libffi=no)
859859
860 dnl Only Windows needs dynamic libCompilerDriver to support plugins.
861 if test "$llvm_cv_os_type" = "Win32" ; then
862 llvmc_dynamic="yes"
863 else
864 llvmc_dynamic="no"
865 fi
866
867 dnl --enable-llvmc-dynamic : should LLVMC link libCompilerDriver dynamically?
868 AC_ARG_ENABLE(llvmc-dynamic,AS_HELP_STRING(
869 --enable-llvmc-dynamic,
870 [Link LLVMC dynamically (default is NO, unless on Win32)]),,
871 enableval=$llvmc_dynamic)
872 if test ${enableval} = "yes" && test "$ENABLE_PIC" -eq 1 ; then
873 AC_SUBST(ENABLE_LLVMC_DYNAMIC,[[ENABLE_LLVMC_DYNAMIC=1]])
874 else
875 AC_SUBST(ENABLE_LLVMC_DYNAMIC,[[]])
876 fi
877
878 dnl --enable-llvmc-dynamic-plugins : should LLVMC support dynamic plugins?
879 AC_ARG_ENABLE(llvmc-dynamic-plugins,AS_HELP_STRING(
880 --enable-llvmc-dynamic-plugins,
881 [Enable dynamic LLVMC plugins (default is YES)]),,
882 enableval=yes)
883 if test ${enableval} = "yes" ; then
884 AC_SUBST(ENABLE_LLVMC_DYNAMIC_PLUGINS,[[ENABLE_LLVMC_DYNAMIC_PLUGINS=1]])
885 else
886 AC_SUBST(ENABLE_LLVMC_DYNAMIC_PLUGINS,[[]])
887 fi
888
889860 dnl===-----------------------------------------------------------------------===
890861 dnl===
891862 dnl=== SECTION 4: Check for programs we need and that they are the right version
16001571 AC_CONFIG_FILES([llvm.spec])
16011572
16021573 dnl Configure llvmc's Base plugin
1603 AC_CONFIG_FILES([tools/llvmc/plugins/Base/Base.td])
1574 AC_CONFIG_FILES([tools/llvmc/src/Base.td])
16041575
16051576 dnl Do the first stage of configuration for llvm-config.in.
16061577 AC_CONFIG_FILES([tools/llvm-config/llvm-config.in])
0 //===--- AutoGenerated.h - The LLVM Compiler Driver -------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open
5 // Source License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Interface to the autogenerated driver code.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #ifndef LLVM_INCLUDE_COMPILER_DRIVER_AUTOGENERATED_H
14 #define LLVM_INCLUDE_COMPILER_DRIVER_AUTOGENERATED_H
15
16 namespace llvmc {
17 class LanguageMap;
18 class CompilationGraph;
19
20 namespace autogenerated {
21
22 int PreprocessOptions();
23 int PopulateLanguageMap(LanguageMap& langMap);
24 int PopulateCompilationGraph(CompilationGraph& graph);
25
26 inline int RunInitialization (LanguageMap& M, CompilationGraph& G) {
27 if (int ret = PreprocessOptions())
28 return ret;
29 if (int ret = PopulateLanguageMap(M))
30 return ret;
31 if (int ret = PopulateCompilationGraph(G))
32 return ret;
33
34 return 0;
35 }
36 }
37 }
38
39 #endif // LLVM_INCLUDE_COMPILER_DRIVER_AUTOGENERATED_H
3939
4040 // Possible option properties.
4141
42 def extern;
4342 def help;
4443 def hidden;
4544 def init;
10099 // Empty DAG marker.
101100 def empty_dag_marker;
102101
103 // Used to specify plugin priority.
104 class PluginPriority {
105 int priority = p;
106 }
107
108102 // Option list - a single place to specify options.
109103 class OptionList l> {
110104 list options = l;
+0
-122
include/llvm/CompilerDriver/ForceLinkage.h less more
None //===--- ForceLinkage.h - The LLVM Compiler Driver --------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open
5 // Source License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // A bit of preprocessor magic to force references to static libraries. Needed
10 // because plugin initialization is done via static variables.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_INCLUDE_COMPILER_DRIVER_FORCE_LINKAGE_H
15 #define LLVM_INCLUDE_COMPILER_DRIVER_FORCE_LINKAGE_H
16
17 #include "llvm/CompilerDriver/ForceLinkageMacros.h"
18
19 namespace llvmc {
20
21 // Declare all ForceLinkage$(PluginName) functions.
22
23 #ifdef LLVMC_BUILTIN_PLUGIN_1
24 LLVMC_FORCE_LINKAGE_DECL(LLVMC_BUILTIN_PLUGIN_1);
25 #endif
26
27 #ifdef LLVMC_BUILTIN_PLUGIN_2
28 LLVMC_FORCE_LINKAGE_DECL(LLVMC_BUILTIN_PLUGIN_2);
29 #endif
30
31 #ifdef LLVMC_BUILTIN_PLUGIN_3
32 LLVMC_FORCE_LINKAGE_DECL(LLVMC_BUILTIN_PLUGIN_3);
33 #endif
34
35 #ifdef LLVMC_BUILTIN_PLUGIN_4
36 LLVMC_FORCE_LINKAGE_DECL(LLVMC_BUILTIN_PLUGIN_4);
37 #endif
38
39 #ifdef LLVMC_BUILTIN_PLUGIN_5
40 LLVMC_FORCE_LINKAGE_DECL(LLVMC_BUILTIN_PLUGIN_5);
41 #endif
42
43 #ifdef LLVMC_BUILTIN_PLUGIN_6
44 LLVMC_FORCE_LINKAGE_DECL(LLVMC_BUILTIN_PLUGIN_6);
45 #endif
46
47 #ifdef LLVMC_BUILTIN_PLUGIN_7
48 LLVMC_FORCE_LINKAGE_DECL(LLVMC_BUILTIN_PLUGIN_7);
49 #endif
50
51 #ifdef LLVMC_BUILTIN_PLUGIN_8
52 LLVMC_FORCE_LINKAGE_DECL(LLVMC_BUILTIN_PLUGIN_8);
53 #endif
54
55 #ifdef LLVMC_BUILTIN_PLUGIN_9
56 LLVMC_FORCE_LINKAGE_DECL(LLVMC_BUILTIN_PLUGIN_9);
57 #endif
58
59 #ifdef LLVMC_BUILTIN_PLUGIN_10
60 LLVMC_FORCE_LINKAGE_DECL(LLVMC_BUILTIN_PLUGIN_10);
61 #endif
62
63 namespace force_linkage {
64
65 struct LinkageForcer {
66
67 LinkageForcer() {
68
69 // Call all ForceLinkage$(PluginName) functions.
70 #ifdef LLVMC_BUILTIN_PLUGIN_1
71 LLVMC_FORCE_LINKAGE_CALL(LLVMC_BUILTIN_PLUGIN_1);
72 #endif
73
74 #ifdef LLVMC_BUILTIN_PLUGIN_2
75 LLVMC_FORCE_LINKAGE_CALL(LLVMC_BUILTIN_PLUGIN_2);
76 #endif
77
78 #ifdef LLVMC_BUILTIN_PLUGIN_3
79 LLVMC_FORCE_LINKAGE_CALL(LLVMC_BUILTIN_PLUGIN_3);
80 #endif
81
82 #ifdef LLVMC_BUILTIN_PLUGIN_4
83 LLVMC_FORCE_LINKAGE_CALL(LLVMC_BUILTIN_PLUGIN_4);
84 #endif
85
86 #ifdef LLVMC_BUILTIN_PLUGIN_5
87 LLVMC_FORCE_LINKAGE_CALL(LLVMC_BUILTIN_PLUGIN_5);
88 #endif
89
90 #ifdef LLVMC_BUILTIN_PLUGIN_6
91 LLVMC_FORCE_LINKAGE_CALL(LLVMC_BUILTIN_PLUGIN_6);
92 #endif
93
94 #ifdef LLVMC_BUILTIN_PLUGIN_7
95 LLVMC_FORCE_LINKAGE_CALL(LLVMC_BUILTIN_PLUGIN_7);
96 #endif
97
98 #ifdef LLVMC_BUILTIN_PLUGIN_8
99 LLVMC_FORCE_LINKAGE_CALL(LLVMC_BUILTIN_PLUGIN_8);
100 #endif
101
102 #ifdef LLVMC_BUILTIN_PLUGIN_9
103 LLVMC_FORCE_LINKAGE_CALL(LLVMC_BUILTIN_PLUGIN_9);
104 #endif
105
106 #ifdef LLVMC_BUILTIN_PLUGIN_10
107 LLVMC_FORCE_LINKAGE_CALL(LLVMC_BUILTIN_PLUGIN_10);
108 #endif
109
110 }
111 };
112 } // End namespace force_linkage.
113
114 // The only externally used bit.
115 void ForceLinkage() {
116 force_linkage::LinkageForcer dummy;
117 }
118
119 } // End namespace llvmc.
120
121 #endif // LLVM_INCLUDE_COMPILER_DRIVER_FORCE_LINKAGE_H
+0
-29
include/llvm/CompilerDriver/ForceLinkageMacros.h less more
None //===--- ForceLinkageMacros.h - The LLVM Compiler Driver --------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open
5 // Source License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Preprocessor magic that forces references to static libraries - common
10 // macros used by both driver and plugins.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_INCLUDE_COMPILER_DRIVER_FORCE_LINKAGE_MACROS_H
15 #define LLVM_INCLUDE_COMPILER_DRIVER_FORCE_LINKAGE_MACROS_H
16
17 #define LLVMC_FORCE_LINKAGE_PREFIX(PluginName) ForceLinkage ## PluginName
18
19 #define LLVMC_FORCE_LINKAGE_FUN(PluginName) \
20 LLVMC_FORCE_LINKAGE_PREFIX(PluginName)
21
22 #define LLVMC_FORCE_LINKAGE_DECL(PluginName) \
23 void LLVMC_FORCE_LINKAGE_FUN(PluginName) ()
24
25 #define LLVMC_FORCE_LINKAGE_CALL(PluginName) \
26 LLVMC_FORCE_LINKAGE_FUN(PluginName) ()
27
28 #endif // LLVM_INCLUDE_COMPILER_DRIVER_FORCE_LINKAGE_MACROS_H
0 //===--- Main.h - The LLVM Compiler Driver ----------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open
5 // Source License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Entry point for the driver executable.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #ifndef LLVM_INCLUDE_COMPILER_DRIVER_MAIN_H
14 #define LLVM_INCLUDE_COMPILER_DRIVER_MAIN_H
15
16 namespace llvmc {
17 int Main(int argc, char** argv);
18 }
19
20 #endif // LLVM_INCLUDE_COMPILER_DRIVER_MAIN_H
66 //
77 //===----------------------------------------------------------------------===//
88 //
9 // This tool provides a single point of access to the LLVM
10 // compilation tools. It has many options. To discover the options
11 // supported please refer to the tools' manual page or run the tool
12 // with the -help option.
13 //
14 // This file provides the default entry point for the driver executable.
9 // Default main() for the driver executable.
1510 //
1611 //===----------------------------------------------------------------------===//
1712
1813 #ifndef LLVM_INCLUDE_COMPILER_DRIVER_MAIN_INC
1914 #define LLVM_INCLUDE_COMPILER_DRIVER_MAIN_INC
2015
21 #include "llvm/CompilerDriver/ForceLinkage.h"
22
23 namespace llvmc {
24 int Main(int argc, char** argv);
25 }
16 #include "llvm/CompilerDriver/Main.h"
2617
2718 int main(int argc, char** argv) {
28 llvmc::ForceLinkage();
2919 return llvmc::Main(argc, argv);
3020 }
3121
+0
-81
include/llvm/CompilerDriver/Plugin.h less more
None //===--- Plugin.h - The LLVM Compiler Driver --------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open
5 // Source License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Plugin support for llvmc.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #ifndef LLVM_INCLUDE_COMPILER_DRIVER_PLUGIN_H
14 #define LLVM_INCLUDE_COMPILER_DRIVER_PLUGIN_H
15
16 #include "llvm/Support/Registry.h"
17
18 namespace llvmc {
19
20 class LanguageMap;
21 class CompilationGraph;
22
23 /// BasePlugin - An abstract base class for all LLVMC plugins.
24 struct BasePlugin {
25
26 /// Priority - Plugin priority, useful for handling dependencies
27 /// between plugins. Plugins with lower priorities are loaded
28 /// first.
29 virtual int Priority() const { return 0; }
30
31 /// PreprocessOptions - The auto-generated function that performs various
32 /// consistency checks on options (like ensuring that -O2 and -O3 are not
33 /// used together).
34 virtual int PreprocessOptions() const = 0;
35
36 /// PopulateLanguageMap - The auto-generated function that fills in
37 /// the language map (map from file extensions to language names).
38 virtual int PopulateLanguageMap(LanguageMap&) const = 0;
39
40 /// PopulateCompilationGraph - The auto-generated function that
41 /// populates the compilation graph with nodes and edges.
42 virtual int PopulateCompilationGraph(CompilationGraph&) const = 0;
43
44 /// Needed to avoid a compiler warning.
45 virtual ~BasePlugin() {}
46 };
47
48 typedef llvm::Registry PluginRegistry;
49
50 template
51 struct RegisterPlugin
52 : public PluginRegistry::Add

{

53 typedef PluginRegistry::Add

Base;

54
55 RegisterPlugin(const char* Name = "Nameless",
56 const char* Desc = "Auto-generated plugin")
57 : Base(Name, Desc) {}
58 };
59
60
61 /// PluginLoader - Helper class used by the main program for
62 /// lifetime management.
63 struct PluginLoader {
64 PluginLoader();
65 ~PluginLoader();
66
67 /// RunInitialization - Calls PreprocessOptions, PopulateLanguageMap and
68 /// PopulateCompilationGraph methods of all plugins. This populates the
69 /// global language map and the compilation graph.
70 int RunInitialization(LanguageMap& langMap, CompilationGraph& graph) const;
71
72 private:
73 // noncopyable
74 PluginLoader(const PluginLoader& other);
75 const PluginLoader& operator=(const PluginLoader& other);
76 };
77
78 }
79
80 #endif // LLVM_INCLUDE_COMPILER_DRIVER_PLUGIN_H
1010 //
1111 //===----------------------------------------------------------------------===//
1212
13 #include "llvm/CompilerDriver/AutoGenerated.h"
1314 #include "llvm/CompilerDriver/BuiltinOptions.h"
1415 #include "llvm/CompilerDriver/CompilationGraph.h"
1516 #include "llvm/CompilerDriver/Error.h"
16 #include "llvm/CompilerDriver/Plugin.h"
1717
1818 #include "llvm/Support/raw_ostream.h"
1919 #include "llvm/System/Path.h"
6161 return 0;
6262 }
6363
64 /// BuildTargets - A small wrapper for CompilationGraph::Build. Returns non-zero value
64 /// BuildTargets - A small wrapper for CompilationGraph::Build. Returns
65 /// non-zero value in case of error.
6566 int BuildTargets(CompilationGraph& graph, const LanguageMap& langMap) {
6667 int ret;
6768 sys::Path tempDir;
8687 *GlobalTimeLog << "# " << cmd << ' ' << time << '\n';
8788 }
8889
89 // Sometimes plugins want to condition on the value in argv[0].
90 // Sometimes user code wants to access the argv[0] value.
9091 const char* ProgramName;
9192
9293 int Main(int argc, char** argv) {
9798 ProgramName = argv[0];
9899
99100 cl::ParseCommandLineOptions
100 (argc, argv, "LLVM Compiler Driver (Work In Progress)",
101 (argc, argv,
102 /* Overview = */ "LLVM Compiler Driver (Work In Progress)",
101103 /* ReadResponseFiles = */ false);
102104
103 PluginLoader Plugins;
104 if (int ret = Plugins.RunInitialization(langMap, graph))
105 if (int ret = autogenerated::RunInitialization(langMap, graph))
105106 return ret;
106107
107108 if (CheckGraph) {
1111 # We don't want this library to appear in `llvm-config --libs` output, so its
1212 # name doesn't start with "LLVM".
1313
14 ifeq ($(ENABLE_LLVMC_DYNAMIC),1)
15 LIBRARYNAME = libCompilerDriver
16 LLVMLIBS = LLVMSupport.a LLVMSystem.a
17 LOADABLE_MODULE := 1
18 else
19 LIBRARYNAME = CompilerDriver
20 LINK_COMPONENTS = support system
21 endif
14 LIBRARYNAME = CompilerDriver
15 LINK_COMPONENTS = support system
2216
2317 include $(LEVEL)/Makefile.common
24
25 ifeq ($(ENABLE_LLVMC_DYNAMIC_PLUGINS), 1)
26 CPP.Flags += -DENABLE_LLVMC_DYNAMIC_PLUGINS
27 endif
28
29 # Copy libCompilerDriver to the bin dir so that llvmc can find it.
30 ifeq ($(ENABLE_LLVMC_DYNAMIC),1)
31
32 FullLibName = $(LIBRARYNAME)$(SHLIBEXT)
33
34 all-local:: $(ToolDir)/$(FullLibName)
35
36 $(ToolDir)/$(FullLibName): $(LibDir)/$(FullLibName) $(ToolDir)/.dir
37 $(Echo) Copying $(BuildMode) Shared Library $(FullLibName) to $@
38 -$(Verb) $(CP) $< $@
39
40 clean-local::
41 $(Echo) Removing $(BuildMode) Shared Library $(FullLibName) \
42 from $(ToolDir)
43 -$(Verb) $(RM) -f $(ToolDir)/$(FullLibName)
44 endif
+0
-83
lib/CompilerDriver/Plugin.cpp less more
None //===--- Plugin.cpp - The LLVM Compiler Driver ------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open
5 // Source License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Plugin support.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #include "llvm/CompilerDriver/Plugin.h"
14 #include "llvm/Support/ManagedStatic.h"
15 #include "llvm/System/Mutex.h"
16 #include
17 #include
18
19 namespace {
20
21 // Registry::Add<> does not do lifetime management (probably issues
22 // with static constructor/destructor ordering), so we have to
23 // implement it here.
24 //
25 // All this static registration/life-before-main model seems
26 // unnecessary convoluted to me.
27
28 static bool pluginListInitialized = false;
29 typedef std::vector PluginList;
30 static PluginList Plugins;
31 static llvm::ManagedStatic > PluginMutex;
32
33 struct ByPriority {
34 bool operator()(const llvmc::BasePlugin* lhs,
35 const llvmc::BasePlugin* rhs) {
36 return lhs->Priority() < rhs->Priority();
37 }
38 };
39 }
40
41 namespace llvmc {
42
43 PluginLoader::PluginLoader() {
44 llvm::sys::SmartScopedLock Lock(*PluginMutex);
45 if (!pluginListInitialized) {
46 for (PluginRegistry::iterator B = PluginRegistry::begin(),
47 E = PluginRegistry::end(); B != E; ++B)
48 Plugins.push_back(B->instantiate());
49 std::sort(Plugins.begin(), Plugins.end(), ByPriority());
50 }
51 pluginListInitialized = true;
52 }
53
54 PluginLoader::~PluginLoader() {
55 llvm::sys::SmartScopedLock Lock(*PluginMutex);
56 if (pluginListInitialized) {
57 for (PluginList::iterator B = Plugins.begin(), E = Plugins.end();
58 B != E; ++B)
59 delete (*B);
60 }
61 pluginListInitialized = false;
62 }
63
64 int PluginLoader::RunInitialization(LanguageMap& langMap,
65 CompilationGraph& graph) const
66 {
67 llvm::sys::SmartScopedLock Lock(*PluginMutex);
68 for (PluginList::iterator B = Plugins.begin(), E = Plugins.end();
69 B != E; ++B) {
70 const BasePlugin* BP = *B;
71 if (int ret = BP->PreprocessOptions())
72 return ret;
73 if (int ret = BP->PopulateLanguageMap(langMap))
74 return ret;
75 if (int ret = BP->PopulateCompilationGraph(graph))
76 return ret;
77 }
78
79 return 0;
80 }
81
82 }
None # add_subdirectory(driver)
0 # add_subdirectory(src)
11
22 # TODO: support plugins and user-configured builds.
33 # See ./doc/LLVMC-Reference.rst "Customizing LLVMC: the compilation graph"
88
99 LEVEL = ../..
1010
11 export LLVMC_BASED_DRIVER_NAME = llvmc
12 export LLVMC_BUILTIN_PLUGINS = Base Clang
13
14 DIRS = plugins driver
11 DIRS = src
1512
1613 include $(LEVEL)/Makefile.common
+0
-14
tools/llvmc/driver/Main.cpp less more
None //===--- Main.cpp - The LLVM Compiler Driver -------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open
5 // Source License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Just include CompilerDriver/Main.inc.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #include "llvm/CompilerDriver/Main.inc"
+0
-13
tools/llvmc/driver/Makefile less more
None ##===- tools/llvmc/driver/Makefile -------------------------*- Makefile -*-===##
1 #
2 # The LLVM Compiler Infrastructure
3 #
4 # This file is distributed under the University of Illinois Open
5 # Source License. See LICENSE.TXT for details.
6 #
7 ##===----------------------------------------------------------------------===##
8
9 LEVEL = ../../..
10 LLVMC_BASED_DRIVER = $(LLVMC_BASED_DRIVER_NAME)
11
12 include $(LEVEL)/Makefile.common
+0
-377
tools/llvmc/plugins/Base/Base.td.in less more
None //===- Base.td - LLVMC toolchain descriptions --------------*- tablegen -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file contains compilation graph description used by llvmc.
10 //
11 //===----------------------------------------------------------------------===//
12
13 include "llvm/CompilerDriver/Common.td"
14
15 // Options
16
17 def OptList : OptionList<[
18 (switch_option "emit-llvm",
19 (help "Emit LLVM .ll files instead of native object files")),
20 (switch_option "E",
21 (help "Stop after the preprocessing stage, do not run the compiler")),
22 (switch_option "fsyntax-only",
23 (help "Stop after checking the input for syntax errors")),
24 (switch_option "opt",
25 (help "Enable opt")),
26 (switch_option "O0",
27 (help "Turn off optimization"), (zero_or_more)),
28 (switch_option "O1",
29 (help "Optimization level 1"), (zero_or_more)),
30 (switch_option "O2",
31 (help "Optimization level 2"), (zero_or_more)),
32 (switch_option "O3",
33 (help "Optimization level 3"), (zero_or_more)),
34 (switch_option "S",
35 (help "Stop after compilation, do not assemble")),
36 (switch_option "c",
37 (help "Compile and assemble, but do not link")),
38 (switch_option "pthread",
39 (help "Enable threads")),
40 (switch_option "m32",
41 (help "Generate code for a 32-bit environment"), (hidden)),
42 (switch_option "m64",
43 (help "Generate code for a 64-bit environment"), (hidden)),
44 (switch_option "fPIC",
45 (help "Relocation model: PIC"), (hidden)),
46 (switch_option "mdynamic-no-pic",
47 (help "Relocation model: dynamic-no-pic"), (hidden)),
48 (switch_option "shared",
49 (help "Create a DLL instead of the regular executable")),
50 (parameter_option "linker",
51 (help "Choose linker (possible values: gcc, g++)")),
52 (parameter_option "mtune",
53 (help "Target a specific CPU type"), (hidden), (forward_not_split)),
54
55 // TODO: Add a conditional compilation mechanism to make Darwin-only options
56 // like '-arch' really Darwin-only.
57
58 (parameter_option "arch",
59 (help "Compile for the specified target architecture"), (hidden)),
60 (parameter_option "march",
61 (help "A synonym for -mtune"), (hidden), (forward_not_split)),
62 (parameter_option "mcpu",
63 (help "A deprecated synonym for -mtune"), (hidden), (forward_not_split)),
64 (switch_option "mfix-and-continue",
65 (help "Needed by gdb to load .o files dynamically"), (hidden)),
66 (parameter_option "MF",
67 (help "Specify a file to write dependencies to"), (hidden)),
68 (parameter_list_option "MT",
69 (help "Change the name of the rule emitted by dependency generation"),
70 (hidden)),
71 (parameter_list_option "include",
72 (help "Include the named file prior to preprocessing")),
73 (parameter_list_option "iquote",
74 (help "Search dir only for files requested with #inlcude \"file\""),
75 (hidden)),
76 (parameter_list_option "framework",
77 (help "Specifies a framework to link against")),
78 (parameter_list_option "weak_framework",
79 (help "Specifies a framework to weakly link against"), (hidden)),
80 (parameter_option "filelist", (hidden),
81 (help "Link the files listed in file")),
82 (prefix_list_option "F",
83 (help "Add a directory to framework search path")),
84 (prefix_list_option "I",
85 (help "Add a directory to include path")),
86 (prefix_list_option "D",
87 (help "Define a macro")),
88 (parameter_list_option "Xpreprocessor", (hidden),
89 (help "Pass options to preprocessor")),
90 (prefix_list_option "Wa,", (comma_separated),
91 (help "Pass options to assembler")),
92 (parameter_list_option "Xassembler", (hidden),
93 (help "Pass options to assembler")),
94 (prefix_list_option "Wllc,", (comma_separated),
95 (help "Pass options to llc")),
96 (prefix_list_option "L",
97 (help "Add a directory to link path")),
98 (prefix_list_option "l",
99 (help "Search a library when linking")),
100 (prefix_list_option "Wl,",
101 (help "Pass options to linker")),
102 (parameter_list_option "Xlinker", (hidden),
103 (help "Pass options to linker")),
104 (prefix_list_option "Wo,", (comma_separated),
105 (help "Pass options to opt")),
106 (prefix_list_option "m",
107 (help "Enable or disable various extensions (-mmmx, -msse, etc.)"),
108 (hidden)),
109 (switch_option "dynamiclib", (hidden),
110 (help "Produce a dynamic library")),
111 (switch_option "prebind", (hidden),
112 (help "Prebind all undefined symbols")),
113 (switch_option "dead_strip", (hidden),
114 (help "Remove unreachable blocks of code")),
115 (switch_option "single_module", (hidden),
116 (help "Build the library so it contains only one module")),
117 (parameter_option "install_name", (hidden),
118 (help "File name the library will be installed in")),
119 (parameter_option "compatibility_version", (hidden),
120 (help "Compatibility version number")),
121 (parameter_option "current_version", (hidden),
122 (help "Current version number"))
123 ]>;
124
125 // Option preprocessor.
126
127 def Preprocess : OptionPreprocessor<
128 (case (not (any_switch_on ["O0", "O1", "O2", "O3"])),
129 (set_option "O2"),
130 (and (switch_on "O3"), (any_switch_on ["O0", "O1", "O2"])),
131 (unset_option ["O0", "O1", "O2"]),
132 (and (switch_on "O2"), (any_switch_on ["O0", "O1"])),
133 (unset_option ["O0", "O1"]),
134 (switch_on ["O1", "O0"]),
135 (unset_option "O0"))
136 >;
137
138 // Tools
139
140 class llvm_gcc_based
141 string E_ext, string out_lang> : Tool<
142 [(in_language in_lang),
143 (out_language "llvm-bitcode"),
144 (output_suffix out_lang),
145 (command cmd_prefix),
146 (actions
147 (case
148 (and (not_empty "o"),
149 (multiple_input_files), (or (switch_on "S"), (switch_on "c"))),
150 (error "cannot specify -o with -c or -S with multiple files"),
151 (switch_on "E"),
152 [(forward "E"), (stop_compilation), (output_suffix E_ext)],
153 (and (switch_on "E"), (empty "o")), (no_out_file),
154 (switch_on ["emit-llvm", "S"]),
155 [(output_suffix "ll"), (stop_compilation)],
156 (switch_on ["emit-llvm", "c"]), (stop_compilation),
157 (switch_on "fsyntax-only"), [(forward "fsyntax-only"),
158 (no_out_file), (stop_compilation)],
159 (switch_on ["S", "emit-llvm"]), [(forward "S"), (forward "emit-llvm")],
160 (not (or (switch_on ["S", "emit-llvm"]), (switch_on "fsyntax-only"))),
161 [(append_cmd "-c"), (append_cmd "-emit-llvm")],
162
163 // Forwards
164 (not_empty "Xpreprocessor"), (forward "Xpreprocessor"),
165 (not_empty "include"), (forward "include"),
166 (not_empty "iquote"), (forward "iquote"),
167 (not_empty "save-temps"), (append_cmd "-save-temps"),
168 (not_empty "I"), (forward "I"),
169 (not_empty "F"), (forward "F"),
170 (not_empty "D"), (forward "D"),
171 (not_empty "arch"), (forward "arch"),
172 (not_empty "march"), (forward "march"),
173 (not_empty "mtune"), (forward "mtune"),
174 (not_empty "mcpu"), (forward "mcpu"),
175 (not_empty "m"), (forward "m"),
176 (switch_on "mfix-and-continue"), (forward "mfix-and-continue"),
177 (switch_on "m32"), (forward "m32"),
178 (switch_on "m64"), (forward "m64"),
179 (switch_on "O0"), (forward "O0"),
180 (switch_on "O1"), (forward "O1"),
181 (switch_on "O2"), (forward "O2"),
182 (switch_on "O3"), (forward "O3"),
183 (switch_on "fPIC"), (forward "fPIC"),
184 (switch_on "mdynamic-no-pic"), (forward "mdynamic-no-pic"),
185 (not_empty "MF"), (forward "MF"),
186 (not_empty "MT"), (forward "MT"))),
187 (sink)
188 ]>;
189
190 def llvm_gcc_c : llvm_gcc_based<"@LLVMGCCCOMMAND@ -x c", "c", "i", "bc">;
191 def llvm_gcc_cpp : llvm_gcc_based<"@LLVMGXXCOMMAND@ -x c++", "c++", "i", "bc">;
192 def llvm_gcc_m : llvm_gcc_based<"@LLVMGCCCOMMAND@ -x objective-c",
193 "objective-c", "mi", "bc">;
194 def llvm_gcc_mxx : llvm_gcc_based<"@LLVMGCCCOMMAND@ -x objective-c++",
195 "objective-c++", "mi", "bc">;
196
197 def llvm_gcc_c_pch : llvm_gcc_based<"@LLVMGCCCOMMAND@ -x c-header",
198 "c-header", "i", "gch">;
199 def llvm_gcc_cpp_pch : llvm_gcc_based<"@LLVMGXXCOMMAND@ -x c++-header",
200 "c++-header",
201 "i", "gch">;
202 def llvm_gcc_m_pch : llvm_gcc_based<"@LLVMGCCCOMMAND@ -x objective-c-header",
203 "objective-c-header",
204 "mi", "gch">;
205 def llvm_gcc_mxx_pch
206 : llvm_gcc_based<"@LLVMGCCCOMMAND@ -x objective-c++-header",
207 "objective-c++-header", "mi", "gch">;
208
209 def opt : Tool<
210 [(in_language "llvm-bitcode"),
211 (out_language "llvm-bitcode"),
212 (output_suffix "bc"),
213 (actions (case (not_empty "Wo,"), (forward_value "Wo,"),
214 (switch_on "O1"), (forward "O1"),
215 (switch_on "O2"), (forward "O2"),
216 (switch_on "O3"), (forward "O3"))),
217 (command "opt -f")
218 ]>;
219
220 def llvm_as : Tool<
221 [(in_language "llvm-assembler"),
222 (out_language "llvm-bitcode"),
223 (output_suffix "bc"),
224 (command "llvm-as"),
225 (actions (case (switch_on "emit-llvm"), (stop_compilation)))
226 ]>;
227
228 def llvm_gcc_assembler : Tool<
229 [(in_language "assembler"),
230 (out_language "object-code"),
231 (output_suffix "o"),
232 (command "@LLVMGCCCOMMAND@ -c -x assembler"),
233 (actions (case
234 (switch_on "c"), (stop_compilation),
235 (not_empty "arch"), (forward "arch"),
236 (not_empty "Xassembler"), (forward "Xassembler"),
237 (switch_on "m32"), (forward "m32"),
238 (switch_on "m64"), (forward "m64"),
239 (not_empty "Wa,"), (forward "Wa,")))
240 ]>;
241
242 def llc : Tool<
243 [(in_language ["llvm-bitcode", "llvm-assembler"]),
244 (out_language "assembler"),
245 (output_suffix "s"),
246 (command "llc"),
247 (actions (case
248 (switch_on "S"), (stop_compilation),
249 (switch_on "O0"), (forward "O0"),
250 (switch_on "O1"), (forward "O1"),
251 (switch_on "O2"), (forward "O2"),
252 (switch_on "O3"), (forward "O3"),
253 (switch_on "fPIC"), (append_cmd "-relocation-model=pic"),
254 (switch_on "mdynamic-no-pic"),
255 (append_cmd "-relocation-model=dynamic-no-pic"),
256 (not_empty "march"), (forward_as "mtune", "-mcpu"),
257 (not_empty "mtune"), (forward_as "mtune", "-mcpu"),
258 (not_empty "mcpu"), (forward "mcpu"),
259 (not_empty "m"), (forward_transformed_value "m", "ConvertToMAttr"),
260 (not_empty "Wllc,"), (forward_value "Wllc,")))
261 ]>;
262
263 // Base class for linkers
264 class llvm_gcc_based_linker : Tool<
265 [(in_language ["object-code", "static-library"]),
266 (out_language "executable"),
267 (output_suffix "out"),
268 (command cmd_prefix),
269 (works_on_empty (case (and (not_empty "filelist"), on_empty), true,
270 (default), false)),
271 (join),
272 (actions (case
273 (switch_on "pthread"), (append_cmd "-lpthread"),
274 (not_empty "L"), (forward "L"),
275 (not_empty "F"), (forward "F"),
276 (not_empty "arch"), (forward "arch"),
277 (not_empty "framework"), (forward "framework"),
278 (not_empty "weak_framework"), (forward "weak_framework"),
279 (not_empty "filelist"), (forward "filelist"),
280 (switch_on "m32"), (forward "m32"),
281 (switch_on "m64"), (forward "m64"),
282 (not_empty "l"), (forward "l"),
283 (not_empty "Xlinker"), (forward "Xlinker"),
284 (not_empty "Wl,"), (forward "Wl,"),
285 (switch_on "shared"), (forward "shared"),
286 (switch_on "dynamiclib"), (forward "dynamiclib"),
287 (switch_on "prebind"), (forward "prebind"),
288 (switch_on "dead_strip"), (forward "dead_strip"),
289 (switch_on "single_module"), (forward "single_module"),
290 (not_empty "compatibility_version"),
291 (forward "compatibility_version"),
292 (not_empty "current_version"), (forward "current_version"),
293 (not_empty "install_name"), (forward "install_name")))
294 ]>;
295
296 // Default linker
297 def llvm_gcc_linker : llvm_gcc_based_linker<"@LLVMGCCCOMMAND@",
298 (not (or (parameter_equals "linker", "g++"),
299 (parameter_equals "linker", "c++")))>;
300 // Alternative linker for C++
301 def llvm_gcc_cpp_linker : llvm_gcc_based_linker<"@LLVMGXXCOMMAND@",
302 (or (parameter_equals "linker", "g++"),
303 (parameter_equals "linker", "c++"))>;
304
305 // Language map
306
307 def LanguageMap : LanguageMap<
308 [LangToSuffixes<"c++", ["cc", "cp", "cxx", "cpp", "CPP", "c++", "C"]>,
309 LangToSuffixes<"c++-header", ["hpp"]>,
310 LangToSuffixes<"c", ["c"]>,
311 LangToSuffixes<"c-header", ["h"]>,
312 LangToSuffixes<"c-cpp-output", ["i"]>,
313 LangToSuffixes<"objective-c-cpp-output", ["mi"]>,
314 LangToSuffixes<"objective-c++", ["mm"]>,
315 LangToSuffixes<"objective-c++-header", ["hmm"]>,
316 LangToSuffixes<"objective-c", ["m"]>,
317 LangToSuffixes<"objective-c-header", ["hm"]>,
318 LangToSuffixes<"assembler", ["s"]>,
319 LangToSuffixes<"assembler-with-cpp", ["S"]>,
320 LangToSuffixes<"llvm-assembler", ["ll"]>,
321 LangToSuffixes<"llvm-bitcode", ["bc"]>,
322 LangToSuffixes<"object-code", ["o", "*empty*"]>,
323 LangToSuffixes<"static-library", ["a", "lib"]>,
324 LangToSuffixes<"executable", ["out"]>
325 ]>;
326
327 // Compilation graph
328
329 def CompilationGraph : CompilationGraph<[
330 Edge<"root", "llvm_gcc_c">,
331 Edge<"root", "llvm_gcc_assembler">,
332 Edge<"root", "llvm_gcc_cpp">,
333 Edge<"root", "llvm_gcc_m">,
334 Edge<"root", "llvm_gcc_mxx">,
335 Edge<"root", "llc">,
336
337 Edge<"root", "llvm_gcc_c_pch">,
338 Edge<"root", "llvm_gcc_cpp_pch">,
339 Edge<"root", "llvm_gcc_m_pch">,
340 Edge<"root", "llvm_gcc_mxx_pch">,
341
342 Edge<"llvm_gcc_c", "llc">,
343 Edge<"llvm_gcc_cpp", "llc">,
344 Edge<"llvm_gcc_m", "llc">,
345 Edge<"llvm_gcc_mxx", "llc">,
346 Edge<"llvm_as", "llc">,
347
348 OptionalEdge<"root", "llvm_as",
349 (case (switch_on "emit-llvm"), (inc_weight))>,
350 OptionalEdge<"llvm_gcc_c", "opt", (case (switch_on "opt"), (inc_weight))>,
351 OptionalEdge<"llvm_gcc_cpp", "opt", (case (switch_on "opt"), (inc_weight))>,
352 OptionalEdge<"llvm_gcc_m", "opt", (case (switch_on "opt"), (inc_weight))>,
353 OptionalEdge<"llvm_gcc_mxx", "opt", (case (switch_on "opt"), (inc_weight))>,
354 OptionalEdge<"llvm_as", "opt", (case (switch_on "opt"), (inc_weight))>,
355 Edge<"opt", "llc">,
356
357 Edge<"llc", "llvm_gcc_assembler">,
358 Edge<"llvm_gcc_assembler", "llvm_gcc_linker">,
359 OptionalEdge<"llvm_gcc_assembler", "llvm_gcc_cpp_linker",
360 (case
361 (or (input_languages_contain "c++"),
362 (input_languages_contain "objective-c++")),
363 (inc_weight),
364 (or (parameter_equals "linker", "g++"),
365 (parameter_equals "linker", "c++")), (inc_weight))>,
366
367
368 Edge<"root", "llvm_gcc_linker">,
369 OptionalEdge<"root", "llvm_gcc_cpp_linker",
370 (case
371 (or (input_languages_contain "c++"),
372 (input_languages_contain "objective-c++")),
373 (inc_weight),
374 (or (parameter_equals "linker", "g++"),
375 (parameter_equals "linker", "c++")), (inc_weight))>
376 ]>;
+0
-33
tools/llvmc/plugins/Base/Hooks.cpp less more
None #include
1 #include
2
3 namespace hooks {
4 typedef std::vector StrVec;
5
6 /// ConvertToMAttr - Convert -m* and -mno-* to -mattr=+*,-*
7 std::string ConvertToMAttr(const StrVec& Opts) {
8 std::string out("-mattr=");
9
10 bool firstIter = true;
11 for (StrVec::const_iterator B = Opts.begin(), E = Opts.end(); B!=E; ++B) {
12 const std::string& Arg = *B;
13
14 if (firstIter)
15 firstIter = false;
16 else
17 out += ",";
18
19 if (Arg.find("no-") == 0 && Arg[3] != 0) {
20 out += '-';
21 out += Arg.c_str() + 3;
22 }
23 else {
24 out += '+';
25 out += Arg;
26 }
27 }
28
29 return out;
30 }
31
32 }
+0
-15
tools/llvmc/plugins/Base/Makefile less more
None ##===- tools/llvmc/plugins/Base/Makefile -------------------*- Makefile -*-===##
1 #
2 # The LLVM Compiler Infrastructure
3 #
4 # This file is distributed under the University of Illinois Open Source
5 # License. See LICENSE.TXT for details.
6 #
7 ##===----------------------------------------------------------------------===##
8
9 LEVEL = ../../../..
10
11 LLVMC_PLUGIN = Base
12 BUILT_SOURCES = AutoGenerated.inc
13
14 include $(LEVEL)/Makefile.common
+0
-1
tools/llvmc/plugins/Base/PluginMain.cpp less more
None #include "AutoGenerated.inc"
+0
-101
tools/llvmc/plugins/Clang/Clang.td less more
None include "llvm/CompilerDriver/Common.td"
1
2 def Priority : PluginPriority<1>;
3
4 def Options : OptionList<[
5 // Extern options
6 (switch_option "E", (extern)),
7 (switch_option "S", (extern)),
8 (switch_option "c", (extern)),
9 (switch_option "fsyntax-only", (extern)),
10 (switch_option "emit-llvm", (extern)),
11 (switch_option "pthread", (extern)),
12 (parameter_list_option "I", (extern)),
13 (parameter_list_option "include", (extern)),
14 (parameter_list_option "L", (extern)),
15 (parameter_list_option "l", (extern)),
16 (prefix_list_option "Wa,", (extern)),
17 (prefix_list_option "Wl,", (extern)),
18
19 (switch_option "clang", (help "Use Clang instead of llvm-gcc"))
20 ]>;
21
22 class clang_based : Tool<
23 [(in_language language),
24 (out_language "llvm-bitcode"),
25 (output_suffix "bc"),
26 (command cmd),
27 (actions (case (switch_on "E"),
28 [(forward "E"), (stop_compilation), (output_suffix ext_E)],
29 (and (switch_on "E"), (empty "o")), (no_out_file),
30 (switch_on "fsyntax-only"), (stop_compilation),
31 (switch_on ["S", "emit-llvm"]),
32 [(append_cmd "-emit-llvm"),
33 (stop_compilation), (output_suffix "ll")],
34 (not (switch_on ["S", "emit-llvm"])),
35 (append_cmd "-emit-llvm-bc"),
36 (switch_on ["c", "emit-llvm"]),
37 (stop_compilation),
38 (not_empty "include"), (forward "include"),
39 (not_empty "I"), (forward "I"))),
40 (sink)
41 ]>;
42
43 def clang_c : clang_based<"c", "clang -x c", "i">;
44 def clang_cpp : clang_based<"c++", "clang -x c++", "i">;
45 def clang_objective_c : clang_based<"objective-c",
46 "clang -x objective-c", "mi">;
47 def clang_objective_cpp : clang_based<"objective-c++",
48 "clang -x objective-c++", "mi">;
49
50 def as : Tool<
51 [(in_language "assembler"),
52 (out_language "object-code"),
53 (output_suffix "o"),
54 (command "as"),
55 (actions (case (not_empty "Wa,"), (forward_value "Wa,"),
56 (switch_on "c"), (stop_compilation)))
57 ]>;
58
59 // Default linker
60 def llvm_ld : Tool<
61 [(in_language "object-code"),
62 (out_language "executable"),
63 (output_suffix "out"),
64 (command "llvm-ld -native -disable-internalize"),
65 (actions (case
66 (switch_on "pthread"), (append_cmd "-lpthread"),
67 (not_empty "L"), (forward "L"),
68 (not_empty "l"), (forward "l"),
69 (not_empty "Wl,"), (forward_value "Wl,"))),
70 (join)
71 ]>;
72
73 // Language map
74
75 def LanguageMap : LanguageMap<[
76 LangToSuffixes<"c++", ["cc", "cp", "cxx", "cpp", "CPP", "c++", "C"]>,
77 LangToSuffixes<"c", ["c"]>,
78 LangToSuffixes<"objective-c", ["m"]>,
79 LangToSuffixes<"c-cpp-output", ["i"]>,
80 LangToSuffixes<"objective-c-cpp-output", ["mi"]>
81 ]>;
82
83 // Compilation graph
84
85 def CompilationGraph : CompilationGraph<[
86 OptionalEdge<"root", "clang_c",
87 (case (switch_on "clang"), (inc_weight))>,
88 OptionalEdge<"root", "clang_cpp",
89 (case (switch_on "clang"), (inc_weight))>,
90 OptionalEdge<"root", "clang_objective_c",
91 (case (switch_on "clang"), (inc_weight))>,
92 OptionalEdge<"root", "clang_objective_cpp",
93 (case (switch_on "clang"), (inc_weight))>,
94 Edge<"clang_c", "llc">,
95 Edge<"clang_cpp", "llc">,
96 Edge<"clang_objective_c", "llc">,
97 Edge<"clang_objective_cpp", "llc">,
98 OptionalEdge<"llc", "as", (case (switch_on "clang"), (inc_weight))>,
99 Edge<"as", "llvm_ld">
100 ]>;
+0
-15
tools/llvmc/plugins/Clang/Makefile less more
None ##===- tools/llvmc/plugins/Clang/Makefile ------------------*- Makefile -*-===##
1 #
2 # The LLVM Compiler Infrastructure
3 #
4 # This file is distributed under the University of Illinois Open Source
5 # License. See LICENSE.TXT for details.
6 #
7 ##===----------------------------------------------------------------------===##
8
9 LEVEL = ../../../..
10
11 LLVMC_PLUGIN = Clang
12 BUILT_SOURCES = AutoGenerated.inc
13
14 include $(LEVEL)/Makefile.common
+0
-1
tools/llvmc/plugins/Clang/PluginMain.cpp less more
None #include "AutoGenerated.inc"
+0
-18
tools/llvmc/plugins/Makefile less more
None ##===- tools/llvmc/plugins/Makefile ------------------------*- Makefile -*-===##
1 #
2 # The LLVM Compiler Infrastructure
3 #
4 # This file is distributed under the University of Illinois Open
5 # Source License. See LICENSE.TXT for details.
6 #
7 ##===----------------------------------------------------------------------===##
8
9 LEVEL = ../../..
10
11 ifneq ($(LLVMC_BUILTIN_PLUGINS),)
12 DIRS = $(LLVMC_BUILTIN_PLUGINS)
13 endif
14
15 export LLVMC_BUILTIN_PLUGIN=1
16
17 include $(LEVEL)/Makefile.common
0 //===- AutoGenerated.td - LLVMC toolchain descriptions -----*- tablegen -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file contains compilation graph description used by llvmc.
10 //
11 //===----------------------------------------------------------------------===//
12
13 include "llvm/CompilerDriver/Common.td"
14
15 include "Base.td"
16 include "Clang.td"
0 //===- Base.td - LLVMC toolchain descriptions --------------*- tablegen -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file contains compilation graph description used by llvmc.
10 //
11 //===----------------------------------------------------------------------===//
12
13
14 // Options
15
16 def OptList : OptionList<[
17 (switch_option "emit-llvm",
18 (help "Emit LLVM .ll files instead of native object files")),
19 (switch_option "E",
20 (help "Stop after the preprocessing stage, do not run the compiler")),
21 (switch_option "fsyntax-only",
22 (help "Stop after checking the input for syntax errors")),
23 (switch_option "opt",
24 (help "Enable opt")),
25 (switch_option "O0",
26 (help "Turn off optimization"), (zero_or_more)),
27 (switch_option "O1",
28 (help "Optimization level 1"), (zero_or_more)),
29 (switch_option "O2",
30 (help "Optimization level 2"), (zero_or_more)),
31 (switch_option "O3",
32 (help "Optimization level 3"), (zero_or_more)),
33 (switch_option "S",
34 (help "Stop after compilation, do not assemble")),
35 (switch_option "c",
36 (help "Compile and assemble, but do not link")),
37 (switch_option "pthread",
38 (help "Enable threads")),
39 (switch_option "m32",
40 (help "Generate code for a 32-bit environment"), (hidden)),
41 (switch_option "m64",
42 (help "Generate code for a 64-bit environment"), (hidden)),
43 (switch_option "fPIC",
44 (help "Relocation model: PIC"), (hidden)),
45 (switch_option "mdynamic-no-pic",
46 (help "Relocation model: dynamic-no-pic"), (hidden)),
47 (switch_option "shared",
48 (help "Create a DLL instead of the regular executable")),
49 (parameter_option "linker",
50 (help "Choose linker (possible values: gcc, g++)")),
51 (parameter_option "mtune",
52 (help "Target a specific CPU type"), (hidden), (forward_not_split)),
53
54 // TODO: Add a conditional compilation mechanism to make Darwin-only options
55 // like '-arch' really Darwin-only.
56
57 (parameter_option "arch",
58 (help "Compile for the specified target architecture"), (hidden)),
59 (parameter_option "march",
60 (help "A synonym for -mtune"), (hidden), (forward_not_split)),
61 (parameter_option "mcpu",
62 (help "A deprecated synonym for -mtune"), (hidden), (forward_not_split)),
63 (switch_option "mfix-and-continue",
64 (help "Needed by gdb to load .o files dynamically"), (hidden)),
65 (parameter_option "MF",
66 (help "Specify a file to write dependencies to"), (hidden)),
67 (parameter_list_option "MT",
68 (help "Change the name of the rule emitted by dependency generation"),
69 (hidden)),
70 (parameter_list_option "include",
71 (help "Include the named file prior to preprocessing")),
72 (parameter_list_option "iquote",
73 (help "Search dir only for files requested with #inlcude \"file\""),
74 (hidden)),
75 (parameter_list_option "framework",
76 (help "Specifies a framework to link against")),
77 (parameter_list_option "weak_framework",
78 (help "Specifies a framework to weakly link against"), (hidden)),
79 (parameter_option "filelist", (hidden),
80 (help "Link the files listed in file")),
81 (prefix_list_option "F",
82 (help "Add a directory to framework search path")),
83 (prefix_list_option "I",
84 (help "Add a directory to include path")),
85 (prefix_list_option "D",
86 (help "Define a macro")),
87 (parameter_list_option "Xpreprocessor", (hidden),
88 (help "Pass options to preprocessor")),
89 (prefix_list_option "Wa,", (comma_separated),
90 (help "Pass options to assembler")),
91 (parameter_list_option "Xassembler", (hidden),
92 (help "Pass options to assembler")),
93 (prefix_list_option "Wllc,", (comma_separated),
94 (help "Pass options to llc")),
95 (prefix_list_option "L",
96 (help "Add a directory to link path")),
97 (prefix_list_option "l",
98 (help "Search a library when linking")),
99 (prefix_list_option "Wl,",
100 (help "Pass options to linker")),
101 (parameter_list_option "Xlinker", (hidden),
102 (help "Pass options to linker")),
103 (prefix_list_option "Wo,", (comma_separated),
104 (help "Pass options to opt")),
105 (prefix_list_option "m",
106 (help "Enable or disable various extensions (-mmmx, -msse, etc.)"),
107 (hidden)),
108 (switch_option "dynamiclib", (hidden),
109 (help "Produce a dynamic library")),
110 (switch_option "prebind", (hidden),
111 (help "Prebind all undefined symbols")),
112 (switch_option "dead_strip", (hidden),
113 (help "Remove unreachable blocks of code")),
114 (switch_option "single_module", (hidden),
115 (help "Build the library so it contains only one module")),
116 (parameter_option "install_name", (hidden),
117 (help "File name the library will be installed in")),
118 (parameter_option "compatibility_version", (hidden),
119 (help "Compatibility version number")),
120 (parameter_option "current_version", (hidden),
121 (help "Current version number"))
122 ]>;
123
124 // Option preprocessor.
125
126 def Preprocess : OptionPreprocessor<
127 (case (not (any_switch_on ["O0", "O1", "O2", "O3"])),
128 (set_option "O2"),
129 (and (switch_on "O3"), (any_switch_on ["O0", "O1", "O2"])),
130 (unset_option ["O0", "O1", "O2"]),
131 (and (switch_on "O2"), (any_switch_on ["O0", "O1"])),
132 (unset_option ["O0", "O1"]),
133 (switch_on ["O1", "O0"]),
134 (unset_option "O0"))
135 >;
136
137 // Tools
138
139 class llvm_gcc_based
140 string E_ext, string out_lang> : Tool<
141 [(in_language in_lang),
142 (out_language "llvm-bitcode"),
143 (output_suffix out_lang),
144 (command cmd_prefix),
145 (actions
146 (case
147 (and (not_empty "o"),
148 (multiple_input_files), (or (switch_on "S"), (switch_on "c"))),
149 (error "cannot specify -o with -c or -S with multiple files"),
150 (switch_on "E"),
151 [(forward "E"), (stop_compilation), (output_suffix E_ext)],
152 (and (switch_on "E"), (empty "o")), (no_out_file),
153 (switch_on ["emit-llvm", "S"]),
154 [(output_suffix "ll"), (stop_compilation)],
155 (switch_on ["emit-llvm", "c"]), (stop_compilation),
156 (switch_on "fsyntax-only"), [(forward "fsyntax-only"),
157 (no_out_file), (stop_compilation)],
158 (switch_on ["S", "emit-llvm"]), [(forward "S"), (forward "emit-llvm")],
159 (not (or (switch_on ["S", "emit-llvm"]), (switch_on "fsyntax-only"))),
160 [(append_cmd "-c"), (append_cmd "-emit-llvm")],
161
162 // Forwards
163 (not_empty "Xpreprocessor"), (forward "Xpreprocessor"),
164 (not_empty "include"), (forward "include"),
165 (not_empty "iquote"), (forward "iquote"),
166 (not_empty "save-temps"), (append_cmd "-save-temps"),
167 (not_empty "I"), (forward "I"),
168 (not_empty "F"), (forward "F"),
169 (not_empty "D"), (forward "D"),
170 (not_empty "arch"), (forward "arch"),
171 (not_empty "march"), (forward "march"),
172 (not_empty "mtune"), (forward "mtune"),
173 (not_empty "mcpu"), (forward "mcpu"),
174 (not_empty "m"), (forward "m"),
175 (switch_on "mfix-and-continue"), (forward "mfix-and-continue"),
176 (switch_on "m32"), (forward "m32"),
177 (switch_on "m64"), (forward "m64"),
178 (switch_on "O0"), (forward "O0"),
179 (switch_on "O1"), (forward "O1"),
180 (switch_on "O2"), (forward "O2"),
181 (switch_on "O3"), (forward "O3"),
182 (switch_on "fPIC"), (forward "fPIC"),
183 (switch_on "mdynamic-no-pic"), (forward "mdynamic-no-pic"),
184 (not_empty "MF"), (forward "MF"),
185 (not_empty "MT"), (forward "MT"))),
186 (sink)
187 ]>;
188
189 def llvm_gcc_c : llvm_gcc_based<"@LLVMGCCCOMMAND@ -x c", "c", "i", "bc">;
190 def llvm_gcc_cpp : llvm_gcc_based<"@LLVMGXXCOMMAND@ -x c++", "c++", "i", "bc">;
191 def llvm_gcc_m : llvm_gcc_based<"@LLVMGCCCOMMAND@ -x objective-c",
192 "objective-c", "mi", "bc">;
193 def llvm_gcc_mxx : llvm_gcc_based<"@LLVMGCCCOMMAND@ -x objective-c++",
194 "objective-c++", "mi", "bc">;
195
196 def llvm_gcc_c_pch : llvm_gcc_based<"@LLVMGCCCOMMAND@ -x c-header",
197 "c-header", "i", "gch">;
198 def llvm_gcc_cpp_pch : llvm_gcc_based<"@LLVMGXXCOMMAND@ -x c++-header",
199 "c++-header",
200 "i", "gch">;
201 def llvm_gcc_m_pch : llvm_gcc_based<"@LLVMGCCCOMMAND@ -x objective-c-header",
202 "objective-c-header",
203 "mi", "gch">;
204 def llvm_gcc_mxx_pch
205 : llvm_gcc_based<"@LLVMGCCCOMMAND@ -x objective-c++-header",
206 "objective-c++-header", "mi", "gch">;
207
208 def opt : Tool<
209 [(in_language "llvm-bitcode"),
210 (out_language "llvm-bitcode"),
211 (output_suffix "bc"),
212 (actions (case (not_empty "Wo,"), (forward_value "Wo,"),
213 (switch_on "O1"), (forward "O1"),
214 (switch_on "O2"), (forward "O2"),
215 (switch_on "O3"), (forward "O3"))),
216 (command "opt -f")
217 ]>;
218
219 def llvm_as : Tool<
220 [(in_language "llvm-assembler"),
221 (out_language "llvm-bitcode"),
222 (output_suffix "bc"),
223 (command "llvm-as"),
224 (actions (case (switch_on "emit-llvm"), (stop_compilation)))
225 ]>;
226
227 def llvm_gcc_assembler : Tool<
228 [(in_language "assembler"),
229 (out_language "object-code"),
230 (output_suffix "o"),
231 (command "@LLVMGCCCOMMAND@ -c -x assembler"),
232 (actions (case
233 (switch_on "c"), (stop_compilation),
234 (not_empty "arch"), (forward "arch"),
235 (not_empty "Xassembler"), (forward "Xassembler"),
236 (switch_on "m32"), (forward "m32"),
237 (switch_on "m64"), (forward "m64"),
238 (not_empty "Wa,"), (forward "Wa,")))
239 ]>;
240
241 def llc : Tool<
242 [(in_language ["llvm-bitcode", "llvm-assembler"]),
243 (out_language "assembler"),
244 (output_suffix "s"),
245 (command "llc"),
246 (actions (case
247 (switch_on "S"), (stop_compilation),
248 (switch_on "O0"), (forward "O0"),
249 (switch_on "O1"), (forward "O1"),
250 (switch_on "O2"), (forward "O2"),
251 (switch_on "O3"), (forward "O3"),
252 (switch_on "fPIC"), (append_cmd "-relocation-model=pic"),
253 (switch_on "mdynamic-no-pic"),
254 (append_cmd "-relocation-model=dynamic-no-pic"),
255 (not_empty "march"), (forward_as "mtune", "-mcpu"),
256 (not_empty "mtune"), (forward_as "mtune", "-mcpu"),
257 (not_empty "mcpu"), (forward "mcpu"),
258 (not_empty "m"), (forward_transformed_value "m", "ConvertToMAttr"),
259 (not_empty "Wllc,"), (forward_value "Wllc,")))
260 ]>;
261
262 // Base class for linkers
263 class llvm_gcc_based_linker : Tool<
264 [(in_language ["object-code", "static-library"]),
265 (out_language "executable"),
266 (output_suffix "out"),
267 (command cmd_prefix),
268 (works_on_empty (case (and (not_empty "filelist"), on_empty), true,
269 (default), false)),
270 (join),
271 (actions (case
272 (switch_on "pthread"), (append_cmd "-lpthread"),
273 (not_empty "L"), (forward "L"),
274 (not_empty "F"), (forward "F"),
275 (not_empty "arch"), (forward "arch"),
276 (not_empty "framework"), (forward "framework"),
277 (not_empty "weak_framework"), (forward "weak_framework"),
278 (not_empty "filelist"), (forward "filelist"),
279 (switch_on "m32"), (forward "m32"),
280 (switch_on "m64"), (forward "m64"),
281 (not_empty "l"), (forward "l"),
282 (not_empty "Xlinker"), (forward "Xlinker"),
283 (not_empty "Wl,"), (forward "Wl,"),
284 (switch_on "shared"), (forward "shared"),
285 (switch_on "dynamiclib"), (forward "dynamiclib"),
286 (switch_on "prebind"), (forward "prebind"),
287 (switch_on "dead_strip"), (forward "dead_strip"),
288 (switch_on "single_module"), (forward "single_module"),
289 (not_empty "compatibility_version"),
290 (forward "compatibility_version"),
291 (not_empty "current_version"), (forward "current_version"),
292 (not_empty "install_name"), (forward "install_name")))
293 ]>;
294
295 // Default linker
296 def llvm_gcc_linker : llvm_gcc_based_linker<"@LLVMGCCCOMMAND@",
297 (not (or (parameter_equals "linker", "g++"),
298 (parameter_equals "linker", "c++")))>;
299 // Alternative linker for C++
300 def llvm_gcc_cpp_linker : llvm_gcc_based_linker<"@LLVMGXXCOMMAND@",
301 (or (parameter_equals "linker", "g++"),
302 (parameter_equals "linker", "c++"))>;
303
304 // Language map
305
306 def LanguageMap : LanguageMap<
307 [LangToSuffixes<"c++", ["cc", "cp", "cxx", "cpp", "CPP", "c++", "C"]>,
308 LangToSuffixes<"c++-header", ["hpp"]>,
309 LangToSuffixes<"c", ["c"]>,
310 LangToSuffixes<"c-header", ["h"]>,
311 LangToSuffixes<"c-cpp-output", ["i"]>,
312 LangToSuffixes<"objective-c-cpp-output", ["mi"]>,
313 LangToSuffixes<"objective-c++", ["mm"]>,
314 LangToSuffixes<"objective-c++-header", ["hmm"]>,
315 LangToSuffixes<"objective-c", ["m"]>,
316 LangToSuffixes<"objective-c-header", ["hm"]>,
317 LangToSuffixes<"assembler", ["s"]>,
318 LangToSuffixes<"assembler-with-cpp", ["S"]>,
319 LangToSuffixes<"llvm-assembler", ["ll"]>,
320 LangToSuffixes<"llvm-bitcode", ["bc"]>,
321 LangToSuffixes<"object-code", ["o", "*empty*"]>,
322 LangToSuffixes<"static-library", ["a", "lib"]>,
323 LangToSuffixes<"executable", ["out"]>
324 ]>;
325
326 // Compilation graph
327
328 def CompilationGraph : CompilationGraph<[
329 Edge<"root", "llvm_gcc_c">,
330 Edge<"root", "llvm_gcc_assembler">,
331 Edge<"root", "llvm_gcc_cpp">,
332 Edge<"root", "llvm_gcc_m">,
333 Edge<"root", "llvm_gcc_mxx">,
334 Edge<"root", "llc">,
335
336 Edge<"root", "llvm_gcc_c_pch">,
337 Edge<"root", "llvm_gcc_cpp_pch">,
338 Edge<"root", "llvm_gcc_m_pch">,
339 Edge<"root", "llvm_gcc_mxx_pch">,
340
341 Edge<"llvm_gcc_c", "llc">,
342 Edge<"llvm_gcc_cpp", "llc">,
343 Edge<"llvm_gcc_m", "llc">,
344 Edge<"llvm_gcc_mxx", "llc">,
345 Edge<"llvm_as", "llc">,
346
347 OptionalEdge<"root", "llvm_as",
348 (case (switch_on "emit-llvm"), (inc_weight))>,
349 OptionalEdge<"llvm_gcc_c", "opt", (case (switch_on "opt"), (inc_weight))>,
350 OptionalEdge<"llvm_gcc_cpp", "opt", (case (switch_on "opt"), (inc_weight))>,
351 OptionalEdge<"llvm_gcc_m", "opt", (case (switch_on "opt"), (inc_weight))>,
352 OptionalEdge<"llvm_gcc_mxx", "opt", (case (switch_on "opt"), (inc_weight))>,
353 OptionalEdge<"llvm_as", "opt", (case (switch_on "opt"), (inc_weight))>,
354 Edge<"opt", "llc">,
355
356 Edge<"llc", "llvm_gcc_assembler">,
357 Edge<"llvm_gcc_assembler", "llvm_gcc_linker">,
358 OptionalEdge<"llvm_gcc_assembler", "llvm_gcc_cpp_linker",
359 (case
360 (or (input_languages_contain "c++"),
361 (input_languages_contain "objective-c++")),
362 (inc_weight),
363 (or (parameter_equals "linker", "g++"),
364 (parameter_equals "linker", "c++")), (inc_weight))>,
365
366
367 Edge<"root", "llvm_gcc_linker">,
368 OptionalEdge<"root", "llvm_gcc_cpp_linker",
369 (case
370 (or (input_languages_contain "c++"),
371 (input_languages_contain "objective-c++")),
372 (inc_weight),
373 (or (parameter_equals "linker", "g++"),
374 (parameter_equals "linker", "c++")), (inc_weight))>
375 ]>;
0 //===- Clang.td - LLVMC toolchain descriptions -------------*- tablegen -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file contains compilation graph description used by llvmc.
10 //
11 //===----------------------------------------------------------------------===//
12
13
14 def Options : OptionList<[
15 (switch_option "clang", (help "Use Clang instead of llvm-gcc"))
16 ]>;
17
18 class clang_based : Tool<
19 [(in_language language),
20 (out_language "llvm-bitcode"),
21 (output_suffix "bc"),
22 (command cmd),
23 (actions (case (switch_on "E"),
24 [(forward "E"), (stop_compilation), (output_suffix ext_E)],
25 (and (switch_on "E"), (empty "o")), (no_out_file),
26 (switch_on "fsyntax-only"), (stop_compilation),
27 (switch_on ["S", "emit-llvm"]),
28 [(append_cmd "-emit-llvm"),
29 (stop_compilation), (output_suffix "ll")],
30 (not (switch_on ["S", "emit-llvm"])),
31 (append_cmd "-emit-llvm-bc"),
32 (switch_on ["c", "emit-llvm"]),
33 (stop_compilation),
34 (not_empty "include"), (forward "include"),
35 (not_empty "I"), (forward "I"))),
36 (sink)
37 ]>;
38
39 def clang_c : clang_based<"c", "clang -x c", "i">;
40 def clang_cpp : clang_based<"c++", "clang -x c++", "i">;
41 def clang_objective_c : clang_based<"objective-c",
42 "clang -x objective-c", "mi">;
43 def clang_objective_cpp : clang_based<"objective-c++",
44 "clang -x objective-c++", "mi">;
45
46 def as : Tool<
47 [(in_language "assembler"),
48 (out_language "object-code"),
49 (output_suffix "o"),
50 (command "as"),
51 (actions (case (not_empty "Wa,"), (forward_value "Wa,"),
52 (switch_on "c"), (stop_compilation)))
53 ]>;
54
55 // Default linker
56 def llvm_ld : Tool<
57 [(in_language "object-code"),
58 (out_language "executable"),
59 (output_suffix "out"),
60 (command "llvm-ld -native -disable-internalize"),
61 (actions (case
62 (switch_on "pthread"), (append_cmd "-lpthread"),
63 (not_empty "L"), (forward "L"),
64 (not_empty "l"), (forward "l"),
65 (not_empty "Wl,"), (forward_value "Wl,"))),
66 (join)
67 ]>;
68
69 // Compilation graph
70
71 def ClangCompilationGraph : CompilationGraph<[
72 OptionalEdge<"root", "clang_c",
73 (case (switch_on "clang"), (inc_weight))>,
74 OptionalEdge<"root", "clang_cpp",
75 (case (switch_on "clang"), (inc_weight))>,
76 OptionalEdge<"root", "clang_objective_c",
77 (case (switch_on "clang"), (inc_weight))>,
78 OptionalEdge<"root", "clang_objective_cpp",
79 (case (switch_on "clang"), (inc_weight))>,
80 Edge<"clang_c", "llc">,
81 Edge<"clang_cpp", "llc">,
82 Edge<"clang_objective_c", "llc">,
83 Edge<"clang_objective_cpp", "llc">,
84 OptionalEdge<"llc", "as", (case (switch_on "clang"), (inc_weight))>,
85 Edge<"as", "llvm_ld">
86 ]>;
0 #include
1 #include
2
3 namespace hooks {
4 typedef std::vector StrVec;
5
6 /// ConvertToMAttr - Convert -m* and -mno-* to -mattr=+*,-*
7 std::string ConvertToMAttr(const StrVec& Opts) {
8 std::string out("-mattr=");
9
10 bool firstIter = true;
11 for (StrVec::const_iterator B = Opts.begin(), E = Opts.end(); B!=E; ++B) {
12 const std::string& Arg = *B;
13
14 if (firstIter)
15 firstIter = false;
16 else
17 out += ",";
18
19 if (Arg.find("no-") == 0 && Arg[3] != 0) {
20 out += '-';
21 out += Arg.c_str() + 3;
22 }
23 else {
24 out += '+';
25 out += Arg;
26 }
27 }
28
29 return out;
30 }
31
32 }
0 //===--- Main.cpp - The LLVM Compiler Driver -------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open
5 // Source License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Just include AutoGenerated.inc and CompilerDriver/Main.inc.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #include "AutoGenerated.inc"
14
15 #include "llvm/CompilerDriver/Main.inc"
0 ##===- tools/llvmc/driver/Makefile -------------------------*- Makefile -*-===##
1 #
2 # The LLVM Compiler Infrastructure
3 #
4 # This file is distributed under the University of Illinois Open
5 # Source License. See LICENSE.TXT for details.
6 #
7 ##===----------------------------------------------------------------------===##
8
9 LEVEL = ../../..
10 LLVMC_BASED_DRIVER = llvmc
11 BUILT_SOURCES = AutoGenerated.inc
12
13 include $(LEVEL)/Makefile.common
233233
234234 namespace OptionDescriptionFlags {
235235 enum OptionDescriptionFlags { Required = 0x1, Hidden = 0x2,
236 ReallyHidden = 0x4, Extern = 0x8,
237 OneOrMore = 0x10, Optional = 0x20,
238 CommaSeparated = 0x40, ForwardNotSplit = 0x80,
239 ZeroOrMore = 0x100 };
236 ReallyHidden = 0x4, OneOrMore = 0x8,
237 Optional = 0x10, CommaSeparated = 0x20,
238 ForwardNotSplit = 0x40, ZeroOrMore = 0x80 };
240239 }
241240
242241 /// OptionDescription - Represents data contained in a single
278277 bool isCommaSeparated() const;
279278 void setCommaSeparated();
280279
281 bool isExtern() const;
282 void setExtern();
283
284280 bool isForwardNotSplit() const;
285281 void setForwardNotSplit();
286282
369365 }
370366 void OptionDescription::setForwardNotSplit() {
371367 Flags |= OptionDescriptionFlags::ForwardNotSplit;
372 }
373
374 bool OptionDescription::isExtern() const {
375 return Flags & OptionDescriptionFlags::Extern;
376 }
377 void OptionDescription::setExtern() {
378 Flags |= OptionDescriptionFlags::Extern;
379368 }
380369
381370 bool OptionDescription::isRequired() const {
652641 : optDesc_(OD)
653642 {
654643 if (!staticMembersInitialized_) {
655 AddHandler("extern", &CollectOptionProperties::onExtern);
656644 AddHandler("help", &CollectOptionProperties::onHelp);
657645 AddHandler("hidden", &CollectOptionProperties::onHidden);
658646 AddHandler("init", &CollectOptionProperties::onInit);
681669 /// Option property handlers --
682670 /// Methods that handle option properties such as (help) or (hidden).
683671
684 void onExtern (const DagInit& d) {
685 CheckNumberOfArguments(d, 0);
686 optDesc_.setExtern();
687 }
688
689672 void onHelp (const DagInit& d) {
690673 CheckNumberOfArguments(d, 1);
691674 optDesc_.Help = EscapeQuotes(InitPtrToString(d.getArg(0)));
798781
799782 OptionDescription OD(Type, Name);
800783
801 if (!OD.isExtern())
802 CheckNumberOfArguments(d, 2);
784
785 CheckNumberOfArguments(d, 2);
803786
804787 if (OD.isAlias()) {
805788 // Aliases store the aliased option name in the 'Help' field.
806789 OD.Help = InitPtrToString(d.getArg(1));
807790 }
808 else if (!OD.isExtern()) {
791 else {
809792 processOptionProperties(d, OD);
810793 }
794
811795 OptDescs_.InsertDescription(OD);
812796 }
813797
10401024 for (unsigned i = 0; i < edges->size(); ++i)
10411025 Out.push_back(edges->getElementAsRecord(i));
10421026 }
1043 }
1044
1045 /// CalculatePriority - Calculate the priority of this plugin.
1046 int CalculatePriority(RecordVector::const_iterator B,
1047 RecordVector::const_iterator E) {
1048 int priority = 0;
1049
1050 if (B != E) {
1051 priority = static_cast((*B)->getValueAsInt("priority"));
1052
1053 if (++B != E)
1054 throw "More than one 'PluginPriority' instance found: "
1055 "most probably an error!";
1056 }
1057
1058 return priority;
10591027 }
10601028
10611029 /// NotInGraph - Helper function object for FilterNotInGraph.
23812349 /// EmitOptionDefinitions - Iterate over a list of option descriptions
23822350 /// and emit registration code.
23832351 void EmitOptionDefinitions (const OptionDescriptions& descs,
2384 bool HasSink, bool HasExterns,
2385 raw_ostream& O)
2352 bool HasSink, raw_ostream& O)
23862353 {
23872354 std::vector Aliases;
23882355
23962363 continue;
23972364 }
23982365
2399 if (val.isExtern())
2400 O << "extern ";
2401
24022366 O << val.GenTypeDeclaration() << ' '
24032367 << val.GenVariableName();
2404
2405 if (val.isExtern()) {
2406 O << ";\n";
2407 continue;
2408 }
24092368
24102369 O << "(\"" << val.Name << "\"\n";
24112370
24672426
24682427 // Emit the sink option.
24692428 if (HasSink)
2470 O << (HasExterns ? "extern cl" : "cl")
2471 << "::list " << SinkOptionName
2472 << (HasExterns ? ";\n" : "(cl::Sink);\n");
2429 O << "cl" << "::list " << SinkOptionName << "(cl::Sink);\n";
24732430
24742431 O << '\n';
24752432 }
26282585
26292586 };
26302587
2631 /// EmitPreprocessOptions - Emit the PreprocessOptionsLocal() function.
2588 /// EmitPreprocessOptions - Emit the PreprocessOptions() function.
26322589 void EmitPreprocessOptions (const RecordKeeper& Records,
26332590 const OptionDescriptions& OptDecs, raw_ostream& O)
26342591 {
2635 O << "int PreprocessOptionsLocal() {\n";
2592 O << "int PreprocessOptions () {\n";
26362593
26372594 const RecordVector& OptionPreprocessors =
26382595 Records.getAllDerivedDefinitions("OptionPreprocessor");
26502607 O << "}\n\n";
26512608 }
26522609
2653 /// EmitPopulateLanguageMap - Emit the PopulateLanguageMapLocal() function.
2610 /// EmitPopulateLanguageMap - Emit the PopulateLanguageMap() function.
26542611 void EmitPopulateLanguageMap (const RecordKeeper& Records, raw_ostream& O)
26552612 {
2656 O << "int PopulateLanguageMapLocal(LanguageMap& langMap) {\n";
2613 O << "int PopulateLanguageMap (LanguageMap& langMap) {\n";
26572614
26582615 // Get the relevant field out of RecordKeeper
2616 // TODO: change this to getAllDerivedDefinitions.
26592617 const Record* LangMapRecord = Records.getDef("LanguageMap");
26602618
26612619 // It is allowed for a plugin to have no language map.
27572715 }
27582716 }
27592717
2760 /// EmitPopulateCompilationGraph - Emit the PopulateCompilationGraphLocal()
2761 /// function.
2718 /// EmitPopulateCompilationGraph - Emit the PopulateCompilationGraph() function.
27622719 void EmitPopulateCompilationGraph (const RecordVector& EdgeVector,
27632720 const ToolDescriptions& ToolDescs,
27642721 raw_ostream& O)
27652722 {
2766 O << "int PopulateCompilationGraphLocal(CompilationGraph& G) {\n";
2723 O << "int PopulateCompilationGraph (CompilationGraph& G) {\n";
27672724
27682725 for (ToolDescriptions::const_iterator B = ToolDescs.begin(),
27692726 E = ToolDescs.end(); B != E; ++B)
29732930 O << "}\n\n";
29742931 }
29752932
2976 /// EmitRegisterPlugin - Emit code to register this plugin.
2977 void EmitRegisterPlugin(int Priority, raw_ostream& O) {
2978 O << "struct Plugin : public llvmc::BasePlugin {\n\n";
2979 O.indent(Indent1) << "int Priority() const { return "
2980 << Priority << "; }\n\n";
2981 O.indent(Indent1) << "int PreprocessOptions() const\n";
2982 O.indent(Indent1) << "{ return PreprocessOptionsLocal(); }\n\n";
2983 O.indent(Indent1) << "int PopulateLanguageMap(LanguageMap& langMap) const\n";
2984 O.indent(Indent1) << "{ return PopulateLanguageMapLocal(langMap); }\n\n";
2985 O.indent(Indent1)
2986 << "int PopulateCompilationGraph(CompilationGraph& graph) const\n";
2987 O.indent(Indent1) << "{ return PopulateCompilationGraphLocal(graph); }\n"
2988 << "};\n\n"
2989 << "static llvmc::RegisterPlugin RP;\n\n";
2990 }
2991
29922933 /// EmitIncludes - Emit necessary #include directives and some
29932934 /// additional declarations.
29942935 void EmitIncludes(raw_ostream& O) {
29952936 O << "#include \"llvm/CompilerDriver/BuiltinOptions.h\"\n"
29962937 << "#include \"llvm/CompilerDriver/CompilationGraph.h\"\n"
29972938 << "#include \"llvm/CompilerDriver/Error.h\"\n"
2998 << "#include \"llvm/CompilerDriver/ForceLinkageMacros.h\"\n"
2999 << "#include \"llvm/CompilerDriver/Plugin.h\"\n"
30002939 << "#include \"llvm/CompilerDriver/Tool.h\"\n\n"
30012940
30022941 << "#include \"llvm/Support/CommandLine.h\"\n"
30212960 struct PluginData {
30222961 OptionDescriptions OptDescs;
30232962 bool HasSink;
3024 bool HasExterns;
30252963 ToolDescriptions ToolDescs;
30262964 RecordVector Edges;
3027 int Priority;
30282965 };
30292966
30302967 /// HasSink - Go through the list of tool descriptions and check if
30382975 return false;
30392976 }
30402977
3041 /// HasExterns - Go through the list of option descriptions and check
3042 /// if there are any external options.
3043 bool HasExterns(const OptionDescriptions& OptDescs) {
3044 for (OptionDescriptions::const_iterator B = OptDescs.begin(),
3045 E = OptDescs.end(); B != E; ++B)
3046 if (B->second.isExtern())
3047 return true;
3048
3049 return false;
3050 }
3051
3052 /// CollectPluginData - Collect tool and option properties,
3053 /// compilation graph edges and plugin priority from the parse tree.
2978 /// CollectPluginData - Collect compilation graph edges, tool properties and
2979 /// option properties from the parse tree.
30542980 void CollectPluginData (const RecordKeeper& Records, PluginData& Data) {
30552981 // Collect option properties.
30562982 const RecordVector& OptionLists =
30622988 const RecordVector& Tools = Records.getAllDerivedDefinitions("Tool");
30632989 CollectToolDescriptions(Tools.begin(), Tools.end(), Data.ToolDescs);
30642990 Data.HasSink = HasSink(Data.ToolDescs);
3065 Data.HasExterns = HasExterns(Data.OptDescs);
30662991
30672992 // Collect compilation graph edges.
30682993 const RecordVector& CompilationGraphs =
30692994 Records.getAllDerivedDefinitions("CompilationGraph");
30702995 FillInEdgeVector(CompilationGraphs.begin(), CompilationGraphs.end(),
30712996 Data.Edges);
3072
3073 // Calculate the priority of this plugin.
3074 const RecordVector& Priorities =
3075 Records.getAllDerivedDefinitions("PluginPriority");
3076 Data.Priority = CalculatePriority(Priorities.begin(), Priorities.end());
30772997 }
30782998
30792999 /// CheckPluginData - Perform some sanity checks on the collected data.
30943014 EmitIncludes(O);
30953015
30963016 // Emit global option registration code.
3097 EmitOptionDefinitions(Data.OptDescs, Data.HasSink, Data.HasExterns, O);
3017 EmitOptionDefinitions(Data.OptDescs, Data.HasSink, O);
30983018
30993019 // Emit hook declarations.
31003020 EmitHookDeclarations(Data.ToolDescs, Data.OptDescs, O);
31013021
31023022 O << "namespace {\n\n";
3103
3104 // Emit PreprocessOptionsLocal() function.
3105 EmitPreprocessOptions(Records, Data.OptDescs, O);
3106
3107 // Emit PopulateLanguageMapLocal() function
3108 // (language map maps from file extensions to language names).
3109 EmitPopulateLanguageMap(Records, O);
31103023
31113024 // Emit Tool classes.
31123025 for (ToolDescriptions::const_iterator B = Data.ToolDescs.begin(),
31163029 // Emit Edge# classes.
31173030 EmitEdgeClasses(Data.Edges, Data.OptDescs, O);
31183031
3119 // Emit PopulateCompilationGraphLocal() function.
3032 O << "} // End anonymous namespace.\n\n";
3033
3034 O << "namespace llvmc {\n";
3035 O << "namespace autogenerated {\n\n";
3036
3037 // Emit PreprocessOptions() function.
3038 EmitPreprocessOptions(Records, Data.OptDescs, O);
3039
3040 // Emit PopulateLanguageMap() function
3041 // (language map maps from file extensions to language names).
3042 EmitPopulateLanguageMap(Records, O);
3043
3044 // Emit PopulateCompilationGraph() function.
31203045 EmitPopulateCompilationGraph(Data.Edges, Data.ToolDescs, O);
31213046
3122 // Emit code for plugin registration.
3123 EmitRegisterPlugin(Data.Priority, O);
3124
3125 O << "} // End anonymous namespace.\n\n";
3126
3127 // Force linkage magic.
3128 O << "namespace llvmc {\n";
3129 O << "LLVMC_FORCE_LINKAGE_DECL(LLVMC_PLUGIN_NAME) {}\n";
3130 O << "}\n";
3047 O << "} // End namespace autogenerated.\n";
3048 O << "} // End namespace llvmc.\n\n";
31313049
31323050 // EOF
31333051 }