LLVM 20.0.0git
Macros | Functions | Variables
BPFPreserveStaticOffset.cpp File Reference
#include "BPF.h"
#include "BPFCORE.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/IR/Attributes.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DebugInfoMetadata.h"
#include "llvm/IR/DiagnosticInfo.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/InstIterator.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/Intrinsics.h"
#include "llvm/IR/IntrinsicsBPF.h"
#include "llvm/IR/Module.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"

Go to the source code of this file.

Macros

#define DEBUG_TYPE   "bpf-preserve-static-offset"
 

Functions

static bool isIntrinsicCall (Value *I, Intrinsic::ID Id)
 
static bool isPreserveStaticOffsetCall (Value *I)
 
static CallInstisGEPAndLoad (Value *I)
 
static CallInstisGEPAndStore (Value *I)
 
template<class T = Instruction>
static DILocationmergeDILocations (SmallVector< T * > &Insns)
 
static CallInstmakeIntrinsicCall (Module *M, Intrinsic::BPFIntrinsics Intrinsic, ArrayRef< Type * > Types, ArrayRef< Value * > Args)
 
static void setParamElementType (CallInst *Call, unsigned ArgNo, Type *Type)
 
static void setParamReadNone (CallInst *Call, unsigned ArgNo)
 
static void setParamReadOnly (CallInst *Call, unsigned ArgNo)
 
static void setParamWriteOnly (CallInst *Call, unsigned ArgNo)
 
template<class T = std::disjunction<LoadInst, StoreInst>>
static void fillCommonArgs (LLVMContext &C, SmallVector< Value * > &Args, GEPChainInfo &GEP, T *Insn)
 
static InstructionmakeGEPAndLoad (Module *M, GEPChainInfo &GEP, LoadInst *Load)
 
static InstructionmakeGEPAndStore (Module *M, GEPChainInfo &GEP, StoreInst *Store)
 
static unsigned getOperandAsUnsigned (CallInst *Call, unsigned ArgNo)
 
static GetElementPtrInstreconstructGEP (CallInst *Call, int Delta)
 
template<class T = std::disjunction<LoadInst, StoreInst>>
static void reconstructCommon (CallInst *Call, GetElementPtrInst *GEP, T *Insn, int Delta)
 
static bool isZero (Value *V)
 
static bool foldGEPChainAsStructAccess (SmallVector< GetElementPtrInst * > &GEPs, GEPChainInfo &Info)
 
static bool foldGEPChainAsU8Access (SmallVector< GetElementPtrInst * > &GEPs, GEPChainInfo &Info)
 
static void reportNonStaticGEPChain (Instruction *Insn)
 
static bool allZeroIndices (SmallVector< GetElementPtrInst * > &GEPs)
 
static bool tryToReplaceWithGEPBuiltin (Instruction *LoadOrStoreTemplate, SmallVector< GetElementPtrInst * > &GEPs, Instruction *InsnToReplace)
 
static bool isPointerOperand (Value *I, User *U)
 
static bool isInlineableCall (User *U)
 
static void rewriteAccessChain (Instruction *Insn, SmallVector< GetElementPtrInst * > &GEPs, SmallVector< Instruction * > &Visited, bool AllowPatial, bool &StillUsed)
 
static void rewriteUses (Instruction *Insn, SmallVector< GetElementPtrInst * > &GEPs, SmallVector< Instruction * > &Visited, bool AllowPatial, bool &StillUsed)
 
static void removeMarkerCall (Instruction *Marker)
 
static bool rewriteAccessChain (Instruction *Marker, bool AllowPatial, SmallPtrSetImpl< Instruction * > &RemovedMarkers)
 
static std::vector< Instruction * > collectPreserveStaticOffsetCalls (Function &F)
 
bool isPreserveArrayIndex (Value *V)
 
bool isPreserveStructIndex (Value *V)
 
bool isPreserveUnionIndex (Value *V)
 
static void removePAICalls (Instruction *Marker)
 
static bool rewriteFunction (Function &F, bool AllowPartial)
 

Variables

static const unsigned GepAndLoadFirstIdxArg = 6
 
static const unsigned GepAndStoreFirstIdxArg = 7
 

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "bpf-preserve-static-offset"

Definition at line 122 of file BPFPreserveStaticOffset.cpp.

Function Documentation

◆ allZeroIndices()

static bool allZeroIndices ( SmallVector< GetElementPtrInst * > &  GEPs)
static

◆ collectPreserveStaticOffsetCalls()

static std::vector< Instruction * > collectPreserveStaticOffsetCalls ( Function F)
static

Definition at line 593 of file BPFPreserveStaticOffset.cpp.

References F, Insn, instructions, and isPreserveStaticOffsetCall().

Referenced by rewriteFunction().

◆ fillCommonArgs()

template<class T = std::disjunction<LoadInst, StoreInst>>
static void fillCommonArgs ( LLVMContext C,
SmallVector< Value * > &  Args,
GEPChainInfo &  GEP,
T Insn 
)
static

◆ foldGEPChainAsStructAccess()

static bool foldGEPChainAsStructAccess ( SmallVector< GetElementPtrInst * > &  GEPs,
GEPChainInfo &  Info 
)
static

◆ foldGEPChainAsU8Access()

static bool foldGEPChainAsU8Access ( SmallVector< GetElementPtrInst * > &  GEPs,
GEPChainInfo &  Info 
)
static

◆ getOperandAsUnsigned()

static unsigned getOperandAsUnsigned ( CallInst Call,
unsigned  ArgNo 
)
static

Definition at line 267 of file BPFPreserveStaticOffset.cpp.

References Int, and llvm::report_fatal_error().

Referenced by reconstructCommon(), and reconstructGEP().

◆ isGEPAndLoad()

static CallInst * isGEPAndLoad ( Value I)
static

Definition at line 140 of file BPFPreserveStaticOffset.cpp.

References I, and isIntrinsicCall().

Referenced by isPointerOperand(), and rewriteAccessChain().

◆ isGEPAndStore()

static CallInst * isGEPAndStore ( Value I)
static

Definition at line 146 of file BPFPreserveStaticOffset.cpp.

References I, and isIntrinsicCall().

Referenced by isPointerOperand(), and rewriteAccessChain().

◆ isInlineableCall()

static bool isInlineableCall ( User U)
static

Definition at line 449 of file BPFPreserveStaticOffset.cpp.

Referenced by rewriteAccessChain(), and rewriteUses().

◆ isIntrinsicCall()

static bool isIntrinsicCall ( Value I,
Intrinsic::ID  Id 
)
static

Definition at line 129 of file BPFPreserveStaticOffset.cpp.

References I.

Referenced by isGEPAndLoad(), isGEPAndStore(), and isPreserveStaticOffsetCall().

◆ isPointerOperand()

static bool isPointerOperand ( Value I,
User U 
)
static

◆ isPreserveArrayIndex()

bool isPreserveArrayIndex ( Value V)

Definition at line 601 of file BPFPreserveStaticOffset.cpp.

References isIntrinsicCall().

Referenced by removePAICalls().

◆ isPreserveStaticOffsetCall()

static bool isPreserveStaticOffsetCall ( Value I)
static

◆ isPreserveStructIndex()

bool isPreserveStructIndex ( Value V)

Definition at line 605 of file BPFPreserveStaticOffset.cpp.

References isIntrinsicCall().

Referenced by removePAICalls().

◆ isPreserveUnionIndex()

bool isPreserveUnionIndex ( Value V)

Definition at line 609 of file BPFPreserveStaticOffset.cpp.

References isIntrinsicCall().

Referenced by removePAICalls().

◆ isZero()

static bool isZero ( Value V)
static

Definition at line 323 of file BPFPreserveStaticOffset.cpp.

◆ makeGEPAndLoad()

static Instruction * makeGEPAndLoad ( Module M,
GEPChainInfo &  GEP,
LoadInst Load 
)
static

◆ makeGEPAndStore()

static Instruction * makeGEPAndStore ( Module M,
GEPChainInfo &  GEP,
StoreInst Store 
)
static

◆ makeIntrinsicCall()

static CallInst * makeIntrinsicCall ( Module M,
Intrinsic::BPFIntrinsics  Intrinsic,
ArrayRef< Type * >  Types,
ArrayRef< Value * >  Args 
)
static

◆ mergeDILocations()

template<class T = Instruction>
static DILocation * mergeDILocations ( SmallVector< T * > &  Insns)
static

◆ reconstructCommon()

template<class T = std::disjunction<LoadInst, StoreInst>>
static void reconstructCommon ( CallInst Call,
GetElementPtrInst GEP,
T Insn,
int  Delta 
)
static

◆ reconstructGEP()

static GetElementPtrInst * reconstructGEP ( CallInst Call,
int  Delta 
)
static

◆ removeMarkerCall()

static void removeMarkerCall ( Instruction Marker)
static

◆ removePAICalls()

static void removePAICalls ( Instruction Marker)
static

◆ reportNonStaticGEPChain()

static void reportNonStaticGEPChain ( Instruction Insn)
static

Definition at line 395 of file BPFPreserveStaticOffset.cpp.

References llvm::concat(), llvm::DS_Warning, and Insn.

Referenced by rewriteAccessChain().

◆ rewriteAccessChain() [1/2]

static void rewriteAccessChain ( Instruction Insn,
SmallVector< GetElementPtrInst * > &  GEPs,
SmallVector< Instruction * > &  Visited,
bool  AllowPatial,
bool StillUsed 
)
static

◆ rewriteAccessChain() [2/2]

static bool rewriteAccessChain ( Instruction Marker,
bool  AllowPatial,
SmallPtrSetImpl< Instruction * > &  RemovedMarkers 
)
static

◆ rewriteFunction()

static bool rewriteFunction ( Function F,
bool  AllowPartial 
)
static

◆ rewriteUses()

static void rewriteUses ( Instruction Insn,
SmallVector< GetElementPtrInst * > &  GEPs,
SmallVector< Instruction * > &  Visited,
bool  AllowPatial,
bool StillUsed 
)
static

◆ setParamElementType()

static void setParamElementType ( CallInst Call,
unsigned  ArgNo,
Type Type 
)
static

Definition at line 169 of file BPFPreserveStaticOffset.cpp.

References llvm::CallingConv::C, and llvm::Attribute::get().

Referenced by makeGEPAndLoad(), and makeGEPAndStore().

◆ setParamReadNone()

static void setParamReadNone ( CallInst Call,
unsigned  ArgNo 
)
static

Definition at line 174 of file BPFPreserveStaticOffset.cpp.

References llvm::CallingConv::C, and llvm::Attribute::get().

Referenced by makeGEPAndStore().

◆ setParamReadOnly()

static void setParamReadOnly ( CallInst Call,
unsigned  ArgNo 
)
static

Definition at line 179 of file BPFPreserveStaticOffset.cpp.

References llvm::CallingConv::C, and llvm::Attribute::get().

Referenced by makeGEPAndLoad().

◆ setParamWriteOnly()

static void setParamWriteOnly ( CallInst Call,
unsigned  ArgNo 
)
static

Definition at line 184 of file BPFPreserveStaticOffset.cpp.

References llvm::CallingConv::C, and llvm::Attribute::get().

Referenced by makeGEPAndStore().

◆ tryToReplaceWithGEPBuiltin()

static bool tryToReplaceWithGEPBuiltin ( Instruction LoadOrStoreTemplate,
SmallVector< GetElementPtrInst * > &  GEPs,
Instruction InsnToReplace 
)
static

Variable Documentation

◆ GepAndLoadFirstIdxArg

const unsigned GepAndLoadFirstIdxArg = 6
static

Definition at line 126 of file BPFPreserveStaticOffset.cpp.

Referenced by makeGEPAndLoad().

◆ GepAndStoreFirstIdxArg

const unsigned GepAndStoreFirstIdxArg = 7
static

Definition at line 127 of file BPFPreserveStaticOffset.cpp.

Referenced by makeGEPAndStore().