28#include "llvm/IR/IntrinsicsNVPTX.h"
51 cl::desc(
"Disable load/store vectorizer"),
56 "disable-nvptx-require-structured-cfg",
57 cl::desc(
"Transitional flag to turn off NVPTX's requirement on preserving "
58 "structured CFG. The requirement should be disabled only when "
59 "unexpected regressions happen."),
65 "Use 32-bit pointers for accessing const/local/shared address spaces."),
87 "nvptx-early-byval-copy",
88 cl::desc(
"Create a copy of byval function arguments early."),
122 std::string Ret =
"e";
128 Ret +=
"-p:32:32-p6:32:32-p7:32:32";
129 else if (UseShortPointers)
130 Ret +=
"-p3:32:32-p4:32:32-p5:32:32-p6:32:32-p7:32:32";
134 Ret +=
"-i64:64-i128:128-i256:256-v16:16-v32:32-n16:32:64";
142 std::optional<Reloc::Model> RM,
143 std::optional<CodeModel::Model> CM,
149 TT, CPU, FS,
Options, Reloc::PIC_,
165void NVPTXTargetMachine32::anchor() {}
170 std::optional<Reloc::Model> RM,
171 std::optional<CodeModel::Model> CM,
175void NVPTXTargetMachine64::anchor() {}
180 std::optional<Reloc::Model> RM,
181 std::optional<CodeModel::Model> CM,
193 return getTM<NVPTXTargetMachine>();
196 void addIRPasses()
override;
197 bool addInstSelector()
override;
198 void addPreRegAlloc()
override;
199 void addPostRegAlloc()
override;
200 void addMachineSSAOptimization()
override;
202 FunctionPass *createTargetRegisterAllocator(
bool)
override;
203 void addFastRegAlloc()
override;
204 void addOptimizedRegAlloc()
override;
206 bool addRegAssignAndRewriteFast()
override {
210 bool addRegAssignAndRewriteOptimized()
override {
217 void addEarlyCSEOrGVNPass();
220 void addAddressSpaceInferencePasses();
223 void addStraightLineScalarOptimizationPasses();
229 return new NVPTXPassConfig(*
this, PM);
235 return NVPTXMachineFunctionInfo::create<NVPTXMachineFunctionInfo>(
Allocator,
244#define GET_PASS_REGISTRY "NVPTXPassRegistry.def"
278std::pair<const Value *, unsigned>
280 if (
auto *
II = dyn_cast<IntrinsicInst>(V)) {
281 switch (
II->getIntrinsicID()) {
282 case Intrinsic::nvvm_isspacep_const:
284 case Intrinsic::nvvm_isspacep_global:
286 case Intrinsic::nvvm_isspacep_local:
288 case Intrinsic::nvvm_isspacep_shared:
290 case Intrinsic::nvvm_isspacep_shared_cluster:
291 return std::make_pair(
II->getArgOperand(0),
297 return std::make_pair(
nullptr, -1);
300void NVPTXPassConfig::addEarlyCSEOrGVNPass() {
307void NVPTXPassConfig::addAddressSpaceInferencePasses() {
318void NVPTXPassConfig::addStraightLineScalarOptimizationPasses() {
327 addEarlyCSEOrGVNPass();
335void NVPTXPassConfig::addIRPasses() {
372 addAddressSpaceInferencePasses();
373 addStraightLineScalarOptimizationPasses();
395 addEarlyCSEOrGVNPass();
402 if (
ST.hasPTXASUnreachableBug()) {
405 const auto &
Options = getNVPTXTargetMachine().Options;
411bool NVPTXPassConfig::addInstSelector() {
420void NVPTXPassConfig::addPreRegAlloc() {
426void NVPTXPassConfig::addPostRegAlloc() {
436FunctionPass *NVPTXPassConfig::createTargetRegisterAllocator(
bool) {
440void NVPTXPassConfig::addFastRegAlloc() {
445void NVPTXPassConfig::addOptimizedRegAlloc() {
456 printAndVerify(
"After Machine Scheduling");
463 printAndVerify(
"After StackSlotColoring");
466void NVPTXPassConfig::addMachineSSAOptimization() {
469 printAndVerify(
"After Pre-RegAlloc TailDuplicate");
488 printAndVerify(
"After codegen DCE pass");
494 printAndVerify(
"After ILP optimizations");
500 printAndVerify(
"After Machine LICM, CSE and Sinking passes");
503 printAndVerify(
"After codegen peephole optimization pass");
#define LLVM_EXTERNAL_VISIBILITY
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
This file provides the interface for LLVM's Global Value Numbering pass which eliminates fully redund...
static std::string computeDataLayout()
This is the NVPTX address space based alias analysis pass.
static cl::opt< bool > DisableLoadStoreVectorizer("disable-nvptx-load-store-vectorizer", cl::desc("Disable load/store vectorizer"), cl::init(false), cl::Hidden)
static cl::opt< bool > DisableRequireStructuredCFG("disable-nvptx-require-structured-cfg", cl::desc("Transitional flag to turn off NVPTX's requirement on preserving " "structured CFG. The requirement should be disabled only when " "unexpected regressions happen."), cl::init(false), cl::Hidden)
static cl::opt< bool > UseShortPointersOpt("nvptx-short-ptr", cl::desc("Use 32-bit pointers for accessing const/local/shared address spaces."), cl::init(false), cl::Hidden)
static cl::opt< bool > EarlyByValArgsCopy("nvptx-early-byval-copy", cl::desc("Create a copy of byval function arguments early."), cl::init(false), cl::Hidden)
LLVM_ABI LLVM_EXTERNAL_VISIBILITY void LLVMInitializeNVPTXTarget()
uint64_t IntrinsicInst * II
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
PassBuilder PB(Machine, PassOpts->PTO, std::nullopt, &PIC)
Target-Independent Code Generator Pass Configuration Options pass.
static bool is64Bit(const char *name)
A manager for alias analyses.
void registerFunctionAnalysis()
Register a specific AA result.
Allocate memory in an ever growing pool, as if by bump-pointer.
implements a set of functionality in the TargetMachine class for targets that make use of the indepen...
FunctionPass class - This class is used to implement most global optimizations.
Analysis pass providing a never-invalidated alias analysis result.
unsigned int getSmVersion() const
bool hasTargetName() const
NVPTXTargetMachine32(const Target &T, const Triple &TT, StringRef CPU, StringRef FS, const TargetOptions &Options, std::optional< Reloc::Model > RM, std::optional< CodeModel::Model > CM, CodeGenOptLevel OL, bool JIT)
NVPTXTargetMachine64(const Target &T, const Triple &TT, StringRef CPU, StringRef FS, const TargetOptions &Options, std::optional< Reloc::Model > RM, std::optional< CodeModel::Model > CM, CodeGenOptLevel OL, bool JIT)
TargetTransformInfo getTargetTransformInfo(const Function &F) const override
Get a TargetTransformInfo implementation for the target.
std::pair< const Value *, unsigned > getPredicatedAddrSpace(const Value *V) const override
If the specified predicate checks whether a generic pointer falls within a specified address space,...
void registerPassBuilderCallbacks(PassBuilder &PB) override
Allow the target to modify the pass pipeline.
void registerEarlyDefaultAliasAnalyses(AAManager &AAM) override
Allow the target to register early alias analyses (AA before BasicAA) with the AAManager for use with...
~NVPTXTargetMachine() override
NVPTXTargetMachine(const Target &T, const Triple &TT, StringRef CPU, StringRef FS, const TargetOptions &Options, std::optional< Reloc::Model > RM, std::optional< CodeModel::Model > CM, CodeGenOptLevel OP, bool is64bit)
MachineFunctionInfo * createMachineFunctionInfo(BumpPtrAllocator &Allocator, const Function &F, const TargetSubtargetInfo *STI) const override
Create the target's instance of MachineFunctionInfo.
TargetPassConfig * createPassConfig(PassManagerBase &PM) override
Create a pass configuration object to be used by addPassToEmitX methods for generating a pipeline of ...
This class provides access to building LLVM's passes.
void registerPipelineStartEPCallback(const std::function< void(ModulePassManager &, OptimizationLevel)> &C)
Register a callback for a default optimizer pipeline extension point.
void registerFullLinkTimeOptimizationLastEPCallback(const std::function< void(ModulePassManager &, OptimizationLevel)> &C)
Register a callback for a default optimizer pipeline extension point.
LLVM_ATTRIBUTE_MINSIZE std::enable_if_t<!std::is_same_v< PassT, PassManager > > addPass(PassT &&Pass)
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...
static LLVM_ABI PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
StringRef - Represent a constant reference to a string, i.e.
void setRequiresStructuredCFG(bool Value)
std::unique_ptr< const MCSubtargetInfo > STI
Target-Independent Code Generator Pass Configuration Options.
virtual void addIRPasses()
Add common target configurable passes that perform LLVM IR to IR transforms following machine indepen...
TargetSubtargetInfo - Generic base class for all target subtargets.
Target - Wrapper for Target specific information.
Triple - Helper class for working with autoconf configuration names.
LLVM Value Representation.
PassManagerBase - An abstract interface to allow code to add passes to a pass manager without having ...
Interfaces for registering analysis passes, producing common pass manager configurations,...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
LLVM_ABI llvm::cl::opt< bool > NoKernelInfoEndLTO
This file defines the TargetMachine class.
@ ADDRESS_SPACE_SHARED_CLUSTER
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
void initializeNVPTXLowerAllocaPass(PassRegistry &)
LLVM_ABI char & EarlyMachineLICMID
This pass performs loop invariant code motion on machine instructions.
ModulePass * createNVPTXAssignValidGlobalNamesPass()
void initializeNVPTXPrologEpilogPassPass(PassRegistry &)
MachineFunctionPass * createNVPTXReplaceImageHandlesPass()
FunctionPass * createNVPTXLowerUnreachablePass(bool TrapUnreachable, bool NoTrapAfterNoreturn)
void initializeNVPTXAssignValidGlobalNamesPass(PassRegistry &)
ModulePass * createExpandVariadicsPass(ExpandVariadicsMode)
LLVM_ABI char & RegisterCoalescerID
RegisterCoalescer - This pass merges live ranges to eliminate copies.
ModuleToFunctionPassAdaptor createModuleToFunctionPassAdaptor(FunctionPassT &&Pass, bool EagerlyInvalidate=false)
A function to deduce a function pass type and wrap it in the templated adaptor.
ModulePass * createGenericToNVVMLegacyPass()
void initializeNVPTXLowerAggrCopiesPass(PassRegistry &)
void initializeNVPTXExternalAAWrapperPass(PassRegistry &)
MachineFunctionPass * createNVPTXPrologEpilogPass()
MachineFunctionPass * createNVPTXProxyRegErasurePass()
LLVM_ABI char & TailDuplicateLegacyID
TailDuplicate - Duplicate blocks with unconditional branches into tails of their predecessors.
LLVM_ABI Pass * createLoadStoreVectorizerPass()
Create a legacy pass manager instance of the LoadStoreVectorizer pass.
LLVM_ABI FunctionPass * createNaryReassociatePass()
LLVM_ABI char & PatchableFunctionID
This pass implements the "patchable-function" attribute.
ImmutablePass * createNVPTXExternalAAWrapperPass()
void initializeNVPTXLowerArgsLegacyPassPass(PassRegistry &)
LLVM_ABI char & PostRASchedulerID
PostRAScheduler - This pass performs post register allocation scheduling.
LLVM_ABI char & RemoveLoadsIntoFakeUsesID
RemoveLoadsIntoFakeUses pass.
MachineFunctionPass * createNVPTXPeephole()
LLVM_ABI char & MachineSchedulerID
MachineScheduler - This pass schedules machine instructions.
LLVM_ABI char & PeepholeOptimizerLegacyID
PeepholeOptimizer - This pass performs peephole optimizations - like extension and comparison elimina...
FunctionPass * createNVPTXISelDag(NVPTXTargetMachine &TM, llvm::CodeGenOptLevel OptLevel)
createNVPTXISelDag - This pass converts a legalized DAG into a NVPTX-specific DAG,...
LLVM_ABI char & PrologEpilogCodeInserterID
PrologEpilogCodeInserter - This pass inserts prolog and epilog code, and eliminates abstract frame re...
void initializeGenericToNVVMLegacyPassPass(PassRegistry &)
void initializeNVPTXPeepholePass(PassRegistry &)
void initializeNVPTXCtorDtorLoweringLegacyPass(PassRegistry &)
void initializeNVPTXLowerUnreachablePass(PassRegistry &)
FunctionPass * createNVPTXTagInvariantLoadsPass()
LLVM_ABI char & MachineLoopInfoID
MachineLoopInfo - This pass is a loop analysis pass.
void initializeNVVMReflectLegacyPassPass(PassRegistry &)
FunctionPass * createNVPTXLowerArgsPass()
CodeModel::Model getEffectiveCodeModel(std::optional< CodeModel::Model > CM, CodeModel::Model Default)
Helper method for getting the code model, returning Default if CM does not have a value.
LLVM_ABI char & ShrinkWrapID
ShrinkWrap pass. Look for the best place to insert save and restore.
LLVM_ABI char & MachineLateInstrsCleanupID
MachineLateInstrsCleanup - This pass removes redundant identical instructions after register allocati...
void initializeNVPTXAAWrapperPassPass(PassRegistry &)
FunctionPass * createNVPTXImageOptimizerPass()
FunctionPass * createNVPTXLowerAllocaPass()
MachineFunctionPass * createNVPTXForwardParamsPass()
LLVM_ABI char & OptimizePHIsLegacyID
OptimizePHIs - This pass optimizes machine instruction PHIs to take advantage of opportunities create...
LLVM_ABI FunctionPass * createSpeculativeExecutionPass()
LLVM_ABI char & StackMapLivenessID
StackMapLiveness - This pass analyses the register live-out set of stackmap/patchpoint intrinsics and...
LLVM_ABI char & FuncletLayoutID
This pass lays out funclets contiguously.
FunctionPass * createAllocaHoisting()
void initializeNVVMIntrRangePass(PassRegistry &)
LLVM_ABI char & PostRAMachineSinkingID
This pass perform post-ra machine sink for COPY instructions.
CodeGenOptLevel
Code generation optimization level.
LLVM_ABI char & StackSlotColoringID
StackSlotColoring - This pass performs stack slot coloring.
void initializeNVPTXAsmPrinterPass(PassRegistry &)
LLVM_ABI FunctionPass * createSeparateConstOffsetFromGEPPass(bool LowerGEP=false)
FunctionPass * createLowerAggrCopies()
LLVM_ABI char & ProcessImplicitDefsID
ProcessImpicitDefs pass - This pass removes IMPLICIT_DEFs.
void initializeNVPTXTagInvariantLoadLegacyPassPass(PassRegistry &)
LLVM_ABI FunctionPass * createGVNPass()
Create a legacy GVN pass.
FunctionPass * createNVPTXAtomicLowerPass()
ModulePass * createNVPTXCtorDtorLoweringLegacyPass()
LLVM_ABI char & MachineCSELegacyID
MachineCSE - This pass performs global CSE on machine instructions.
LLVM_ABI char & LiveVariablesID
LiveVariables pass - This pass computes the set of blocks in which each variable is life and sets mac...
LLVM_ABI char & EarlyTailDuplicateLegacyID
Duplicate blocks with unconditional branches into tails of their predecessors.
void initializeNVPTXAllocaHoistingPass(PassRegistry &)
Target & getTheNVPTXTarget64()
LLVM_ABI char & StackColoringLegacyID
StackSlotColoring - This pass performs stack coloring and merging.
LLVM_ABI FunctionPass * createInferAddressSpacesPass(unsigned AddressSpace=~0u)
void initializeNVPTXProxyRegErasurePass(PassRegistry &)
ImmutablePass * createNVPTXAAWrapperPass()
LLVM_ABI char & MachineSinkingLegacyID
MachineSinking - This pass performs sinking on machine instructions.
ModulePass * createNVVMReflectPass(unsigned int SmVersion)
LLVM_ABI char & TwoAddressInstructionPassID
TwoAddressInstruction - This pass reduces two-address instructions to use two operands.
LLVM_ABI FunctionPass * createAtomicExpandLegacyPass()
AtomicExpandPass - At IR level this pass replace atomic instructions with __atomic_* library calls,...
LLVM_ABI char & LocalStackSlotAllocationID
LocalStackSlotAllocation - This pass assigns local frame indices to stack slots relative to one anoth...
LLVM_ABI FunctionPass * createStraightLineStrengthReducePass()
LLVM_ABI FunctionPass * createEarlyCSEPass(bool UseMemorySSA=false)
LLVM_ABI char & PHIEliminationID
PHIElimination - This pass eliminates machine instruction PHI nodes by inserting copy instructions.
LLVM_ABI FunctionPass * createSROAPass(bool PreserveCFG=true)
void initializeNVPTXAtomicLowerPass(PassRegistry &)
void initializeNVPTXForwardParamsPassPass(PassRegistry &)
LLVM_ABI char & MachineCopyPropagationID
MachineCopyPropagation - This pass performs copy propagation on machine instructions.
LLVM_ABI char & DeadMachineInstructionElimID
DeadMachineInstructionElim - This pass removes dead machine instructions.
Target & getTheNVPTXTarget32()
void initializeNVPTXDAGToDAGISelLegacyPass(PassRegistry &)
Implement std::hash so that hash_code can be used in STL containers.
MachineFunctionInfo - This class can be derived from and used by targets to hold private target-speci...
RegisterTargetMachine - Helper template for registering a target machine implementation,...