Skip to content

Commit ecb3e1f

Browse files
committed
Revert "[NVPTX] Auto-Upgrade some nvvm.annotations to attributes (llvm#119261)"
This reverts commit de7438e.
1 parent c0cd20b commit ecb3e1f

File tree

10 files changed

+48
-122
lines changed

10 files changed

+48
-122
lines changed

llvm/include/llvm/IR/AutoUpgrade.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,6 @@ namespace llvm {
6161
/// module is modified.
6262
bool UpgradeModuleFlags(Module &M);
6363

64-
/// Convert legacy nvvm.annotations metadata to appropriate function
65-
/// attributes.
66-
void UpgradeNVVMAnnotations(Module &M);
67-
6864
/// Convert calls to ARC runtime functions to intrinsic calls and upgrade the
6965
/// old retain release marker to new module flag format.
7066
void UpgradeARCRuntime(Module &M);

llvm/lib/AsmParser/LLParser.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,6 @@ bool LLParser::validateEndOfModule(bool UpgradeDebugInfo) {
448448
llvm::UpgradeDebugInfo(*M);
449449

450450
UpgradeModuleFlags(*M);
451-
UpgradeNVVMAnnotations(*M);
452451
UpgradeSectionAttributes(*M);
453452

454453
if (PreserveInputDbgFormat != cl::boolOrDefault::BOU_TRUE)

llvm/lib/Bitcode/Reader/BitcodeReader.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7158,8 +7158,6 @@ Error BitcodeReader::materializeModule() {
71587158

71597159
UpgradeModuleFlags(*TheModule);
71607160

7161-
UpgradeNVVMAnnotations(*TheModule);
7162-
71637161
UpgradeARCRuntime(*TheModule);
71647162

71657163
return Error::success();

llvm/lib/IR/AutoUpgrade.cpp

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include "llvm/ADT/StringSwitch.h"
1818
#include "llvm/BinaryFormat/Dwarf.h"
1919
#include "llvm/IR/AttributeMask.h"
20-
#include "llvm/IR/CallingConv.h"
2120
#include "llvm/IR/Constants.h"
2221
#include "llvm/IR/DebugInfo.h"
2322
#include "llvm/IR/DebugInfoMetadata.h"
@@ -5022,72 +5021,6 @@ bool llvm::UpgradeDebugInfo(Module &M) {
50225021
return Modified;
50235022
}
50245023

5025-
bool static upgradeSingleNVVMAnnotation(GlobalValue *GV, StringRef K,
5026-
const Metadata *V) {
5027-
if (K == "kernel") {
5028-
if (!mdconst::extract<ConstantInt>(V)->isZero())
5029-
cast<Function>(GV)->setCallingConv(CallingConv::PTX_Kernel);
5030-
return true;
5031-
}
5032-
if (K == "align") {
5033-
// V is a bitfeild specifying two 16-bit values. The alignment value is
5034-
// specfied in low 16-bits, The index is specified in the high bits. For the
5035-
// index, 0 indicates the return value while higher values correspond to
5036-
// each parameter (idx = param + 1).
5037-
const uint64_t AlignIdxValuePair =
5038-
mdconst::extract<ConstantInt>(V)->getZExtValue();
5039-
const unsigned Idx = (AlignIdxValuePair >> 16);
5040-
const Align StackAlign = Align(AlignIdxValuePair & 0xFFFF);
5041-
// TODO: Skip adding the stackalign attribute for returns, for now.
5042-
if (!Idx)
5043-
return false;
5044-
cast<Function>(GV)->addAttributeAtIndex(
5045-
Idx, Attribute::getWithStackAlignment(GV->getContext(), StackAlign));
5046-
return true;
5047-
}
5048-
5049-
return false;
5050-
}
5051-
5052-
void llvm::UpgradeNVVMAnnotations(Module &M) {
5053-
NamedMDNode *NamedMD = M.getNamedMetadata("nvvm.annotations");
5054-
if (!NamedMD)
5055-
return;
5056-
5057-
SmallVector<MDNode *, 8> NewNodes;
5058-
SmallSet<const MDNode *, 8> SeenNodes;
5059-
for (MDNode *MD : NamedMD->operands()) {
5060-
if (!SeenNodes.insert(MD).second)
5061-
continue;
5062-
5063-
auto *GV = mdconst::dyn_extract_or_null<GlobalValue>(MD->getOperand(0));
5064-
if (!GV)
5065-
continue;
5066-
5067-
assert((MD->getNumOperands() % 2) == 1 && "Invalid number of operands");
5068-
5069-
SmallVector<Metadata *, 8> NewOperands{MD->getOperand(0)};
5070-
// Each nvvm.annotations metadata entry will be of the following form:
5071-
// !{ ptr @gv, !"key1", value1, !"key2", value2, ... }
5072-
// start index = 1, to skip the global variable key
5073-
// increment = 2, to skip the value for each property-value pairs
5074-
for (unsigned j = 1, je = MD->getNumOperands(); j < je; j += 2) {
5075-
MDString *K = cast<MDString>(MD->getOperand(j));
5076-
const MDOperand &V = MD->getOperand(j + 1);
5077-
bool Upgraded = upgradeSingleNVVMAnnotation(GV, K->getString(), V);
5078-
if (!Upgraded)
5079-
NewOperands.append({K, V});
5080-
}
5081-
5082-
if (NewOperands.size() > 1)
5083-
NewNodes.push_back(MDNode::get(M.getContext(), NewOperands));
5084-
}
5085-
5086-
NamedMD->clearOperands();
5087-
for (MDNode *N : NewNodes)
5088-
NamedMD->addOperand(N);
5089-
}
5090-
50915024
/// This checks for objc retain release marker which should be upgraded. It
50925025
/// returns true if module is modified.
50935026
static bool upgradeRetainReleaseMarker(Module &M) {

llvm/lib/Linker/IRMover.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1244,7 +1244,6 @@ Error IRLinker::linkModuleFlagsMetadata() {
12441244

12451245
// Check for module flag for updates before do anything.
12461246
UpgradeModuleFlags(*SrcM);
1247-
UpgradeNVVMAnnotations(*SrcM);
12481247

12491248
// If the destination module doesn't have module flags yet, then just copy
12501249
// over the source module's flags.

llvm/lib/Target/NVPTX/NVPTXUtilities.cpp

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -310,21 +310,30 @@ std::optional<unsigned> getMaxNReg(const Function &F) {
310310
return findOneNVVMAnnotation(&F, "maxnreg");
311311
}
312312

313+
bool isKernelFunction(const Function &F) {
314+
if (F.getCallingConv() == CallingConv::PTX_Kernel)
315+
return true;
316+
317+
if (const auto X = findOneNVVMAnnotation(&F, "kernel"))
318+
return (*X == 1);
319+
320+
return false;
321+
}
322+
313323
MaybeAlign getAlign(const Function &F, unsigned Index) {
314324
// First check the alignstack metadata
315325
if (MaybeAlign StackAlign =
316326
F.getAttributes().getAttributes(Index).getStackAlignment())
317327
return StackAlign;
318328

319-
// check the legacy nvvm metadata only for the return value since llvm does
320-
// not support stackalign attribute for this.
321-
if (Index == 0) {
322-
std::vector<unsigned> Vs;
323-
if (findAllNVVMAnnotation(&F, "align", Vs))
324-
for (unsigned V : Vs)
325-
if ((V >> 16) == Index)
326-
return Align(V & 0xFFFF);
327-
}
329+
// If that is missing, check the legacy nvvm metadata
330+
std::vector<unsigned> Vs;
331+
bool retval = findAllNVVMAnnotation(&F, "align", Vs);
332+
if (!retval)
333+
return std::nullopt;
334+
for (unsigned V : Vs)
335+
if ((V >> 16) == Index)
336+
return Align(V & 0xFFFF);
328337

329338
return std::nullopt;
330339
}

llvm/lib/Target/NVPTX/NVPTXUtilities.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include "NVPTX.h"
1717
#include "llvm/ADT/StringExtras.h"
1818
#include "llvm/CodeGen/ValueTypes.h"
19-
#include "llvm/IR/CallingConv.h"
2019
#include "llvm/IR/Function.h"
2120
#include "llvm/IR/GlobalVariable.h"
2221
#include "llvm/IR/IntrinsicInst.h"
@@ -64,11 +63,7 @@ std::optional<unsigned> getClusterDimz(const Function &);
6463
std::optional<unsigned> getMaxClusterRank(const Function &);
6564
std::optional<unsigned> getMinCTASm(const Function &);
6665
std::optional<unsigned> getMaxNReg(const Function &);
67-
68-
inline bool isKernelFunction(const Function &F) {
69-
return F.getCallingConv() == CallingConv::PTX_Kernel;
70-
}
71-
66+
bool isKernelFunction(const Function &);
7267
bool isParamGridConstant(const Value &);
7368

7469
MaybeAlign getAlign(const Function &, unsigned);

llvm/lib/Transforms/IPO/OpenMPOpt.cpp

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5935,19 +5935,39 @@ bool llvm::omp::isOpenMPKernel(Function &Fn) {
59355935
}
59365936

59375937
KernelSet llvm::omp::getDeviceKernels(Module &M) {
5938+
// TODO: Create a more cross-platform way of determining device kernels.
59385939
KernelSet Kernels;
59395940

5940-
for (Function &F : M)
5941-
if (F.hasKernelCallingConv()) {
5941+
DenseSet<const Function *> SeenKernels;
5942+
auto ProcessKernel = [&](Function &KF) {
5943+
if (SeenKernels.insert(&KF).second) {
59425944
// We are only interested in OpenMP target regions. Others, such as
59435945
// kernels generated by CUDA but linked together, are not interesting to
59445946
// this pass.
5945-
if (isOpenMPKernel(F)) {
5947+
if (isOpenMPKernel(KF)) {
59465948
++NumOpenMPTargetRegionKernels;
5947-
Kernels.insert(&F);
5949+
Kernels.insert(&KF);
59485950
} else
59495951
++NumNonOpenMPTargetRegionKernels;
59505952
}
5953+
};
5954+
5955+
if (NamedMDNode *MD = M.getNamedMetadata("nvvm.annotations"))
5956+
for (auto *Op : MD->operands()) {
5957+
if (Op->getNumOperands() < 2)
5958+
continue;
5959+
MDString *KindID = dyn_cast<MDString>(Op->getOperand(1));
5960+
if (!KindID || KindID->getString() != "kernel")
5961+
continue;
5962+
5963+
if (auto *KernelFn =
5964+
mdconst::dyn_extract_or_null<Function>(Op->getOperand(0)))
5965+
ProcessKernel(*KernelFn);
5966+
}
5967+
5968+
for (Function &F : M)
5969+
if (F.hasKernelCallingConv())
5970+
ProcessKernel(F);
59515971

59525972
return Kernels;
59535973
}

llvm/test/CodeGen/NVPTX/upgrade-nvvm-annotations.ll

Lines changed: 0 additions & 28 deletions
This file was deleted.

revert_patches.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,8 @@ revert: breaks build of rccl __cpuidex
2828
1c28b92373 [Clang] __has_builtin should return false for aux triple builtins (#121839)
2929
Ron and Saiyed
3030
---
31+
32+
--
33+
revert: breaks classic flang
34+
de7438e47283 - [NVPTX] Auto-Upgrade some nvvm.annotations to attributes
35+
Ron

0 commit comments

Comments
 (0)