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