Skip to content

Commit 12b82b2

Browse files
committed
memoize the arglist filter, and clean up the second phase skipping.
1 parent a879ee4 commit 12b82b2

File tree

3 files changed

+28
-18
lines changed

3 files changed

+28
-18
lines changed

wllvm/arglistfilter.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,16 @@ def __init__(self, inputList, exactMatches={}, patternMatches={}):
309309
if DUMPING:
310310
self.dump()
311311

312+
313+
def skipBitcodeGeneration(self):
314+
if os.environ.get('WLLVM_CONFIGURE_ONLY', False):
315+
return True
316+
if not self.inputFiles or self.isEmitLLVM or self.isAssembly or self.isAssembleOnly:
317+
return True
318+
if self.isPreprocessOnly or self.isStandardIn or (self.isDependencyOnly and not self.isCompileOnly):
319+
return True
320+
return False
321+
312322
def _shiftArgs(self, nargs):
313323
ret = []
314324
while nargs > 0:

wllvm/compilers.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
# Internal logger
1818
_logger = logConfig(__name__)
1919

20-
2120
def wcompile(mode):
2221
""" The workhorse, called from wllvm and wllvm++.
2322
"""
@@ -28,24 +27,29 @@ def wcompile(mode):
2827
cmd = list(sys.argv)
2928
cmd = cmd[1:]
3029
builder = getBuilder(cmd, mode)
30+
31+
af = builder.getBitcodeArglistFilter()
32+
3133
rc = buildObject(builder)
3234

3335
# phase one compile failed. no point continuing
3436
if rc != 0:
3537
_logger.info('phase one failed: %s', str(sys.argv))
3638
return rc
3739

38-
# configure only; continuing not desired
39-
if os.environ.get('WLLVM_CONFIGURE_ONLY', False):
40+
# no need to generate bitcode (e.g. configure only, assembly, ....)
41+
if af.skipBitcodeGeneration():
42+
_logger.info('No work to do')
43+
_logger.debug(af.__dict__)
4044
return rc
4145

4246
# phase two
43-
buildAndAttachBitcode(builder)
47+
buildAndAttachBitcode(builder, af)
4448

4549
except Exception as e:
4650
_logger.warning('%s: exception case: %s', mode, str(e))
4751

48-
_logger.info('Calling %s returned %d', list(sys.argv), rc)
52+
_logger.info('Calling %s returned %d', list(sys.argv), rc)
4953
return rc
5054

5155

@@ -145,6 +149,7 @@ def attachBitcodePathToObject(bcPath, outFileName):
145149

146150
class BuilderBase(object):
147151
def __init__(self, cmd, mode, prefixPath=None):
152+
self.af = None #memoize the arglist filter
148153
self.cmd = cmd
149154
self.mode = mode
150155

@@ -180,7 +185,9 @@ def getCompiler(self):
180185
return ['{0}{1}'.format(self.prefixPath, os.getenv(env) or prog)]
181186

182187
def getBitcodeArglistFilter(self):
183-
return ClangBitcodeArgumentListFilter(self.cmd)
188+
if self.af is None:
189+
self.af = ClangBitcodeArgumentListFilter(self.cmd)
190+
return self.af
184191

185192
class DragoneggBuilder(BuilderBase):
186193
def getBitcodeCompiler(self):
@@ -209,7 +216,9 @@ def getCompiler(self):
209216
return ['{0}{1}{2}'.format(self.prefixPath, pfx, mode)]
210217

211218
def getBitcodeArglistFilter(self):
212-
return ArgumentListFilter(self.cmd)
219+
if self.af is None:
220+
self.af = ArgumentListFilter(self.cmd)
221+
return self.af
213222

214223
def getBuilder(cmd, mode):
215224
compilerEnv = 'LLVM_COMPILER'
@@ -242,15 +251,7 @@ def buildObject(builder):
242251

243252

244253
# This command does not have the executable with it
245-
def buildAndAttachBitcode(builder):
246-
247-
af = builder.getBitcodeArglistFilter()
248-
249-
250-
if not af.inputFiles or af.isEmitLLVM or af.isAssembly or af.isAssembleOnly or (af.isDependencyOnly and not af.isCompileOnly) or af.isPreprocessOnly or af.isStandardIn:
251-
_logger.debug('No work to do')
252-
_logger.debug(af.__dict__)
253-
return
254+
def buildAndAttachBitcode(builder, af):
254255

255256
#iam: when we have multiple input files we'll have to keep track of their object files.
256257
newObjectFiles = []

wllvm/logconfig.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
def logConfig(name):
1919

2020
destination = os.getenv(_loggingDestination)
21-
2221

2322
if destination:
2423
logging.basicConfig(filename=destination, level=logging.WARNING, format='%(levelname)s:%(message)s')
@@ -28,7 +27,7 @@ def logConfig(name):
2827
retval = logging.getLogger(name)
2928

3029
# ignore old setting
31-
level = os.getenv(_loggingEnvLevel_new)
30+
level = os.getenv(_loggingEnvLevel_new)
3231

3332
if level:
3433
level = level.upper()

0 commit comments

Comments
 (0)