142 for (
const auto &subst : llvm::reverse(substitutions)) {
143 auto pos = str.find(subst.first);
144 while (pos != std::string::npos) {
145 str.replace(pos, subst.first.size(), std::string(subst.second));
148 pos += subst.second.size();
150 pos = str.find(subst.first, pos);
161 SpecificBumpPtrAllocator<PredNode> &allocator,
163 auto *rootNode = allocator.Allocate();
164 new (rootNode) PredNode;
166 rootNode->predicate = &root;
175 auto allSubstitutions = llvm::to_vector<4>(substitutions);
176 if (rootNode->kind == PredCombinerKind::SubstLeaves) {
178 allSubstitutions.push_back(
179 {substPred.getPattern(), substPred.getReplacement()});
182 }
else if (rootNode->kind == PredCombinerKind::Concat) {
183 const auto &concatPred =
static_cast<const ConcatPred &
>(root);
184 rootNode->prefix = std::string(concatPred.getPrefix());
186 rootNode->suffix = std::string(concatPred.getSuffix());
191 auto combined =
static_cast<const CombinedPred &
>(root);
192 for (
const auto *record : combined.getChildren()) {
195 rootNode->children.push_back(childTree);
211 if (knownTruePreds.count(node->predicate) != 0) {
212 node->kind = PredCombinerKind::True;
213 node->children.clear();
216 if (knownFalsePreds.count(node->predicate) != 0) {
217 node->kind = PredCombinerKind::False;
218 node->children.clear();
233 if (node->kind == PredCombinerKind::SubstLeaves) {
237 if (node->kind == PredCombinerKind::And && node->children.empty()) {
238 node->kind = PredCombinerKind::True;
242 if (node->kind == PredCombinerKind::Or && node->children.empty()) {
243 node->kind = PredCombinerKind::False;
252 std::swap(node->children, children);
254 for (
auto &child : children) {
256 auto *simplifiedChild =
260 if (node->kind != PredCombinerKind::And &&
261 node->kind != PredCombinerKind::Or) {
262 node->children.push_back(simplifiedChild);
273 auto collapseKind = node->kind == PredCombinerKind::And
274 ? PredCombinerKind::False
275 : PredCombinerKind::True;
276 auto eraseKind = node->kind == PredCombinerKind::And
277 ? PredCombinerKind::True
278 : PredCombinerKind::False;
279 const auto &collapseList =
280 node->kind == PredCombinerKind::And ? knownFalsePreds : knownTruePreds;
281 const auto &eraseList =
282 node->kind == PredCombinerKind::And ? knownTruePreds : knownFalsePreds;
283 if (simplifiedChild->kind == collapseKind ||
284 collapseList.count(simplifiedChild->predicate) != 0) {
285 node->kind = collapseKind;
286 node->children.clear();
289 if (simplifiedChild->kind == eraseKind ||
290 eraseList.count(simplifiedChild->predicate) != 0) {
293 node->children.push_back(simplifiedChild);
329 if (root.kind == PredCombinerKind::Leaf)
331 if (root.kind == PredCombinerKind::True)
333 if (root.kind == PredCombinerKind::False)
338 childExpressions.reserve(root.children.size());
339 for (
const auto &child : root.children)
343 if (root.kind == PredCombinerKind::And)
345 if (root.kind == PredCombinerKind::Or)
347 if (root.kind == PredCombinerKind::Not)
349 if (root.kind == PredCombinerKind::Concat) {
350 assert(childExpressions.size() == 1 &&
351 "ConcatPred should only have one child");
352 return root.prefix + childExpressions.front() + root.suffix;
356 if (root.kind == PredCombinerKind::SubstLeaves) {
357 assert(childExpressions.size() == 1 &&
358 "substitution predicate must have one child");
359 return childExpressions[0];
362 llvm::PrintFatalError(root.predicate->
getLoc(),
"unsupported predicate kind");