LLVM: lib/Transforms/IPO/GlobalSplit.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

33#include

34#include

35

36using namespace llvm;

37

39

40

42 return false;

43

44

47 return false;

48

52 unsigned IndexWidth = DL.getIndexTypeSizeInBits(GV.getType());

53

54

55

56 struct GEPInfo {

58 unsigned MemberIndex;

59 APInt MemberRelativeOffset;

60

61 GEPInfo(GEPOperator *GEP, unsigned MemberIndex, APInt MemberRelativeOffset)

62 : GEP(GEP), MemberIndex(MemberIndex),

63 MemberRelativeOffset(std::move(MemberRelativeOffset)) {}

64 };

69 return false;

70

71 std::optional InRange = GEP->getInRange();

73 return false;

74

76 if (GEP->accumulateConstantOffset(DL, Offset))

77 return false;

78

79

81

82

83

85 return false;

86

87

89 return false;

90

91 unsigned MemberIndex =

93 TypeSize MemberStart = MemberOffsets[MemberIndex];

94 TypeSize MemberEnd = MemberIndex == MemberOffsets.size() - 1

96 : MemberOffsets[MemberIndex + 1];

97

98

99 if (SrcInRange.getLower() != MemberStart ||

100 SrcInRange.getUpper() != MemberEnd)

101 return false;

102

104 }

105

107 GV.getMetadata(LLVMContext::MD_type, Types);

108

110

111 std::vector<GlobalVariable *> SplitGlobals(Init->getNumOperands());

112 for (unsigned I = 0; I != Init->getNumOperands(); ++I) {

113

114 auto *SplitGV =

118 SplitGlobals[I] = SplitGV;

119

121 unsigned SplitEnd = (I == Init->getNumOperands() - 1)

124

125

126

130 ->getZExtValue();

131

132

133

134

135

136

137

138

139 uint64_t AttachedTo = (ByteOffset == 0) ? ByteOffset : ByteOffset - 1;

140 if (AttachedTo < SplitBegin || AttachedTo >= SplitEnd)

141 continue;

142 SplitGV->addMetadata(

143 LLVMContext::MD_type,

145 {ConstantAsMetadata::get(

146 ConstantInt::get(Int32Ty, ByteOffset - SplitBegin)),

147 Type->getOperand(1)}));

148 }

149

150 if (GV.hasMetadata(LLVMContext::MD_vcall_visibility))

152 }

153

154 for (const GEPInfo &Info : Infos) {

155 assert(Info.MemberIndex < SplitGlobals.size() && "Invalid member");

158 ConstantInt::get(GV.getContext(), Info.MemberRelativeOffset),

159 Info.GEP->isInBounds());

160 Info.GEP->replaceAllUsesWith(NewGEP);

161 }

162

163

164

168 return true;

169}

170

172

173

174

177 Function *TypeCheckedLoadFunc =

180 &M, Intrinsic::type_checked_load_relative);

181 if ((!TypeTestFunc || TypeTestFunc->use_empty()) &&

182 (!TypeCheckedLoadFunc || TypeCheckedLoadFunc->use_empty()) &&

183 (!TypeCheckedLoadRelativeFunc ||

184 TypeCheckedLoadRelativeFunc->use_empty()))

185 return false;

186

191}

192

assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")

MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL

Analysis containing CSE Info

This file contains the declarations for the subclasses of Constant, which represent the different fla...

static bool splitGlobals(Module &M)

Definition GlobalSplit.cpp:171

static bool splitGlobal(GlobalVariable &GV)

Definition GlobalSplit.cpp:38

Module.h This file contains the declarations for the Module class.

static bool InRange(int64_t Value, unsigned short Shift, int LBound, int HBound)

This file defines the SmallVector class.

Class for arbitrary precision integers.

uint64_t getZExtValue() const

Get zero extended value.

bool uge(const APInt &RHS) const

Unsigned greater or equal comparison.

ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...

size_t size() const

size - Get the array size.

static Constant * getGetElementPtr(Type *Ty, Constant *C, ArrayRef< Constant * > IdxList, GEPNoWrapFlags NW=GEPNoWrapFlags::none(), std::optional< ConstantRange > InRange=std::nullopt, Type *OnlyIfReducedTy=nullptr)

Getelementptr form.

This class represents a range of values.

const APInt & getLower() const

Return the lower value for this range.

const APInt & getUpper() const

Return the upper value for this range.

LLVM_ABI bool contains(const APInt &Val) const

Return true if the specified value is in the set.

A parsed version of the target data layout string in and methods for querying it.

bool hasMetadata() const

Return true if this value has any metadata attached to it.

LLVM_ABI VCallVisibility getVCallVisibility() const

MDNode * getMetadata(unsigned KindID) const

Get the current metadata attachments for the given kind, if any.

PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)

Definition GlobalSplit.cpp:193

bool hasLocalLinkage() const

Module * getParent()

Get the module that this global value is contained inside of...

PointerType * getType() const

Global values are always pointers.

LLVM_ABI const DataLayout & getDataLayout() const

Get the data layout of the module this global belongs to.

@ PrivateLinkage

Like Internal, but omit from symbol table.

const Constant * getInitializer() const

getInitializer - Return the initializer for this global variable.

bool isConstant() const

If the value is a global constant, its value is immutable throughout the runtime execution of the pro...

LLVM_ABI void eraseFromParent()

eraseFromParent - This method unlinks 'this' from the containing module and deletes it.

Class to represent integer types.

static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)

A Module instance is used to store all the information related to an LLVM module.

static LLVM_ABI PoisonValue * get(Type *T)

Static factory methods - Return an 'poison' object of the specified type.

A set of analyses that are preserved following a run of a transformation pass.

static PreservedAnalyses none()

Convenience factory function for the empty preserved set.

static PreservedAnalyses all()

Construct a special preserved set that preserves all passes.

reference emplace_back(ArgTypes &&... Args)

This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.

Used to lazily calculate structure layout information for a target machine, based on the DataLayout s...

TypeSize getSizeInBytes() const

MutableArrayRef< TypeSize > getMemberOffsets()

LLVM_ABI unsigned getElementContainingOffset(uint64_t FixedOffset) const

Given a valid byte offset into the structure, returns the structure index that contains it.

TypeSize getElementOffset(unsigned Idx) const

The instances of the Type class are immutable: once they are created, they are never changed.

static LLVM_ABI IntegerType * getInt32Ty(LLVMContext &C)

static LLVM_ABI IntegerType * getInt8Ty(LLVMContext &C)

LLVM_ABI void replaceAllUsesWith(Value *V)

Change all uses of this to point to a new Value.

iterator_range< user_iterator > users()

LLVM_ABI LLVMContext & getContext() const

All values hold a context through their type.

LLVM_ABI StringRef getName() const

Return a constant reference to the value's name.

LLVM_ABI Function * getDeclarationIfExists(const Module *M, ID id)

Look up the Function declaration of the intrinsic id in the Module M and return it if it exists.

This is an optimization pass for GlobalISel generic memory operations.

decltype(auto) dyn_cast(const From &Val)

dyn_cast - Return the argument parameter cast to the specified type.

FunctionAddr VTableAddr uintptr_t uintptr_t Int32Ty

iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)

Make a range that does early increment to allow mutation of the underlying range without disrupting i...

std::string utostr(uint64_t X, bool isNeg=false)

auto dyn_cast_or_null(const Y &Val)

decltype(auto) cast(const From &Val)

cast - Return the argument parameter cast to the specified type.

AnalysisManager< Module > ModuleAnalysisManager

Convenience typedef for the Module analysis manager.