17d449d31SJustin Bogner //===-- OpDescriptor.cpp --------------------------------------------------===//
27d449d31SJustin Bogner //
3*2946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*2946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
5*2946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
67d449d31SJustin Bogner //
77d449d31SJustin Bogner //===----------------------------------------------------------------------===//
87d449d31SJustin Bogner
97d449d31SJustin Bogner #include "llvm/FuzzMutate/OpDescriptor.h"
107d449d31SJustin Bogner #include "llvm/IR/Constants.h"
117d449d31SJustin Bogner
127d449d31SJustin Bogner using namespace llvm;
137d449d31SJustin Bogner using namespace fuzzerop;
147d449d31SJustin Bogner
makeConstantsWithType(Type * T,std::vector<Constant * > & Cs)157d449d31SJustin Bogner void fuzzerop::makeConstantsWithType(Type *T, std::vector<Constant *> &Cs) {
167d449d31SJustin Bogner if (auto *IntTy = dyn_cast<IntegerType>(T)) {
177d449d31SJustin Bogner uint64_t W = IntTy->getBitWidth();
187d449d31SJustin Bogner Cs.push_back(ConstantInt::get(IntTy, APInt::getMaxValue(W)));
197d449d31SJustin Bogner Cs.push_back(ConstantInt::get(IntTy, APInt::getMinValue(W)));
207d449d31SJustin Bogner Cs.push_back(ConstantInt::get(IntTy, APInt::getSignedMaxValue(W)));
217d449d31SJustin Bogner Cs.push_back(ConstantInt::get(IntTy, APInt::getSignedMinValue(W)));
227d449d31SJustin Bogner Cs.push_back(ConstantInt::get(IntTy, APInt::getOneBitSet(W, W / 2)));
237d449d31SJustin Bogner } else if (T->isFloatingPointTy()) {
247d449d31SJustin Bogner auto &Ctx = T->getContext();
257d449d31SJustin Bogner auto &Sem = T->getFltSemantics();
267d449d31SJustin Bogner Cs.push_back(ConstantFP::get(Ctx, APFloat::getZero(Sem)));
277d449d31SJustin Bogner Cs.push_back(ConstantFP::get(Ctx, APFloat::getLargest(Sem)));
287d449d31SJustin Bogner Cs.push_back(ConstantFP::get(Ctx, APFloat::getSmallest(Sem)));
297d449d31SJustin Bogner } else
307d449d31SJustin Bogner Cs.push_back(UndefValue::get(T));
317d449d31SJustin Bogner }
327d449d31SJustin Bogner
makeConstantsWithType(Type * T)337d449d31SJustin Bogner std::vector<Constant *> fuzzerop::makeConstantsWithType(Type *T) {
347d449d31SJustin Bogner std::vector<Constant *> Result;
357d449d31SJustin Bogner makeConstantsWithType(T, Result);
367d449d31SJustin Bogner return Result;
377d449d31SJustin Bogner }
38