llvm.org GIT mirror llvm / 300b82b
[NVPTX] do not rely on cached subtarget info. If a module has function references, but no functions themselves, we may end up never calling runOnMachineFunction and therefore would never initialize nvptxSubtarget field which would eventually cause a crash. Instead of relying on nvptxSubtarget being initialized by one of the methods, retrieve subtarget info directly. Differential Revision: https://reviews.llvm.org/D55580 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@348952 91177308-0d34-0410-b5e6-96231b3b80d8 Artem Belevich 1 year, 11 months ago
3 changed file(s) with 29 addition(s) and 13 deletion(s). Raw diff Collapse all Expand all
218218 return;
219219 }
220220
221 const NVPTXSubtarget &STI = MI->getMF()->getSubtarget();
221222 for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
222223 const MachineOperand &MO = MI->getOperand(i);
223224
224225 MCOperand MCOp;
225 if (!nvptxSubtarget->hasImageHandles()) {
226 if (!STI.hasImageHandles()) {
226227 if (lowerImageHandleOperand(MI, i, MCOp)) {
227228 OutMI.addOperand(MCOp);
228229 continue;
328329
329330 void NVPTXAsmPrinter::printReturnValStr(const Function *F, raw_ostream &O) {
330331 const DataLayout &DL = getDataLayout();
331 const TargetLowering *TLI = nvptxSubtarget->getTargetLowering();
332 const NVPTXSubtarget &STI = TM.getSubtarget(*F);
333 const TargetLowering *TLI = STI.getTargetLowering();
332334
333335 Type *Ty = F->getReturnType();
334336
335 bool isABI = (nvptxSubtarget->getSmVersion() >= 20);
337 bool isABI = (STI.getSmVersion() >= 20);
336338
337339 if (Ty->getTypeID() == Type::VoidTyID)
338340 return;
473475 }
474476
475477 bool NVPTXAsmPrinter::runOnMachineFunction(MachineFunction &F) {
476 nvptxSubtarget = &F.getSubtarget();
477478 bool Result = AsmPrinter::runOnMachineFunction(F);
478479 // Emit closing brace for the body of function F.
479480 // The closing brace must be emitted here because we need to emit additional
507508 OutStreamer->AddComment(Twine("implicit-def: ") +
508509 getVirtualRegisterName(RegNo));
509510 } else {
511 const NVPTXSubtarget &STI = MI->getMF()->getSubtarget();
510512 OutStreamer->AddComment(Twine("implicit-def: ") +
511 nvptxSubtarget->getRegisterInfo()->getName(RegNo));
513 STI.getRegisterInfo()->getName(RegNo));
512514 }
513515 OutStreamer->AddBlankLine();
514516 }
14301432 void NVPTXAsmPrinter::emitFunctionParamList(const Function *F, raw_ostream &O) {
14311433 const DataLayout &DL = getDataLayout();
14321434 const AttributeList &PAL = F->getAttributes();
1433 const TargetLowering *TLI = nvptxSubtarget->getTargetLowering();
1435 const NVPTXSubtarget &STI = TM.getSubtarget(*F);
1436 const TargetLowering *TLI = STI.getTargetLowering();
14341437 Function::const_arg_iterator I, E;
14351438 unsigned paramIndex = 0;
14361439 bool first = true;
14371440 bool isKernelFunc = isKernelFunction(*F);
1438 bool isABI = (nvptxSubtarget->getSmVersion() >= 20);
1441 bool isABI = (STI.getSmVersion() >= 20);
1442 bool hasImageHandles = STI.hasImageHandles();
14391443 MVT thePointerTy = TLI->getPointerTy(DL);
14401444
14411445 if (F->arg_empty()) {
14591463 if (isImage(*I)) {
14601464 std::string sname = I->getName();
14611465 if (isImageWriteOnly(*I) || isImageReadWrite(*I)) {
1462 if (nvptxSubtarget->hasImageHandles())
1466 if (hasImageHandles)
14631467 O << "\t.param .u64 .ptr .surfref ";
14641468 else
14651469 O << "\t.param .surfref ";
14671471 O << "_param_" << paramIndex;
14681472 }
14691473 else { // Default image is read_only
1470 if (nvptxSubtarget->hasImageHandles())
1474 if (hasImageHandles)
14711475 O << "\t.param .u64 .ptr .texref ";
14721476 else
14731477 O << "\t.param .texref ";
14751479 O << "_param_" << paramIndex;
14761480 }
14771481 } else {
1478 if (nvptxSubtarget->hasImageHandles())
1482 if (hasImageHandles)
14791483 O << "\t.param .u64 .ptr .samplerref ";
14801484 else
14811485 O << "\t.param .samplerref ";
257257 typedef DenseMap VRegRCMap;
258258 VRegRCMap VRegMapping;
259259
260 // Cache the subtarget here.
261 const NVPTXSubtarget *nvptxSubtarget;
262
263260 // List of variables demoted to a function scope.
264261 std::map> localDecls;
265262
0 ; RUN: llc < %s -march=nvptx -mcpu=sm_20 | FileCheck %s
1 ; RUN: llc < %s -march=nvptx64 -mcpu=sm_20 | FileCheck %s
2
3 ; Test that we don't crash if we're compiling a module with function references,
4 ; but without any functions in it.
5
6 target datalayout = "e-i64:64-i128:128-v16:16-v32:32-n16:32:64"
7 target triple = "nvptx64-nvidia-cuda"
8
9 @Funcs = local_unnamed_addr addrspace(1) externally_initialized
10 global [1 x void (i8*)*] [void (i8*)* @func], align 8
11
12 declare void @func(i8*)
13
14 ; CHECK: Funcs[1] = {func}