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