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