LLVM: lib/Target/NVPTX/NVPTXTargetMachine.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

28#include "llvm/IR/IntrinsicsNVPTX.h"

41#include

42#include

43#include

44

45using namespace llvm;

46

47

48

51 cl::desc("Disable load/store vectorizer"),

53

54

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."),

61

63 "nvptx-short-ptr",

65 "Use 32-bit pointers for accessing const/local/shared address spaces."),

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

87 "nvptx-early-byval-copy",

88 cl::desc("Create a copy of byval function arguments early."),

90

120

124 std::optionalReloc::Model RM,

125 std::optionalCodeModel::Model CM,

127

128

134 Subtarget(TT, std::string(CPU), std::string(FS), *this),

135 StrPool(StrAlloc) {

138 else

143}

144

146

147void NVPTXTargetMachine32::anchor() {}

148

152 std::optionalReloc::Model RM,

153 std::optionalCodeModel::Model CM,

156

157void NVPTXTargetMachine64::anchor() {}

158

162 std::optionalReloc::Model RM,

163 std::optionalCodeModel::Model CM,

166

167namespace {

168

170public:

173

176 }

177

178 void addIRPasses() override;

179 bool addInstSelector() override;

180 void addPreRegAlloc() override;

181 void addPostRegAlloc() override;

182 void addMachineSSAOptimization() override;

183

184 FunctionPass *createTargetRegisterAllocator(bool) override;

185 void addFastRegAlloc() override;

186 void addOptimizedRegAlloc() override;

187

188 bool addRegAssignAndRewriteFast() override {

190 }

191

192 bool addRegAssignAndRewriteOptimized() override {

194 }

195

196private:

197

198

199 void addEarlyCSEOrGVNPass();

200

201

202 void addAddressSpaceInferencePasses();

203

204

205 void addStraightLineScalarOptimizationPasses();

206};

207

208}

209

211 return new NVPTXPassConfig(*this, PM);

212}

213

220

224

226#define GET_PASS_REGISTRY "NVPTXPassRegistry.def"

228

229 PB.registerPipelineStartEPCallback(

231

232

233 if (Subtarget.hasTargetName())

235

237

238

243 });

244

246 PB.registerFullLinkTimeOptimizationLastEPCallback(

251 });

252 }

253}

254

259

260std::pair<const Value *, unsigned>

263 switch (II->getIntrinsicID()) {

264 case Intrinsic::nvvm_isspacep_const:

266 case Intrinsic::nvvm_isspacep_global:

268 case Intrinsic::nvvm_isspacep_local:

270 case Intrinsic::nvvm_isspacep_shared:

272 case Intrinsic::nvvm_isspacep_shared_cluster:

273 return std::make_pair(II->getArgOperand(0),

275 default:

276 break;

277 }

278 }

279 return std::make_pair(nullptr, -1);

280}

281

282void NVPTXPassConfig::addEarlyCSEOrGVNPass() {

285 else

287}

288

289void NVPTXPassConfig::addAddressSpaceInferencePasses() {

290

291

294

295

298}

299

300void NVPTXPassConfig::addStraightLineScalarOptimizationPasses() {

303

304

306

307

308

309 addEarlyCSEOrGVNPass();

310

312

313

315}

316

317void NVPTXPassConfig::addIRPasses() {

318

319

320

321

322

334

337

338

339

340

341

344

349

350

351

354 addAddressSpaceInferencePasses();

355 addStraightLineScalarOptimizationPasses();

356 }

357

361

362

364

365

366

367

368

369

370

371

372

373

374

375

377 addEarlyCSEOrGVNPass();

382 }

383

384 if (ST.hasPTXASUnreachableBug()) {

385

386

387 const auto &Options = getNVPTXTargetMachine().Options;

389 Options.NoTrapAfterNoreturn));

390 }

391}

392

393bool NVPTXPassConfig::addInstSelector() {

398

399 return false;

400}

401

402void NVPTXPassConfig::addPreRegAlloc() {

404

406}

407

408void NVPTXPassConfig::addPostRegAlloc() {

411

412

413

415 }

416}

417

418FunctionPass *NVPTXPassConfig::createTargetRegisterAllocator(bool) {

419 return nullptr;

420}

421

422void NVPTXPassConfig::addFastRegAlloc() {

425}

426

427void NVPTXPassConfig::addOptimizedRegAlloc() {

432

435

436

438 printAndVerify("After Machine Scheduling");

439

441

442

443

444

445 printAndVerify("After StackSlotColoring");

446}

447

448void NVPTXPassConfig::addMachineSSAOptimization() {

449

451 printAndVerify("After Pre-RegAlloc TailDuplicate");

452

453

454

456

457

458

460

461

462

464

465

466

467

468

470 printAndVerify("After codegen DCE pass");

471

472

473

474

475 if (addILPOpts())

476 printAndVerify("After ILP optimizations");

477

480

482 printAndVerify("After Machine LICM, CSE and Sinking passes");

483

485 printAndVerify("After codegen peephole optimization pass");

486}

#define LLVM_EXTERNAL_VISIBILITY

This file provides the interface for LLVM's Global Value Numbering pass which eliminates fully redund...

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()

Definition NVPTXTargetMachine.cpp:91

This file a TargetTransformInfoImplBase conforming object specific to the NVPTX target machine.

uint64_t IntrinsicInst * II

PassBuilder PB(Machine, PassOpts->PTO, std::nullopt, &PIC)

const GCNTargetMachine & getTM(const GCNSubtarget *STI)

static TableGen::Emitter::Opt Y("gen-skeleton-entry", EmitSkeleton, "Generate example skeleton entry")

static TableGen::Emitter::OptClass< SkeletonEmitter > X("gen-skeleton-class", "Generate example skeleton class")

Target-Independent Code Generator Pass Configuration Options pass.

This pass exposes codegen information to IR-level passes.

A manager for alias analyses.

void registerFunctionAnalysis()

Register a specific AA result.

CodeGenTargetMachineImpl(const Target &T, StringRef DataLayoutString, const Triple &TT, StringRef CPU, StringRef FS, const TargetOptions &Options, Reloc::Model RM, CodeModel::Model CM, CodeGenOptLevel OL)

FunctionPass class - This class is used to implement most global optimizations.

const TargetSubtargetInfo * getSubtargetImpl(const Function &) const override

Virtual method implemented by subclasses that returns a reference to that target's TargetSubtargetInf...

Analysis pass providing a never-invalidated alias analysis result.

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)

Definition NVPTXTargetMachine.cpp:149

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)

Definition NVPTXTargetMachine.cpp:159

TargetTransformInfo getTargetTransformInfo(const Function &F) const override

Get a TargetTransformInfo implementation for the target.

Definition NVPTXTargetMachine.cpp:256

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,...

Definition NVPTXTargetMachine.cpp:261

void registerPassBuilderCallbacks(PassBuilder &PB) override

Allow the target to modify the pass pipeline.

Definition NVPTXTargetMachine.cpp:225

void registerEarlyDefaultAliasAnalyses(AAManager &AAM) override

Allow the target to register early alias analyses (AA before BasicAA) with the AAManager for use with...

Definition NVPTXTargetMachine.cpp:221

~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)

Definition NVPTXTargetMachine.cpp:121

MachineFunctionInfo * createMachineFunctionInfo(BumpPtrAllocator &Allocator, const Function &F, const TargetSubtargetInfo *STI) const override

Create the target's instance of MachineFunctionInfo.

Definition NVPTXTargetMachine.cpp:214

TargetPassConfig * createPassConfig(PassManagerBase &PM) override

Create a pass configuration object to be used by addPassToEmitX methods for generating a pipeline of ...

Definition NVPTXTargetMachine.cpp:210

This class provides access to building LLVM's passes.

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.

This pass provides access to the codegen interfaces that are needed for IR-level transformations.

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:🆑: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.

decltype(auto) dyn_cast(const From &Val)

dyn_cast - Return the argument parameter cast to the specified type.

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()

PassManager< Module > ModulePassManager

Convenience typedef for a pass manager over modules.

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.

BumpPtrAllocatorImpl BumpPtrAllocator

The standard BumpPtrAllocator which just uses the default template parameters.

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.

PassManager< Function > FunctionPassManager

Convenience typedef for a pass manager over functions.

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...

static FuncInfoTy * create(BumpPtrAllocator &Allocator, const Function &F, const SubtargetTy *STI)

Factory function: default behavior is to call new using the supplied allocator.

RegisterTargetMachine - Helper template for registering a target machine implementation,...