<div dir="ltr">Thank you very much for the suggestion, it helped clean up the algorithm for what I was trying to do in r251388.<div><br></div><div>-eric</div></div><br><div class="gmail_quote"><div dir="ltr">On Mon, Oct 26, 2015 at 5:12 PM Eric Christopher <<a href="mailto:echristo@gmail.com">echristo@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Mon, Oct 26, 2015 at 5:11 PM David Blaikie <<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Oct 26, 2015 at 5:06 PM, Eric Christopher via cfe-commits <span dir="ltr"><<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: echristo<br>
Date: Mon Oct 26 19:06:21 2015<br>
New Revision: 251371<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=251371&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=251371&view=rev</a><br>
Log:<br>
Use early exits to reduce indentation.<br>
<br>
Modified:<br>
    cfe/trunk/lib/CodeGen/CGBuiltin.cpp<br>
<br>
Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=251371&r1=251370&r2=251371&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=251371&r1=251370&r2=251371&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)<br>
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Mon Oct 26 19:06:21 2015<br>
@@ -296,53 +296,55 @@ bool CodeGenFunction::checkBuiltinTarget<br>
   if (!TargetDecl)<br>
     return true;<br>
<br>
-  // Get the current enclosing function if it exists.<br>
-  if (const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(CurFuncDecl)) {<br>
-    unsigned BuiltinID = TargetDecl->getBuiltinID();<br>
-    const char *FeatureList =<br>
-        CGM.getContext().BuiltinInfo.getRequiredFeatures(BuiltinID);<br>
-    if (FeatureList && StringRef(FeatureList) != "") {<br>
-      StringRef TargetCPU = Target.getTargetOpts().CPU;<br>
-      llvm::StringMap<bool> FeatureMap;<br>
-<br>
-      if (const auto *TD = FD->getAttr<TargetAttr>()) {<br>
-        // If we have a TargetAttr build up the feature map based on that.<br>
-        TargetAttr::ParsedTargetAttr ParsedAttr = TD->parse();<br>
-<br>
-        // Make a copy of the features as passed on the command line into the<br>
-        // beginning of the additional features from the function to override.<br>
-        ParsedAttr.first.insert(<br>
-            ParsedAttr.first.begin(),<br>
-            Target.getTargetOpts().FeaturesAsWritten.begin(),<br>
-            Target.getTargetOpts().FeaturesAsWritten.end());<br>
-<br>
-        if (ParsedAttr.second != "")<br>
-          TargetCPU = ParsedAttr.second;<br>
-<br>
-        // Now populate the feature map, first with the TargetCPU which is<br>
-        // either<br>
-        // the default or a new one from the target attribute string. Then we'll<br>
-        // use the passed in features (FeaturesAsWritten) along with the new<br>
-        // ones<br>
-        // from the attribute.<br>
-        Target.initFeatureMap(FeatureMap, CGM.getDiags(), TargetCPU,<br>
-                              ParsedAttr.first);<br>
-      } else {<br>
-        Target.initFeatureMap(FeatureMap, CGM.getDiags(), TargetCPU,<br>
-                              Target.getTargetOpts().Features);<br>
-      }<br>
-<br>
-      // If we have at least one of the features in the feature list return<br>
-      // true, otherwise return false.<br>
-      SmallVector<StringRef, 1> AttrFeatures;<br>
-      StringRef(FeatureList).split(AttrFeatures, ",");<br>
-      for (const auto &Feature : AttrFeatures)<br>
-        if (FeatureMap[Feature])<br>
-         return true;<br>
-      return false;<br>
-    }<br>
+  // Get the current enclosing function if it exists. If it doesn't<br>
+  // we can't check the target features anyhow.<br>
+  const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(CurFuncDecl);<br>
+  if (!FD) return true;<br>
+<br>
+  unsigned BuiltinID = TargetDecl->getBuiltinID();<br>
+  const char *FeatureList =<br>
+      CGM.getContext().BuiltinInfo.getRequiredFeatures(BuiltinID);<br>
+<br>
+  if (!FeatureList || StringRef(FeatureList) == "")<br>
+    return true;<br>
+<br>
+  StringRef TargetCPU = Target.getTargetOpts().CPU;<br>
+  llvm::StringMap<bool> FeatureMap;<br>
+<br>
+  if (const auto *TD = FD->getAttr<TargetAttr>()) {<br>
+    // If we have a TargetAttr build up the feature map based on that.<br>
+    TargetAttr::ParsedTargetAttr ParsedAttr = TD->parse();<br>
+<br>
+    // Make a copy of the features as passed on the command line into the<br>
+    // beginning of the additional features from the function to override.<br>
+    ParsedAttr.first.insert(ParsedAttr.first.begin(),<br>
+                            Target.getTargetOpts().FeaturesAsWritten.begin(),<br>
+                            Target.getTargetOpts().FeaturesAsWritten.end());<br>
+<br>
+    if (ParsedAttr.second != "")<br>
+      TargetCPU = ParsedAttr.second;<br>
+<br>
+    // Now populate the feature map, first with the TargetCPU which is<br>
+    // either<br>
+    // the default or a new one from the target attribute string. Then we'll<br>
+    // use the passed in features (FeaturesAsWritten) along with the new<br>
+    // ones<br>
+    // from the attribute.<br>
+    Target.initFeatureMap(FeatureMap, CGM.getDiags(), TargetCPU,<br>
+                          ParsedAttr.first);<br>
+  } else {<br>
+    Target.initFeatureMap(FeatureMap, CGM.getDiags(), TargetCPU,<br>
+                          Target.getTargetOpts().Features);<br>
   }<br>
-  return true;<br>
+<br>
+  // If we have at least one of the features in the feature list return<br>
+  // true, otherwise return false.<br>
+  SmallVector<StringRef, 1> AttrFeatures;<br>
+  StringRef(FeatureList).split(AttrFeatures, ",");<br>
+  for (const auto &Feature : AttrFeatures)<br>
+    if (FeatureMap[Feature])<br>
+      return true;<br>
+  return false;<br></blockquote></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><br>This last bit could be written as:<br><br>return std::any_of(AttrFeatures.begin(), AttrFeatures.end(), [&](mumble &Feature) { return FeatureMap[Feature]; });<br><br>if you like/if that seems better.<br><br>(also, I wouldn't mind if people start writing llvm versions of the standard algorithms that take a range instead of a begin/end iterator pair either... )<br></div></div></div></div></blockquote><div><br></div></div></div><div dir="ltr"><div class="gmail_quote"><div>That would totally be awesome, except I'm about to refactor that code more.</div><div><br></div><div>But I'll keep it in mind and see if I can manage it :)</div></div></div><div dir="ltr"><div class="gmail_quote"><div><br></div><div>-eric</div></div></div><div dir="ltr"><div class="gmail_quote"><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div> </div></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
 }<br>
<br>
 RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD,<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
</blockquote></div></div></div></blockquote></div></div></blockquote></div>