[llvm-commits] [PATCH] Add Foreach Loop

David Greene dag at cray.com
Thu Feb 9 12:21:58 PST 2012


Here is an updated version of the foreach patch series, squashed
as requested.  I think I have addressed all of the review feedback.
Please review.

Thanks!

                           -Dave

Add some data structures to represent for loops.  These will be
referenced during object processing to do any needed iteration and
instantiation.

Add foreach keyword support to the lexer.

Add a mode to indicate that we're parsing a foreach loop.  This allows
the value parser to early-out when processing the foreach value list.

Add a routine to parse foreach iteration declarations.  This is
separate from ParseDeclaration because the type of the named value
(the iterator) doesn't match the type of the initializer value (the
value list).  It also needs to add two values to the foreach record:
the iterator and the value list.

Add parsing support for foreach.

Add the code to process foreach loops and create defs based
on iterator values.

Allow foreach loops to be matched at the top level.

When parsing an IDValue check if it is a foreach loop iterator for one
of the active loops.  If so, return a VarInit for it.

Add Emacs keyword support for foreach.

Add VIM keyword support for foreach.

Add tests to check foreach operation.

Add TableGen documentation for foreach.
---
 llvm/docs/TableGenFundamentals.html |   28 +++++
 llvm/include/llvm/TableGen/Record.h |    1 +
 llvm/lib/TableGen/TGLexer.cpp       |    1 +
 llvm/lib/TableGen/TGLexer.h         |    2 +-
 llvm/lib/TableGen/TGParser.cpp      |  195 ++++++++++++++++++++++++++++++++++-
 llvm/lib/TableGen/TGParser.h        |   73 +++++++++++++-
 llvm/test/TableGen/ForeachLoop.td   |   43 ++++++++
 llvm/test/TableGen/NestedForeach.td |   74 +++++++++++++
 llvm/utils/emacs/tablegen-mode.el   |    2 +-
 llvm/utils/vim/tablegen.vim         |    2 +-
 10 files changed, 414 insertions(+), 7 deletions(-)
 create mode 100644 llvm/test/TableGen/ForeachLoop.td
 create mode 100644 llvm/test/TableGen/NestedForeach.td

diff --git old/llvm/docs/TableGenFundamentals.html new/llvm/docs/TableGenFundamentals.html
index 6db1827..2030bc8 100644
--- old/llvm/docs/TableGenFundamentals.html
+++ new/llvm/docs/TableGenFundamentals.html
@@ -37,6 +37,7 @@
     <ol>
       <li><a href="#include">File inclusion</a></li>
       <li><a href="#globallet">'let' expressions</a></li>
+      <li><a href="#foreach">'foreach' blocks</a></li>
     </ol></li>
   </ol></li>
   <li><a href="#backends">TableGen backends</a>
@@ -401,6 +402,11 @@ which case the user must specify it explicitly.</dd>
 <dt><tt>list[4-7,17,2-3]</tt></dt>
   <dd>A slice of the 'list' list, including elements 4,5,6,7,17,2, and 3 from
   it.  Elements may be included multiple times.</dd>
+<dt><tt>foreach <var> = <list> { <body> }</tt></dt>
+  <dd> Replicate <body> replacing instances of <var> with each value
+  in <list>.  <var> is scoped at the level of the <tt>foreach</tt>
+  loop and must not conflict with any other object introduced in <body>.
+  Currently only <tt>def</tt>s are expanded within <body>.</dd>
 <dt><tt>(DEF a, b)</tt></dt>
   <dd>a dag value.  The first element is required to be a record definition, the
   remaining elements in the list may be arbitrary other values, including nested
@@ -880,6 +886,28 @@ several levels of multiclass instanciations. This also avoids the need of using
 </pre>
 </div>
 
+<!-- -------------------------------------------------------------------------->
+<h4>
+  <a name="foreach">Looping</a>
+</h4>
+
+<div>
+<p>TableGen supports the '<tt>foreach</tt>' block, which textually replicates
+the loop body, substituting iterator values for iterator references in the
+body.  Example:</p>
+
+<div class="doc_code">
+<pre>
+<b>foreach</b> i = [0, 1, 2, 3] {
+  <b>def</b> R#i : Register<...>;
+}
+</pre>
+</div>
+
+<p>This will create objects <tt>R0</tt>, <tt>R1</tt>, <tt>R2</tt> and
+<tt>R3</tt>.  <tt>foreach</tt> blocks may be nested.</p>
+</div>
+
 </div>
 
 </div>
diff --git old/llvm/include/llvm/TableGen/Record.h new/llvm/include/llvm/TableGen/Record.h
index f51af28..5e68c10 100644
--- old/llvm/include/llvm/TableGen/Record.h
+++ new/llvm/include/llvm/TableGen/Record.h
@@ -1535,6 +1535,7 @@ struct MultiClass {
 
 class RecordKeeper {
   std::map<std::string, Record*> Classes, Defs;
+
 public:
   ~RecordKeeper() {
     for (std::map<std::string, Record*>::iterator I = Classes.begin(),
diff --git old/llvm/lib/TableGen/TGLexer.cpp new/llvm/lib/TableGen/TGLexer.cpp
index 79d9ed2..ff322e7 100644
--- old/llvm/lib/TableGen/TGLexer.cpp
+++ new/llvm/lib/TableGen/TGLexer.cpp
@@ -274,6 +274,7 @@ tgtok::TokKind TGLexer::LexIdentifier() {
     .Case("dag", tgtok::Dag)
     .Case("class", tgtok::Class)
     .Case("def", tgtok::Def)
+    .Case("foreach", tgtok::Foreach)
     .Case("defm", tgtok::Defm)
     .Case("multiclass", tgtok::MultiClass)
     .Case("field", tgtok::Field)
diff --git old/llvm/lib/TableGen/TGLexer.h new/llvm/lib/TableGen/TGLexer.h
index 0246ab6..8a850b5 100644
--- old/llvm/lib/TableGen/TGLexer.h
+++ new/llvm/lib/TableGen/TGLexer.h
@@ -42,7 +42,7 @@ namespace tgtok {
     paste,              // #
 
     // Keywords.
-    Bit, Bits, Class, Code, Dag, Def, Defm, Field, In, Int, Let, List,
+    Bit, Bits, Class, Code, Dag, Def, Foreach, Defm, Field, In, Int, Let, List,
     MultiClass, String,
     
     // !keywords.
diff --git old/llvm/lib/TableGen/TGParser.cpp new/llvm/lib/TableGen/TGParser.cpp
index c7cf097..6a25455 100644
--- old/llvm/lib/TableGen/TGParser.cpp
+++ new/llvm/lib/TableGen/TGParser.cpp
@@ -289,6 +289,108 @@ bool TGParser::AddSubMultiClass(MultiClass *CurMC,
   return false;
 }
 
+/// ProcessForeachDefs - Given a record, apply all of the variable
+/// values in all surrounding foreach loops, creating new records for
+/// each combination of values.
+bool TGParser::ProcessForeachDefs(Record *CurRec, MultiClass *CurMultiClass,
+                                  SMLoc Loc) {
+  // We want to instantiate a new copy of CurRec for each combination
+  // of nested loop iterator values.  We don't want top instantiate
+  // any copies until we have values for each loop iterator.
+  IterSet IterVals;
+  for (loop_iterator Loop = loops_begin(), LoopEnd = loops_end();
+       Loop != LoopEnd;
+       ++Loop) {
+    // Process this loop.
+    if (ProcessForeachDefs(CurRec, CurMultiClass, Loc,
+                           IterVals, *Loop, Loop+1)) {
+      Error(Loc,
+            "Could not process loops for def " + CurRec->getNameInitAsString());
+      return true;
+    }
+  }
+
+  return false;
+}
+
+/// ProcessForeachDefs - Given a record, a loop and a loop iterator,
+/// apply each of the variable values in this loop and then process
+/// subloops.
+bool TGParser::ProcessForeachDefs(Record *CurRec, MultiClass *CurMultiClass,
+                                  SMLoc Loc, IterSet &IterVals,
+                                  ForeachLoop &CurLoop,
+                                  loop_iterator NextLoop) {
+  Init *IterVar = CurLoop.IterVar;
+  ListInit *List = dynamic_cast<ListInit *>(CurLoop.ListValue);
+
+  if (List == 0) {
+    Error(Loc, "Loop list is not a list");
+    return true;
+  }
+
+  // Process each value.
+  for (int64_t i = 0; i < List->getSize(); ++i) {
+    Init *ItemVal = List->resolveListElementReference(*CurRec, 0, i);
+    IterVals.push_back(IterRecord(IterVar, ItemVal));
+
+    if (IterVals.size() == loops_size()) {
+      // Ok, we have all of the iterator values for this point in the
+      // iteration space.  Instantiate a new record to reflect this
+      // combination of values.
+      Record *IterRec = new Record(*CurRec);
+
+      // Set the iterator values now.
+      for (IterSet::iterator i = IterVals.begin(), iend = IterVals.end();
+           i != iend;
+           ++i) {
+        VarInit *IterVar = dynamic_cast<VarInit *>(i->IterVar);
+        if (IterVar == 0) {
+          Error(Loc, "foreach iterator is unresolved");
+          return true;
+        }
+
+        TypedInit *IVal  = dynamic_cast<TypedInit *>(i->IterValue);
+        if (IVal == 0) {
+          Error(Loc, "foreach iterator value is untyped");
+          return true;
+        }
+
+        IterRec->addValue(RecordVal(IterVar->getName(), IVal->getType(), false));
+
+        if (SetValue(IterRec, Loc, IterVar->getName(),
+                     std::vector<unsigned>(), IVal)) {
+          Error(Loc, "when instantiating this def");
+          return true;
+        }
+
+        // Resolve it next.
+        IterRec->resolveReferencesTo(IterRec->getValue(IterVar->getName()));
+
+        // Remove it.
+        IterRec->removeValue(IterVar->getName());
+      }
+
+      Records.addDef(IterRec);
+      IterRec->resolveReferences();
+    }
+
+    if (NextLoop != loops_end()) {
+      // Process nested loops.
+      if (ProcessForeachDefs(CurRec, CurMultiClass, Loc, IterVals, *NextLoop,
+                             NextLoop+1)) {
+        Error(Loc,
+              "Could not process loops for def " +
+              CurRec->getNameInitAsString());
+        return true;
+      }
+    }
+
+    // We're done with this iterator.
+    IterVals.pop_back();
+  }
+  return false;
+}
+
 //===----------------------------------------------------------------------===//
 // Parser Code
 //===----------------------------------------------------------------------===//
@@ -296,7 +398,8 @@ bool TGParser::AddSubMultiClass(MultiClass *CurMC,
 /// isObjectStart - Return true if this is a valid first token for an Object.
 static bool isObjectStart(tgtok::TokKind K) {
   return K == tgtok::Class || K == tgtok::Def ||
-         K == tgtok::Defm || K == tgtok::Let || K == tgtok::MultiClass;
+         K == tgtok::Defm || K == tgtok::Let ||
+         K == tgtok::MultiClass || K == tgtok::Foreach;
 }
 
 static std::string GetNewAnonymousName() {
@@ -698,6 +801,15 @@ Init *TGParser::ParseIDValue(Record *CurRec,
     }
   }
 
+  // If this is in a foreach loop, make sure it's not a loop iterator
+  for (loop_iterator i = loops_begin(), iend = loops_end();
+       i != iend;
+       ++i) {
+    VarInit *IterVar = dynamic_cast<VarInit *>(i->IterVar);
+    if (IterVar && IterVar->getName() == Name)
+      return IterVar;
+  }
+
   if (Mode == ParseNameMode)
     return StringInit::get(Name);
 
@@ -1353,7 +1465,7 @@ Init *TGParser::ParseValue(Record *CurRec, RecTy *ItemType, IDParseMode Mode) {
     switch (Lex.getCode()) {
     default: return Result;
     case tgtok::l_brace: {
-      if (Mode == ParseNameMode)
+      if (Mode == ParseNameMode || Mode == ParseForeachMode)
         // This is the beginning of the object body.
         return Result;
 
@@ -1605,6 +1717,42 @@ Init *TGParser::ParseDeclaration(Record *CurRec,
   return DeclName;
 }
 
+/// ParseForeachDeclaration - Read a foreach declaration, returning
+/// the name of the declared object or a NULL Init on error.  Return
+/// the name of the parsed initializer list through ForeachListName.
+///
+///  ForeachDeclaration ::= Type ID '=' Value
+///
+Init *TGParser::ParseForeachDeclaration(Init *&ForeachListValue) {
+  RecTy *Type = ParseType();
+  if (Type == 0) return 0;
+
+  if (Lex.getCode() != tgtok::Id) {
+    TokError("Expected identifier in foreach declaration");
+    return 0;
+  }
+
+  Init *DeclName = StringInit::get(Lex.getCurStrVal());
+  Lex.Lex();
+
+  VarInit *IterVar = VarInit::get(DeclName, Type);
+
+  // If a value is present, parse it.
+  if (Lex.getCode() != tgtok::equal) {
+    TokError("Expected '=' in foreach declaration");
+    return 0;
+  }
+  Lex.Lex();  // Eat the '='
+
+  RecTy *ValueType = Type;
+
+  // Expect a list initializer.
+  ValueType = ListRecTy::get(Type);
+  ForeachListValue = ParseValue(0, ValueType, ParseForeachMode);
+
+  return IterVar;
+}
+
 /// ParseTemplateArgList - Read a template argument list, which is a non-empty
 /// sequence of template-declarations in <>'s.  If CurRec is non-null, these are
 /// template args for a def, which may or may not be in a multiclass.  If null,
@@ -1817,6 +1965,47 @@ bool TGParser::ParseDef(MultiClass *CurMultiClass) {
     }
   }
 
+  if (ProcessForeachDefs(CurRec, CurMultiClass, DefLoc)) {
+    Error(DefLoc,
+          "Could not process loops for def" + CurRec->getNameInitAsString());
+    return true;
+  }
+
+  return false;
+}
+
+/// ParseForeach - Parse a for statement.  Return the record corresponding
+/// to it.  This returns true on error.
+///
+///   For ::= FOREACH Declaration '=' Value ObjectBody
+///
+bool TGParser::ParseForeach(MultiClass *CurMultiClass) {
+  assert(Lex.getCode() == tgtok::Foreach && "Unknown tok");
+  Lex.Lex();  // Eat the 'for' token.
+
+  // Make a temporary object to record items associated with the for
+  // loop.
+  Init *ListValue = 0;
+  Init *IterName = ParseForeachDeclaration(ListValue);
+  if (IterName == 0)
+    return TokError("expected declaration in for");
+
+  if (Lex.getCode() != tgtok::l_brace)
+    return TokError("Unknown tok");
+  Lex.Lex();  // Eat the {
+
+  // Create a loop object and remember it.
+  pushLoop(ForeachLoop(IterName, ListValue));
+
+  while (Lex.getCode() != tgtok::r_brace) {
+    if (ParseObject(CurMultiClass))
+      return true;
+  }
+  Lex.Lex();  // Eat the }
+
+  // We've processed everything in this loop.
+  popLoop();
+
   return false;
 }
 
@@ -2010,6 +2199,7 @@ bool TGParser::ParseMultiClass() {
         case tgtok::Let:
         case tgtok::Def:
         case tgtok::Defm:
+        case tgtok::Foreach:
           if (ParseObject(CurMultiClass))
             return true;
          break;
@@ -2305,6 +2495,7 @@ bool TGParser::ParseObject(MultiClass *MC) {
     return TokError("Expected class, def, defm, multiclass or let definition");
   case tgtok::Let:   return ParseTopLevelLet(MC);
   case tgtok::Def:   return ParseDef(MC);
+  case tgtok::Foreach:   return ParseForeach(MC);
   case tgtok::Defm:  return ParseDefm(MC);
   case tgtok::Class: return ParseClass();
   case tgtok::MultiClass: return ParseMultiClass();
diff --git old/llvm/lib/TableGen/TGParser.h new/llvm/lib/TableGen/TGParser.h
index 54cd99a..e8b370e 100644
--- old/llvm/lib/TableGen/TGParser.h
+++ new/llvm/lib/TableGen/TGParser.h
@@ -42,11 +42,25 @@ namespace llvm {
     }
   };
   
+  /// ForeachLoop - Record the iteration state associated with a for loop.
+  /// This is used to instantiate items in the loop body.
+  struct ForeachLoop {
+    Init *IterVar;
+    Init *ListValue;
+
+    ForeachLoop(Init *IVar, Init *LValue) : IterVar(IVar), ListValue(LValue) {};
+  };
+
 class TGParser {
   TGLexer Lex;
   std::vector<std::vector<LetRecord> > LetStack;
   std::map<std::string, MultiClass*> MultiClasses;
   
+  /// Loops - Keep track of any foreach loops we are within.
+  ///
+  typedef std::vector<ForeachLoop> LoopVector;
+  LoopVector Loops;
+
   /// CurMultiClass - If we are parsing a 'multiclass' definition, this is the 
   /// current value.
   MultiClass *CurMultiClass;
@@ -60,8 +74,10 @@ class TGParser {
   // in the middle of creating in.  For those situations, allow the
   // parser to ignore missing object errors.
   enum IDParseMode {
-    ParseValueMode, // We are parsing a value we expect to look up.
-    ParseNameMode // We are parsing a name of an object that does not yet exist.
+    ParseValueMode,   // We are parsing a value we expect to look up.
+    ParseNameMode,    // We are parsing a name of an object that does not yet
+                      // exist.
+    ParseForeachMode  // We are parsing a foreach init.
   };
 
 public:
@@ -82,6 +98,40 @@ public:
   const std::vector<std::string> &getDependencies() const {
     return Lex.getDependencies();
   }
+
+  // Foreach management.
+
+  /// pushLoop - Add a loop to the existing loop context.
+  ///
+  void pushLoop(const ForeachLoop &loop) {
+    Loops.push_back(loop);
+  }
+
+  /// popLoop - Pop a loop from the existing loop context.
+  ///
+  void popLoop() {
+    Loops.pop_back();
+  }
+
+  /// topLoop - Return a reference to the current innermost loop.
+  ///
+  ForeachLoop &topLoop() {
+    assert(!Loops.empty() && "Loop underflow!");
+    return Loops.back();
+  }
+
+  typedef LoopVector::iterator loop_iterator;
+
+  loop_iterator loops_begin() {
+    return Loops.begin();
+  }
+  loop_iterator loops_end() {
+    return Loops.end();
+  }
+  std::size_t loops_size() {
+    return Loops.size();
+  }
+
 private:  // Semantic analysis methods.
   bool AddValue(Record *TheRec, SMLoc Loc, const RecordVal &RV);
   bool SetValue(Record *TheRec, SMLoc Loc, Init *ValName, 
@@ -94,6 +144,23 @@ private:  // Semantic analysis methods.
   bool AddSubMultiClass(MultiClass *CurMC,
                         SubMultiClassReference &SubMultiClass);
 
+  // IterRecord: Map an iterator name to a value.
+  struct IterRecord {
+    Init *IterVar;
+    Init *IterValue;
+    IterRecord(Init *Var, Init *Val) : IterVar(Var), IterValue(Val) {}
+  };
+
+  // IterSet: The set of all iterator values at some point in the
+  // iteration space.
+  typedef std::vector<IterRecord> IterSet;
+
+  bool ProcessForeachDefs(Record *CurRec, MultiClass *CurMultiClass,
+                          SMLoc Loc);
+  bool ProcessForeachDefs(Record *CurRec, MultiClass *CurMultiClass,
+                          SMLoc Loc, IterSet &IterVals, ForeachLoop &CurLoop,
+                          loop_iterator NextLoop);
+
 private:  // Parser methods.
   bool ParseObjectList(MultiClass *MC = 0);
   bool ParseObject(MultiClass *MC);
@@ -116,6 +183,7 @@ private:  // Parser methods.
                             SMLoc DefmPrefixLoc);
   bool ParseDefm(MultiClass *CurMultiClass);
   bool ParseDef(MultiClass *CurMultiClass);
+  bool ParseForeach(MultiClass *CurMultiClass);
   bool ParseTopLevelLet(MultiClass *CurMultiClass);
   std::vector<LetRecord> ParseLetList();
 
@@ -125,6 +193,7 @@ private:  // Parser methods.
 
   bool ParseTemplateArgList(Record *CurRec);
   Init *ParseDeclaration(Record *CurRec, bool ParsingTemplateArgs);
+  Init *ParseForeachDeclaration(Init *&ForeachListValue);
 
   SubClassReference ParseSubClassReference(Record *CurRec, bool isDefm);
   SubMultiClassReference ParseSubMultiClassReference(MultiClass *CurMC);
diff --git old/llvm/test/TableGen/ForeachLoop.td new/llvm/test/TableGen/ForeachLoop.td
new file mode 100644
index 0000000..97fc8af3
--- /dev/null
+++ new/llvm/test/TableGen/ForeachLoop.td
@@ -0,0 +1,43 @@
+// RUN: llvm-tblgen %s | FileCheck %s
+// XFAIL: vg_leak
+
+class Register<string name, int idx> {
+  string Name = name;
+  int Index = idx;
+}
+
+foreach int i = [0, 1, 2, 3, 4, 5, 6, 7] {
+  def R#i : Register<"R"#i, i>;
+}
+
+// CHECK: def R0
+// CHECK: string Name = "R0";
+// CHECK: int Index = 0;
+
+// CHECK: def R1
+// CHECK: string Name = "R1";
+// CHECK: int Index = 1;
+
+// CHECK: def R2
+// CHECK: string Name = "R2";
+// CHECK: int Index = 2;
+
+// CHECK: def R3
+// CHECK: string Name = "R3";
+// CHECK: int Index = 3;
+
+// CHECK: def R4
+// CHECK: string Name = "R4";
+// CHECK: int Index = 4;
+
+// CHECK: def R5
+// CHECK: string Name = "R5";
+// CHECK: int Index = 5;
+
+// CHECK: def R6
+// CHECK: string Name = "R6";
+// CHECK: int Index = 6;
+
+// CHECK: def R7
+// CHECK: string Name = "R7";
+// CHECK: int Index = 7;
diff --git old/llvm/test/TableGen/NestedForeach.td new/llvm/test/TableGen/NestedForeach.td
new file mode 100644
index 0000000..05e0952
--- /dev/null
+++ new/llvm/test/TableGen/NestedForeach.td
@@ -0,0 +1,74 @@
+// RUN: llvm-tblgen %s | FileCheck %s
+// XFAIL: vg_leak
+
+class Droid<string series, int release, string model, int patchlevel> {
+  string Series = series;
+  int Release = release;
+  string Model = model;
+  int Patchlevel = patchlevel;
+}
+
+foreach string S = ["R", "C"] {
+  foreach int R = [2, 3, 4] {
+    foreach string M = ["D", "P", "Q"] {
+      foreach int P = [0, 2, 4] {
+        def S#R#M#P : Droid<S, R, M, P>;
+      }
+    }
+  }
+}
+
+// CHECK: def C2D0
+// CHECK: def C2D2
+// CHECK: def C2D4
+// CHECK: def C2P0
+// CHECK: def C2P2
+// CHECK: def C2P4
+// CHECK: def C2Q0
+// CHECK: def C2Q2
+// CHECK: def C2Q4
+// CHECK: def C3D0
+// CHECK: def C3D2
+// CHECK: def C3D4
+// CHECK: def C3P0
+// CHECK: def C3P2
+// CHECK: def C3P4
+// CHECK: def C3Q0
+// CHECK: def C3Q2
+// CHECK: def C3Q4
+// CHECK: def C4D0
+// CHECK: def C4D2
+// CHECK: def C4D4
+// CHECK: def C4P0
+// CHECK: def C4P2
+// CHECK: def C4P4
+// CHECK: def C4Q0
+// CHECK: def C4Q2
+// CHECK: def C4Q4
+// CHECK: def R2D0
+// CHECK: def R2D2
+// CHECK: def R2D4
+// CHECK: def R2P0
+// CHECK: def R2P2
+// CHECK: def R2P4
+// CHECK: def R2Q0
+// CHECK: def R2Q2
+// CHECK: def R2Q4
+// CHECK: def R3D0
+// CHECK: def R3D2
+// CHECK: def R3D4
+// CHECK: def R3P0
+// CHECK: def R3P2
+// CHECK: def R3P4
+// CHECK: def R3Q0
+// CHECK: def R3Q2
+// CHECK: def R3Q4
+// CHECK: def R4D0
+// CHECK: def R4D2
+// CHECK: def R4D4
+// CHECK: def R4P0
+// CHECK: def R4P2
+// CHECK: def R4P4
+// CHECK: def R4Q0
+// CHECK: def R4Q2
+// CHECK: def R4Q4
diff --git old/llvm/utils/emacs/tablegen-mode.el new/llvm/utils/emacs/tablegen-mode.el
index 3853ce6..26b6639 100644
--- old/llvm/utils/emacs/tablegen-mode.el
+++ new/llvm/utils/emacs/tablegen-mode.el
@@ -13,7 +13,7 @@
 
 (defvar tablegen-font-lock-keywords
   (let ((kw (regexp-opt '("class" "defm" "def" "field" "include" "in"
-                         "let" "multiclass")
+                         "let" "multiclass", "foreach")
                         'words))
         (type-kw (regexp-opt '("bit" "bits" "code" "dag" "int" "list" "string")
                              'words))
diff --git old/llvm/utils/vim/tablegen.vim new/llvm/utils/vim/tablegen.vim
index 3043489..a9b0e4e 100644
--- old/llvm/utils/vim/tablegen.vim
+++ new/llvm/utils/vim/tablegen.vim
@@ -14,7 +14,7 @@ syntax sync minlines=100
 
 syn case match
 
-syn keyword tgKeyword   def let in code dag field include defm
+syn keyword tgKeyword   def let in code dag field include defm foreach
 syn keyword tgType      class int string list bit bits multiclass
 
 syn match   tgNumber    /\<\d\+\>/
-- 
1.7.8.4




More information about the llvm-commits mailing list