Skip to content

Commit 1fcca8d

Browse files
Anton Sidorenkoigcbot
authored andcommitted
[Autobackout][FuncReg]Revert of change: 590c1ba
Prepare VCBE to handle standalone stack calls State before: The head of a function group is a kernel. Each function that is used in different function groups (kernels and theirs call graphs) must be copied. This rule must be applied even for stack calls. In other words, stack calls are kernel-dependent functions. Such an approach was OK until there was a need to compile standalone stack calls. How it is now reorganized: Each kernel is a head of a function group of type GROUP. Each stack call (or indirect function) is a head of function group of type SUBGROUP (legacy, we may consider removal of different types later). Stack calls won't be copied. Function group passes are run on each function group independently. This allows the creation of independent stack calls with no need in a kernel. So, each SUBGROUP is independent function group and compiles separately, but at the same time, its head may be referenced by others function groups of type GROUP of SUBGROUP.
1 parent 9802595 commit 1fcca8d

19 files changed

+153
-355
lines changed

IGC/VectorCompiler/igcdeps/src/TranslationInterface.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,6 @@ static void adjustTransformationsAndOptimizations(vc::CompileOptions &Opts) {
193193
Opts.ForceDisableNonOverlappingRegionOpt = true;
194194
if (IGC_IS_FLAG_ENABLED(VCPassDebugToFinalizer))
195195
Opts.ForcePassDebugToFinalizer = true;
196-
if (IGC_IS_FLAG_ENABLED(VCSaveStackCallLinkage))
197-
Opts.SaveStackCallLinkage = true;
198196
}
199197

200198
static void adjustDumpOptions(vc::CompileOptions &Opts) {

IGC/VectorCompiler/include/vc/Driver/Driver.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ struct CompileOptions {
9797

9898
// from IGC_XXX env
9999
FunctionControl FCtrl = FunctionControl::Default;
100-
bool SaveStackCallLinkage = false;
101100
};
102101

103102
struct ExternalData {

IGC/VectorCompiler/include/vc/Support/BackendConfig.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,6 @@ struct GenXBackendOptions {
9999
// max private stateless memory size per thread
100100
unsigned StatelessPrivateMemSize;
101101

102-
// Historically stack calls linkage is changed to internal in CMABI. This
103-
// option allows saving the original linkage type for such functions. This is
104-
// required for linking (e.g. invoke_simd).
105-
bool SaveStackCallLinkage = false;
106-
107102
GenXBackendOptions();
108103
};
109104

@@ -222,8 +217,6 @@ class GenXBackendConfig : public ImmutablePass {
222217
}
223218

224219
bool useBindlessBuffers() const { return Options.UseBindlessBuffers; }
225-
226-
bool saveStackCallLinkage() const { return Options.SaveStackCallLinkage; }
227220
};
228221
} // namespace llvm
229222

IGC/VectorCompiler/lib/Driver/Driver.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,6 @@ static GenXBackendOptions createBackendOptions(const vc::CompileOptions &Opts) {
232232
BackendOpts.WATable = Opts.WATable;
233233
BackendOpts.IsLargeGRFMode = Opts.IsLargeGRFMode;
234234
BackendOpts.UseBindlessBuffers = Opts.UseBindlessBuffers;
235-
if (Opts.SaveStackCallLinkage)
236-
BackendOpts.SaveStackCallLinkage = true;
237235
return BackendOpts;
238236
}
239237

IGC/VectorCompiler/lib/GenXCodeGen/FunctionGroup.cpp

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ SPDX-License-Identifier: MIT
1818
//===----------------------------------------------------------------------===//
1919

2020
#include "FunctionGroup.h"
21-
#include "vc/GenXOpts/Utils/KernelInfo.h"
2221
#include "llvm/Analysis/LoopInfo.h"
2322
#include "llvm/GenXIntrinsics/GenXMetadata.h"
2423
#include "llvm/IR/Dominators.h"
@@ -84,14 +83,6 @@ FunctionGroup *FunctionGroupAnalysis::getSubGroup(const Function *F) const {
8483
return getGroup(F, FGType::SUBGROUP);
8584
}
8685

87-
FunctionGroup *FunctionGroupAnalysis::getAnyGroup(const Function *F) const {
88-
auto *Group = getGroup(F, FGType::SUBGROUP);
89-
if (!Group)
90-
Group = getGroup(F, FGType::GROUP);
91-
IGC_ASSERT_MESSAGE(Group, "Function isn't assigned to any function group");
92-
return Group;
93-
}
94-
9586
// getGroupForHead : get the FunctionGroup for which Function F is the
9687
// head, else 0
9788
FunctionGroup *FunctionGroupAnalysis::getGroupForHead(const Function *F) const {
@@ -107,8 +98,7 @@ FunctionGroup *FunctionGroupAnalysis::getGroupForHead(const Function *F) const {
10798
void FunctionGroupAnalysis::replaceFunction(Function *OldF, Function *NewF) {
10899
for (auto T : TypesToProcess) {
109100
auto OldFIt = GroupMap[T].find(OldF);
110-
if (OldFIt == GroupMap[T].end())
111-
continue;
101+
IGC_ASSERT(OldFIt != GroupMap[T].end());
112102
FunctionGroup *FG = OldFIt->second;
113103
GroupMap[T].erase(OldFIt);
114104
GroupMap[T][NewF] = FG;
@@ -176,12 +166,8 @@ bool FunctionGroupAnalysis::buildGroup(CallGraph &Callees, Function *F,
176166
LLVM_DEBUG(dbgs() << "process function " << F->getName() << " from " << curGr
177167
<< ", type = " << Type << "\n");
178168
if (Visited.count(F) > 0) {
179-
bool NeedCloning =
180-
std::any_of(std::begin(TypesToProcess), std::end(TypesToProcess),
181-
[&GM = GroupMap, curGr, F](FGType CurType) {
182-
return GM[CurType].count(F) && GM[CurType][F] != curGr;
183-
});
184-
if (NeedCloning && !F->hasFnAttribute(TypeToAttr(Type))) {
169+
if (GroupMap[Type].count(F) > 0 && GroupMap[Type][F] != curGr &&
170+
!F->hasFnAttribute(TypeToAttr(Type))) {
185171
ValueToValueMapTy VMap;
186172
Function *ClonedFunc = CloneFunction(F, VMap);
187173
LLVM_DEBUG(dbgs() << "Cloning: " << ClonedFunc->getName() << "\n");
@@ -195,17 +181,16 @@ bool FunctionGroupAnalysis::buildGroup(CallGraph &Callees, Function *F,
195181
if (GroupMap[Type][CI->getFunction()] == curGr)
196182
*u = ClonedFunc;
197183
}
184+
for (auto T : TypesToProcess) {
185+
if (T >= Type)
186+
break;
187+
addToFunctionGroup(getGroup(F, T), ClonedFunc, T);
188+
}
198189
addToFunctionGroup(curGr, ClonedFunc, Type);
199190

200191
for (auto &Callee : Callees[F]) {
201192
if (Callee == F)
202193
continue;
203-
if (genx::requiresStackCall(Callee)) {
204-
LLVM_DEBUG(dbgs()
205-
<< "\tDo not process next callee " << Callee->getName()
206-
<< " because it's a stack call\n");
207-
continue;
208-
}
209194
LLVM_DEBUG(dbgs() << "Next callee: " << Callee->getName() << "\n");
210195
result |= buildGroup(Callees, Callee, curGr, Type);
211196
}
@@ -224,13 +209,6 @@ bool FunctionGroupAnalysis::buildGroup(CallGraph &Callees, Function *F,
224209
addToFunctionGroup(curGr, F, Type);
225210
}
226211
for (auto &Callee : Callees[F]) {
227-
if (genx::requiresStackCall(Callee)) {
228-
LLVM_DEBUG(dbgs() << "\tDo not process next callee "
229-
<< Callee->getName()
230-
<< " because it's a stack call\n");
231-
continue;
232-
}
233-
234212
LLVM_DEBUG(dbgs() << "Next callee: " << Callee->getName() << "\n");
235213
result |= buildGroup(Callees, Callee, curGr, Type);
236214
}
@@ -440,7 +418,7 @@ bool FGPassManager::runFGPassSequence(unsigned &Pass) {
440418
bool Changed = false;
441419

442420
Changed |= doFGInitialization(BeginPass, Pass, FGA);
443-
for (auto *FG : FGA.AllGroups())
421+
for (auto *FG : FGA)
444422
Changed |= runPassesOnFunctionGroup(BeginPass, Pass, *FG);
445423
Changed |= doFGFinalization(BeginPass, Pass, FGA);
446424

IGC/VectorCompiler/lib/GenXCodeGen/FunctionGroup.h

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ SPDX-License-Identifier: MIT
2727
#ifndef FUNCTIONGROUP_H
2828
#define FUNCTIONGROUP_H
2929

30-
#include "vc/GenXOpts/Utils/KernelInfo.h"
31-
#include "llvm/ADT/SetVector.h"
3230
#include "llvm/ADT/SmallVector.h"
3331
#include "llvm/IR/Module.h"
3432
#include "llvm/IR/ValueHandle.h"
@@ -43,18 +41,6 @@ class FunctionGroupAnalysis;
4341
class LLVMContext;
4442
class PMStack;
4543

46-
namespace genx {
47-
namespace fg {
48-
inline bool isGroupHead(const Function &F) { return genx::isKernel(&F); }
49-
inline bool isSubGroupHead(const Function &F) {
50-
return genx::isReferencedIndirectly(&F) || genx::requiresStackCall(&F);
51-
}
52-
inline bool isHead(const Function &F) {
53-
return isGroupHead(F) || isSubGroupHead(F);
54-
}
55-
} // namespace fg
56-
} // namespace genx
57-
5844
//----------------------------------------------------------------------
5945
// FunctionGroup : a group of Functions
6046
//
@@ -64,9 +50,6 @@ class FunctionGroup {
6450
// Elements are asserting value handles, so we spot when a Function
6551
// in the group gets destroyed too early.
6652
SmallVector<AssertingVH<Function>, 8> Functions;
67-
// FunctionGroup can call the head function of another FunctionGroups with
68-
// SUBGROUP type.
69-
SetVector<const FunctionGroup *> Subgroups;
7053

7154
public:
7255
FunctionGroup(FunctionGroupAnalysis *FGA) : FGA(FGA) {}
@@ -100,25 +83,6 @@ class FunctionGroup {
10083
StringRef getName() { return getHead()->getName(); }
10184
LLVMContext &getContext() { return getHead()->getContext(); }
10285
Module *getModule() { return getHead()->getParent(); }
103-
void addSubgroup(FunctionGroup *FG) {
104-
IGC_ASSERT(FG);
105-
IGC_ASSERT(FG->getHead());
106-
IGC_ASSERT_MESSAGE(genx::fg::isSubGroupHead(*FG->getHead()),
107-
"Provided function group has incorrect type");
108-
Subgroups.insert(FG);
109-
}
110-
using subgroup_iterator = decltype(Subgroups)::iterator;
111-
using const_subgroup_iterator = decltype(Subgroups)::const_iterator;
112-
subgroup_iterator begin_subgroup() { return Subgroups.begin(); }
113-
subgroup_iterator end_subgroup() { return Subgroups.end(); }
114-
const_subgroup_iterator begin_subgroup() const { return Subgroups.begin(); }
115-
const_subgroup_iterator end_subgroup() const { return Subgroups.end(); }
116-
iterator_range<subgroup_iterator> subgroups() {
117-
return make_range(begin_subgroup(), end_subgroup());
118-
}
119-
iterator_range<const_subgroup_iterator> subgroups() const {
120-
return make_range(begin_subgroup(), end_subgroup());
121-
}
12286
};
12387

12488
//----------------------------------------------------------------------
@@ -189,8 +153,6 @@ class FunctionGroupAnalysis : public ModulePass {
189153
FunctionGroup *getGroup(const Function *F, FGType Type) const;
190154
FunctionGroup *getGroup(const Function *F) const;
191155
FunctionGroup *getSubGroup(const Function *F) const;
192-
// get group or subgroup depending on where the function is.
193-
FunctionGroup *getAnyGroup(const Function *F) const;
194156
// getGroupForHead : get the FunctionGroup for which Function F is the
195157
// head, else 0
196158
FunctionGroup *getGroupForHead(const Function *F) const;
@@ -199,40 +161,10 @@ class FunctionGroupAnalysis : public ModulePass {
199161
// iterator for FunctionGroups in the analysis
200162
typedef SmallVectorImpl<FunctionGroup *>::iterator iterator;
201163
typedef SmallVectorImpl<FunctionGroup *>::const_iterator const_iterator;
202-
using all_iterator = concat_iterator<FunctionGroup *, iterator, iterator>;
203-
using const_all_iterator =
204-
concat_iterator<FunctionGroup *const, const_iterator, const_iterator>;
205164
iterator begin() { return iterator(Groups.begin()); }
206165
iterator end() { return iterator(Groups.end()); }
207166
const_iterator begin() const { return const_iterator(Groups.begin()); }
208167
const_iterator end() const { return const_iterator(Groups.end()); }
209-
210-
iterator subgroup_begin() { return iterator(NonMainGroups.begin()); }
211-
iterator subgroup_end() { return iterator(NonMainGroups.end()); }
212-
const_iterator subgroup_begin() const {
213-
return const_iterator(NonMainGroups.begin());
214-
}
215-
const_iterator subgroup_end() const {
216-
return const_iterator(NonMainGroups.end());
217-
}
218-
iterator_range<iterator> subgroups() {
219-
return make_range(subgroup_begin(), subgroup_end());
220-
}
221-
iterator_range<const_iterator> subgroups() const {
222-
return make_range(subgroup_begin(), subgroup_end());
223-
}
224-
225-
iterator_range<all_iterator> AllGroups() {
226-
return concat<FunctionGroup *>(
227-
make_range(begin(), end()),
228-
make_range(subgroup_begin(), subgroup_end()));
229-
}
230-
iterator_range<const_all_iterator> AllGroups() const {
231-
return concat<FunctionGroup *const>(
232-
make_range(begin(), end()),
233-
make_range(subgroup_begin(), subgroup_end()));
234-
}
235-
236168
size_t size() const { return Groups.size(); }
237169
// addToFunctionGroup : add Function F to FunctionGroup FG
238170
// Using this (rather than calling push_back directly on the FunctionGroup)

IGC/VectorCompiler/lib/GenXCodeGen/GenXArgIndirection.cpp

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,14 +1095,9 @@ void SubroutineArg::gatherBalesToModify(Alignment Align)
10951095
auto User = cast<Instruction>(ui->getUser());
10961096
if (auto CI = dyn_cast<CallInst>(User)) {
10971097
Function *CF = CI->getCalledFunction();
1098-
if (!GenXIntrinsic::isAnyNonTrivialIntrinsic(CF) &&
1099-
!genx::requiresStackCall(CF)) {
1098+
if (!GenXIntrinsic::isAnyNonTrivialIntrinsic(CF)) {
11001099
// Non-intrinsic call. Ignore. (A call site using an arg being
11011100
// indirected gets handled differently.)
1102-
// Cannot indirect if there is a stack call. Do not ignore stack
1103-
// calls here and add them to BalesToModify. In checkIndirectBale
1104-
// report that such bale cannot be indirected. This method is
1105-
// confusing, must be improved.
11061101
continue;
11071102
}
11081103
} else {
@@ -1170,13 +1165,6 @@ bool GenXArgIndirection::checkIndirectBale(Bale *B, LiveRange *ArgLR,
11701165
<< "\n\tintrinsic with raw return value\n");
11711166
return false;
11721167
}
1173-
} else if (auto *CI = dyn_cast<CallInst>(MainInst->Inst)) {
1174-
auto *Callee = CI->getCalledFunction();
1175-
IGC_ASSERT_MESSAGE(genx::requiresStackCall(Callee),
1176-
"Expect a stack call to stop indirection. See "
1177-
"SubroutineArg::gatherBalesToModify");
1178-
LLVM_DEBUG(dbgs() << *CI << "\n\tcalls stack call function\n");
1179-
return false;
11801168
}
11811169
}
11821170
// Check the rdregion(s) and wrregion.

IGC/VectorCompiler/lib/GenXCodeGen/GenXCategory.cpp

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -800,14 +800,13 @@ CategoryAndAlignment GenXCategory::getCategoryAndAlignmentForDef(Value *V) const
800800
if (V->getType()->getScalarType()->getPrimitiveSizeInBits() == 1)
801801
return RegCategory::PREDICATE;
802802
if (Argument *Arg = dyn_cast<Argument>(V)) {
803-
auto *F = Arg->getParent();
804803
// This is a function Argument.
805804
if (!InFGHead) {
806805
// It is an arg in a subroutine. Get the category from the corresponding
807806
// arg at some call site. (We should not have disagreement among the
808807
// call sites and the function arg, since whichever one gets a category
809808
// first forces the category of all the others.)
810-
return getCategoryForCallArg(F, Arg->getArgNo());
809+
return getCategoryForCallArg(Arg->getParent(), Arg->getArgNo());
811810
}
812811
unsigned ArgNo = Arg->getArgNo();
813812
if (KM.getNumArgs() > ArgNo) {
@@ -820,12 +819,7 @@ CategoryAndAlignment GenXCategory::getCategoryAndAlignmentForDef(Value *V) const
820819
// determine the category. This is the fallback for compatibility with
821820
// hand coded LLVM IR from before this metadata was added. (If we only
822821
// had to cope with non-kernel functions, we could just return GENERAL.)
823-
// FIXME: temporary fix for stack calls. We need to figure out how to
824-
// determine arguments category if it cannot be deduced from the arg uses.
825-
// * calls from another function groups might help (but we do not have
826-
// liveness -> category for them). What about standalone stack calls?
827-
IGC_ASSERT(genx::requiresStackCall(F));
828-
return getCategoryForCallArg(F, Arg->getArgNo());
822+
return RegCategory::NONE;
829823
}
830824
// The def is a phi-instruction.
831825
if (PHINode *Phi = dyn_cast<PHINode>(V)) {
@@ -1076,19 +1070,22 @@ unsigned GenXCategory::getCategoryForCallArg(Function *Callee, unsigned ArgNo) c
10761070
return Cat;
10771071
}
10781072
// Then try the arg at each call site.
1073+
bool UseUndef = true;
10791074
for (auto *U: Callee->users()) {
10801075
if (auto *CI = checkFunctionCall(U, Callee)) {
10811076
auto ArgV = CI->getArgOperand(ArgNo);
1077+
if (!isa<UndefValue>(ArgV)) {
1078+
UseUndef = false;
10821079
if (auto LR = Liveness->getLiveRangeOrNull(ArgV)) {
10831080
unsigned Cat = LR->getCategory();
10841081
if (Cat != RegCategory::NONE)
10851082
return Cat;
10861083
}
1084+
}
10871085
}
10881086
}
1089-
// special case handling to break deadlock when all uses are undef or stack
1090-
// call arg category cannot be deduced from the uses in the function, force
1091-
// the argument to be GENERAL
1092-
return EnforceCategoryPromotion ? RegCategory::GENERAL : RegCategory::NONE;
1087+
// special case handling to break deadlock when all uses are undef,
1088+
// force the argument to be GENERAL
1089+
return(UseUndef ? RegCategory::GENERAL : RegCategory::NONE);
10931090
}
10941091

0 commit comments

Comments
 (0)