[llvm-commits] [llvm] r91594 - in /llvm/trunk: include/llvm/CompilerDriver/Common.td test/LLVMC/OptionPreprocessor.td tools/llvmc/doc/LLVMC-Reference.rst tools/llvmc/plugins/Base/Base.td.in utils/TableGen/LLVMCConfigurationEmitter.cpp
Mikhail Glushenkov
foldr at codedgers.com
Wed Dec 16 23:49:16 PST 2009
Author: foldr
Date: Thu Dec 17 01:49:16 2009
New Revision: 91594
URL: http://llvm.org/viewvc/llvm-project?rev=91594&view=rev
Log:
Add a 'set_option' action for use in OptionPreprocessor.
Modified:
llvm/trunk/include/llvm/CompilerDriver/Common.td
llvm/trunk/test/LLVMC/OptionPreprocessor.td
llvm/trunk/tools/llvmc/doc/LLVMC-Reference.rst
llvm/trunk/tools/llvmc/plugins/Base/Base.td.in
llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp
Modified: llvm/trunk/include/llvm/CompilerDriver/Common.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CompilerDriver/Common.td?rev=91594&r1=91593&r2=91594&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CompilerDriver/Common.td (original)
+++ llvm/trunk/include/llvm/CompilerDriver/Common.td Thu Dec 17 01:49:16 2009
@@ -84,6 +84,7 @@
def unpack_values;
def warning;
def error;
+def set_option;
def unset_option;
// Increase/decrease the edge weight.
Modified: llvm/trunk/test/LLVMC/OptionPreprocessor.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/LLVMC/OptionPreprocessor.td?rev=91594&r1=91593&r2=91594&view=diff
==============================================================================
--- llvm/trunk/test/LLVMC/OptionPreprocessor.td (original)
+++ llvm/trunk/test/LLVMC/OptionPreprocessor.td Thu Dec 17 01:49:16 2009
@@ -11,20 +11,30 @@
(switch_option "baz", (help "dummy")),
(parameter_option "foo_p", (help "dummy")),
(parameter_option "bar_p", (help "dummy")),
-(parameter_option "baz_p", (help "dummy"))
+(parameter_option "baz_p", (help "dummy")),
+(parameter_list_option "foo_l", (help "dummy"))
]>;
def Preprocess : OptionPreprocessor<
(case
// CHECK: W1
+ // CHECK: foo = false;
+ // CHECK: foo_p = "";
+ // CHECK: foo_l.clear();
(and (switch_on "foo"), (any_switch_on ["bar", "baz"])),
- (warning "W1"),
+ [(warning "W1"), (unset_option "foo"),
+ (unset_option "foo_p"), (unset_option "foo_l")],
// CHECK: W2
+ // CHECK: foo = true;
+ // CHECK: foo_p = "asdf";
(and (switch_on ["foo", "bar"]), (any_empty ["foo_p", "bar_p"])),
- (warning "W2"),
+ [(warning "W2"), (set_option "foo"), (set_option "foo_p", "asdf")],
// CHECK: W3
+ // CHECK: foo = true;
+ // CHECK: bar = true;
+ // CHECK: baz = true;
(and (empty ["foo_p", "bar_p"]), (any_not_empty ["baz_p"])),
- (warning "W3"))
+ [(warning "W3"), (set_option ["foo", "bar", "baz"])])
>;
// Shut up warnings...
@@ -38,7 +48,8 @@
(switch_on "baz"), (error),
(not_empty "foo_p"), (error),
(not_empty "bar_p"), (error),
- (not_empty "baz_p"), (error)))
+ (not_empty "baz_p"), (error),
+ (not_empty "foo_l"), (error)))
]>;
def Graph : CompilationGraph<[Edge<"root", "dummy">]>;
Modified: llvm/trunk/tools/llvmc/doc/LLVMC-Reference.rst
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvmc/doc/LLVMC-Reference.rst?rev=91594&r1=91593&r2=91594&view=diff
==============================================================================
--- llvm/trunk/tools/llvmc/doc/LLVMC-Reference.rst (original)
+++ llvm/trunk/tools/llvmc/doc/LLVMC-Reference.rst Thu Dec 17 01:49:16 2009
@@ -656,10 +656,10 @@
$ llvmc hello.cpp
llvmc: Unknown suffix: cpp
-The language map entries should be added only for tools that are
-linked with the root node. Since tools are not allowed to have
-multiple output languages, for nodes "inside" the graph the input and
-output languages should match. This is enforced at compile-time.
+The language map entries are needed only for the tools that are linked from the
+root node. Since a tool can't have multiple output languages, for inner nodes of
+the graph the input and output languages should match. This is enforced at
+compile-time.
Option preprocessor
===================
@@ -672,24 +672,31 @@
The ``OptionPreprocessor`` feature is reserved specially for these
occasions. Example (adapted from the built-in Base plugin)::
- def Preprocess : OptionPreprocessor<
- (case (and (switch_on "O3"), (any_switch_on ["O0", "O1", "O2"])),
- [(unset_option ["O0", "O1", "O2"]),
- (warning "Multiple -O options specified, defaulted to -O3.")],
- (and (switch_on "O2"), (any_switch_on ["O0", "O1"])),
- (unset_option ["O0", "O1"]),
- (and (switch_on "O1"), (switch_on "O0")),
- (unset_option "O0"))
- >;
-Here, ``OptionPreprocessor`` is used to unset all spurious optimization options
-(so that they are not forwarded to the compiler).
+ def Preprocess : OptionPreprocessor<
+ (case (not (any_switch_on ["O0", "O1", "O2", "O3"])),
+ (set_option "O2"),
+ (and (switch_on "O3"), (any_switch_on ["O0", "O1", "O2"])),
+ (unset_option ["O0", "O1", "O2"]),
+ (and (switch_on "O2"), (any_switch_on ["O0", "O1"])),
+ (unset_option ["O0", "O1"]),
+ (and (switch_on "O1"), (switch_on "O0")),
+ (unset_option "O0"))
+ >;
+
+Here, ``OptionPreprocessor`` is used to unset all spurious ``-O`` options so
+that they are not forwarded to the compiler. If no optimization options are
+specified, ``-O2`` is enabled.
``OptionPreprocessor`` is basically a single big ``case`` expression, which is
evaluated only once right after the plugin is loaded. The only allowed actions
-in ``OptionPreprocessor`` are ``error``, ``warning`` and a special action
-``unset_option``, which, as the name suggests, unsets a given option. For
-convenience, ``unset_option`` also works on lists.
+in ``OptionPreprocessor`` are ``error``, ``warning`` and two special actions:
+``unset_option`` and ``set_option``. As their names suggest, they can be used to
+set or unset a given option. To set a parameter option with ``set_option``, use
+the two-argument form: ``(set_option "parameter", "value")``. For convenience,
+``set_option`` and ``unset_option`` also work on lists (that is, instead of
+``[(unset_option "A"), (unset_option "B")]`` you can use ``(unset_option ["A",
+"B"])``).
More advanced topics
Modified: llvm/trunk/tools/llvmc/plugins/Base/Base.td.in
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvmc/plugins/Base/Base.td.in?rev=91594&r1=91593&r2=91594&view=diff
==============================================================================
--- llvm/trunk/tools/llvmc/plugins/Base/Base.td.in (original)
+++ llvm/trunk/tools/llvmc/plugins/Base/Base.td.in Thu Dec 17 01:49:16 2009
@@ -91,7 +91,9 @@
// Option preprocessor.
def Preprocess : OptionPreprocessor<
-(case (and (switch_on "O3"), (any_switch_on ["O0", "O1", "O2"])),
+(case (not (any_switch_on ["O0", "O1", "O2", "O3"])),
+ (set_option "O2"),
+ (and (switch_on "O3"), (any_switch_on ["O0", "O1", "O2"])),
(unset_option ["O0", "O1", "O2"]),
(and (switch_on "O2"), (any_switch_on ["O0", "O1"])),
(unset_option ["O0", "O1"]),
Modified: llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp?rev=91594&r1=91593&r2=91594&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp (original)
+++ llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp Thu Dec 17 01:49:16 2009
@@ -2303,11 +2303,32 @@
public HandlerTable<EmitPreprocessOptionsCallbackHandler>
{
typedef EmitPreprocessOptionsCallbackHandler Handler;
+ typedef void
+ (EmitPreprocessOptionsCallback::* HandlerImpl)
+ (const Init*, unsigned, raw_ostream&) const;
const OptionDescriptions& OptDescs_;
- void onUnsetOptionStr(const Init* I,
- unsigned IndentLevel, raw_ostream& O) const
+ void onListOrDag(HandlerImpl h,
+ const DagInit& d, unsigned IndentLevel, raw_ostream& O) const
+ {
+ checkNumberOfArguments(d, 1);
+ const Init* I = d.getArg(0);
+
+ // If I is a list, apply h to each element.
+ if (typeid(*I) == typeid(ListInit)) {
+ const ListInit& L = *static_cast<const ListInit*>(I);
+ for (ListInit::const_iterator B = L.begin(), E = L.end(); B != E; ++B)
+ ((this)->*(h))(*B, IndentLevel, O);
+ }
+ // Otherwise, apply h to I.
+ else {
+ ((this)->*(h))(I, IndentLevel, O);
+ }
+ }
+
+ void onUnsetOptionImpl(const Init* I,
+ unsigned IndentLevel, raw_ostream& O) const
{
const std::string& OptName = InitPtrToString(I);
const OptionDescription& OptDesc = OptDescs_.FindOption(OptName);
@@ -2326,26 +2347,52 @@
}
}
- void onUnsetOptionList(const ListInit& L,
- unsigned IndentLevel, raw_ostream& O) const
+ void onUnsetOption(const DagInit& d,
+ unsigned IndentLevel, raw_ostream& O) const
{
- for (ListInit::const_iterator B = L.begin(), E = L.end(); B != E; ++B)
- this->onUnsetOptionStr(*B, IndentLevel, O);
+ this->onListOrDag(&EmitPreprocessOptionsCallback::onUnsetOptionImpl,
+ d, IndentLevel, O);
}
- void onUnsetOption(const DagInit& d,
- unsigned IndentLevel, raw_ostream& O) const
+ void onSetParameter(const DagInit& d,
+ unsigned IndentLevel, raw_ostream& O) const {
+ checkNumberOfArguments(d, 2);
+ const std::string& OptName = InitPtrToString(d.getArg(0));
+ const std::string& Value = InitPtrToString(d.getArg(1));
+ const OptionDescription& OptDesc = OptDescs_.FindOption(OptName);
+
+ if (OptDesc.isParameter())
+ O.indent(IndentLevel) << OptDesc.GenVariableName()
+ << " = \"" << Value << "\";\n";
+ else
+ throw "Two-argument 'set_option' "
+ "can be only applied to parameter options!";
+ }
+
+ void onSetSwitch(const Init* I,
+ unsigned IndentLevel, raw_ostream& O) const {
+ const std::string& OptName = InitPtrToString(I);
+ const OptionDescription& OptDesc = OptDescs_.FindOption(OptName);
+
+ if (OptDesc.isSwitch())
+ O.indent(IndentLevel) << OptDesc.GenVariableName() << " = true;\n";
+ else
+ throw "One-argument 'set_option' can be only applied to switch options!";
+ }
+
+ void onSetOption(const DagInit& d,
+ unsigned IndentLevel, raw_ostream& O) const
{
checkNumberOfArguments(d, 1);
- Init* I = d.getArg(0);
- if (typeid(*I) == typeid(ListInit)) {
- const ListInit& L = *static_cast<const ListInit*>(I);
- this->onUnsetOptionList(L, IndentLevel, O);
- }
- else {
- this->onUnsetOptionStr(I, IndentLevel, O);
- }
+ // Two arguments: (set_option "parameter", "value")
+ if (d.getNumArgs() > 1)
+ this->onSetParameter(d, IndentLevel, O);
+ // One argument: (set_option "switch")
+ // or (set_option ["switch1", "switch2", ...])
+ else
+ this->onListOrDag(&EmitPreprocessOptionsCallback::onSetSwitch,
+ d, IndentLevel, O);
}
public:
@@ -2357,6 +2404,7 @@
AddHandler("error", &EmitPreprocessOptionsCallback::onErrorDag);
AddHandler("warning", &EmitPreprocessOptionsCallback::onWarningDag);
AddHandler("unset_option", &EmitPreprocessOptionsCallback::onUnsetOption);
+ AddHandler("set_option", &EmitPreprocessOptionsCallback::onSetOption);
staticMembersInitialized_ = true;
}
More information about the llvm-commits
mailing list