1*81ad6265SDimitry Andric //==-- ConstantFold.h - DL-independent Constant Folding Interface -*- C++ -*-=// 2*81ad6265SDimitry Andric // 3*81ad6265SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*81ad6265SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 5*81ad6265SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*81ad6265SDimitry Andric // 7*81ad6265SDimitry Andric //===----------------------------------------------------------------------===// 8*81ad6265SDimitry Andric // 9*81ad6265SDimitry Andric // This file defines the DataLayout-independent constant folding interface. 10*81ad6265SDimitry Andric // When possible, the DataLayout-aware constant folding interface in 11*81ad6265SDimitry Andric // Analysis/ConstantFolding.h should be preferred. 12*81ad6265SDimitry Andric // 13*81ad6265SDimitry Andric // These interfaces are used by the ConstantExpr::get* methods to automatically 14*81ad6265SDimitry Andric // fold constants when possible. 15*81ad6265SDimitry Andric // 16*81ad6265SDimitry Andric // These operators may return a null object if they don't know how to perform 17*81ad6265SDimitry Andric // the specified operation on the specified constant types. 18*81ad6265SDimitry Andric // 19*81ad6265SDimitry Andric //===----------------------------------------------------------------------===// 20*81ad6265SDimitry Andric 21*81ad6265SDimitry Andric #ifndef LLVM_IR_CONSTANTFOLD_H 22*81ad6265SDimitry Andric #define LLVM_IR_CONSTANTFOLD_H 23*81ad6265SDimitry Andric 24*81ad6265SDimitry Andric #include "llvm/ADT/Optional.h" 25*81ad6265SDimitry Andric #include "llvm/IR/InstrTypes.h" 26*81ad6265SDimitry Andric 27*81ad6265SDimitry Andric namespace llvm { 28*81ad6265SDimitry Andric template <typename T> class ArrayRef; 29*81ad6265SDimitry Andric class Value; 30*81ad6265SDimitry Andric class Constant; 31*81ad6265SDimitry Andric class Type; 32*81ad6265SDimitry Andric 33*81ad6265SDimitry Andric // Constant fold various types of instruction... 34*81ad6265SDimitry Andric Constant *ConstantFoldCastInstruction( 35*81ad6265SDimitry Andric unsigned opcode, ///< The opcode of the cast 36*81ad6265SDimitry Andric Constant *V, ///< The source constant 37*81ad6265SDimitry Andric Type *DestTy ///< The destination type 38*81ad6265SDimitry Andric ); 39*81ad6265SDimitry Andric Constant *ConstantFoldSelectInstruction(Constant *Cond, 40*81ad6265SDimitry Andric Constant *V1, Constant *V2); 41*81ad6265SDimitry Andric Constant *ConstantFoldExtractElementInstruction(Constant *Val, Constant *Idx); 42*81ad6265SDimitry Andric Constant *ConstantFoldInsertElementInstruction(Constant *Val, Constant *Elt, 43*81ad6265SDimitry Andric Constant *Idx); 44*81ad6265SDimitry Andric Constant *ConstantFoldShuffleVectorInstruction(Constant *V1, Constant *V2, 45*81ad6265SDimitry Andric ArrayRef<int> Mask); 46*81ad6265SDimitry Andric Constant *ConstantFoldExtractValueInstruction(Constant *Agg, 47*81ad6265SDimitry Andric ArrayRef<unsigned> Idxs); 48*81ad6265SDimitry Andric Constant *ConstantFoldInsertValueInstruction(Constant *Agg, Constant *Val, 49*81ad6265SDimitry Andric ArrayRef<unsigned> Idxs); 50*81ad6265SDimitry Andric Constant *ConstantFoldUnaryInstruction(unsigned Opcode, Constant *V); 51*81ad6265SDimitry Andric Constant *ConstantFoldBinaryInstruction(unsigned Opcode, Constant *V1, 52*81ad6265SDimitry Andric Constant *V2); 53*81ad6265SDimitry Andric Constant *ConstantFoldCompareInstruction(CmpInst::Predicate Predicate, 54*81ad6265SDimitry Andric Constant *C1, Constant *C2); 55*81ad6265SDimitry Andric Constant *ConstantFoldGetElementPtr(Type *Ty, Constant *C, bool InBounds, 56*81ad6265SDimitry Andric Optional<unsigned> InRangeIndex, 57*81ad6265SDimitry Andric ArrayRef<Value *> Idxs); 58*81ad6265SDimitry Andric } // End llvm namespace 59*81ad6265SDimitry Andric 60*81ad6265SDimitry Andric #endif 61