use convenience function for copying IR flags; NFCI
[oota-llvm.git] / lib / Transforms / Scalar / SpeculativeExecution.cpp
index 0e51019cccea8e0287412aa386eb326ba55ebcc7..147d615488ffe17f3ee1075d71690ac73af029a6 100644 (file)
 // Later passes sink back much of the speculated code that did not enable
 // further optimization.
 //
+// This pass is more aggressive than the function SpeculativeyExecuteBB in
+// SimplifyCFG. SimplifyCFG will not speculate if no selects are introduced and
+// it will speculate at most one instruction. It also will not speculate if
+// there is a value defined in the if-block that is only used in the then-block.
+// These restrictions make sense since the speculation in SimplifyCFG seems
+// aimed at introducing cheap selects, while this pass is intended to do more
+// aggressive speculation while counting on later passes to either capitalize on
+// that or clean it up.
+//
 //===----------------------------------------------------------------------===//
 
 #include "llvm/ADT/SmallSet.h"
@@ -74,6 +83,7 @@ static cl::opt<unsigned> SpecExecMaxNotHoisted(
              "number of instructions that would not be speculatively executed "
              "exceeds this limit."));
 
+namespace {
 class SpeculativeExecution : public FunctionPass {
  public:
   static char ID;
@@ -88,6 +98,7 @@ class SpeculativeExecution : public FunctionPass {
 
   const TargetTransformInfo *TTI = nullptr;
 };
+} // namespace
 
 char SpeculativeExecution::ID = 0;
 INITIALIZE_PASS_BEGIN(SpeculativeExecution, "speculative-execution",
@@ -216,7 +227,7 @@ bool SpeculativeExecution::considerHoistingFromTo(BasicBlock &FromBlock,
     // changes the list that I is iterating through.
     auto Current = I;
     ++I;
-    if (!NotHoisted.count(Current)) {
+    if (!NotHoisted.count(&*Current)) {
       Current->moveBefore(ToBlock.getTerminator());
     }
   }