aboutsummaryrefslogtreecommitdiffstats
path: root/utils/TableGen/LLVMCConfigurationEmitter.cpp
diff options
context:
space:
mode:
authorMikhail Glushenkov <foldr@codedgers.com>2009-10-09 05:45:21 +0000
committerMikhail Glushenkov <foldr@codedgers.com>2009-10-09 05:45:21 +0000
commit0b599391f88e26d2b0f57393f1f6880431ac6e0d (patch)
tree1ef71fd17ad41e23d2595df530128315cbf2e917 /utils/TableGen/LLVMCConfigurationEmitter.cpp
parent3ab68895b4c01cf1a788b49da8f2d61f7d58c108 (diff)
downloadexternal_llvm-0b599391f88e26d2b0f57393f1f6880431ac6e0d.tar.gz
external_llvm-0b599391f88e26d2b0f57393f1f6880431ac6e0d.tar.bz2
external_llvm-0b599391f88e26d2b0f57393f1f6880431ac6e0d.zip
Omit the 'out_file_index != -1' check when possible.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@83619 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils/TableGen/LLVMCConfigurationEmitter.cpp')
-rw-r--r--utils/TableGen/LLVMCConfigurationEmitter.cpp60
1 files changed, 54 insertions, 6 deletions
diff --git a/utils/TableGen/LLVMCConfigurationEmitter.cpp b/utils/TableGen/LLVMCConfigurationEmitter.cpp
index bcf7613e94..06afaf73a0 100644
--- a/utils/TableGen/LLVMCConfigurationEmitter.cpp
+++ b/utils/TableGen/LLVMCConfigurationEmitter.cpp
@@ -1572,6 +1572,47 @@ class EmitActionHandler {
}
};
+bool IsOutFileIndexCheckRequiredStr (const Init* CmdLine) {
+ StrVector StrVec;
+ TokenizeCmdline(InitPtrToString(CmdLine), StrVec);
+
+ for (StrVector::const_iterator I = StrVec.begin(), E = StrVec.end();
+ I != E; ++I) {
+ if (*I == "$OUTFILE")
+ return false;
+ }
+
+ return true;
+}
+
+class IsOutFileIndexCheckRequiredStrCallback {
+ bool* ret_;
+
+public:
+ IsOutFileIndexCheckRequiredStrCallback(bool* ret) : ret_(ret)
+ {}
+
+ void operator()(const Init* CmdLine) {
+ if (IsOutFileIndexCheckRequiredStr(CmdLine))
+ *ret_ = true;
+ }
+};
+
+bool IsOutFileIndexCheckRequiredCase (Init* CmdLine) {
+ bool ret = false;
+ WalkCase(CmdLine, Id(), IsOutFileIndexCheckRequiredStrCallback(&ret));
+ return ret;
+}
+
+/// IsOutFileIndexCheckRequired - Should we emit an "out_file_index != -1" check
+/// in EmitGenerateActionMethod() ?
+bool IsOutFileIndexCheckRequired (Init* CmdLine) {
+ if (typeid(*CmdLine) == typeid(StringInit))
+ return IsOutFileIndexCheckRequiredStr(CmdLine);
+ else
+ return IsOutFileIndexCheckRequiredCase(CmdLine);
+}
+
// EmitGenerateActionMethod - Emit either a normal or a "join" version of the
// Tool::GenerateAction() method.
void EmitGenerateActionMethod (const ToolDescription& D,
@@ -1592,12 +1633,17 @@ void EmitGenerateActionMethod (const ToolDescription& D,
O.indent(Indent2) << "bool stop_compilation = !HasChildren;\n";
O.indent(Indent2) << "const char* output_suffix = \""
<< D.OutputSuffix << "\";\n";
- O.indent(Indent2) << "int out_file_index = -1;\n\n";
- // cmd_line is either a string or a 'case' construct.
if (!D.CmdLine)
throw "Tool " + D.Name + " has no cmd_line property!";
- else if (typeid(*D.CmdLine) == typeid(StringInit))
+
+ bool IndexCheckRequired = IsOutFileIndexCheckRequired(D.CmdLine);
+ O.indent(Indent2) << "int out_file_index"
+ << (IndexCheckRequired ? " = -1" : "")
+ << ";\n\n";
+
+ // Process the cmd_line property.
+ if (typeid(*D.CmdLine) == typeid(StringInit))
EmitCmdLineVecFill(D.CmdLine, D.Name, IsJoin, Indent2, O);
else
EmitCaseConstructHandler(D.CmdLine, Indent2,
@@ -1614,9 +1660,11 @@ void EmitGenerateActionMethod (const ToolDescription& D,
<< "std::string out_file = OutFilename("
<< (IsJoin ? "sys::Path(),\n" : "inFile,\n");
O.indent(Indent3) << "TempDir, stop_compilation, output_suffix).str();\n\n";
- // TODO: emit this check only when necessary.
- O.indent(Indent2) << "if (out_file_index != -1)\n";
- O.indent(Indent3) << "vec[out_file_index] = out_file;\n";
+
+ if (IndexCheckRequired)
+ O.indent(Indent2) << "if (out_file_index != -1)\n";
+ O.indent(IndexCheckRequired ? Indent3 : Indent2)
+ << "vec[out_file_index] = out_file;\n";
// Handle the Sink property.
if (D.isSink()) {