LLVM 23.0.0git
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///
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//===----------------------------------------------------------------------===//
23
24#ifndef LLVM_TRANSFORMS_UTILS_VNCOERCION_H
25#define LLVM_TRANSFORMS_UTILS_VNCOERCION_H
26
27namespace llvm {
28class Constant;
29class Function;
30class StoreInst;
31class LoadInst;
32class MemIntrinsic;
33class Instruction;
34class IRBuilderBase;
35class Value;
36class Type;
37class DataLayout;
38
39namespace VNCoercion {
40/// Return true if CoerceAvailableValueToLoadType would succeed if it was
41/// called.
42bool canCoerceMustAliasedValueToLoad(Value *StoredVal, Type *LoadTy,
43 Function *F);
44
45/// If we saw a store of a value to memory, and then a load from a must-aliased
46/// pointer of a different type, try to coerce the stored value to the loaded
47/// type. LoadedTy is the type of the load we want to replace. IRB is
48/// IRBuilder used to insert new instructions.
49///
50/// If we can't do it, return null.
51Value *coerceAvailableValueToLoadType(Value *StoredVal, Type *LoadedTy,
52 IRBuilderBase &IRB, Function *F);
53
54/// This function determines whether a value for the pointer LoadPtr can be
55/// extracted from the store at DepSI.
56///
57/// On success, it returns the offset into DepSI that extraction would start.
58/// On failure, it returns -1.
59int analyzeLoadFromClobberingStore(Type *LoadTy, Value *LoadPtr,
60 StoreInst *DepSI, const DataLayout &DL);
61
62/// This function determines whether a value for the pointer LoadPtr can be
63/// extracted from the load at DepLI.
64///
65/// On success, it returns the offset into DepLI that extraction would start.
66/// On failure, it returns -1.
67int analyzeLoadFromClobberingLoad(Type *LoadTy, Value *LoadPtr, LoadInst *DepLI,
68 const DataLayout &DL);
69
70/// This function determines whether a value for the pointer LoadPtr can be
71/// extracted from the memory intrinsic at DepMI.
72///
73/// On success, it returns the offset into DepMI that extraction would start.
74/// On failure, it returns -1.
75int analyzeLoadFromClobberingMemInst(Type *LoadTy, Value *LoadPtr,
76 MemIntrinsic *DepMI, const DataLayout &DL);
77
78/// If analyzeLoadFromClobberingStore/Load returned an offset, this function
79/// can be used to actually perform the extraction of the bits from the store.
80/// It inserts instructions to do so at InsertPt, and returns the extracted
81/// value.
82Value *getValueForLoad(Value *SrcVal, unsigned Offset, Type *LoadTy,
83 Instruction *InsertPt, Function *F);
84// This is the same as getValueForLoad, except it performs no insertion.
85// It only allows constant inputs.
87 Type *LoadTy, const DataLayout &DL);
88
89/// If analyzeLoadFromClobberingMemInst returned an offset, this function can be
90/// used to actually perform the extraction of the bits from the memory
91/// intrinsic. It inserts instructions to do so at InsertPt, and returns the
92/// extracted value.
94 Type *LoadTy, Instruction *InsertPt,
95 const DataLayout &DL);
96// This is the same as getStoreValueForLoad, except it performs no insertion.
97// It returns nullptr if it cannot produce a constant.
99 Type *LoadTy, const DataLayout &DL);
100} // namespace VNCoercion
101} // namespace llvm
102
103#endif // LLVM_TRANSFORMS_UTILS_VNCOERCION_H
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
#define F(x, y, z)
Definition MD5.cpp:54
This is an important base class in LLVM.
Definition Constant.h:43
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
Common base class shared among various IRBuilders.
Definition IRBuilder.h:114
An instruction for reading from memory.
This is the common base class for memset/memcpy/memmove.
An instruction for storing to memory.
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:45
LLVM Value Representation.
Definition Value.h:75
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...
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...
Constant * getConstantValueForLoad(Constant *SrcVal, unsigned Offset, Type *LoadTy, const DataLayout &DL)
Value * coerceAvailableValueToLoadType(Value *StoredVal, Type *LoadedTy, IRBuilderBase &IRB, Function *F)
If we saw a store of a value to memory, and then a load from a must-aliased pointer of a different ty...
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...
Constant * getConstantMemInstValueForLoad(MemIntrinsic *SrcInst, unsigned Offset, Type *LoadTy, const DataLayout &DL)
Value * getValueForLoad(Value *SrcVal, unsigned Offset, Type *LoadTy, Instruction *InsertPt, Function *F)
If analyzeLoadFromClobberingStore/Load returned an offset, this function can be used to actually perf...
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...
bool canCoerceMustAliasedValueToLoad(Value *StoredVal, Type *LoadTy, Function *F)
Return true if CoerceAvailableValueToLoadType would succeed if it was called.
This is an optimization pass for GlobalISel generic memory operations.
Definition Types.h:26
@ Offset
Definition DWP.cpp:532