LLVM  14.0.0git
Macros | Functions
AtomicExpandPass.cpp File Reference
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/Analysis/OptimizationRemarkEmitter.h"
#include "llvm/CodeGen/AtomicExpandUtils.h"
#include "llvm/CodeGen/RuntimeLibcalls.h"
#include "llvm/CodeGen/TargetLowering.h"
#include "llvm/CodeGen/TargetPassConfig.h"
#include "llvm/CodeGen/TargetSubtargetInfo.h"
#include "llvm/CodeGen/ValueTypes.h"
#include "llvm/IR/Attributes.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/Constant.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/InstIterator.h"
#include "llvm/IR/Instruction.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/User.h"
#include "llvm/IR/Value.h"
#include "llvm/InitializePasses.h"
#include "llvm/Pass.h"
#include "llvm/Support/AtomicOrdering.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Target/TargetMachine.h"
#include <cassert>
#include <cstdint>
#include <iterator>
Include dependency graph for AtomicExpandPass.cpp:

Go to the source code of this file.

Macros

#define DEBUG_TYPE   "atomic-expand"
 

Functions

 INITIALIZE_PASS (AtomicExpand, DEBUG_TYPE, "Expand Atomic instructions", false, false) FunctionPass *llvm
 
static unsigned getAtomicOpSize (LoadInst *LI)
 
static unsigned getAtomicOpSize (StoreInst *SI)
 
static unsigned getAtomicOpSize (AtomicRMWInst *RMWI)
 
static unsigned getAtomicOpSize (AtomicCmpXchgInst *CASI)
 
template<typename Inst >
static bool atomicSizeSupported (const TargetLowering *TLI, Inst *I)
 
static void createCmpXchgInstFun (IRBuilder<> &Builder, Value *Addr, Value *Loaded, Value *NewVal, Align AddrAlign, AtomicOrdering MemOpOrder, SyncScope::ID SSID, Value *&Success, Value *&NewLoaded)
 
static ValueperformAtomicOp (AtomicRMWInst::BinOp Op, IRBuilder<> &Builder, Value *Loaded, Value *Inc)
 Emit IR to implement the given atomicrmw operation on values in registers, returning the new value. More...
 
static PartwordMaskValues createMaskInstrs (IRBuilder<> &Builder, Instruction *I, Type *ValueType, Value *Addr, Align AddrAlign, unsigned MinWordSize)
 This is a helper function which builds instructions to provide values necessary for partword atomic operations. More...
 
static ValueextractMaskedValue (IRBuilder<> &Builder, Value *WideWord, const PartwordMaskValues &PMV)
 
static ValueinsertMaskedValue (IRBuilder<> &Builder, Value *WideWord, Value *Updated, const PartwordMaskValues &PMV)
 
static ValueperformMaskedAtomicOp (AtomicRMWInst::BinOp Op, IRBuilder<> &Builder, Value *Loaded, Value *Shifted_Inc, Value *Inc, const PartwordMaskValues &PMV)
 Emit IR to implement a masked version of a given atomicrmw operation. More...
 
static bool canUseSizedAtomicCall (unsigned Size, Align Alignment, const DataLayout &DL)
 
static ArrayRef< RTLIB::LibcallGetRMWLibcall (AtomicRMWInst::BinOp Op)
 

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "atomic-expand"

Definition at line 56 of file AtomicExpandPass.cpp.

Function Documentation

◆ atomicSizeSupported()

template<typename Inst >
static bool atomicSizeSupported ( const TargetLowering TLI,
Inst *  I 
)
static

◆ canUseSizedAtomicCall()

static bool canUseSizedAtomicCall ( unsigned  Size,
Align  Alignment,
const DataLayout DL 
)
static

Definition at line 1555 of file AtomicExpandPass.cpp.

References DL, and llvm::Check::Size.

◆ createCmpXchgInstFun()

static void createCmpXchgInstFun ( IRBuilder<> &  Builder,
Value Addr,
Value Loaded,
Value NewVal,
Align  AddrAlign,
AtomicOrdering  MemOpOrder,
SyncScope::ID  SSID,
Value *&  Success,
Value *&  NewLoaded 
)
static

◆ createMaskInstrs()

static PartwordMaskValues createMaskInstrs ( IRBuilder<> &  Builder,
Instruction I,
Type ValueType,
Value Addr,
Align  AddrAlign,
unsigned  MinWordSize 
)
static

This is a helper function which builds instructions to provide values necessary for partword atomic operations.

It takes an incoming address, Addr, and ValueType, and constructs the address, shift-amounts and masks needed to work with a larger value of size WordSize.

AlignedAddr: Addr rounded down to a multiple of WordSize

ShiftAmt: Number of bits to right-shift a WordSize value loaded from AlignAddr for it to have the same value as if ValueType was loaded from Addr.

Mask: Value to mask with the value loaded from AlignAddr to include only the part that would've been loaded from Addr.

Inv_Mask: The inverse of Mask.

Definition at line 690 of file AtomicExpandPass.cpp.

References Addr, Align, assert(), Builder, DL, llvm::ConstantInt::get(), llvm::Type::getIntNTy(), I, and M.

◆ extractMaskedValue()

static Value* extractMaskedValue ( IRBuilder<> &  Builder,
Value WideWord,
const PartwordMaskValues &  PMV 
)
static

Definition at line 742 of file AtomicExpandPass.cpp.

References assert(), Builder, llvm::Value::getType(), and Shift.

Referenced by performMaskedAtomicOp().

◆ getAtomicOpSize() [1/4]

static unsigned getAtomicOpSize ( AtomicCmpXchgInst CASI)
static

◆ getAtomicOpSize() [2/4]

static unsigned getAtomicOpSize ( AtomicRMWInst RMWI)
static

◆ getAtomicOpSize() [3/4]

static unsigned getAtomicOpSize ( LoadInst LI)
static

◆ getAtomicOpSize() [4/4]

static unsigned getAtomicOpSize ( StoreInst SI)
static

Definition at line 143 of file AtomicExpandPass.cpp.

References DL, and SI.

◆ GetRMWLibcall()

static ArrayRef<RTLIB::Libcall> GetRMWLibcall ( AtomicRMWInst::BinOp  Op)
static

◆ INITIALIZE_PASS()

INITIALIZE_PASS ( AtomicExpand  ,
DEBUG_TYPE  ,
"Expand Atomic instructions ,
false  ,
false   
)

Definition at line 132 of file AtomicExpandPass.cpp.

◆ insertMaskedValue()

static Value* insertMaskedValue ( IRBuilder<> &  Builder,
Value WideWord,
Value Updated,
const PartwordMaskValues &  PMV 
)
static

Definition at line 753 of file AtomicExpandPass.cpp.

References llvm::And, assert(), Builder, llvm::Value::getType(), llvm::Or, and Shift.

Referenced by performMaskedAtomicOp().

◆ performAtomicOp()

static Value* performAtomicOp ( AtomicRMWInst::BinOp  Op,
IRBuilder<> &  Builder,
Value Loaded,
Value Inc 
)
static

◆ performMaskedAtomicOp()

static Value* performMaskedAtomicOp ( AtomicRMWInst::BinOp  Op,
IRBuilder<> &  Builder,
Value Loaded,
Value Shifted_Inc,
Value Inc,
const PartwordMaskValues &  PMV 
)
static