LLVM 22.0.0git
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/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 DebugLoc mergeDebugLocs (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 121 of file BPFPreserveStaticOffset.cpp.

Function Documentation

◆ allZeroIndices()

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

◆ collectPreserveStaticOffsetCalls()

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

Definition at line 589 of file BPFPreserveStaticOffset.cpp.

References F, instructions, and isPreserveStaticOffsetCall().

Referenced by rewriteFunction().

◆ fillCommonArgs()

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

◆ foldGEPChainAsStructAccess()

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

◆ foldGEPChainAsU8Access()

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

◆ getOperandAsUnsigned()

unsigned getOperandAsUnsigned ( CallInst * Call,
unsigned ArgNo )
static

Definition at line 265 of file BPFPreserveStaticOffset.cpp.

References Call, llvm::dyn_cast(), Int, and llvm::report_fatal_error().

Referenced by reconstructCommon(), and reconstructGEP().

◆ isGEPAndLoad()

CallInst * isGEPAndLoad ( Value * I)
static

Definition at line 139 of file BPFPreserveStaticOffset.cpp.

References llvm::cast(), I, and isIntrinsicCall().

Referenced by isPointerOperand(), and rewriteAccessChain().

◆ isGEPAndStore()

CallInst * isGEPAndStore ( Value * I)
static

Definition at line 145 of file BPFPreserveStaticOffset.cpp.

References llvm::cast(), I, and isIntrinsicCall().

Referenced by isPointerOperand(), and rewriteAccessChain().

◆ isInlineableCall()

bool isInlineableCall ( User * U)
static

Definition at line 445 of file BPFPreserveStaticOffset.cpp.

References Call, and llvm::dyn_cast().

Referenced by rewriteAccessChain(), and rewriteUses().

◆ isIntrinsicCall()

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

Definition at line 128 of file BPFPreserveStaticOffset.cpp.

References Call, llvm::dyn_cast(), and I.

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

◆ isPointerOperand()

bool isPointerOperand ( Value * I,
User * U )
static

◆ isPreserveArrayIndex()

bool isPreserveArrayIndex ( Value * V)

Definition at line 597 of file BPFPreserveStaticOffset.cpp.

References isIntrinsicCall().

Referenced by removePAICalls().

◆ isPreserveStaticOffsetCall()

bool isPreserveStaticOffsetCall ( Value * I)
static

◆ isPreserveStructIndex()

bool isPreserveStructIndex ( Value * V)

Definition at line 601 of file BPFPreserveStaticOffset.cpp.

References isIntrinsicCall().

Referenced by removePAICalls().

◆ isPreserveUnionIndex()

bool isPreserveUnionIndex ( Value * V)

Definition at line 605 of file BPFPreserveStaticOffset.cpp.

References isIntrinsicCall().

Referenced by removePAICalls().

◆ isZero()

bool isZero ( Value * V)
static

Definition at line 321 of file BPFPreserveStaticOffset.cpp.

References llvm::dyn_cast().

◆ makeGEPAndLoad()

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

◆ makeGEPAndStore()

◆ makeIntrinsicCall()

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

◆ mergeDebugLocs()

template<class T = Instruction>
DebugLoc mergeDebugLocs ( SmallVector< T * > & Insns)
static

◆ reconstructCommon()

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

◆ reconstructGEP()

◆ removeMarkerCall()

void removeMarkerCall ( Instruction * Marker)
static

◆ removePAICalls()

◆ reportNonStaticGEPChain()

◆ rewriteAccessChain() [1/2]

◆ rewriteAccessChain() [2/2]

◆ rewriteFunction()

◆ rewriteUses()

◆ setParamElementType()

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

Definition at line 168 of file BPFPreserveStaticOffset.cpp.

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

Referenced by makeGEPAndLoad(), and makeGEPAndStore().

◆ setParamReadNone()

void setParamReadNone ( CallInst * Call,
unsigned ArgNo )
static

Definition at line 173 of file BPFPreserveStaticOffset.cpp.

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

Referenced by makeGEPAndStore().

◆ setParamReadOnly()

void setParamReadOnly ( CallInst * Call,
unsigned ArgNo )
static

Definition at line 178 of file BPFPreserveStaticOffset.cpp.

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

Referenced by makeGEPAndLoad().

◆ setParamWriteOnly()

void setParamWriteOnly ( CallInst * Call,
unsigned ArgNo )
static

Definition at line 183 of file BPFPreserveStaticOffset.cpp.

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

Referenced by makeGEPAndStore().

◆ tryToReplaceWithGEPBuiltin()

Variable Documentation

◆ GepAndLoadFirstIdxArg

const unsigned GepAndLoadFirstIdxArg = 6
static

Definition at line 125 of file BPFPreserveStaticOffset.cpp.

Referenced by makeGEPAndLoad().

◆ GepAndStoreFirstIdxArg

const unsigned GepAndStoreFirstIdxArg = 7
static

Definition at line 126 of file BPFPreserveStaticOffset.cpp.

Referenced by makeGEPAndStore().