xref: /freebsd-src/contrib/llvm-project/llvm/include/llvm/IR/ConstantFold.h (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
181ad6265SDimitry Andric //==-- ConstantFold.h - DL-independent Constant Folding Interface -*- C++ -*-=//
281ad6265SDimitry Andric //
381ad6265SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
481ad6265SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
581ad6265SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
681ad6265SDimitry Andric //
781ad6265SDimitry Andric //===----------------------------------------------------------------------===//
881ad6265SDimitry Andric //
981ad6265SDimitry Andric // This file defines the DataLayout-independent constant folding interface.
1081ad6265SDimitry Andric // When possible, the DataLayout-aware constant folding interface in
1181ad6265SDimitry Andric // Analysis/ConstantFolding.h should be preferred.
1281ad6265SDimitry Andric //
1381ad6265SDimitry Andric // These interfaces are used by the ConstantExpr::get* methods to automatically
1481ad6265SDimitry Andric // fold constants when possible.
1581ad6265SDimitry Andric //
1681ad6265SDimitry Andric // These operators may return a null object if they don't know how to perform
1781ad6265SDimitry Andric // the specified operation on the specified constant types.
1881ad6265SDimitry Andric //
1981ad6265SDimitry Andric //===----------------------------------------------------------------------===//
2081ad6265SDimitry Andric 
2181ad6265SDimitry Andric #ifndef LLVM_IR_CONSTANTFOLD_H
2281ad6265SDimitry Andric #define LLVM_IR_CONSTANTFOLD_H
2381ad6265SDimitry Andric 
2481ad6265SDimitry Andric #include "llvm/IR/InstrTypes.h"
25bdd1243dSDimitry Andric #include <optional>
2681ad6265SDimitry Andric 
2781ad6265SDimitry Andric namespace llvm {
2881ad6265SDimitry Andric   template <typename T> class ArrayRef;
2981ad6265SDimitry Andric   class Value;
3081ad6265SDimitry Andric   class Constant;
3181ad6265SDimitry Andric   class Type;
3281ad6265SDimitry Andric 
3381ad6265SDimitry Andric   // Constant fold various types of instruction...
3481ad6265SDimitry Andric   Constant *ConstantFoldCastInstruction(
3581ad6265SDimitry Andric     unsigned opcode,     ///< The opcode of the cast
3681ad6265SDimitry Andric     Constant *V,         ///< The source constant
3781ad6265SDimitry Andric     Type *DestTy   ///< The destination type
3881ad6265SDimitry Andric   );
3981ad6265SDimitry Andric   Constant *ConstantFoldSelectInstruction(Constant *Cond,
4081ad6265SDimitry Andric                                           Constant *V1, Constant *V2);
4181ad6265SDimitry Andric   Constant *ConstantFoldExtractElementInstruction(Constant *Val, Constant *Idx);
4281ad6265SDimitry Andric   Constant *ConstantFoldInsertElementInstruction(Constant *Val, Constant *Elt,
4381ad6265SDimitry Andric                                                  Constant *Idx);
4481ad6265SDimitry Andric   Constant *ConstantFoldShuffleVectorInstruction(Constant *V1, Constant *V2,
4581ad6265SDimitry Andric                                                  ArrayRef<int> Mask);
4681ad6265SDimitry Andric   Constant *ConstantFoldExtractValueInstruction(Constant *Agg,
4781ad6265SDimitry Andric                                                 ArrayRef<unsigned> Idxs);
4881ad6265SDimitry Andric   Constant *ConstantFoldInsertValueInstruction(Constant *Agg, Constant *Val,
4981ad6265SDimitry Andric                                                ArrayRef<unsigned> Idxs);
5081ad6265SDimitry Andric   Constant *ConstantFoldUnaryInstruction(unsigned Opcode, Constant *V);
5181ad6265SDimitry Andric   Constant *ConstantFoldBinaryInstruction(unsigned Opcode, Constant *V1,
5281ad6265SDimitry Andric                                           Constant *V2);
5381ad6265SDimitry Andric   Constant *ConstantFoldCompareInstruction(CmpInst::Predicate Predicate,
5481ad6265SDimitry Andric                                            Constant *C1, Constant *C2);
55*0fca6ea1SDimitry Andric   Constant *ConstantFoldGetElementPtr(Type *Ty, Constant *C,
56*0fca6ea1SDimitry Andric                                       std::optional<ConstantRange> InRange,
5781ad6265SDimitry Andric                                       ArrayRef<Value *> Idxs);
5881ad6265SDimitry Andric } // End llvm namespace
5981ad6265SDimitry Andric 
6081ad6265SDimitry Andric #endif
61