1*0b57cec5SDimitry Andric //===-- OpDescriptor.cpp --------------------------------------------------===//
2*0b57cec5SDimitry Andric //
3*0b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*0b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5*0b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*0b57cec5SDimitry Andric //
7*0b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
8*0b57cec5SDimitry Andric
9*0b57cec5SDimitry Andric #include "llvm/FuzzMutate/OpDescriptor.h"
10*0b57cec5SDimitry Andric #include "llvm/IR/Constants.h"
11*0b57cec5SDimitry Andric
12*0b57cec5SDimitry Andric using namespace llvm;
13*0b57cec5SDimitry Andric using namespace fuzzerop;
14*0b57cec5SDimitry Andric
makeConstantsWithType(Type * T,std::vector<Constant * > & Cs)15*0b57cec5SDimitry Andric void fuzzerop::makeConstantsWithType(Type *T, std::vector<Constant *> &Cs) {
16*0b57cec5SDimitry Andric if (auto *IntTy = dyn_cast<IntegerType>(T)) {
17*0b57cec5SDimitry Andric uint64_t W = IntTy->getBitWidth();
18*0b57cec5SDimitry Andric Cs.push_back(ConstantInt::get(IntTy, APInt::getMaxValue(W)));
19*0b57cec5SDimitry Andric Cs.push_back(ConstantInt::get(IntTy, APInt::getMinValue(W)));
20*0b57cec5SDimitry Andric Cs.push_back(ConstantInt::get(IntTy, APInt::getSignedMaxValue(W)));
21*0b57cec5SDimitry Andric Cs.push_back(ConstantInt::get(IntTy, APInt::getSignedMinValue(W)));
22*0b57cec5SDimitry Andric Cs.push_back(ConstantInt::get(IntTy, APInt::getOneBitSet(W, W / 2)));
23*0b57cec5SDimitry Andric } else if (T->isFloatingPointTy()) {
24*0b57cec5SDimitry Andric auto &Ctx = T->getContext();
25*0b57cec5SDimitry Andric auto &Sem = T->getFltSemantics();
26*0b57cec5SDimitry Andric Cs.push_back(ConstantFP::get(Ctx, APFloat::getZero(Sem)));
27*0b57cec5SDimitry Andric Cs.push_back(ConstantFP::get(Ctx, APFloat::getLargest(Sem)));
28*0b57cec5SDimitry Andric Cs.push_back(ConstantFP::get(Ctx, APFloat::getSmallest(Sem)));
29*0b57cec5SDimitry Andric } else
30*0b57cec5SDimitry Andric Cs.push_back(UndefValue::get(T));
31*0b57cec5SDimitry Andric }
32*0b57cec5SDimitry Andric
makeConstantsWithType(Type * T)33*0b57cec5SDimitry Andric std::vector<Constant *> fuzzerop::makeConstantsWithType(Type *T) {
34*0b57cec5SDimitry Andric std::vector<Constant *> Result;
35*0b57cec5SDimitry Andric makeConstantsWithType(T, Result);
36*0b57cec5SDimitry Andric return Result;
37*0b57cec5SDimitry Andric }
38