@@ -222,43 +222,21 @@ struct SizeOffsetAPInt : public SizeOffsetType<APInt, SizeOffsetAPInt> {
222
222
static bool known (const APInt &V) { return V.getBitWidth () > 1 ; }
223
223
};
224
224
225
- // / OffsetSpan - Used internally by \p ObjectSizeOffsetVisitor. Represents a
226
- // / point in memory as a pair of allocated bytes before and after it.
227
- struct OffsetSpan {
228
- APInt Before; // / Number of allocated bytes before this point.
229
- APInt After; // / Number of allocated bytes after this point.
230
-
231
- OffsetSpan () = default ;
232
- OffsetSpan (APInt Before, APInt After) : Before(Before), After(After) {}
233
-
234
- bool knownBefore () const { return known (Before); }
235
- bool knownAfter () const { return known (After); }
236
- bool anyKnown () const { return knownBefore () || knownAfter (); }
237
- bool bothKnown () const { return knownBefore () && knownAfter (); }
238
-
239
- bool operator ==(const OffsetSpan &RHS) const {
240
- return Before == RHS.Before && After == RHS.After ;
241
- }
242
- bool operator !=(const OffsetSpan &RHS) const { return !(*this == RHS); }
243
-
244
- static bool known (const APInt &V) { return V.getBitWidth () > 1 ; }
245
- };
246
-
247
225
// / Evaluate the size and offset of an object pointed to by a Value*
248
226
// / statically. Fails if size or offset are not known at compile time.
249
227
class ObjectSizeOffsetVisitor
250
- : public InstVisitor<ObjectSizeOffsetVisitor, OffsetSpan > {
228
+ : public InstVisitor<ObjectSizeOffsetVisitor, SizeOffsetAPInt > {
251
229
const DataLayout &DL;
252
230
const TargetLibraryInfo *TLI;
253
231
ObjectSizeOpts Options;
254
232
unsigned IntTyBits;
255
233
APInt Zero;
256
- SmallDenseMap<Instruction *, OffsetSpan , 8 > SeenInsts;
234
+ SmallDenseMap<Instruction *, SizeOffsetAPInt , 8 > SeenInsts;
257
235
unsigned InstructionsVisited;
258
236
259
237
APInt align (APInt Size, MaybeAlign Align);
260
238
261
- static OffsetSpan unknown () { return OffsetSpan (); }
239
+ static SizeOffsetAPInt unknown () { return SizeOffsetAPInt (); }
262
240
263
241
public:
264
242
ObjectSizeOffsetVisitor (const DataLayout &DL, const TargetLibraryInfo *TLI,
@@ -268,30 +246,29 @@ class ObjectSizeOffsetVisitor
268
246
269
247
// These are "private", except they can't actually be made private. Only
270
248
// compute() should be used by external users.
271
- OffsetSpan visitAllocaInst (AllocaInst &I);
272
- OffsetSpan visitArgument (Argument &A);
273
- OffsetSpan visitCallBase (CallBase &CB);
274
- OffsetSpan visitConstantPointerNull (ConstantPointerNull &);
275
- OffsetSpan visitExtractElementInst (ExtractElementInst &I);
276
- OffsetSpan visitExtractValueInst (ExtractValueInst &I);
277
- OffsetSpan visitGlobalAlias (GlobalAlias &GA);
278
- OffsetSpan visitGlobalVariable (GlobalVariable &GV);
279
- OffsetSpan visitIntToPtrInst (IntToPtrInst &);
280
- OffsetSpan visitLoadInst (LoadInst &I);
281
- OffsetSpan visitPHINode (PHINode &);
282
- OffsetSpan visitSelectInst (SelectInst &I);
283
- OffsetSpan visitUndefValue (UndefValue &);
284
- OffsetSpan visitInstruction (Instruction &I);
249
+ SizeOffsetAPInt visitAllocaInst (AllocaInst &I);
250
+ SizeOffsetAPInt visitArgument (Argument &A);
251
+ SizeOffsetAPInt visitCallBase (CallBase &CB);
252
+ SizeOffsetAPInt visitConstantPointerNull (ConstantPointerNull &);
253
+ SizeOffsetAPInt visitExtractElementInst (ExtractElementInst &I);
254
+ SizeOffsetAPInt visitExtractValueInst (ExtractValueInst &I);
255
+ SizeOffsetAPInt visitGlobalAlias (GlobalAlias &GA);
256
+ SizeOffsetAPInt visitGlobalVariable (GlobalVariable &GV);
257
+ SizeOffsetAPInt visitIntToPtrInst (IntToPtrInst &);
258
+ SizeOffsetAPInt visitLoadInst (LoadInst &I);
259
+ SizeOffsetAPInt visitPHINode (PHINode &);
260
+ SizeOffsetAPInt visitSelectInst (SelectInst &I);
261
+ SizeOffsetAPInt visitUndefValue (UndefValue &);
262
+ SizeOffsetAPInt visitInstruction (Instruction &I);
285
263
286
264
private:
287
- OffsetSpan
288
- findLoadOffsetRange (LoadInst &LoadFrom, BasicBlock &BB,
289
- BasicBlock::iterator From,
290
- SmallDenseMap<BasicBlock *, OffsetSpan, 8 > &VisitedBlocks,
291
- unsigned &ScannedInstCount);
292
- OffsetSpan combineOffsetRange (OffsetSpan LHS, OffsetSpan RHS);
293
- OffsetSpan computeImpl (Value *V);
294
- OffsetSpan computeValue (Value *V);
265
+ SizeOffsetAPInt findLoadSizeOffset (
266
+ LoadInst &LoadFrom, BasicBlock &BB, BasicBlock::iterator From,
267
+ SmallDenseMap<BasicBlock *, SizeOffsetAPInt, 8 > &VisitedBlocks,
268
+ unsigned &ScannedInstCount);
269
+ SizeOffsetAPInt combineSizeOffset (SizeOffsetAPInt LHS, SizeOffsetAPInt RHS);
270
+ SizeOffsetAPInt computeImpl (Value *V);
271
+ SizeOffsetAPInt computeValue (Value *V);
295
272
bool CheckedZextOrTrunc (APInt &I);
296
273
};
297
274
0 commit comments