llvm.org GIT mirror llvm / 8229e33
[llvm-stress] Enhance scalar type selection from command line. llvm-stress command line options like -generate-x86-fp80 has been replaced with one list-like option -types. E.g. llvm-stress -types=x86_fp80,i100,i256,half. Default types (i1, i8, i16, i32, i64, float, double) are always added at the beginning of that list. Reviewers: hfinkel Differential Revision: http://reviews.llvm.org/D10667 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241896 91177308-0d34-0410-b5e6-96231b3b80d8 Pawel Bylica 4 years ago
1 changed file(s) with 55 addition(s) and 40 deletion(s). Raw diff Collapse all Expand all
3030 #include
3131 #include
3232 #include
33 using namespace llvm;
33
34 namespace llvm {
3435
3536 static cl::opt SeedCL("seed",
3637 cl::desc("Seed used for randomness"), cl::init(0));
4142 OutputFilename("o", cl::desc("Override output filename"),
4243 cl::value_desc("filename"));
4344
44 static cl::opt GenHalfFloat("generate-half-float",
45 cl::desc("Generate half-length floating-point values"), cl::init(false));
46 static cl::opt GenX86FP80("generate-x86-fp80",
47 cl::desc("Generate 80-bit X86 floating-point values"), cl::init(false));
48 static cl::opt GenFP128("generate-fp128",
49 cl::desc("Generate 128-bit floating-point values"), cl::init(false));
50 static cl::opt GenPPCFP128("generate-ppc-fp128",
51 cl::desc("Generate 128-bit PPC floating-point values"), cl::init(false));
52 static cl::opt GenX86MMX("generate-x86-mmx",
53 cl::desc("Generate X86 MMX floating-point values"), cl::init(false));
45 namespace cl {
46 template <> class parser final : public basic_parser {
47 public:
48 parser(Option &O) : basic_parser(O) {}
49
50 // Parse options as IR types. Return true on error.
51 bool parse(Option &O, StringRef, StringRef Arg, Type *&Value) {
52 auto &Context = getGlobalContext();
53 if (Arg == "half") Value = Type::getHalfTy(Context);
54 else if (Arg == "fp128") Value = Type::getFP128Ty(Context);
55 else if (Arg == "x86_fp80") Value = Type::getX86_FP80Ty(Context);
56 else if (Arg == "ppc_fp128") Value = Type::getPPC_FP128Ty(Context);
57 else if (Arg == "x86_mmx") Value = Type::getX86_MMXTy(Context);
58 else if (Arg.startswith("i")) {
59 unsigned N = 0;
60 Arg.drop_front().getAsInteger(10, N);
61 if (N > 0)
62 Value = Type::getIntNTy(Context, N);
63 }
64
65 if (!Value)
66 return O.error("Invalid IR scalar type: '" + Arg + "'!");
67 return false;
68 }
69
70 const char *getValueName() const override { return "IR scalar type"; }
71 };
72 }
73
74
75 static cl::list AdditionalScalarTypes("types", cl::CommaSeparated,
76 cl::desc("Additional IR scalar types "
77 "(always includes i1, i8, i16, i32, i64, float and double)"));
5478
5579 namespace {
5680 /// A utility class to provide a pseudo-random number generator which is
242266
243267 /// Pick a random scalar type.
244268 Type *pickScalarType() {
245 Type *t = nullptr;
246 do {
247 switch (Ran->Rand() % 30) {
248 case 0: t = Type::getInt1Ty(Context); break;
249 case 1: t = Type::getInt8Ty(Context); break;
250 case 2: t = Type::getInt16Ty(Context); break;
251 case 3: case 4:
252 case 5: t = Type::getFloatTy(Context); break;
253 case 6: case 7:
254 case 8: t = Type::getDoubleTy(Context); break;
255 case 9: case 10:
256 case 11: t = Type::getInt32Ty(Context); break;
257 case 12: case 13:
258 case 14: t = Type::getInt64Ty(Context); break;
259 case 15: case 16:
260 case 17: if (GenHalfFloat) t = Type::getHalfTy(Context); break;
261 case 18: case 19:
262 case 20: if (GenX86FP80) t = Type::getX86_FP80Ty(Context); break;
263 case 21: case 22:
264 case 23: if (GenFP128) t = Type::getFP128Ty(Context); break;
265 case 24: case 25:
266 case 26: if (GenPPCFP128) t = Type::getPPC_FP128Ty(Context); break;
267 case 27: case 28:
268 case 29: if (GenX86MMX) t = Type::getX86_MMXTy(Context); break;
269 default: llvm_unreachable("Invalid scalar value");
270 }
271 } while (t == nullptr);
272
273 return t;
269 static std::vector ScalarTypes;
270 if (ScalarTypes.empty()) {
271 ScalarTypes.assign({
272 Type::getInt1Ty(Context),
273 Type::getInt8Ty(Context),
274 Type::getInt16Ty(Context),
275 Type::getInt32Ty(Context),
276 Type::getInt64Ty(Context),
277 Type::getFloatTy(Context),
278 Type::getDoubleTy(Context)
279 });
280 ScalarTypes.insert(ScalarTypes.end(),
281 AdditionalScalarTypes.begin(), AdditionalScalarTypes.end());
282 }
283
284 return ScalarTypes[Ran->Rand() % ScalarTypes.size()];
274285 }
275286
276287 /// Basic block to populate
664675 }
665676 }
666677
678 }
679
667680 int main(int argc, char **argv) {
681 using namespace llvm;
682
668683 // Init LLVM, call llvm_shutdown() on exit, parse args, etc.
669684 llvm::PrettyStackTraceProgram X(argc, argv);
670685 cl::ParseCommandLineOptions(argc, argv, "llvm codegen stress-tester\n");