blob: afa997876721329ec348f3316b374520ccf13f56 [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
Chris Lattner5a945e32004-01-12 21:13:12 +000019#ifndef CONSTANTFOLDING_H
20#define CONSTANTFOLDING_H
Chris Lattner2f7c9632001-06-06 20:29:01 +000021
Brian Gaeke960707c2003-11-11 22:41:34 +000022namespace llvm {
Chris Lattner13128ab2004-10-11 22:52:25 +000023 class Value;
Chris Lattner6ff6cea2004-01-12 21:02:29 +000024 class Constant;
Chris Lattner7dfc2d22004-10-27 16:14:51 +000025 class Type;
Owen Anderson53a52212009-07-13 04:09:18 +000026 class LLVMContext;
Misha Brukmanb1c93172005-04-21 23:48:37 +000027
Chris Lattner5a945e32004-01-12 21:13:12 +000028 // Constant fold various types of instruction...
Reid Spencer6c38f0b2006-11-27 01:05:10 +000029 Constant *ConstantFoldCastInstruction(
Owen Anderson53a52212009-07-13 04:09:18 +000030 LLVMContext &Context,
Reid Spencer6c38f0b2006-11-27 01:05:10 +000031 unsigned opcode, ///< The opcode of the cast
32 const Constant *V, ///< The source constant
Owen Anderson2cda7d72009-06-20 00:26:26 +000033 const Type *DestTy ///< The destination type
Reid Spencer6c38f0b2006-11-27 01:05:10 +000034 );
Owen Anderson53a52212009-07-13 04:09:18 +000035 Constant *ConstantFoldSelectInstruction(LLVMContext &Context,
36 const Constant *Cond,
Chris Lattner16375e32004-03-12 05:53:41 +000037 const Constant *V1,
Owen Anderson2cda7d72009-06-20 00:26:26 +000038 const Constant *V2);
Owen Anderson53a52212009-07-13 04:09:18 +000039 Constant *ConstantFoldExtractElementInstruction(LLVMContext &Context,
40 const Constant *Val,
Robert Bocchinode7f1c92006-01-10 20:03:46 +000041 const Constant *Idx);
Owen Anderson53a52212009-07-13 04:09:18 +000042 Constant *ConstantFoldInsertElementInstruction(LLVMContext &Context,
43 const Constant *Val,
Robert Bocchinoca27f032006-01-17 20:07:22 +000044 const Constant *Elt,
45 const Constant *Idx);
Owen Anderson53a52212009-07-13 04:09:18 +000046 Constant *ConstantFoldShuffleVectorInstruction(LLVMContext &Context,
47 const Constant *V1,
Chris Lattnerbbe0a422006-04-08 01:18:18 +000048 const Constant *V2,
49 const Constant *Mask);
Owen Anderson53a52212009-07-13 04:09:18 +000050 Constant *ConstantFoldExtractValueInstruction(LLVMContext &Context,
51 const Constant *Agg,
Dan Gohman3db11c22008-06-03 00:15:20 +000052 const unsigned *Idxs,
53 unsigned NumIdx);
Owen Anderson53a52212009-07-13 04:09:18 +000054 Constant *ConstantFoldInsertValueInstruction(LLVMContext &Context,
55 const Constant *Agg,
Dan Gohman3db11c22008-06-03 00:15:20 +000056 const Constant *Val,
57 const unsigned* Idxs,
58 unsigned NumIdx);
Owen Anderson53a52212009-07-13 04:09:18 +000059 Constant *ConstantFoldBinaryInstruction(LLVMContext &Context,
60 unsigned Opcode, const Constant *V1,
Owen Anderson2cda7d72009-06-20 00:26:26 +000061 const Constant *V2);
Owen Anderson53a52212009-07-13 04:09:18 +000062 Constant *ConstantFoldCompareInstruction(LLVMContext &Context,
63 unsigned short predicate,
Reid Spencer9d36acf2006-12-24 18:52:08 +000064 const Constant *C1,
65 const Constant *C2);
Owen Anderson53a52212009-07-13 04:09:18 +000066 Constant *ConstantFoldGetElementPtr(LLVMContext &Context, const Constant *C,
Owen Anderson2cda7d72009-06-20 00:26:26 +000067 Constant* const *Idxs, unsigned NumIdx);
Brian Gaeke960707c2003-11-11 22:41:34 +000068} // End llvm namespace
69
Chris Lattner2f7c9632001-06-06 20:29:01 +000070#endif