LLVM  6.0.0svn
VNCoercion.h
Go to the documentation of this file.
1 //===- VNCoercion.h - Value Numbering Coercion Utilities --------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 /// \file / This file provides routines used by LLVM's value numbering passes to
10 /// perform various forms of value extraction from memory when the types are not
11 /// identical. For example, given
12 ///
13 /// store i32 8, i32 *%foo
14 /// %a = bitcast i32 *%foo to i16
15 /// %val = load i16, i16 *%a
16 ///
17 /// It possible to extract the value of the load of %a from the store to %foo.
18 /// These routines know how to tell whether they can do that (the analyze*
19 /// routines), and can also insert the necessary IR to do it (the get*
20 /// routines).
21 
22 #ifndef LLVM_TRANSFORMS_UTILS_VNCOERCION_H
23 #define LLVM_TRANSFORMS_UTILS_VNCOERCION_H
24 #include "llvm/IR/IRBuilder.h"
25 
26 namespace llvm {
27 class Function;
28 class StoreInst;
29 class LoadInst;
30 class MemIntrinsic;
31 class Instruction;
32 class Value;
33 class Type;
34 class DataLayout;
35 namespace VNCoercion {
36 /// Return true if CoerceAvailableValueToLoadType would succeed if it was
37 /// called.
38 bool canCoerceMustAliasedValueToLoad(Value *StoredVal, Type *LoadTy,
39  const DataLayout &DL);
40 
41 /// If we saw a store of a value to memory, and then a load from a must-aliased
42 /// pointer of a different type, try to coerce the stored value to the loaded
43 /// type. LoadedTy is the type of the load we want to replace. IRB is
44 /// IRBuilder used to insert new instructions.
45 ///
46 /// If we can't do it, return null.
47 Value *coerceAvailableValueToLoadType(Value *StoredVal, Type *LoadedTy,
48  IRBuilder<> &IRB, const DataLayout &DL);
49 
50 /// This function determines whether a value for the pointer LoadPtr can be
51 /// extracted from the store at DepSI.
52 ///
53 /// On success, it returns the offset into DepSI that extraction would start.
54 /// On failure, it returns -1.
55 int analyzeLoadFromClobberingStore(Type *LoadTy, Value *LoadPtr,
56  StoreInst *DepSI, const DataLayout &DL);
57 
58 /// This function determines whether a value for the pointer LoadPtr can be
59 /// extracted from the load at DepLI.
60 ///
61 /// On success, it returns the offset into DepLI that extraction would start.
62 /// On failure, it returns -1.
63 int analyzeLoadFromClobberingLoad(Type *LoadTy, Value *LoadPtr, LoadInst *DepLI,
64  const DataLayout &DL);
65 
66 /// This function determines whether a value for the pointer LoadPtr can be
67 /// extracted from the memory intrinsic at DepMI.
68 ///
69 /// On success, it returns the offset into DepMI that extraction would start.
70 /// On failure, it returns -1.
71 int analyzeLoadFromClobberingMemInst(Type *LoadTy, Value *LoadPtr,
72  MemIntrinsic *DepMI, const DataLayout &DL);
73 
74 /// If analyzeLoadFromClobberingStore returned an offset, this function can be
75 /// used to actually perform the extraction of the bits from the store. It
76 /// inserts instructions to do so at InsertPt, and returns the extracted value.
77 Value *getStoreValueForLoad(Value *SrcVal, unsigned Offset, Type *LoadTy,
78  Instruction *InsertPt, const DataLayout &DL);
79 // This is the same as getStoreValueForLoad, except it performs no insertion
80 // It only allows constant inputs.
81 Constant *getConstantStoreValueForLoad(Constant *SrcVal, unsigned Offset,
82  Type *LoadTy, const DataLayout &DL);
83 
84 /// If analyzeLoadFromClobberingLoad returned an offset, this function can be
85 /// used to actually perform the extraction of the bits from the load, including
86 /// any necessary load widening. It inserts instructions to do so at InsertPt,
87 /// and returns the extracted value.
88 Value *getLoadValueForLoad(LoadInst *SrcVal, unsigned Offset, Type *LoadTy,
89  Instruction *InsertPt, const DataLayout &DL);
90 // This is the same as getLoadValueForLoad, except it is given the load value as
91 // a constant. It returns nullptr if it would require widening the load.
92 Constant *getConstantLoadValueForLoad(Constant *SrcVal, unsigned Offset,
93  Type *LoadTy, const DataLayout &DL);
94 
95 /// If analyzeLoadFromClobberingMemInst returned an offset, this function can be
96 /// used to actually perform the extraction of the bits from the memory
97 /// intrinsic. It inserts instructions to do so at InsertPt, and returns the
98 /// extracted value.
99 Value *getMemInstValueForLoad(MemIntrinsic *SrcInst, unsigned Offset,
100  Type *LoadTy, Instruction *InsertPt,
101  const DataLayout &DL);
102 // This is the same as getStoreValueForLoad, except it performs no insertion.
103 // It returns nullptr if it cannot produce a constant.
104 Constant *getConstantMemInstValueForLoad(MemIntrinsic *SrcInst, unsigned Offset,
105  Type *LoadTy, const DataLayout &DL);
106 }
107 }
108 #endif
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:109
int analyzeLoadFromClobberingLoad(Type *LoadTy, Value *LoadPtr, LoadInst *DepLI, const DataLayout &DL)
This function determines whether a value for the pointer LoadPtr can be extracted from the load at De...
Definition: VNCoercion.cpp:219
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
An instruction for reading from memory.
Definition: Instructions.h:164
Constant * getConstantMemInstValueForLoad(MemIntrinsic *SrcInst, unsigned Offset, Type *LoadTy, const DataLayout &DL)
Definition: VNCoercion.cpp:483
Value * getMemInstValueForLoad(MemIntrinsic *SrcInst, unsigned Offset, Type *LoadTy, Instruction *InsertPt, const DataLayout &DL)
If analyzeLoadFromClobberingMemInst returned an offset, this function can be used to actually perform...
Definition: VNCoercion.cpp:475
Value * coerceAvailableValueToLoadType(Value *StoredVal, Type *LoadedTy, IRBuilder<> &IRB, const DataLayout &DL)
If we saw a store of a value to memory, and then a load from a must-aliased pointer of a different ty...
Definition: VNCoercion.cpp:134
int analyzeLoadFromClobberingMemInst(Type *LoadTy, Value *LoadPtr, MemIntrinsic *DepMI, const DataLayout &DL)
This function determines whether a value for the pointer LoadPtr can be extracted from the memory int...
Definition: VNCoercion.cpp:251
Constant * getConstantStoreValueForLoad(Constant *SrcVal, unsigned Offset, Type *LoadTy, const DataLayout &DL)
Definition: VNCoercion.cpp:351
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Definition: IRBuilder.h:664
bool canCoerceMustAliasedValueToLoad(Value *StoredVal, Type *LoadTy, const DataLayout &DL)
Return true if CoerceAvailableValueToLoadType would succeed if it was called.
Definition: VNCoercion.cpp:15
An instruction for storing to memory.
Definition: Instructions.h:306
int analyzeLoadFromClobberingStore(Type *LoadTy, Value *LoadPtr, StoreInst *DepSI, const DataLayout &DL)
This function determines whether a value for the pointer LoadPtr can be extracted from the store at D...
Definition: VNCoercion.cpp:202
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
This is an important base class in LLVM.
Definition: Constant.h:42
Constant * getConstantLoadValueForLoad(Constant *SrcVal, unsigned Offset, Type *LoadTy, const DataLayout &DL)
Definition: VNCoercion.cpp:409
Value * getLoadValueForLoad(LoadInst *SrcVal, unsigned Offset, Type *LoadTy, Instruction *InsertPt, const DataLayout &DL)
If analyzeLoadFromClobberingLoad returned an offset, this function can be used to actually perform th...
Definition: VNCoercion.cpp:363
This is the common base class for memset/memcpy/memmove.
Value * getStoreValueForLoad(Value *SrcVal, unsigned Offset, Type *LoadTy, Instruction *InsertPt, const DataLayout &DL)
If analyzeLoadFromClobberingStore returned an offset, this function can be used to actually perform t...
Definition: VNCoercion.cpp:343
LLVM Value Representation.
Definition: Value.h:73