LLVM 22.0.0git
Atomic.h
Go to the documentation of this file.
1//===--- Atomic.h - Codegen of atomic operations ------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_FRONTEND_ATOMIC_ATOMIC_H
10#define LLVM_FRONTEND_ATOMIC_ATOMIC_H
11
12#include "llvm/IR/IRBuilder.h"
13#include "llvm/IR/Module.h"
15
16namespace llvm {
18protected:
27
28public:
35
36 virtual ~AtomicInfo() = default;
37
41 bool shouldUseLibcall() const { return UseLibcall; }
42 Type *getAtomicTy() const { return Ty; }
43
44 virtual Value *getAtomicPointer() const = 0;
45 virtual void decorateWithTBAA(Instruction *I) = 0;
46 virtual AllocaInst *CreateAlloca(Type *Ty, const Twine &Name) const = 0;
47
48 /*
49 * Is the atomic size larger than the underlying value type?
50 * Note that the absence of padding does not mean that atomic
51 * objects are completely interchangeable with non-atomic
52 * objects: we might have promoted the alignment of a type
53 * without making it bigger.
54 */
55 bool hasPadding() const { return (ValueSizeInBits != AtomicSizeInBits); }
56
58
59 LLVM_ABI bool shouldCastToInt(Type *ValTy, bool CmpXchg);
60
61 LLVM_ABI Value *EmitAtomicLoadOp(AtomicOrdering AO, bool IsVolatile,
62 bool CmpXchg = false);
63
66
69 // TODO: Get from llvm::TargetMachine / clang::TargetInfo
70 // if clang shares this codegen in future
71 constexpr uint16_t SizeTBits = 64;
72 constexpr uint16_t BitsPerByte = 8;
73 return ConstantInt::get(IntegerType::get(ctx, SizeTBits),
74 AtomicSizeInBits / BitsPerByte);
75 }
76
77 LLVM_ABI std::pair<Value *, Value *>
78 EmitAtomicCompareExchangeLibcall(Value *ExpectedVal, Value *DesiredVal,
80 AtomicOrdering Failure);
81
83 return addr; // opaque pointer
84 }
85
88 }
89
90 LLVM_ABI std::pair<Value *, Value *>
91 EmitAtomicCompareExchangeOp(Value *ExpectedVal, Value *DesiredVal,
93 bool IsVolatile = false, bool IsWeak = false);
94
95 LLVM_ABI std::pair<Value *, Value *>
96 EmitAtomicCompareExchange(Value *ExpectedVal, Value *DesiredVal,
98 bool IsVolatile, bool IsWeak);
99
100 LLVM_ABI std::pair<LoadInst *, AllocaInst *>
102
104};
105} // end namespace llvm
106
107#endif /* LLVM_FRONTEND_ATOMIC_ATOMIC_H */
#define LLVM_ABI
Definition: Compiler.h:213
std::string Name
Module.h This file contains the declarations for the Module class.
#define I(x, y, z)
Definition: MD5.cpp:58
an instruction to allocate memory on the stack
Definition: Instructions.h:64
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
Align AtomicAlign
Definition: Atomic.h:23
uint64_t getValueSizeInBits() const
Definition: Atomic.h:40
bool UseLibcall
Definition: Atomic.h:25
virtual ~AtomicInfo()=default
IRBuilderBase * Builder
Definition: Atomic.h:19
AtomicInfo(IRBuilderBase *Builder, Type *Ty, uint64_t AtomicSizeInBits, uint64_t ValueSizeInBits, Align AtomicAlign, Align ValueAlign, bool UseLibcall, IRBuilderBase::InsertPoint AllocaIP)
Definition: Atomic.h:29
LLVM_ABI std::pair< Value *, Value * > EmitAtomicCompareExchange(Value *ExpectedVal, Value *DesiredVal, AtomicOrdering Success, AtomicOrdering Failure, bool IsVolatile, bool IsWeak)
Definition: Atomic.cpp:184
virtual AllocaInst * CreateAlloca(Type *Ty, const Twine &Name) const =0
LLVM_ABI std::pair< LoadInst *, AllocaInst * > EmitAtomicLoadLibcall(AtomicOrdering AO)
Definition: Atomic.cpp:107
LLVM_ABI std::pair< Value *, Value * > EmitAtomicCompareExchangeOp(Value *ExpectedVal, Value *DesiredVal, AtomicOrdering Success, AtomicOrdering Failure, bool IsVolatile=false, bool IsWeak=false)
Definition: Atomic.cpp:89
Type * getAtomicTy() const
Definition: Atomic.h:42
uint64_t getAtomicSizeInBits() const
Definition: Atomic.h:39
LLVM_ABI Value * EmitAtomicLoadOp(AtomicOrdering AO, bool IsVolatile, bool CmpXchg=false)
Definition: Atomic.cpp:22
virtual Value * getAtomicPointer() const =0
Value * castToAtomicIntPointer(Value *addr) const
Definition: Atomic.h:82
LLVM_ABI std::pair< Value *, Value * > EmitAtomicCompareExchangeLibcall(Value *ExpectedVal, Value *DesiredVal, AtomicOrdering Success, AtomicOrdering Failure)
Definition: Atomic.cpp:57
LLVM_ABI bool shouldCastToInt(Type *ValTy, bool CmpXchg)
Definition: Atomic.cpp:16
bool hasPadding() const
Definition: Atomic.h:55
uint64_t AtomicSizeInBits
Definition: Atomic.h:21
uint64_t ValueSizeInBits
Definition: Atomic.h:22
LLVM_ABI void EmitAtomicStoreLibcall(AtomicOrdering AO, Value *Source)
Definition: Atomic.cpp:148
IRBuilderBase::InsertPoint AllocaIP
Definition: Atomic.h:26
LLVMContext & getLLVMContext() const
Definition: Atomic.h:57
Value * getAtomicAddressAsAtomicIntPointer() const
Definition: Atomic.h:86
Align ValueAlign
Definition: Atomic.h:24
virtual void decorateWithTBAA(Instruction *I)=0
LLVM_ABI CallInst * EmitAtomicLibcall(StringRef fnName, Type *ResultType, ArrayRef< Value * > Args)
Definition: Atomic.cpp:37
Value * getAtomicSizeValue() const
Definition: Atomic.h:67
bool shouldUseLibcall() const
Definition: Atomic.h:41
Type * Ty
Definition: Atomic.h:20
Align getAtomicAlignment() const
Definition: Atomic.h:38
This class represents a function call, abstracting a target machine's calling convention.
InsertPoint - A saved insertion point.
Definition: IRBuilder.h:291
Common base class shared among various IRBuilders.
Definition: IRBuilder.h:114
LLVMContext & getContext() const
Definition: IRBuilder.h:203
static LLVM_ABI IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
Definition: Type.cpp:319
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:68
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:82
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
LLVM Value Representation.
Definition: Value.h:75
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Success
The lock was released successfully.
AtomicOrdering
Atomic ordering for LLVM's memory model.
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39