Skip to content

Commit ded532c

Browse files
authored
fix shared-library build (#348)
Move a table from being a static variable in the dependee lib into a function returning a reference in the dependence lib. Link enough stuff in CMake.
1 parent eda0c6c commit ded532c

File tree

3 files changed

+21
-14
lines changed

3 files changed

+21
-14
lines changed

lib/polygeist/Ops.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,16 @@ class BarrierHoist final : public OpRewritePattern<BarrierOp> {
494494
}
495495
};
496496

497-
extern std::set<std::string> NonCapturingFunctions;
497+
const std::set<std::string> &getNonCapturingFunctions() {
498+
static std::set<std::string> NonCapturingFunctions = {
499+
"free", "printf", "fprintf", "scanf",
500+
"fscanf", "gettimeofday", "clock_gettime", "getenv",
501+
"strrchr", "strlen", "sprintf", "sscanf",
502+
"mkdir", "fwrite", "fread", "memcpy",
503+
"cudaMemcpy", "memset", "cudaMemset", "__isoc99_scanf",
504+
"__isoc99_fscanf"};
505+
return NonCapturingFunctions;
506+
}
498507

499508
bool isCaptured(Value v, Operation *potentialUser = nullptr,
500509
bool *seenuse = nullptr) {
@@ -560,12 +569,12 @@ bool isCaptured(Value v, Operation *potentialUser = nullptr,
560569
}
561570
if (auto cop = dyn_cast<LLVM::CallOp>(u)) {
562571
if (auto callee = cop.getCallee()) {
563-
if (NonCapturingFunctions.count(callee->str()))
572+
if (getNonCapturingFunctions().count(callee->str()))
564573
continue;
565574
}
566575
}
567576
if (auto cop = dyn_cast<func::CallOp>(u)) {
568-
if (NonCapturingFunctions.count(cop.getCallee().str()))
577+
if (getNonCapturingFunctions().count(cop.getCallee().str()))
569578
continue;
570579
}
571580
return true;

lib/polygeist/Passes/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ add_mlir_dialect_library(MLIRPolygeistTransforms
3232
MLIRFuncDialect
3333
MLIRFuncTransforms
3434
MLIRGPUOps
35+
MLIRGPUToGPURuntimeTransforms
36+
MLIRGPUTransforms
37+
MLIRGPUToNVVMTransforms
3538
MLIRIR
3639
MLIRLLVMDialect
3740
MLIRMathDialect

lib/polygeist/Passes/Mem2Reg.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,13 +1066,8 @@ void removeRedundantBlockArgs(
10661066
}
10671067
}
10681068

1069-
std::set<std::string> NonCapturingFunctions = {
1070-
"free", "printf", "fprintf", "scanf",
1071-
"fscanf", "gettimeofday", "clock_gettime", "getenv",
1072-
"strrchr", "strlen", "sprintf", "sscanf",
1073-
"mkdir", "fwrite", "fread", "memcpy",
1074-
"cudaMemcpy", "memset", "cudaMemset", "__isoc99_scanf",
1075-
"__isoc99_fscanf"};
1069+
const std::set<std::string> &getNonCapturingFunctions();
1070+
10761071
// fopen, fclose
10771072
std::set<std::string> NoWriteFunctions = {"exit", "__errno_location"};
10781073
// This is a straightforward implementation not optimized for speed. Optimize
@@ -1241,7 +1236,7 @@ bool Mem2Reg::forwardStoreToLoad(
12411236
if (callOp.getCallee() != "free") {
12421237
LLVM_DEBUG(llvm::dbgs() << "Aliasing Store: " << callOp << "\n");
12431238
AliasingStoreOperations.insert(callOp);
1244-
if (!NonCapturingFunctions.count(callOp.getCallee().str()))
1239+
if (!getNonCapturingFunctions().count(callOp.getCallee().str()))
12451240
captured = true;
12461241
}
12471242
continue;
@@ -1251,7 +1246,7 @@ bool Mem2Reg::forwardStoreToLoad(
12511246
LLVM_DEBUG(llvm::dbgs() << "Aliasing Store: " << callOp << "\n");
12521247
AliasingStoreOperations.insert(callOp);
12531248
if (!callOp.getCallee() ||
1254-
!NonCapturingFunctions.count(callOp.getCallee()->str()))
1249+
!getNonCapturingFunctions().count(callOp.getCallee()->str()))
12551250
captured = true;
12561251
}
12571252
continue;
@@ -1825,11 +1820,11 @@ bool isPromotable(mlir::Value AI) {
18251820
} else if (isa<memref::DeallocOp>(U)) {
18261821
continue;
18271822
} else if (auto callOp = dyn_cast<func::CallOp>(U)) {
1828-
if (NonCapturingFunctions.count(callOp.getCallee().str()))
1823+
if (getNonCapturingFunctions().count(callOp.getCallee().str()))
18291824
continue;
18301825
} else if (auto callOp = dyn_cast<LLVM::CallOp>(U)) {
18311826
if (auto callee = callOp.getCallee())
1832-
if (NonCapturingFunctions.count(callee->str()))
1827+
if (getNonCapturingFunctions().count(callee->str()))
18331828
continue;
18341829
} else if (auto CO = dyn_cast<memref::CastOp>(U)) {
18351830
list.push_back(CO);

0 commit comments

Comments
 (0)