LLVM 24.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, 0));
19 Cs.push_back(ConstantInt::get(IntTy, 1));
20 Cs.push_back(ConstantInt::get(IntTy, 42, /*IsSigned=*/false,
21 /*ImplicitTrunc=*/true));
22 Cs.push_back(ConstantInt::get(IntTy, APInt::getMaxValue(W)));
23 Cs.push_back(ConstantInt::get(IntTy, APInt::getMinValue(W)));
24 Cs.push_back(ConstantInt::get(IntTy, APInt::getSignedMaxValue(W)));
25 Cs.push_back(ConstantInt::get(IntTy, APInt::getSignedMinValue(W)));
26 Cs.push_back(ConstantInt::get(IntTy, APInt::getOneBitSet(W, W / 2)));
27 } else if (T->isFloatingPointTy()) {
28 auto &Ctx = T->getContext();
29 auto &Sem = T->getFltSemantics();
30 Cs.push_back(ConstantFP::get(Ctx, APFloat::getZero(Sem)));
31 Cs.push_back(ConstantFP::get(Ctx, APFloat(Sem, 1)));
32 Cs.push_back(ConstantFP::get(Ctx, APFloat(Sem, 42)));
33 Cs.push_back(ConstantFP::get(Ctx, APFloat::getLargest(Sem)));
34 Cs.push_back(ConstantFP::get(Ctx, APFloat::getSmallest(Sem)));
35 Cs.push_back(ConstantFP::get(Ctx, APFloat::getInf(Sem)));
36 Cs.push_back(ConstantFP::get(Ctx, APFloat::getNaN(Sem)));
37 } else if (VectorType *VecTy = dyn_cast<VectorType>(T)) {
38 std::vector<Constant *> EleCs;
39 Type *EltTy = VecTy->getElementType();
40 makeConstantsWithType(EltTy, EleCs);
41 ElementCount EC = VecTy->getElementCount();
42 for (Constant *Elt : EleCs) {
43 Cs.push_back(ConstantVector::getSplat(EC, Elt));
44 }
45 } else {
46 Cs.push_back(PoisonValue::get(T));
47 }
48}
49
50std::vector<Constant *> fuzzerop::makeConstantsWithType(Type *T) {
51 std::vector<Constant *> Result;
52 makeConstantsWithType(T, Result);
53 return Result;
54}
This file contains the declarations for the subclasses of Constant, which represent the different fla...
#define T
static APFloat getLargest(const fltSemantics &Sem, bool Negative=false)
Returns the largest finite number in the given semantics.
Definition APFloat.h:1275
static APFloat getInf(const fltSemantics &Sem, bool Negative=false)
Factory for Positive and Negative Infinity.
Definition APFloat.h:1235
static APFloat getSmallest(const fltSemantics &Sem, bool Negative=false)
Returns the smallest (by magnitude) finite number in the given semantics.
Definition APFloat.h:1285
static APFloat getNaN(const fltSemantics &Sem, bool Negative=false, uint64_t payload=0)
Factory for NaN values.
Definition APFloat.h:1246
static APFloat getZero(const fltSemantics &Sem, bool Negative=false)
Factory for Positive and Negative Zero.
Definition APFloat.h:1216
static APInt getMaxValue(unsigned numBits)
Gets maximum unsigned value of APInt for specific bit width.
Definition APInt.h:202
static APInt getSignedMaxValue(unsigned numBits)
Gets maximum signed value of APInt for a specific bit width.
Definition APInt.h:205
static APInt getMinValue(unsigned numBits)
Gets minimum unsigned value of APInt for a specific bit width.
Definition APInt.h:212
static APInt getSignedMinValue(unsigned numBits)
Gets minimum signed value of APInt for a specific bit width.
Definition APInt.h:215
static APInt getOneBitSet(unsigned numBits, unsigned BitNo)
Return an APInt with exactly one bit set in the result.
Definition APInt.h:235
static LLVM_ABI Constant * getSplat(ElementCount EC, Constant *Elt)
Return a ConstantVector with the specified constant in each element.
This is an important base class in LLVM.
Definition Constant.h:44
static LLVM_ABI PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
Base class of all SIMD vector types.
LLVM_ABI void makeConstantsWithType(Type *T, std::vector< Constant * > &Cs)
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643