Skip to content

Commit 2a905af

Browse files
AlexVlxscchan
authored andcommitted
Further tweaks / fixes.
1 parent ef2d53b commit 2a905af

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

llvm/lib/Transforms/HC/PromotePointerKernArgsToGlobal/PromotePointerKernArgsToGlobal.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,18 @@ class PromotePointerKernArgsToGlobal : public FunctionPass {
5454
&*Builder.GetInsertPoint());
5555
}
5656

57-
void maybePromoteUse(IRBuilder<>& Builder, Instruction *UI) {
57+
void maybePromoteUser(IRBuilder<>& Builder, Instruction *UI) {
5858
if (!UI)
5959
return;
6060

61-
Builder.SetInsertPoint(UI->getNextNonDebugInstruction());
61+
Instruction *NI = UI->getNextNonDebugInstruction();
62+
while (NI && isa<PHINode>(NI))
63+
NI = NI->getNextNonDebugInstruction();
64+
65+
if (!NI)
66+
return;
67+
68+
Builder.SetInsertPoint(NI);
6269

6370
createPromotableCast(Builder, UI, createTemporary(Builder, UI->getType()));
6471
}
@@ -77,15 +84,15 @@ class PromotePointerKernArgsToGlobal : public FunctionPass {
7784
return false;
7885

7986
SmallVector<Argument *, 8> PromotableArgs;
80-
SmallVector<User *, 8> PromotableUses;
87+
SmallVector<User *, 8> PromotableUsers;
8188
for (auto &&Arg : F.args()) {
8289
for (auto &&U : Arg.users()) {
8390
if (!U->getType()->isPointerTy())
8491
continue;
8592
if (U->getType()->getPointerAddressSpace() != FlatAddrSpace)
8693
continue;
8794

88-
PromotableUses.push_back(U);
95+
PromotableUsers.push_back(U);
8996
}
9097

9198
if (!Arg.getType()->isPointerTy())
@@ -96,12 +103,12 @@ class PromotePointerKernArgsToGlobal : public FunctionPass {
96103
PromotableArgs.push_back(&Arg);
97104
}
98105

99-
if (PromotableArgs.empty() && PromotableUses.empty())
106+
if (PromotableArgs.empty() && PromotableUsers.empty())
100107
return false;
101108

102109
IRBuilder<> Builder(F.getContext());
103-
for (auto &&PU : PromotableUses)
104-
maybePromoteUse(Builder, dyn_cast<Instruction>(PU));
110+
for (auto &&PU : PromotableUsers)
111+
maybePromoteUser(Builder, dyn_cast<Instruction>(PU));
105112

106113
Builder.SetInsertPoint(&F.getEntryBlock().front());
107114
for (auto &&Arg : PromotableArgs)

llvm/lib/Transforms/HC/SelectAcceleratorCode/SelectAcceleratorCode.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ class SelectAcceleratorCode : public ModulePass {
132132
}
133133

134134
static bool setFunctionAttributes(Function &F) {
135+
if (F.isIntrinsic())
136+
return false;
135137
if (F.getCallingConv() == CallingConv::AMDGPU_KERNEL)
136138
return false;
137139
if (!EnableFunctionCalls)
@@ -142,8 +144,13 @@ class SelectAcceleratorCode : public ModulePass {
142144
F.addFnAttr(Attribute::NoRecurse);
143145
Modified = true;
144146
}
145-
if (F.getVisibility() != Function::VisibilityTypes::HiddenVisibility) {
146-
F.setVisibility(Function::VisibilityTypes::HiddenVisibility);
147+
if (!F.isDSOLocal()) {
148+
F.setDSOLocal(true);
149+
Modified = true;
150+
}
151+
if (!F.isDeclaration() && !F.hasInternalLinkage()) {
152+
F.setVisibility(Function::VisibilityTypes::DefaultVisibility);
153+
F.setLinkage(Function::LinkageTypes::InternalLinkage);
147154
Modified = true;
148155
}
149156

@@ -174,7 +181,7 @@ class SelectAcceleratorCode : public ModulePass {
174181
Modified = eraseDeadAliases_(M) || Modified;
175182

176183
for (auto &&F : M.functions())
177-
Modified = setFunctionAttributes(F);
184+
Modified = setFunctionAttributes(F) || Modified;
178185

179186
return Modified;
180187
}

0 commit comments

Comments
 (0)