1*2cab237bSDimitry Andric //===-- OpDescriptor.cpp --------------------------------------------------===//
2*2cab237bSDimitry Andric //
3*2cab237bSDimitry Andric // The LLVM Compiler Infrastructure
4*2cab237bSDimitry Andric //
5*2cab237bSDimitry Andric // This file is distributed under the University of Illinois Open Source
6*2cab237bSDimitry Andric // License. See LICENSE.TXT for details.
7*2cab237bSDimitry Andric //
8*2cab237bSDimitry Andric //===----------------------------------------------------------------------===//
9*2cab237bSDimitry Andric
10*2cab237bSDimitry Andric #include "llvm/FuzzMutate/OpDescriptor.h"
11*2cab237bSDimitry Andric #include "llvm/IR/Constants.h"
12*2cab237bSDimitry Andric
13*2cab237bSDimitry Andric using namespace llvm;
14*2cab237bSDimitry Andric using namespace fuzzerop;
15*2cab237bSDimitry Andric
makeConstantsWithType(Type * T,std::vector<Constant * > & Cs)16*2cab237bSDimitry Andric void fuzzerop::makeConstantsWithType(Type *T, std::vector<Constant *> &Cs) {
17*2cab237bSDimitry Andric if (auto *IntTy = dyn_cast<IntegerType>(T)) {
18*2cab237bSDimitry Andric uint64_t W = IntTy->getBitWidth();
19*2cab237bSDimitry Andric Cs.push_back(ConstantInt::get(IntTy, APInt::getMaxValue(W)));
20*2cab237bSDimitry Andric Cs.push_back(ConstantInt::get(IntTy, APInt::getMinValue(W)));
21*2cab237bSDimitry Andric Cs.push_back(ConstantInt::get(IntTy, APInt::getSignedMaxValue(W)));
22*2cab237bSDimitry Andric Cs.push_back(ConstantInt::get(IntTy, APInt::getSignedMinValue(W)));
23*2cab237bSDimitry Andric Cs.push_back(ConstantInt::get(IntTy, APInt::getOneBitSet(W, W / 2)));
24*2cab237bSDimitry Andric } else if (T->isFloatingPointTy()) {
25*2cab237bSDimitry Andric auto &Ctx = T->getContext();
26*2cab237bSDimitry Andric auto &Sem = T->getFltSemantics();
27*2cab237bSDimitry Andric Cs.push_back(ConstantFP::get(Ctx, APFloat::getZero(Sem)));
28*2cab237bSDimitry Andric Cs.push_back(ConstantFP::get(Ctx, APFloat::getLargest(Sem)));
29*2cab237bSDimitry Andric Cs.push_back(ConstantFP::get(Ctx, APFloat::getSmallest(Sem)));
30*2cab237bSDimitry Andric } else
31*2cab237bSDimitry Andric Cs.push_back(UndefValue::get(T));
32*2cab237bSDimitry Andric }
33*2cab237bSDimitry Andric
makeConstantsWithType(Type * T)34*2cab237bSDimitry Andric std::vector<Constant *> fuzzerop::makeConstantsWithType(Type *T) {
35*2cab237bSDimitry Andric std::vector<Constant *> Result;
36*2cab237bSDimitry Andric makeConstantsWithType(T, Result);
37*2cab237bSDimitry Andric return Result;
38*2cab237bSDimitry Andric }
39