OLD | NEW |
---|---|
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
341 | 341 |
342 typedef std::map<std::string, int> SymbolTable; | 342 typedef std::map<std::string, int> SymbolTable; |
343 | 343 |
344 bool IsAlive(const std::string& name) const { | 344 bool IsAlive(const std::string& name) const { |
345 SymbolTable::iterator code = symbol_table_.find(name); | 345 SymbolTable::iterator code = symbol_table_.find(name); |
346 if (code == symbol_table_.end()) return false; | 346 if (code == symbol_table_.end()) return false; |
347 return is_live(code->second); | 347 return is_live(code->second); |
348 } | 348 } |
349 | 349 |
350 bool Equal(const Environment& env) { | 350 bool Equal(const Environment& env) { |
351 if (unreachable_) return env.unreachable_; | 351 if (unreachable_ && env.unreachable_) return true; |
352 size_t size = std::max(live_.size(), env.live_.size()); | 352 size_t size = std::max(live_.size(), env.live_.size()); |
353 for (size_t i = 0; i < size; ++i) { | 353 for (size_t i = 0; i < size; ++i) { |
354 if (is_live(i) != env.is_live(i)) return false; | 354 if (is_live(i) != env.is_live(i)) return false; |
355 } | 355 } |
356 return true; | 356 return true; |
357 } | 357 } |
358 | 358 |
359 Environment Define(const std::string& name) const { | 359 Environment Define(const std::string& name) const { |
360 return Environment(*this, SymbolToCode(name)); | 360 return Environment(*this, SymbolToCode(name)); |
361 } | 361 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
398 return allocated_env; | 398 return allocated_env; |
399 } | 399 } |
400 | 400 |
401 private: | 401 private: |
402 Environment(const Environment& l, int code) | 402 Environment(const Environment& l, int code) |
403 : live_(l.live_) { | 403 : live_(l.live_) { |
404 set_live(code); | 404 set_live(code); |
405 } | 405 } |
406 | 406 |
407 void set_live(size_t pos) { | 407 void set_live(size_t pos) { |
408 if (live_.size() <= pos) live_.resize(std::max(pos + 1, 2 * live_.size())); | 408 if (unreachable_) return; |
409 if (pos >= live_.size()) live_.resize(pos + 1); | |
409 live_[pos] = true; | 410 live_[pos] = true; |
410 } | 411 } |
411 | 412 |
412 bool is_live(size_t pos) const { | 413 bool is_live(size_t pos) const { |
413 return unreachable_ || (live_.size() > pos && live_[pos]); | 414 return unreachable_ || (live_.size() > pos && live_[pos]); |
414 } | 415 } |
415 | 416 |
416 Environment& operator|=(const Environment& o) { | 417 Environment& operator|=(const Environment& o) { |
417 unreachable_ |= o.unreachable_; | 418 if (o.unreachable_) { |
418 for (size_t i = 0, e = o.live_.size(); i < e; ++i) { | 419 unreachable_ = true; |
419 if (o.live_[i]) set_live(i); | 420 live_.clear(); |
421 } else if (!unreachable_) { | |
422 for (size_t i = 0, e = o.live_.size(); i < e; ++i) { | |
423 if (o.live_[i]) set_live(i); | |
424 } | |
420 } | 425 } |
421 return *this; | 426 return *this; |
422 } | 427 } |
423 | 428 |
424 Environment& operator&=(const Environment& o) { | 429 Environment& operator&=(const Environment& o) { |
425 unreachable_ &= o.unreachable_; | 430 if (o.unreachable_) return *this; |
426 size_t size = std::min(live_.size(), o.live_.size()); | 431 if (unreachable_) return *this = o; |
427 if (live_.size() > size) live_.resize(size); | 432 |
433 size_t size = std::max(live_.size(), o.live_.size()); | |
Vyacheslav Egorov (Google)
2017/02/16 11:53:00
I think now that unreachable is handled above it w
Clemens Hammacher
2017/02/16 12:02:26
What if |o| > |this| and the tail of o is all fals
Vyacheslav Egorov (Google)
2017/02/16 12:17:31
I see what you mean. Yeah, this subtle. Might warr
Clemens Hammacher
2017/02/16 13:13:04
Added comment.
| |
434 if (size > live_.size()) live_.resize(size); | |
428 for (size_t i = 0; i < size; ++i) { | 435 for (size_t i = 0; i < size; ++i) { |
429 if (live_[i] && (i > o.live_.size() || !o.live_[i])) live_[i] = false; | 436 if (live_[i] && (i >= o.live_.size() || !o.live_[i])) live_[i] = false; |
Vyacheslav Egorov (Google)
2017/02/16 11:53:00
this should just be
live_[i] = live_[i] && o.liv
| |
430 } | 437 } |
431 return *this; | 438 return *this; |
432 } | 439 } |
433 | 440 |
434 static SymbolTable symbol_table_; | 441 static SymbolTable symbol_table_; |
435 static std::vector<Environment*> envs_; | 442 static std::vector<Environment*> envs_; |
436 | 443 |
437 std::vector<bool> live_; | 444 std::vector<bool> live_; |
445 // unreachable_ == true implies live_.empty(), but still is_live(i) returns | |
446 // true for all i. | |
438 bool unreachable_ = false; | 447 bool unreachable_ = false; |
439 | 448 |
440 friend class ExprEffect; | 449 friend class ExprEffect; |
441 friend class CallProps; | 450 friend class CallProps; |
442 }; | 451 }; |
443 | 452 |
444 | 453 |
445 class CallProps { | 454 class CallProps { |
446 public: | 455 public: |
447 CallProps() : env_(NULL) { } | 456 CallProps() : env_(NULL) { } |
(...skipping 831 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1279 | 1288 |
1280 | 1289 |
1281 } | 1290 } |
1282 | 1291 |
1283 static clang::FrontendPluginRegistry::Add<Action<ProblemsFinder> > | 1292 static clang::FrontendPluginRegistry::Add<Action<ProblemsFinder> > |
1284 FindProblems("find-problems", "Find GC-unsafe places."); | 1293 FindProblems("find-problems", "Find GC-unsafe places."); |
1285 | 1294 |
1286 static clang::FrontendPluginRegistry::Add< | 1295 static clang::FrontendPluginRegistry::Add< |
1287 Action<FunctionDeclarationFinder> > | 1296 Action<FunctionDeclarationFinder> > |
1288 DumpCallees("dump-callees", "Dump callees for each function."); | 1297 DumpCallees("dump-callees", "Dump callees for each function."); |
OLD | NEW |