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
28
29namespace llvm {
30class Constant;
31class Function;
32class StoreInst;
33class LoadInst;
34class MemIntrinsic;
35class Instruction;
36class IRBuilderBase;
37class Value;
38class Type;
39class DataLayout;
40
41namespace VNCoercion {
42/// Return true if CoerceAvailableValueToLoadType would succeed if it was
43/// called.
44LLVM_ABI bool canCoerceMustAliasedValueToLoad(Value *StoredVal, Type *LoadTy,
45 Function *F);
46
47/// If we saw a store of a value to memory, and then a load from a must-aliased
48/// pointer of a different type, try to coerce the stored value to the loaded
49/// type. LoadedTy is the type of the load we want to replace. IRB is
50/// IRBuilder used to insert new instructions.
51///
52/// If we can't do it, return null.
54 IRBuilderBase &IRB, Function *F);
55
56/// This function determines whether a value for the pointer LoadPtr can be
57/// extracted from the store at DepSI.
58///
59/// On success, it returns the offset into DepSI that extraction would start.
60/// On failure, it returns -1.
62 StoreInst *DepSI,
63 const DataLayout &DL);
64
65/// This function determines whether a value for the pointer LoadPtr can be
66/// extracted from the load at DepLI.
67///
68/// On success, it returns the offset into DepLI that extraction would start.
69/// On failure, it returns -1.
71 LoadInst *DepLI,
72 const DataLayout &DL);
73
74/// This function determines whether a value for the pointer LoadPtr can be
75/// extracted from the memory intrinsic at DepMI.
76///
77/// On success, it returns the offset into DepMI that extraction would start.
78/// On failure, it returns -1.
80 MemIntrinsic *DepMI,
81 const DataLayout &DL);
82
83/// If analyzeLoadFromClobberingStore/Load returned an offset, this function
84/// can be used to actually perform the extraction of the bits from the store.
85/// It inserts instructions to do so at InsertPt, and returns the extracted
86/// value.
87LLVM_ABI Value *getValueForLoad(Value *SrcVal, unsigned Offset, Type *LoadTy,
88 Instruction *InsertPt, Function *F);
89// This is the same as getValueForLoad, except it performs no insertion.
90// It only allows constant inputs.
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.
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.
104 unsigned Offset, Type *LoadTy,
105 const DataLayout &DL);
106} // namespace VNCoercion
107} // namespace llvm
108
109#endif // LLVM_TRANSFORMS_UTILS_VNCOERCION_H
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
#define LLVM_ABI
Definition Compiler.h:213
#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:46
LLVM Value Representation.
Definition Value.h:75
LLVM_ABI 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...
LLVM_ABI 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...
LLVM_ABI Constant * getConstantValueForLoad(Constant *SrcVal, unsigned Offset, Type *LoadTy, const DataLayout &DL)
LLVM_ABI 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...
LLVM_ABI 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...
LLVM_ABI Constant * getConstantMemInstValueForLoad(MemIntrinsic *SrcInst, unsigned Offset, Type *LoadTy, const DataLayout &DL)
LLVM_ABI 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...
LLVM_ABI 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...
LLVM_ABI 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.
@ Offset
Definition DWP.cpp:558