[Analysis] Fix some Clang-tidy modernize-use-using and Include What You Use warnings; other minor fixes. Also affected in files (NFC).

llvm-svn: 312289
diff --git a/llvm/tools/llvm-stress/llvm-stress.cpp b/llvm/tools/llvm-stress/llvm-stress.cpp
index 3945da7..650ae96 100644
--- a/llvm/tools/llvm-stress/llvm-stress.cpp
+++ b/llvm/tools/llvm-stress/llvm-stress.cpp
@@ -1,4 +1,4 @@
-//===-- llvm-stress.cpp - Generate random LL files to stress-test LLVM ----===//
+//===- llvm-stress.cpp - Generate random LL files to stress-test LLVM -----===//
 //
 //                     The LLVM Compiler Infrastructure
 //
@@ -12,32 +12,55 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "llvm/Analysis/CallGraphSCCPass.h"
+#include "llvm/ADT/APFloat.h"
+#include "llvm/ADT/APInt.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/Twine.h"
+#include "llvm/IR/BasicBlock.h"
+#include "llvm/IR/CallingConv.h"
 #include "llvm/IR/Constants.h"
+#include "llvm/IR/DataLayout.h"
+#include "llvm/IR/DerivedTypes.h"
+#include "llvm/IR/Function.h"
+#include "llvm/IR/GlobalValue.h"
 #include "llvm/IR/IRPrintingPasses.h"
+#include "llvm/IR/InstrTypes.h"
 #include "llvm/IR/Instruction.h"
+#include "llvm/IR/Instructions.h"
 #include "llvm/IR/LLVMContext.h"
 #include "llvm/IR/LegacyPassManager.h"
-#include "llvm/IR/LegacyPassNameParser.h"
 #include "llvm/IR/Module.h"
+#include "llvm/IR/Type.h"
+#include "llvm/IR/Value.h"
 #include "llvm/IR/Verifier.h"
-#include "llvm/Support/Debug.h"
+#include "llvm/Support/Casting.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/ManagedStatic.h"
-#include "llvm/Support/PluginLoader.h"
 #include "llvm/Support/PrettyStackTrace.h"
 #include "llvm/Support/ToolOutputFile.h"
+#include "llvm/Support/raw_ostream.h"
 #include <algorithm>
-#include <random>
+#include <cassert>
+#include <cstddef>
+#include <cstdint>
+#include <memory>
+#include <string>
+#include <system_error>
 #include <vector>
 
 namespace llvm {
 
 static cl::opt<unsigned> SeedCL("seed",
   cl::desc("Seed used for randomness"), cl::init(0));
+
 static cl::opt<unsigned> SizeCL("size",
   cl::desc("The estimated size of the generated function (# of instrs)"),
   cl::init(100));
+
 static cl::opt<std::string>
 OutputFilename("o", cl::desc("Override output filename"),
                cl::value_desc("filename"));
@@ -45,6 +68,7 @@
 static LLVMContext Context;
 
 namespace cl {
+
 template <> class parser<Type*> final : public basic_parser<Type*> {
 public:
   parser(Option &O) : basic_parser(O) {}
@@ -70,14 +94,15 @@
 
   StringRef getValueName() const override { return "IR scalar type"; }
 };
-}
 
+} // end namespace cl
 
 static cl::list<Type*> AdditionalScalarTypes("types", cl::CommaSeparated,
   cl::desc("Additional IR scalar types "
            "(always includes i1, i8, i16, i32, i64, float and double)"));
 
 namespace {
+
 /// A utility class to provide a pseudo-random number generator which is
 /// the same across all platforms. This is somewhat close to the libc
 /// implementation. Note: This is not a cryptographically secure pseudorandom
@@ -111,9 +136,11 @@
   }
 
   /// Make this like a C++11 random device
-  typedef uint32_t result_type;
+  using result_type = uint32_t ;
+
   static constexpr result_type min() { return 0; }
   static constexpr result_type max() { return 0x7ffff; }
+
   uint32_t operator()() {
     uint32_t Val = Rand();
     assert(Val <= max() && "Random value out of range");
@@ -149,18 +176,19 @@
 /// modifying and adding new random instructions.
 struct Modifier {
   /// Used to store the randomly generated values.
-  typedef std::vector<Value*> PieceTable;
+  using PieceTable = std::vector<Value *>;
 
 public:
   /// C'tor
-  Modifier(BasicBlock *Block, PieceTable *PT, Random *R):
-    BB(Block),PT(PT),Ran(R),Context(BB->getContext()) {}
+  Modifier(BasicBlock *Block, PieceTable *PT, Random *R)
+      : BB(Block), PT(PT), Ran(R), Context(BB->getContext()) {}
 
   /// virtual D'tor to silence warnings.
-  virtual ~Modifier() {}
+  virtual ~Modifier() = default;
 
   /// Add a new instruction.
   virtual void Act() = 0;
+
   /// Add N new instructions,
   virtual void ActN(unsigned n) {
     for (unsigned i=0; i<n; ++i)
@@ -298,16 +326,21 @@
 
   /// Basic block to populate
   BasicBlock *BB;
+
   /// Value table
   PieceTable *PT;
+
   /// Random number generator
   Random *Ran;
+
   /// Context
   LLVMContext &Context;
 };
 
 struct LoadModifier: public Modifier {
-  LoadModifier(BasicBlock *BB, PieceTable *PT, Random *R):Modifier(BB, PT, R) {}
+  LoadModifier(BasicBlock *BB, PieceTable *PT, Random *R)
+      : Modifier(BB, PT, R) {}
+
   void Act() override {
     // Try to use predefined pointers. If non-exist, use undef pointer value;
     Value *Ptr = getRandomPointerValue();
@@ -317,7 +350,9 @@
 };
 
 struct StoreModifier: public Modifier {
-  StoreModifier(BasicBlock *BB, PieceTable *PT, Random *R):Modifier(BB, PT, R) {}
+  StoreModifier(BasicBlock *BB, PieceTable *PT, Random *R)
+      : Modifier(BB, PT, R) {}
+
   void Act() override {
     // Try to use predefined pointers. If non-exist, use undef pointer value;
     Value *Ptr = getRandomPointerValue();
@@ -335,7 +370,8 @@
 };
 
 struct BinModifier: public Modifier {
-  BinModifier(BasicBlock *BB, PieceTable *PT, Random *R):Modifier(BB, PT, R) {}
+  BinModifier(BasicBlock *BB, PieceTable *PT, Random *R)
+      : Modifier(BB, PT, R) {}
 
   void Act() override {
     Value *Val0 = getRandomVal();
@@ -350,7 +386,6 @@
     if (Val0->getType()->getScalarSizeInBits() == 1)
       return;
 
-
     bool isFloat = Val0->getType()->getScalarType()->isFloatingPointTy();
     Instruction* Term = BB->getTerminator();
     unsigned R = getRandom() % (isFloat ? 7 : 13);
@@ -379,7 +414,9 @@
 
 /// Generate constant values.
 struct ConstModifier: public Modifier {
-  ConstModifier(BasicBlock *BB, PieceTable *PT, Random *R):Modifier(BB, PT, R) {}
+  ConstModifier(BasicBlock *BB, PieceTable *PT, Random *R)
+      : Modifier(BB, PT, R) {}
+
   void Act() override {
     Type *Ty = pickType();
 
@@ -428,7 +465,8 @@
 };
 
 struct AllocaModifier: public Modifier {
-  AllocaModifier(BasicBlock *BB, PieceTable *PT, Random *R):Modifier(BB, PT, R){}
+  AllocaModifier(BasicBlock *BB, PieceTable *PT, Random *R)
+      : Modifier(BB, PT, R) {}
 
   void Act() override {
     Type *Tp = pickType();
@@ -439,8 +477,8 @@
 };
 
 struct ExtractElementModifier: public Modifier {
-  ExtractElementModifier(BasicBlock *BB, PieceTable *PT, Random *R):
-    Modifier(BB, PT, R) {}
+  ExtractElementModifier(BasicBlock *BB, PieceTable *PT, Random *R)
+      : Modifier(BB, PT, R) {}
 
   void Act() override {
     Value *Val0 = getRandomVectorValue();
@@ -453,9 +491,10 @@
 };
 
 struct ShuffModifier: public Modifier {
-  ShuffModifier(BasicBlock *BB, PieceTable *PT, Random *R):Modifier(BB, PT, R) {}
-  void Act() override {
+  ShuffModifier(BasicBlock *BB, PieceTable *PT, Random *R)
+      : Modifier(BB, PT, R) {}
 
+  void Act() override {
     Value *Val0 = getRandomVectorValue();
     Value *Val1 = getRandomValue(Val0->getType());
 
@@ -480,8 +519,8 @@
 };
 
 struct InsertElementModifier: public Modifier {
-  InsertElementModifier(BasicBlock *BB, PieceTable *PT, Random *R):
-    Modifier(BB, PT, R) {}
+  InsertElementModifier(BasicBlock *BB, PieceTable *PT, Random *R)
+      : Modifier(BB, PT, R) {}
 
   void Act() override {
     Value *Val0 = getRandomVectorValue();
@@ -493,13 +532,13 @@
               "I",  BB->getTerminator());
     return PT->push_back(V);
   }
-
 };
 
 struct CastModifier: public Modifier {
-  CastModifier(BasicBlock *BB, PieceTable *PT, Random *R):Modifier(BB, PT, R) {}
-  void Act() override {
+  CastModifier(BasicBlock *BB, PieceTable *PT, Random *R)
+      : Modifier(BB, PT, R) {}
 
+  void Act() override {
     Value *V = getRandomVal();
     Type *VTy = V->getType();
     Type *DestTy = pickScalarType();
@@ -558,7 +597,6 @@
         return PT->push_back(
           new SIToFPInst(V, DestTy, "FC", BB->getTerminator()));
       return PT->push_back(new UIToFPInst(V, DestTy, "FC", BB->getTerminator()));
-
     }
 
     // Both floats.
@@ -574,38 +612,37 @@
       // for which there is no defined conversion. So do nothing.
     }
   }
-
 };
 
 struct SelectModifier: public Modifier {
-  SelectModifier(BasicBlock *BB, PieceTable *PT, Random *R):
-    Modifier(BB, PT, R) {}
+  SelectModifier(BasicBlock *BB, PieceTable *PT, Random *R)
+      : Modifier(BB, PT, R) {}
 
   void Act() override {
     // Try a bunch of different select configuration until a valid one is found.
-      Value *Val0 = getRandomVal();
-      Value *Val1 = getRandomValue(Val0->getType());
+    Value *Val0 = getRandomVal();
+    Value *Val1 = getRandomValue(Val0->getType());
 
-      Type *CondTy = Type::getInt1Ty(Context);
+    Type *CondTy = Type::getInt1Ty(Context);
 
-      // If the value type is a vector, and we allow vector select, then in 50%
-      // of the cases generate a vector select.
-      if (Val0->getType()->isVectorTy() && (getRandom() % 1)) {
-        unsigned NumElem = cast<VectorType>(Val0->getType())->getNumElements();
-        CondTy = VectorType::get(CondTy, NumElem);
-      }
+    // If the value type is a vector, and we allow vector select, then in 50%
+    // of the cases generate a vector select.
+    if (Val0->getType()->isVectorTy() && (getRandom() % 1)) {
+      unsigned NumElem = cast<VectorType>(Val0->getType())->getNumElements();
+      CondTy = VectorType::get(CondTy, NumElem);
+    }
 
-      Value *Cond = getRandomValue(CondTy);
-      Value *V = SelectInst::Create(Cond, Val0, Val1, "Sl", BB->getTerminator());
-      return PT->push_back(V);
+    Value *Cond = getRandomValue(CondTy);
+    Value *V = SelectInst::Create(Cond, Val0, Val1, "Sl", BB->getTerminator());
+    return PT->push_back(V);
   }
 };
 
-
 struct CmpModifier: public Modifier {
-  CmpModifier(BasicBlock *BB, PieceTable *PT, Random *R):Modifier(BB, PT, R) {}
-  void Act() override {
+  CmpModifier(BasicBlock *BB, PieceTable *PT, Random *R)
+      : Modifier(BB, PT, R) {}
 
+  void Act() override {
     Value *Val0 = getRandomVal();
     Value *Val1 = getRandomValue(Val0->getType());
 
@@ -689,7 +726,7 @@
   }
 }
 
-}
+} // end namespace llvm
 
 int main(int argc, char **argv) {
   using namespace llvm;
@@ -699,7 +736,7 @@
   cl::ParseCommandLineOptions(argc, argv, "llvm codegen stress-tester\n");
   llvm_shutdown_obj Y;
 
-  auto M = make_unique<Module>("/tmp/autogen.bc", Context);
+  auto M = llvm::make_unique<Module>("/tmp/autogen.bc", Context);
   Function *F = GenEmptyFunction(M.get());
 
   // Pick an initial seed value