llvm/llvm/tools/llvm-stress/llvm-stress.cpp

//===- llvm-stress.cpp - Generate random LL files to stress-test LLVM -----===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This program is a utility that generates random .ll files to stress-test
// different components in LLVM.
//
//===----------------------------------------------------------------------===//

#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/InstrTypes.h"
#include "llvm/IR/Instruction.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/Value.h"
#include "llvm/IR/Verifier.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/InitLLVM.h"
#include "llvm/Support/ToolOutputFile.h"
#include "llvm/Support/WithColor.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <cassert>
#include <cstddef>
#include <cstdint>
#include <memory>
#include <string>
#include <system_error>
#include <vector>

namespace llvm {

static cl::OptionCategory StressCategory("Stress Options");

static cl::opt<unsigned> SeedCL("seed", cl::desc("Seed used for randomness"),
                                cl::init(0), cl::cat(StressCategory));

static cl::opt<unsigned> SizeCL(
    "size",
    cl::desc("The estimated size of the generated function (# of instrs)"),
    cl::init(100), cl::cat(StressCategory));

static cl::opt<std::string> OutputFilename("o",
                                           cl::desc("Override output filename"),
                                           cl::value_desc("filename"),
                                           cl::cat(StressCategory));

static cl::list<StringRef> AdditionalScalarTypes(
    "types", cl::CommaSeparated,
    cl::desc("Additional IR scalar types "
             "(always includes i1, i8, i16, i32, i64, float and double)"));

static cl::opt<bool> EnableScalableVectors(
    "enable-scalable-vectors",
    cl::desc("Generate IR involving scalable vector types"),
    cl::init(false), cl::cat(StressCategory));


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
/// number generator.
class Random {};

/// Generate an empty function with a default argument list.
Function *GenEmptyFunction(Module *M) {}

/// A base class, implementing utilities needed for
/// modifying and adding new random instructions.
struct Modifier {};

struct LoadModifier: public Modifier {};

struct StoreModifier: public Modifier {};

struct BinModifier: public Modifier {};

/// Generate constant values.
struct ConstModifier: public Modifier {};

struct AllocaModifier: public Modifier {};

struct ExtractElementModifier: public Modifier {};

struct ShuffModifier: public Modifier {};

struct InsertElementModifier: public Modifier {};

struct CastModifier: public Modifier {};

struct SelectModifier: public Modifier {};

struct CmpModifier: public Modifier {};

} // end anonymous namespace

static void FillFunction(Function *F, Random &R) {}

static void IntroduceControlFlow(Function *F, Random &R) {}

} // end namespace llvm

int main(int argc, char **argv) {}