LLVM  6.0.0svn
OpDescriptor.cpp
Go to the documentation of this file.
1 //===-- OpDescriptor.cpp --------------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
11 #include "llvm/IR/Constants.h"
12 
13 using namespace llvm;
14 using namespace fuzzerop;
15 
16 void fuzzerop::makeConstantsWithType(Type *T, std::vector<Constant *> &Cs) {
17  if (auto *IntTy = dyn_cast<IntegerType>(T)) {
18  uint64_t W = IntTy->getBitWidth();
19  Cs.push_back(ConstantInt::get(IntTy, APInt::getMaxValue(W)));
20  Cs.push_back(ConstantInt::get(IntTy, APInt::getMinValue(W)));
21  Cs.push_back(ConstantInt::get(IntTy, APInt::getSignedMaxValue(W)));
22  Cs.push_back(ConstantInt::get(IntTy, APInt::getSignedMinValue(W)));
23  Cs.push_back(ConstantInt::get(IntTy, APInt::getOneBitSet(W, W / 2)));
24  } else if (T->isFloatingPointTy()) {
25  auto &Ctx = T->getContext();
26  auto &Sem = T->getFltSemantics();
27  Cs.push_back(ConstantFP::get(Ctx, APFloat::getZero(Sem)));
28  Cs.push_back(ConstantFP::get(Ctx, APFloat::getLargest(Sem)));
29  Cs.push_back(ConstantFP::get(Ctx, APFloat::getSmallest(Sem)));
30  } else
31  Cs.push_back(UndefValue::get(T));
32 }
33 
34 std::vector<Constant *> fuzzerop::makeConstantsWithType(Type *T) {
35  std::vector<Constant *> Result;
36  makeConstantsWithType(T, Result);
37  return Result;
38 }
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
static APFloat getZero(const fltSemantics &Sem, bool Negative=false)
Factory for Positive and Negative Zero.
Definition: APFloat.h:855
static APInt getSignedMaxValue(unsigned numBits)
Gets maximum signed value of APInt for a specific bit width.
Definition: APInt.h:528
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
Definition: Type.h:130
static APFloat getSmallest(const fltSemantics &Sem, bool Negative=false)
Returns the smallest (by magnitude) finite number in the given semantics.
Definition: APFloat.h:914
bool isFloatingPointTy() const
Return true if this is one of the six floating-point types.
Definition: Type.h:162
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
This file contains the declarations for the subclasses of Constant, which represent the different fla...
static APInt getOneBitSet(unsigned numBits, unsigned BitNo)
Return an APInt with exactly one bit set in the result.
Definition: APInt.h:581
void makeConstantsWithType(Type *T, std::vector< Constant *> &Cs)
static UndefValue * get(Type *T)
Static factory methods - Return an &#39;undef&#39; object of the specified type.
Definition: Constants.cpp:1320
static APInt getMinValue(unsigned numBits)
Gets minimum unsigned value of APInt for a specific bit width.
Definition: APInt.h:535
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:560
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:623
static APInt getMaxValue(unsigned numBits)
Gets maximum unsigned value of APInt for specific bit width.
Definition: APInt.h:523
static APFloat getLargest(const fltSemantics &Sem, bool Negative=false)
Returns the largest finite number in the given semantics.
Definition: APFloat.h:904
static APInt getSignedMinValue(unsigned numBits)
Gets minimum signed value of APInt for a specific bit width.
Definition: APInt.h:538
const fltSemantics & getFltSemantics() const
Definition: Type.h:169