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 "llvm/Support/Compiler.h" 26 #include <optional> 27 28 namespace llvm { 29 template <typename T> class ArrayRef; 30 class Value; 31 class Constant; 32 class Type; 33 34 // Constant fold various types of instruction... 35 LLVM_ABI Constant * 36 ConstantFoldCastInstruction(unsigned opcode, ///< The opcode of the cast 37 Constant *V, ///< The source constant 38 Type *DestTy ///< The destination type 39 ); 40 LLVM_ABI Constant *ConstantFoldSelectInstruction(Constant *Cond, Constant *V1, 41 Constant *V2); 42 LLVM_ABI Constant *ConstantFoldExtractElementInstruction(Constant *Val, 43 Constant *Idx); 44 LLVM_ABI Constant *ConstantFoldInsertElementInstruction(Constant *Val, 45 Constant *Elt, 46 Constant *Idx); 47 LLVM_ABI Constant *ConstantFoldShuffleVectorInstruction(Constant *V1, 48 Constant *V2, 49 ArrayRef<int> Mask); 50 LLVM_ABI Constant * 51 ConstantFoldExtractValueInstruction(Constant *Agg, ArrayRef<unsigned> Idxs); 52 LLVM_ABI Constant * 53 ConstantFoldInsertValueInstruction(Constant *Agg, Constant *Val, 54 ArrayRef<unsigned> Idxs); 55 LLVM_ABI Constant *ConstantFoldUnaryInstruction(unsigned Opcode, Constant *V); 56 LLVM_ABI Constant *ConstantFoldBinaryInstruction(unsigned Opcode, 57 Constant *V1, Constant *V2); 58 LLVM_ABI Constant * 59 ConstantFoldCompareInstruction(CmpInst::Predicate Predicate, Constant *C1, 60 Constant *C2); 61 LLVM_ABI Constant * 62 ConstantFoldGetElementPtr(Type *Ty, Constant *C, 63 std::optional<ConstantRange> InRange, 64 ArrayRef<Value *> Idxs); 65 } // End llvm namespace 66 67 #endif 68