[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/ClangAttrEmitter.cpp b/utils/TableGen/ClangAttrEmitter.cpp
index 26bd878..bca4bb6 100644
--- a/utils/TableGen/ClangAttrEmitter.cpp
+++ b/utils/TableGen/ClangAttrEmitter.cpp
@@ -21,17 +21,19 @@
static const std::vector<StringRef>
getValueAsListOfStrings(Record &R, StringRef FieldName) {
- ListInit *List = R.getValueAsListInit(FieldName);
+ const ListInit *List = R.getValueAsListInit(FieldName);
assert (List && "Got a null ListInit");
std::vector<StringRef> Strings;
Strings.reserve(List->getSize());
- for (ListInit::iterator i = List->begin(), e = List->end(); i != e; ++i) {
+ for (ListInit::const_iterator i = List->begin(), e = List->end();
+ i != e;
+ ++i) {
assert(*i && "Got a null element in a ListInit");
- if (StringInit *S = dynamic_cast<StringInit *>(*i))
+ if (const StringInit *S = dynamic_cast<const StringInit *>(*i))
Strings.push_back(S->getValue());
- else if (CodeInit *C = dynamic_cast<CodeInit *>(*i))
+ else if (const CodeInit *C = dynamic_cast<const CodeInit *>(*i))
Strings.push_back(C->getValue());
else
assert(false && "Got a non-string, non-code element in a ListInit");