[AVX] Make Inits Foldable

Manage Inits in a FoldingSet.  This provides several benefits:

- Memory for Inits is properly managed

- Duplicate Inits are folded into Flyweights, saving memory

- It enforces const-correctness, protecting against certain classes
  of bugs

The above benefits allow Inits to be used in more contexts, which in
turn provides more dynamism to TableGen.  This enhanced capability
will be used by the AVX code generator to a fold common patterns
together.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@134907 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/utils/TableGen/LLVMCConfigurationEmitter.cpp b/utils/TableGen/LLVMCConfigurationEmitter.cpp
index 090faf5..9180330 100644
--- a/utils/TableGen/LLVMCConfigurationEmitter.cpp
+++ b/utils/TableGen/LLVMCConfigurationEmitter.cpp
@@ -245,7 +245,7 @@
   unsigned Flags;
   std::string Help;
   unsigned MultiVal;
-  Init* InitVal;
+  const Init* InitVal;
 
   OptionDescription(OptionType::OptionType t = OptionType::Switch,
                     const std::string& n = "",
@@ -589,7 +589,7 @@
 }
 
 template <class FunctionObject>
-void InvokeDagInitHandler(FunctionObject* Obj, Init* I) {
+void InvokeDagInitHandler(FunctionObject* Obj, const Init* I) {
   typedef void (FunctionObject::*Handler) (const DagInit&);
 
   const DagInit& Dag = InitPtrToDag(I);
@@ -658,7 +658,7 @@
 
   /// operator() - Just forwards to the corresponding property
   /// handler.
-  void operator() (Init* I) {
+  void operator() (const Init* I) {
     InvokeDagInitHandler(this, I);
   }
 
@@ -705,10 +705,10 @@
 
   void onInit (const DagInit& d) {
     CheckNumberOfArguments(d, 1);
-    Init* i = d.getArg(0);
+    const Init* i = d.getArg(0);
     const std::string& str = i->getAsString();
 
-    bool correct = optDesc_.isParameter() && dynamic_cast<StringInit*>(i);
+    bool correct = optDesc_.isParameter() && dynamic_cast<const StringInit*>(i);
     correct |= (optDesc_.isSwitch() && (str == "true" || str == "false"));
 
     if (!correct)
@@ -821,7 +821,7 @@
   for (RecordVector::const_iterator B = V.begin(), E = V.end(); B!=E; ++B)
   {
     // Throws an exception if the value does not exist.
-    ListInit* PropList = (*B)->getValueAsListInit("options");
+    const ListInit* PropList = (*B)->getValueAsListInit("options");
 
     // For every option description in this list: invoke AddOption.
     std::for_each(PropList->begin(), PropList->end(), AddOption(OptDescs));
@@ -836,8 +836,8 @@
 
 struct ToolDescription : public RefCountedBase<ToolDescription> {
   std::string Name;
-  Init* CmdLine;
-  Init* Actions;
+  const Init* CmdLine;
+  const Init* Actions;
   StrVector InLanguage;
   std::string InFileOption;
   std::string OutFileOption;
@@ -903,7 +903,7 @@
     }
   }
 
-  void operator() (Init* I) {
+  void operator() (const Init* I) {
     InvokeDagInitHandler(this, I);
   }
 
@@ -915,9 +915,9 @@
 
   void onActions (const DagInit& d) {
     CheckNumberOfArguments(d, 1);
-    Init* Case = d.getArg(0);
+    const Init* Case = d.getArg(0);
     if (typeid(*Case) != typeid(DagInit) ||
-        GetOperatorName(static_cast<DagInit&>(*Case)) != "case")
+        GetOperatorName(static_cast<const DagInit&>(*Case)) != "case")
       throw "The argument to (actions) should be a 'case' construct!";
     toolDesc_.Actions = Case;
   }
@@ -954,7 +954,7 @@
       isReallyJoin = true;
     }
     else {
-      Init* I = d.getArg(0);
+      const Init* I = d.getArg(0);
       isReallyJoin = InitPtrToBool(I);
     }
 
@@ -1007,7 +1007,7 @@
          E = Tools.end(); B!=E; ++B) {
     const Record* T = *B;
     // Throws an exception if the value does not exist.
-    ListInit* PropList = T->getValueAsListInit("properties");
+    const ListInit* PropList = T->getValueAsListInit("properties");
 
     IntrusiveRefCntPtr<ToolDescription>
       ToolDesc(new ToolDescription(T->getName()));
@@ -1163,7 +1163,7 @@
   unsigned i = 1;
   for (DagInit::const_arg_iterator B = d.arg_begin(), E = d.arg_end();
        B != E; ++B) {
-    Init* arg = *B;
+    const Init* arg = *B;
 
     if (!even)
     {
@@ -1181,8 +1181,8 @@
     }
     else
     {
-      if (dynamic_cast<DagInit*>(arg)
-          && GetOperatorName(static_cast<DagInit&>(*arg)) == "case") {
+      if (dynamic_cast<const DagInit*>(arg)
+          && GetOperatorName(static_cast<const DagInit&>(*arg)) == "case") {
         // Nested 'case'.
         WalkCase(arg, TestCallback, StatementCallback, IndentLevel + Indent1);
       }
@@ -1210,7 +1210,7 @@
         ActionName == "parameter_equals" || ActionName == "element_in_list") {
       CheckNumberOfArguments(Stmt, 1);
 
-      Init* Arg = Stmt.getArg(0);
+      const Init* Arg = Stmt.getArg(0);
       if (typeid(*Arg) == typeid(StringInit))
         OptionNames_.insert(InitPtrToString(Arg));
     }
@@ -1218,7 +1218,7 @@
              ActionName == "any_not_empty" || ActionName == "any_empty" ||
              ActionName == "not_empty" || ActionName == "empty") {
       for (unsigned i = 0, NumArgs = Stmt.getNumArgs(); i < NumArgs; ++i) {
-        Init* Arg = Stmt.getArg(i);
+        const Init* Arg = Stmt.getArg(i);
         if (typeid(*Arg) == typeid(StringInit))
           OptionNames_.insert(InitPtrToString(Arg));
       }
@@ -2613,7 +2613,7 @@
 
   for (RecordVector::const_iterator B = OptionPreprocessors.begin(),
          E = OptionPreprocessors.end(); B!=E; ++B) {
-    DagInit* Case = (*B)->getValueAsDag("preprocessor");
+    const DagInit* Case = (*B)->getValueAsDag("preprocessor");
     EmitCaseConstructHandler(Case, Indent1,
                              EmitPreprocessOptionsCallback(OptDecs),
                              false, OptDecs, O);
@@ -2645,7 +2645,7 @@
     }
   }
 
-  void operator() (Init* I) {
+  void operator() (const Init* I) {
     InvokeDagInitHandler(this, I);
   }
 
@@ -2655,7 +2655,7 @@
     CheckNumberOfArguments(d, 2);
 
     const std::string& Lang = InitPtrToString(d.getArg(0));
-    Init* Suffixes = d.getArg(1);
+    const Init* Suffixes = d.getArg(1);
 
     // Second argument to lang_to_suffixes is either a single string...
     if (typeid(*Suffixes) == typeid(StringInit)) {
@@ -2688,7 +2688,7 @@
   // Call DoEmitPopulateLanguageMap.
   for (RecordVector::const_iterator B = LangMaps.begin(),
          E = LangMaps.end(); B!=E; ++B) {
-    ListInit* LangMap = (*B)->getValueAsListInit("map");
+    const ListInit* LangMap = (*B)->getValueAsListInit("map");
     std::for_each(LangMap->begin(), LangMap->end(),
                   DoEmitPopulateLanguageMap(O));
   }
@@ -2947,7 +2947,7 @@
     // Look for hook invocations in 'cmd_line'.
     if (!D.CmdLine)
       continue;
-    if (dynamic_cast<StringInit*>(D.CmdLine))
+    if (dynamic_cast<const StringInit*>(D.CmdLine))
       // This is a string.
       ExtractHookNames(HookNames, OptDescs).operator()(D.CmdLine);
     else