39#define DEBUG_TYPE "nvptx-set-byval-param-align"
44class NVPTXSetByValParamAlignLegacyPass :
public FunctionPass {
51 return "Set alignment of byval parameters (NVPTX)";
56char NVPTXSetByValParamAlignLegacyPass::ID = 0;
59 "nvptx-set-byval-param-align",
60 "Set alignment of byval parameters (NVPTX)",
false,
false)
64 Type *ByValType = Arg->getParamByValType();
68 const Align CurrentAlign = Arg->getParamAlign().valueOrOne();
70 if (CurrentAlign >= OptimizedAlign)
74 <<
" instead of " << CurrentAlign.
value() <<
" for " << *Arg
77 Arg->removeAttr(Attribute::Alignment);
80 return OptimizedAlign;
102 std::queue<LoadContext> Worklist;
103 Worklist.push({Val, 0});
105 while (!Worklist.empty()) {
106 LoadContext Ctx = Worklist.front();
109 for (
User *CurUser : Ctx.InitialVal->
users()) {
115 APInt OffsetAccumulated =
118 if (!
I->accumulateConstantOffset(
DL, OffsetAccumulated))
123 assert(
Offset != OffsetLimit &&
"Expect Offset less than UINT64_MAX");
125 Worklist.push({
I, Ctx.Offset +
Offset});
130 for (Load &CurLoad : Loads) {
132 Align CurLoadAlign = CurLoad.Inst->getAlign();
133 CurLoad.Inst->setAlignment(std::max(NewLoadAlign, CurLoadAlign));
141 if (!Arg.hasByValAttr())
143 const Align NewArgAlign = setByValParamAlign(&Arg);
150bool NVPTXSetByValParamAlignLegacyPass::runOnFunction(
Function &
F) {
155 return new NVPTXSetByValParamAlignLegacyPass();
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static bool runOnFunction(Function &F, bool PostInlining)
static bool setByValParamAlignment(Function &F)
static void propagateAlignmentToLoads(Value *Val, Align NewAlign, const DataLayout &DL)
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Class for arbitrary precision integers.
uint64_t getLimitedValue(uint64_t Limit=UINT64_MAX) const
If this value is smaller than the specified limit, return it, otherwise return the limit value.
static APInt getZero(unsigned numBits)
Get the '0' value for the specified bit-width.
This class represents an incoming formal argument to a Function.
static LLVM_ABI Attribute getWithAlignment(LLVMContext &Context, Align Alignment)
Return a uniquified Attribute object that has the specific alignment set.
A parsed version of the target data layout string in and methods for querying it.
FunctionPass class - This class is used to implement most global optimizations.
An instruction for reading from memory.
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
The instances of the Type class are immutable: once they are created, they are never changed.
LLVM Value Representation.
iterator_range< user_iterator > users()
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
FunctionPass * createNVPTXSetByValParamAlignPass()
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Align commonAlignment(Align A, uint64_t Offset)
Returns the alignment that satisfies both alignments.
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
Align getFunctionParamOptimizedAlign(const Function *F, Type *ArgTy, const DataLayout &DL)
Since function arguments are passed via .param space, we may want to increase their alignment in a wa...
This struct is a compact representation of a valid (non-zero power of two) alignment.
constexpr uint64_t value() const
This is a hole in the type system and should not be abused.
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)