LLVM 19.0.0git
NVPTXAllocaHoisting.cpp
Go to the documentation of this file.
1//===-- AllocaHoisting.cpp - Hoist allocas to the entry block --*- C++ -*-===//
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// Hoist the alloca instructions in the non-entry blocks to the entry blocks.
10//
11//===----------------------------------------------------------------------===//
12
13#include "NVPTXAllocaHoisting.h"
15#include "llvm/IR/Constants.h"
16#include "llvm/IR/Function.h"
18using namespace llvm;
19
20namespace {
21// Hoisting the alloca instructions in the non-entry blocks to the entry
22// block.
23class NVPTXAllocaHoisting : public FunctionPass {
24public:
25 static char ID; // Pass ID
26 NVPTXAllocaHoisting() : FunctionPass(ID) {}
27
28 void getAnalysisUsage(AnalysisUsage &AU) const override {
30 }
31
32 StringRef getPassName() const override {
33 return "NVPTX specific alloca hoisting";
34 }
35
36 bool runOnFunction(Function &function) override;
37};
38} // namespace
39
40bool NVPTXAllocaHoisting::runOnFunction(Function &function) {
41 bool functionModified = false;
43 Instruction *firstTerminatorInst = (I++)->getTerminator();
44
45 for (Function::iterator E = function.end(); I != E; ++I) {
46 for (BasicBlock::iterator BI = I->begin(), BE = I->end(); BI != BE;) {
47 AllocaInst *allocaInst = dyn_cast<AllocaInst>(BI++);
48 if (allocaInst && isa<ConstantInt>(allocaInst->getArraySize())) {
49 allocaInst->moveBefore(firstTerminatorInst);
50 functionModified = true;
51 }
52 }
53 }
54
55 return functionModified;
56}
57
58char NVPTXAllocaHoisting::ID = 0;
59
60namespace llvm {
62}
63
65 NVPTXAllocaHoisting, "alloca-hoisting",
66 "Hoisting alloca instructions in non-entry blocks to the entry block",
67 false, false)
68
69FunctionPass *llvm::createAllocaHoisting() { return new NVPTXAllocaHoisting; }
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Performs the initial survey of the specified function
#define I(x, y, z)
Definition: MD5.cpp:58
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:38
an instruction to allocate memory on the stack
Definition: Instructions.h:59
const Value * getArraySize() const
Get the number of elements allocated.
Definition: Instructions.h:103
Represent the analysis usage information of a pass.
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
InstListType::iterator iterator
Instruction iterators...
Definition: BasicBlock.h:164
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:311
virtual bool runOnFunction(Function &F)=0
runOnFunction - Virtual method overriden by subclasses to do the per-function processing of the pass.
BasicBlockListType::iterator iterator
Definition: Function.h:67
void moveBefore(Instruction *MovePos)
Unlink this instruction from its current basic block and insert it into the basic block that MovePos ...
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...
Definition: PassRegistry.h:37
virtual void getAnalysisUsage(AnalysisUsage &) const
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
Definition: Pass.cpp:98
virtual StringRef getPassName() const
getPassName - Return a nice clean name for a pass.
Definition: Pass.cpp:81
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition: CallingConv.h:24
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
FunctionPass * createAllocaHoisting()
void initializeNVPTXAllocaHoistingPass(PassRegistry &)