diff options
author | Nadav Rotem <nadav.rotem@intel.com> | 2012-02-26 13:56:18 +0000 |
---|---|---|
committer | Nadav Rotem <nadav.rotem@intel.com> | 2012-02-26 13:56:18 +0000 |
commit | bfb7dfa756ffa48d2c968ffcade3295938495b6e (patch) | |
tree | 9fb291dd86ee4cef27d0aadf2bdb1a5d42dee0d4 /tools | |
parent | 794c16ae856f827babb22f862f4e69118ad68b09 (diff) |
Add support for random constant vectors.
Patch by Joey Gouly.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@151489 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools')
-rw-r--r-- | tools/llvm-stress/llvm-stress.cpp | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/tools/llvm-stress/llvm-stress.cpp b/tools/llvm-stress/llvm-stress.cpp index f9bf18faa5..f2d65456b6 100644 --- a/tools/llvm-stress/llvm-stress.cpp +++ b/tools/llvm-stress/llvm-stress.cpp @@ -110,6 +110,19 @@ protected: return PT->at(Ran->Rand() % PT->size()); } + Constant *getRandomConstant(Type *Tp) { + if (Tp->isIntegerTy()) { + if (Ran->Rand() & 1) + return ConstantInt::getAllOnesValue(Tp); + return ConstantInt::getNullValue(Tp); + } else if (Tp->isFloatingPointTy()) { + if (Ran->Rand() & 1) + return ConstantFP::getAllOnesValue(Tp); + return ConstantFP::getNullValue(Tp); + } + return UndefValue::get(Tp); + } + /// Return a random value with a known type. Value *getRandomValue(Type *Tp) { unsigned index = Ran->Rand(); @@ -128,9 +141,18 @@ protected: if (Ran->Rand() & 1) return ConstantFP::getAllOnesValue(Tp); return ConstantFP::getNullValue(Tp); + } else if (Tp->isVectorTy()) { + VectorType *VTp = cast<VectorType>(Tp); + + std::vector<Constant*> TempValues; + TempValues.reserve(VTp->getNumElements()); + for (unsigned i = 0; i < VTp->getNumElements(); ++i) + TempValues.push_back(getRandomConstant(VTp->getScalarType())); + + ArrayRef<Constant*> VectorValue(TempValues); + return ConstantVector::get(VectorValue); } - // TODO: return values for vector types. return UndefValue::get(Tp); } |