LLVM 17.0.0git
OpDescriptor.cpp
Go to the documentation of this file.
1//===-- OpDescriptor.cpp --------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
10#include "llvm/IR/Constants.h"
11
12using namespace llvm;
13using namespace fuzzerop;
14
15void fuzzerop::makeConstantsWithType(Type *T, std::vector<Constant *> &Cs) {
16 if (auto *IntTy = dyn_cast<IntegerType>(T)) {
17 uint64_t W = IntTy->getBitWidth();
18 Cs.push_back(ConstantInt::get(IntTy, APInt::getMaxValue(W)));
19 Cs.push_back(ConstantInt::get(IntTy, APInt::getMinValue(W)));
20 Cs.push_back(ConstantInt::get(IntTy, APInt::getSignedMaxValue(W)));
21 Cs.push_back(ConstantInt::get(IntTy, APInt::getSignedMinValue(W)));
22 Cs.push_back(ConstantInt::get(IntTy, APInt::getOneBitSet(W, W / 2)));
23 } else if (T->isFloatingPointTy()) {
24 auto &Ctx = T->getContext();
25 auto &Sem = T->getFltSemantics();
26 Cs.push_back(ConstantFP::get(Ctx, APFloat::getZero(Sem)));
27 Cs.push_back(ConstantFP::get(Ctx, APFloat::getLargest(Sem)));
28 Cs.push_back(ConstantFP::get(Ctx, APFloat::getSmallest(Sem)));
29 } else
30 Cs.push_back(UndefValue::get(T));
31}
32
33std::vector<Constant *> fuzzerop::makeConstantsWithType(Type *T) {
34 std::vector<Constant *> Result;
35 makeConstantsWithType(T, Result);
36 return Result;
37}
This file contains the declarations for the subclasses of Constant, which represent the different fla...
static APFloat getLargest(const fltSemantics &Sem, bool Negative=false)
Returns the largest finite number in the given semantics.
Definition: APFloat.h:980
static APFloat getSmallest(const fltSemantics &Sem, bool Negative=false)
Returns the smallest (by magnitude) finite number in the given semantics.
Definition: APFloat.h:990
static APFloat getZero(const fltSemantics &Sem, bool Negative=false)
Factory for Positive and Negative Zero.
Definition: APFloat.h:931
static APInt getMaxValue(unsigned numBits)
Gets maximum unsigned value of APInt for specific bit width.
Definition: APInt.h:186
static APInt getSignedMaxValue(unsigned numBits)
Gets maximum signed value of APInt for a specific bit width.
Definition: APInt.h:189
static APInt getMinValue(unsigned numBits)
Gets minimum unsigned value of APInt for a specific bit width.
Definition: APInt.h:196
static APInt getSignedMinValue(unsigned numBits)
Gets minimum signed value of APInt for a specific bit width.
Definition: APInt.h:199
static APInt getOneBitSet(unsigned numBits, unsigned BitNo)
Return an APInt with exactly one bit set in the result.
Definition: APInt.h:222
static Constant * get(Type *Ty, double V)
This returns a ConstantFP, or a vector containing a splat of a ConstantFP, for the specified value in...
Definition: Constants.cpp:927
static Constant * get(Type *Ty, uint64_t V, bool IsSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
Definition: Constants.cpp:888
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
Definition: Constants.cpp:1731
void makeConstantsWithType(Type *T, std::vector< Constant * > &Cs)
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18