blob: b57153bf00b01196fa7157ca4134b3c298a29798 [file] [log] [blame]
Chris Lattner5a945e32004-01-12 21:13:12 +00001//===-- ConstantFolding.h - Internal Constant Folding Interface -*- C++ -*-===//
Misha Brukmanb1c93172005-04-21 23:48:37 +00002//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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
Misha Brukmanb1c93172005-04-21 23:48:37 +00006//
John Criswellb6445982003-10-20 20:19:47 +00007//===----------------------------------------------------------------------===//
Chris Lattner2f7c9632001-06-06 20:29:01 +00008//
Chris Lattner5a945e32004-01-12 21:13:12 +00009// This file defines the (internal) constant folding interfaces for LLVM. These
10// interfaces are used by the ConstantExpr::get* methods to automatically fold
11// constants when possible.
12//
Duncan Sandsc1e48b52008-08-01 12:23:49 +000013// These operators may return a null object if they don't know how to perform
14// the specified operation on the specified constant types.
Chris Lattner2f7c9632001-06-06 20:29:01 +000015//
16//===----------------------------------------------------------------------===//
Chris Lattner2f7c9632001-06-06 20:29:01 +000017
Benjamin Kramera7c40ef2014-08-13 16:26:38 +000018#ifndef LLVM_LIB_IR_CONSTANTFOLD_H
19#define LLVM_LIB_IR_CONSTANTFOLD_H
Chris Lattner2f7c9632001-06-06 20:29:01 +000020
Peter Collingbourned93620b2016-11-10 22:34:55 +000021#include "llvm/ADT/Optional.h"
22
Brian Gaeke960707c2003-11-11 22:41:34 +000023namespace llvm {
Mehdi Aminib550cb12016-04-18 09:17:29 +000024template <typename T> class ArrayRef;
Chris Lattner13128ab2004-10-11 22:52:25 +000025 class Value;
Chris Lattner6ff6cea2004-01-12 21:02:29 +000026 class Constant;
Chris Lattner7dfc2d22004-10-27 16:14:51 +000027 class Type;
Misha Brukmanb1c93172005-04-21 23:48:37 +000028
Chris Lattner5a945e32004-01-12 21:13:12 +000029 // Constant fold various types of instruction...
Reid Spencer6c38f0b2006-11-27 01:05:10 +000030 Constant *ConstantFoldCastInstruction(
31 unsigned opcode, ///< The opcode of the cast
Nick Lewyckye0332982009-09-20 01:35:59 +000032 Constant *V, ///< The source constant
Chris Lattner229907c2011-07-18 04:54:35 +000033 Type *DestTy ///< The destination type
Reid Spencer6c38f0b2006-11-27 01:05:10 +000034 );
Chris Lattnerf5edeeb2010-02-01 20:48:08 +000035 Constant *ConstantFoldSelectInstruction(Constant *Cond,
Nick Lewyckye0332982009-09-20 01:35:59 +000036 Constant *V1, Constant *V2);
Chris Lattnerf5edeeb2010-02-01 20:48:08 +000037 Constant *ConstantFoldExtractElementInstruction(Constant *Val, Constant *Idx);
38 Constant *ConstantFoldInsertElementInstruction(Constant *Val, Constant *Elt,
Nick Lewyckye0332982009-09-20 01:35:59 +000039 Constant *Idx);
Chris Lattnerf5edeeb2010-02-01 20:48:08 +000040 Constant *ConstantFoldShuffleVectorInstruction(Constant *V1, Constant *V2,
Nick Lewyckye0332982009-09-20 01:35:59 +000041 Constant *Mask);
Chris Lattnerf5edeeb2010-02-01 20:48:08 +000042 Constant *ConstantFoldExtractValueInstruction(Constant *Agg,
Jay Foad57aa6362011-07-13 10:26:04 +000043 ArrayRef<unsigned> Idxs);
Chris Lattnerf5edeeb2010-02-01 20:48:08 +000044 Constant *ConstantFoldInsertValueInstruction(Constant *Agg, Constant *Val,
Jay Foad57aa6362011-07-13 10:26:04 +000045 ArrayRef<unsigned> Idxs);
Chris Lattnerf5edeeb2010-02-01 20:48:08 +000046 Constant *ConstantFoldBinaryInstruction(unsigned Opcode, Constant *V1,
Nick Lewyckye0332982009-09-20 01:35:59 +000047 Constant *V2);
Junmo Park5ac1a472016-03-22 04:37:32 +000048 Constant *ConstantFoldCompareInstruction(unsigned short predicate,
Nick Lewyckye0332982009-09-20 01:35:59 +000049 Constant *C1, Constant *C2);
Peter Collingbourned93620b2016-11-10 22:34:55 +000050 Constant *ConstantFoldGetElementPtr(Type *Ty, Constant *C, bool InBounds,
51 Optional<unsigned> InRangeIndex,
David Blaikied9d900c2015-05-07 17:28:58 +000052 ArrayRef<Value *> Idxs);
Alexander Kornienkof00654e2015-06-23 09:49:53 +000053} // End llvm namespace
Brian Gaeke960707c2003-11-11 22:41:34 +000054
Chris Lattner2f7c9632001-06-06 20:29:01 +000055#endif