Path: blob/main/contrib/llvm-project/llvm/lib/FuzzMutate/OpDescriptor.cpp
35233 views
//===-- OpDescriptor.cpp --------------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "llvm/FuzzMutate/OpDescriptor.h"9#include "llvm/IR/Constants.h"10#include "llvm/Support/CommandLine.h"1112using namespace llvm;13using namespace fuzzerop;1415static cl::opt<bool> UseUndef("use-undef",16cl::desc("Use undef when generating programs."),17cl::init(false));1819void fuzzerop::makeConstantsWithType(Type *T, std::vector<Constant *> &Cs) {20if (auto *IntTy = dyn_cast<IntegerType>(T)) {21uint64_t W = IntTy->getBitWidth();22Cs.push_back(ConstantInt::get(IntTy, 0));23Cs.push_back(ConstantInt::get(IntTy, 1));24Cs.push_back(ConstantInt::get(IntTy, 42));25Cs.push_back(ConstantInt::get(IntTy, APInt::getMaxValue(W)));26Cs.push_back(ConstantInt::get(IntTy, APInt::getMinValue(W)));27Cs.push_back(ConstantInt::get(IntTy, APInt::getSignedMaxValue(W)));28Cs.push_back(ConstantInt::get(IntTy, APInt::getSignedMinValue(W)));29Cs.push_back(ConstantInt::get(IntTy, APInt::getOneBitSet(W, W / 2)));30} else if (T->isFloatingPointTy()) {31auto &Ctx = T->getContext();32auto &Sem = T->getFltSemantics();33Cs.push_back(ConstantFP::get(Ctx, APFloat::getZero(Sem)));34Cs.push_back(ConstantFP::get(Ctx, APFloat(Sem, 1)));35Cs.push_back(ConstantFP::get(Ctx, APFloat(Sem, 42)));36Cs.push_back(ConstantFP::get(Ctx, APFloat::getLargest(Sem)));37Cs.push_back(ConstantFP::get(Ctx, APFloat::getSmallest(Sem)));38Cs.push_back(ConstantFP::get(Ctx, APFloat::getInf(Sem)));39Cs.push_back(ConstantFP::get(Ctx, APFloat::getNaN(Sem)));40} else if (VectorType *VecTy = dyn_cast<VectorType>(T)) {41std::vector<Constant *> EleCs;42Type *EltTy = VecTy->getElementType();43makeConstantsWithType(EltTy, EleCs);44ElementCount EC = VecTy->getElementCount();45for (Constant *Elt : EleCs) {46Cs.push_back(ConstantVector::getSplat(EC, Elt));47}48} else {49if (UseUndef)50Cs.push_back(UndefValue::get(T));51Cs.push_back(PoisonValue::get(T));52}53}5455std::vector<Constant *> fuzzerop::makeConstantsWithType(Type *T) {56std::vector<Constant *> Result;57makeConstantsWithType(T, Result);58return Result;59}606162