@@ -41,13 +41,18 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
41
41
42
42
#define DEBUG_TYPE " cmabi"
43
43
44
+ #include " llvmWrapper/Analysis/CallGraph.h"
44
45
#include " llvmWrapper/IR/CallSite.h"
45
- #include " llvmWrapper/Support/Alignment.h"
46
46
#include " llvmWrapper/IR/DerivedTypes.h"
47
47
#include " llvmWrapper/IR/Instructions.h"
48
+ #include " llvmWrapper/Support/Alignment.h"
49
+
50
+ #include " Probe/Assertion.h"
48
51
49
52
#include " vc/GenXOpts/GenXOpts.h"
50
53
#include " vc/GenXOpts/Utils/GenXSTLExtras.h"
54
+ #include " vc/Support/BackendConfig.h"
55
+
51
56
#include " llvm/ADT/DenseMap.h"
52
57
#include " llvm/ADT/PostOrderIterator.h"
53
58
#include " llvm/ADT/SCCIterator.h"
@@ -76,9 +81,6 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
76
81
#include " llvm/Support/raw_ostream.h"
77
82
#include " llvm/Transforms/Scalar.h"
78
83
79
- #include " llvmWrapper/Analysis/CallGraph.h"
80
- #include " Probe/Assertion.h"
81
-
82
84
#include < algorithm>
83
85
#include < iterator>
84
86
#include < numeric>
@@ -89,13 +91,6 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
89
91
90
92
using namespace llvm ;
91
93
92
- using LocalizationLimitT = int32_t ;
93
- static constexpr auto LocalizeAll = std::numeric_limits<LocalizationLimitT>::max();
94
- static cl::opt<LocalizationLimitT>
95
- LocalizationLimit (" cm-abi-issues-localization-limit" ,
96
- cl::desc (" maximum size (in bytes) used to localize global variables" ),
97
- cl::init(LocalizeAll));
98
-
99
94
STATISTIC (NumArgumentsTransformed, " Number of pointer arguments transformed" );
100
95
101
96
// FIXME: find a propper place for addrspace enum, agree on addrspace politics
@@ -253,6 +248,7 @@ int DiagnosticInfoOverlappingArgs::KindID = 0;
253
248
class CMABIAnalysis : public ModulePass {
254
249
// This map captures all global variables to be localized.
255
250
std::vector<LocalizationInfo *> LocalizationInfoObjs;
251
+ GlobalsLocalizationConfig::LimitT GlobalsLocalizationLimit;
256
252
257
253
public:
258
254
static char ID;
@@ -267,6 +263,7 @@ class CMABIAnalysis : public ModulePass {
267
263
268
264
void getAnalysisUsage (AnalysisUsage &AU) const override {
269
265
AU.addRequired <CallGraphWrapperPass>();
266
+ AU.addRequired <GenXBackendConfig>();
270
267
AU.setPreservesAll ();
271
268
}
272
269
@@ -359,10 +356,25 @@ char CMABIAnalysis::ID = 0;
359
356
INITIALIZE_PASS_BEGIN (CMABIAnalysis, " cmabi-analysis" ,
360
357
" helper analysis pass to get info for CMABI" , false , true )
361
358
INITIALIZE_PASS_DEPENDENCY(CallGraphWrapperPass)
359
+ INITIALIZE_PASS_DEPENDENCY(GenXBackendConfig)
362
360
INITIALIZE_PASS_END(CMABIAnalysis, " cmabi-analysis" ,
363
361
" Fix ABI issues for the genx backend" , false , true )
364
362
363
+ static std::size_t
364
+ defineGlobalsLocalizationLimit(const GenXBackendConfig &Config) {
365
+ if (Config.isGlobalsLocalizationForced ())
366
+ return GlobalsLocalizationConfig::NoLimit;
367
+
368
+ // Half of a size of standard GenX register file in bytes.
369
+ // 128 * 32 / 2
370
+ constexpr std::size_t HalfGRF = 2048 ;
371
+ std::size_t Limit = Config.getGlobalsLocalizationLimit ();
372
+ return std::min (Limit, HalfGRF);
373
+ }
374
+
365
375
bool CMABIAnalysis::runOnModule (Module &M) {
376
+ GlobalsLocalizationLimit =
377
+ defineGlobalsLocalizationLimit (getAnalysis<GenXBackendConfig>());
366
378
runOnCallGraph (getAnalysis<CallGraphWrapperPass>().getCallGraph ());
367
379
return false ;
368
380
}
@@ -402,7 +414,7 @@ auto selectGlobalsToLocalize(ForwardRange Globals, T Bound,
402
414
Globals, [ExcludePred](GVRef GV) { return !ExcludePred (GV); });
403
415
using GVWithWeightT = std::pair<GVPtr, int >;
404
416
405
- if (Bound == LocalizeAll ) {
417
+ if (Bound == GlobalsLocalizationConfig::NoLimit ) {
406
418
std::vector<GVPtr> ToLocalize;
407
419
transform (Unexcluded, std::back_inserter (ToLocalize),
408
420
[](GVRef GV) { return &GV; });
@@ -1950,7 +1962,7 @@ void CMABIAnalysis::analyzeGlobals(CallGraph &CG) {
1950
1962
};
1951
1963
const auto &DL = M.getDataLayout ();
1952
1964
std::vector<GlobalVariable *> ToLocalize = selectGlobalsToLocalize (
1953
- M.globals (), LocalizationLimit. getValue () ,
1965
+ M.globals (), GlobalsLocalizationLimit ,
1954
1966
[UsesPrintChecker](const GlobalVariable &GV) {
1955
1967
// don't localize global constant format string if it's used by print_index intrinsic
1956
1968
bool UsesPrintIndex = std::any_of (GV.use_begin (), GV.use_end (), UsesPrintChecker);
0 commit comments