clang  16.0.0git
ThreadSafetyTIL.h
Go to the documentation of this file.
1 //===- ThreadSafetyTIL.h ----------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines a simple Typed Intermediate Language, or TIL, that is used
10 // by the thread safety analysis (See ThreadSafety.cpp). The TIL is intended
11 // to be largely independent of clang, in the hope that the analysis can be
12 // reused for other non-C++ languages. All dependencies on clang/llvm should
13 // go in ThreadSafetyUtil.h.
14 //
15 // Thread safety analysis works by comparing mutex expressions, e.g.
16 //
17 // class A { Mutex mu; int dat GUARDED_BY(this->mu); }
18 // class B { A a; }
19 //
20 // void foo(B* b) {
21 // (*b).a.mu.lock(); // locks (*b).a.mu
22 // b->a.dat = 0; // substitute &b->a for 'this';
23 // // requires lock on (&b->a)->mu
24 // (b->a.mu).unlock(); // unlocks (b->a.mu)
25 // }
26 //
27 // As illustrated by the above example, clang Exprs are not well-suited to
28 // represent mutex expressions directly, since there is no easy way to compare
29 // Exprs for equivalence. The thread safety analysis thus lowers clang Exprs
30 // into a simple intermediate language (IL). The IL supports:
31 //
32 // (1) comparisons for semantic equality of expressions
33 // (2) SSA renaming of variables
34 // (3) wildcards and pattern matching over expressions
35 // (4) hash-based expression lookup
36 //
37 // The TIL is currently very experimental, is intended only for use within
38 // the thread safety analysis, and is subject to change without notice.
39 // After the API stabilizes and matures, it may be appropriate to make this
40 // more generally available to other analyses.
41 //
42 // UNDER CONSTRUCTION. USE AT YOUR OWN RISK.
43 //
44 //===----------------------------------------------------------------------===//
45 
46 #ifndef LLVM_CLANG_ANALYSIS_ANALYSES_THREADSAFETYTIL_H
47 #define LLVM_CLANG_ANALYSIS_ANALYSES_THREADSAFETYTIL_H
48 
49 #include "clang/AST/Decl.h"
51 #include "clang/Basic/LLVM.h"
52 #include "llvm/ADT/ArrayRef.h"
53 #include "llvm/ADT/None.h"
54 #include "llvm/ADT/Optional.h"
55 #include "llvm/ADT/StringRef.h"
56 #include "llvm/Support/Casting.h"
57 #include "llvm/Support/raw_ostream.h"
58 #include <algorithm>
59 #include <cassert>
60 #include <cstddef>
61 #include <cstdint>
62 #include <iterator>
63 #include <string>
64 #include <utility>
65 
66 namespace clang {
67 
68 class CallExpr;
69 class Expr;
70 class Stmt;
71 
72 namespace threadSafety {
73 namespace til {
74 
75 class BasicBlock;
76 
77 /// Enum for the different distinct classes of SExpr
78 enum TIL_Opcode : unsigned char {
79 #define TIL_OPCODE_DEF(X) COP_##X,
80 #include "ThreadSafetyOps.def"
81 #undef TIL_OPCODE_DEF
82 };
83 
84 /// Opcode for unary arithmetic operations.
85 enum TIL_UnaryOpcode : unsigned char {
86  UOP_Minus, // -
87  UOP_BitNot, // ~
89 };
90 
91 /// Opcode for binary arithmetic operations.
92 enum TIL_BinaryOpcode : unsigned char {
93  BOP_Add, // +
94  BOP_Sub, // -
95  BOP_Mul, // *
96  BOP_Div, // /
97  BOP_Rem, // %
98  BOP_Shl, // <<
99  BOP_Shr, // >>
102  BOP_BitOr, // |
103  BOP_Eq, // ==
104  BOP_Neq, // !=
105  BOP_Lt, // <
106  BOP_Leq, // <=
107  BOP_Cmp, // <=>
108  BOP_LogicAnd, // && (no short-circuit)
109  BOP_LogicOr // || (no short-circuit)
110 };
111 
112 /// Opcode for cast operations.
113 enum TIL_CastOpcode : unsigned char {
115 
116  // Extend precision of numeric type
118 
119  // Truncate precision of numeric type
121 
122  // Convert to floating point type
124 
125  // Convert to integer type
127 
128  // Convert smart pointer to pointer (C++ only)
130 };
131 
132 const TIL_Opcode COP_Min = COP_Future;
133 const TIL_Opcode COP_Max = COP_Branch;
140 
141 /// Return the name of a unary opcode.
143 
144 /// Return the name of a binary opcode.
146 
147 /// ValueTypes are data types that can actually be held in registers.
148 /// All variables and expressions must have a value type.
149 /// Pointer types are further subdivided into the various heap-allocated
150 /// types, such as functions, records, etc.
151 /// Structured types that are passed by value (e.g. complex numbers)
152 /// require special handling; they use BT_ValueRef, and size ST_0.
153 struct ValueType {
154  enum BaseType : unsigned char {
155  BT_Void = 0,
159  BT_String, // String literals
162  };
163 
164  enum SizeType : unsigned char {
165  ST_0 = 0,
172  };
173 
174  ValueType(BaseType B, SizeType Sz, bool S, unsigned char VS)
175  : Base(B), Size(Sz), Signed(S), VectSize(VS) {}
176 
177  inline static SizeType getSizeType(unsigned nbytes);
178 
179  template <class T>
180  inline static ValueType getValueType();
181 
184  bool Signed;
185 
186  // 0 for scalar, otherwise num elements in vector
187  unsigned char VectSize;
188 };
189 
191  switch (nbytes) {
192  case 1: return ST_8;
193  case 2: return ST_16;
194  case 4: return ST_32;
195  case 8: return ST_64;
196  case 16: return ST_128;
197  default: return ST_0;
198  }
199 }
200 
201 template<>
202 inline ValueType ValueType::getValueType<void>() {
203  return ValueType(BT_Void, ST_0, false, 0);
204 }
205 
206 template<>
207 inline ValueType ValueType::getValueType<bool>() {
208  return ValueType(BT_Bool, ST_1, false, 0);
209 }
210 
211 template<>
212 inline ValueType ValueType::getValueType<int8_t>() {
213  return ValueType(BT_Int, ST_8, true, 0);
214 }
215 
216 template<>
217 inline ValueType ValueType::getValueType<uint8_t>() {
218  return ValueType(BT_Int, ST_8, false, 0);
219 }
220 
221 template<>
222 inline ValueType ValueType::getValueType<int16_t>() {
223  return ValueType(BT_Int, ST_16, true, 0);
224 }
225 
226 template<>
227 inline ValueType ValueType::getValueType<uint16_t>() {
228  return ValueType(BT_Int, ST_16, false, 0);
229 }
230 
231 template<>
232 inline ValueType ValueType::getValueType<int32_t>() {
233  return ValueType(BT_Int, ST_32, true, 0);
234 }
235 
236 template<>
237 inline ValueType ValueType::getValueType<uint32_t>() {
238  return ValueType(BT_Int, ST_32, false, 0);
239 }
240 
241 template<>
242 inline ValueType ValueType::getValueType<int64_t>() {
243  return ValueType(BT_Int, ST_64, true, 0);
244 }
245 
246 template<>
247 inline ValueType ValueType::getValueType<uint64_t>() {
248  return ValueType(BT_Int, ST_64, false, 0);
249 }
250 
251 template<>
252 inline ValueType ValueType::getValueType<float>() {
253  return ValueType(BT_Float, ST_32, true, 0);
254 }
255 
256 template<>
257 inline ValueType ValueType::getValueType<double>() {
258  return ValueType(BT_Float, ST_64, true, 0);
259 }
260 
261 template<>
262 inline ValueType ValueType::getValueType<long double>() {
263  return ValueType(BT_Float, ST_128, true, 0);
264 }
265 
266 template<>
267 inline ValueType ValueType::getValueType<StringRef>() {
268  return ValueType(BT_String, getSizeType(sizeof(StringRef)), false, 0);
269 }
270 
271 template<>
272 inline ValueType ValueType::getValueType<void*>() {
273  return ValueType(BT_Pointer, getSizeType(sizeof(void*)), false, 0);
274 }
275 
276 /// Base class for AST nodes in the typed intermediate language.
277 class SExpr {
278 public:
279  SExpr() = delete;
280 
281  TIL_Opcode opcode() const { return Opcode; }
282 
283  // Subclasses of SExpr must define the following:
284  //
285  // This(const This& E, ...) {
286  // copy constructor: construct copy of E, with some additional arguments.
287  // }
288  //
289  // template <class V>
290  // typename V::R_SExpr traverse(V &Vs, typename V::R_Ctx Ctx) {
291  // traverse all subexpressions, following the traversal/rewriter interface.
292  // }
293  //
294  // template <class C> typename C::CType compare(CType* E, C& Cmp) {
295  // compare all subexpressions, following the comparator interface
296  // }
297  void *operator new(size_t S, MemRegionRef &R) {
298  return ::operator new(S, R);
299  }
300 
301  /// SExpr objects must be created in an arena.
302  void *operator new(size_t) = delete;
303 
304  /// SExpr objects cannot be deleted.
305  // This declaration is public to workaround a gcc bug that breaks building
306  // with REQUIRES_EH=1.
307  void operator delete(void *) = delete;
308 
309  /// Returns the instruction ID for this expression.
310  /// All basic block instructions have a unique ID (i.e. virtual register).
311  unsigned id() const { return SExprID; }
312 
313  /// Returns the block, if this is an instruction in a basic block,
314  /// otherwise returns null.
315  BasicBlock *block() const { return Block; }
316 
317  /// Set the basic block and instruction ID for this expression.
318  void setID(BasicBlock *B, unsigned id) { Block = B; SExprID = id; }
319 
320 protected:
321  SExpr(TIL_Opcode Op) : Opcode(Op) {}
322  SExpr(const SExpr &E) : Opcode(E.Opcode), Flags(E.Flags) {}
323 
325  unsigned char Reserved = 0;
326  unsigned short Flags = 0;
327  unsigned SExprID = 0;
328  BasicBlock *Block = nullptr;
329 };
330 
331 // Contains various helper functions for SExprs.
332 namespace ThreadSafetyTIL {
333 
334 inline bool isTrivial(const SExpr *E) {
335  TIL_Opcode Op = E->opcode();
336  return Op == COP_Variable || Op == COP_Literal || Op == COP_LiteralPtr;
337 }
338 
339 } // namespace ThreadSafetyTIL
340 
341 // Nodes which declare variables
342 
343 /// A named variable, e.g. "x".
344 ///
345 /// There are two distinct places in which a Variable can appear in the AST.
346 /// A variable declaration introduces a new variable, and can occur in 3 places:
347 /// Let-expressions: (Let (x = t) u)
348 /// Functions: (Function (x : t) u)
349 /// Self-applicable functions (SFunction (x) t)
350 ///
351 /// If a variable occurs in any other location, it is a reference to an existing
352 /// variable declaration -- e.g. 'x' in (x * y + z). To save space, we don't
353 /// allocate a separate AST node for variable references; a reference is just a
354 /// pointer to the original declaration.
355 class Variable : public SExpr {
356 public:
358  /// Let-variable
360 
361  /// Function parameter
363 
364  /// SFunction (self) parameter
366  };
367 
368  Variable(StringRef s, SExpr *D = nullptr)
369  : SExpr(COP_Variable), Name(s), Definition(D) {
370  Flags = VK_Let;
371  }
372 
373  Variable(SExpr *D, const ValueDecl *Cvd = nullptr)
374  : SExpr(COP_Variable), Name(Cvd ? Cvd->getName() : "_x"),
375  Definition(D), Cvdecl(Cvd) {
376  Flags = VK_Let;
377  }
378 
379  Variable(const Variable &Vd, SExpr *D) // rewrite constructor
380  : SExpr(Vd), Name(Vd.Name), Definition(D), Cvdecl(Vd.Cvdecl) {
381  Flags = Vd.kind();
382  }
383 
384  static bool classof(const SExpr *E) { return E->opcode() == COP_Variable; }
385 
386  /// Return the kind of variable (let, function param, or self)
387  VariableKind kind() const { return static_cast<VariableKind>(Flags); }
388 
389  /// Return the name of the variable, if any.
390  StringRef name() const { return Name; }
391 
392  /// Return the clang declaration for this variable, if any.
393  const ValueDecl *clangDecl() const { return Cvdecl; }
394 
395  /// Return the definition of the variable.
396  /// For let-vars, this is the setting expression.
397  /// For function and self parameters, it is the type of the variable.
398  SExpr *definition() { return Definition; }
399  const SExpr *definition() const { return Definition; }
400 
401  void setName(StringRef S) { Name = S; }
402  void setKind(VariableKind K) { Flags = K; }
403  void setDefinition(SExpr *E) { Definition = E; }
404  void setClangDecl(const ValueDecl *VD) { Cvdecl = VD; }
405 
406  template <class V>
407  typename V::R_SExpr traverse(V &Vs, typename V::R_Ctx Ctx) {
408  // This routine is only called for variable references.
409  return Vs.reduceVariableRef(this);
410  }
411 
412  template <class C>
413  typename C::CType compare(const Variable* E, C& Cmp) const {
414  return Cmp.compareVariableRefs(this, E);
415  }
416 
417 private:
418  friend class BasicBlock;
419  friend class Function;
420  friend class Let;
421  friend class SFunction;
422 
423  // The name of the variable.
424  StringRef Name;
425 
426  // The TIL type or definition.
427  SExpr *Definition;
428 
429  // The clang declaration for this variable.
430  const ValueDecl *Cvdecl = nullptr;
431 };
432 
433 /// Placeholder for an expression that has not yet been created.
434 /// Used to implement lazy copy and rewriting strategies.
435 class Future : public SExpr {
436 public:
441  };
442 
443  Future() : SExpr(COP_Future) {}
444  virtual ~Future() = delete;
445 
446  static bool classof(const SExpr *E) { return E->opcode() == COP_Future; }
447 
448  // A lazy rewriting strategy should subclass Future and override this method.
449  virtual SExpr *compute() { return nullptr; }
450 
451  // Return the result of this future if it exists, otherwise return null.
452  SExpr *maybeGetResult() const { return Result; }
453 
454  // Return the result of this future; forcing it if necessary.
456  switch (Status) {
457  case FS_pending:
458  return force();
459  case FS_evaluating:
460  return nullptr; // infinite loop; illegal recursion.
461  case FS_done:
462  return Result;
463  }
464  }
465 
466  template <class V>
467  typename V::R_SExpr traverse(V &Vs, typename V::R_Ctx Ctx) {
468  assert(Result && "Cannot traverse Future that has not been forced.");
469  return Vs.traverse(Result, Ctx);
470  }
471 
472  template <class C>
473  typename C::CType compare(const Future* E, C& Cmp) const {
474  if (!Result || !E->Result)
475  return Cmp.comparePointers(this, E);
476  return Cmp.compare(Result, E->Result);
477  }
478 
479 private:
480  SExpr* force();
481 
482  FutureStatus Status = FS_pending;
483  SExpr *Result = nullptr;
484 };
485 
486 /// Placeholder for expressions that cannot be represented in the TIL.
487 class Undefined : public SExpr {
488 public:
489  Undefined(const Stmt *S = nullptr) : SExpr(COP_Undefined), Cstmt(S) {}
490  Undefined(const Undefined &U) : SExpr(U), Cstmt(U.Cstmt) {}
491 
492  static bool classof(const SExpr *E) { return E->opcode() == COP_Undefined; }
493 
494  template <class V>
495  typename V::R_SExpr traverse(V &Vs, typename V::R_Ctx Ctx) {
496  return Vs.reduceUndefined(*this);
497  }
498 
499  template <class C>
500  typename C::CType compare(const Undefined* E, C& Cmp) const {
501  return Cmp.trueResult();
502  }
503 
504 private:
505  const Stmt *Cstmt;
506 };
507 
508 /// Placeholder for a wildcard that matches any other expression.
509 class Wildcard : public SExpr {
510 public:
511  Wildcard() : SExpr(COP_Wildcard) {}
512  Wildcard(const Wildcard &) = default;
513 
514  static bool classof(const SExpr *E) { return E->opcode() == COP_Wildcard; }
515 
516  template <class V> typename V::R_SExpr traverse(V &Vs, typename V::R_Ctx Ctx) {
517  return Vs.reduceWildcard(*this);
518  }
519 
520  template <class C>
521  typename C::CType compare(const Wildcard* E, C& Cmp) const {
522  return Cmp.trueResult();
523  }
524 };
525 
526 template <class T> class LiteralT;
527 
528 // Base class for literal values.
529 class Literal : public SExpr {
530 public:
531  Literal(const Expr *C)
532  : SExpr(COP_Literal), ValType(ValueType::getValueType<void>()), Cexpr(C) {}
533  Literal(ValueType VT) : SExpr(COP_Literal), ValType(VT) {}
534  Literal(const Literal &) = default;
535 
536  static bool classof(const SExpr *E) { return E->opcode() == COP_Literal; }
537 
538  // The clang expression for this literal.
539  const Expr *clangExpr() const { return Cexpr; }
540 
541  ValueType valueType() const { return ValType; }
542 
543  template<class T> const LiteralT<T>& as() const {
544  return *static_cast<const LiteralT<T>*>(this);
545  }
546  template<class T> LiteralT<T>& as() {
547  return *static_cast<LiteralT<T>*>(this);
548  }
549 
550  template <class V> typename V::R_SExpr traverse(V &Vs, typename V::R_Ctx Ctx);
551 
552  template <class C>
553  typename C::CType compare(const Literal* E, C& Cmp) const {
554  // TODO: defer actual comparison to LiteralT
555  return Cmp.trueResult();
556  }
557 
558 private:
559  const ValueType ValType;
560  const Expr *Cexpr = nullptr;
561 };
562 
563 // Derived class for literal values, which stores the actual value.
564 template<class T>
565 class LiteralT : public Literal {
566 public:
567  LiteralT(T Dat) : Literal(ValueType::getValueType<T>()), Val(Dat) {}
568  LiteralT(const LiteralT<T> &L) : Literal(L), Val(L.Val) {}
569 
570  T value() const { return Val;}
571  T& value() { return Val; }
572 
573 private:
574  T Val;
575 };
576 
577 template <class V>
578 typename V::R_SExpr Literal::traverse(V &Vs, typename V::R_Ctx Ctx) {
579  if (Cexpr)
580  return Vs.reduceLiteral(*this);
581 
582  switch (ValType.Base) {
583  case ValueType::BT_Void:
584  break;
585  case ValueType::BT_Bool:
586  return Vs.reduceLiteralT(as<bool>());
587  case ValueType::BT_Int: {
588  switch (ValType.Size) {
589  case ValueType::ST_8:
590  if (ValType.Signed)
591  return Vs.reduceLiteralT(as<int8_t>());
592  else
593  return Vs.reduceLiteralT(as<uint8_t>());
594  case ValueType::ST_16:
595  if (ValType.Signed)
596  return Vs.reduceLiteralT(as<int16_t>());
597  else
598  return Vs.reduceLiteralT(as<uint16_t>());
599  case ValueType::ST_32:
600  if (ValType.Signed)
601  return Vs.reduceLiteralT(as<int32_t>());
602  else
603  return Vs.reduceLiteralT(as<uint32_t>());
604  case ValueType::ST_64:
605  if (ValType.Signed)
606  return Vs.reduceLiteralT(as<int64_t>());
607  else
608  return Vs.reduceLiteralT(as<uint64_t>());
609  default:
610  break;
611  }
612  }
613  case ValueType::BT_Float: {
614  switch (ValType.Size) {
615  case ValueType::ST_32:
616  return Vs.reduceLiteralT(as<float>());
617  case ValueType::ST_64:
618  return Vs.reduceLiteralT(as<double>());
619  default:
620  break;
621  }
622  }
624  return Vs.reduceLiteralT(as<StringRef>());
626  return Vs.reduceLiteralT(as<void*>());
628  break;
629  }
630  return Vs.reduceLiteral(*this);
631 }
632 
633 /// A Literal pointer to an object allocated in memory.
634 /// At compile time, pointer literals are represented by symbolic names.
635 class LiteralPtr : public SExpr {
636 public:
637  LiteralPtr(const ValueDecl *D) : SExpr(COP_LiteralPtr), Cvdecl(D) {}
638  LiteralPtr(const LiteralPtr &) = default;
639 
640  static bool classof(const SExpr *E) { return E->opcode() == COP_LiteralPtr; }
641 
642  // The clang declaration for the value that this pointer points to.
643  const ValueDecl *clangDecl() const { return Cvdecl; }
644  void setClangDecl(const ValueDecl *VD) { Cvdecl = VD; }
645 
646  template <class V>
647  typename V::R_SExpr traverse(V &Vs, typename V::R_Ctx Ctx) {
648  return Vs.reduceLiteralPtr(*this);
649  }
650 
651  template <class C>
652  typename C::CType compare(const LiteralPtr* E, C& Cmp) const {
653  if (!Cvdecl || !E->Cvdecl)
654  return Cmp.comparePointers(this, E);
655  return Cmp.comparePointers(Cvdecl, E->Cvdecl);
656  }
657 
658 private:
659  const ValueDecl *Cvdecl;
660 };
661 
662 /// A function -- a.k.a. lambda abstraction.
663 /// Functions with multiple arguments are created by currying,
664 /// e.g. (Function (x: Int) (Function (y: Int) (Code { return x + y })))
665 class Function : public SExpr {
666 public:
668  : SExpr(COP_Function), VarDecl(Vd), Body(Bd) {
670  }
671 
672  Function(const Function &F, Variable *Vd, SExpr *Bd) // rewrite constructor
673  : SExpr(F), VarDecl(Vd), Body(Bd) {
675  }
676 
677  static bool classof(const SExpr *E) { return E->opcode() == COP_Function; }
678 
680  const Variable *variableDecl() const { return VarDecl; }
681 
682  SExpr *body() { return Body; }
683  const SExpr *body() const { return Body; }
684 
685  template <class V>
686  typename V::R_SExpr traverse(V &Vs, typename V::R_Ctx Ctx) {
687  // This is a variable declaration, so traverse the definition.
688  auto E0 = Vs.traverse(VarDecl->Definition, Vs.typeCtx(Ctx));
689  // Tell the rewriter to enter the scope of the function.
690  Variable *Nvd = Vs.enterScope(*VarDecl, E0);
691  auto E1 = Vs.traverse(Body, Vs.declCtx(Ctx));
692  Vs.exitScope(*VarDecl);
693  return Vs.reduceFunction(*this, Nvd, E1);
694  }
695 
696  template <class C>
697  typename C::CType compare(const Function* E, C& Cmp) const {
698  typename C::CType Ct =
699  Cmp.compare(VarDecl->definition(), E->VarDecl->definition());
700  if (Cmp.notTrue(Ct))
701  return Ct;
702  Cmp.enterScope(variableDecl(), E->variableDecl());
703  Ct = Cmp.compare(body(), E->body());
704  Cmp.leaveScope();
705  return Ct;
706  }
707 
708 private:
709  Variable *VarDecl;
710  SExpr* Body;
711 };
712 
713 /// A self-applicable function.
714 /// A self-applicable function can be applied to itself. It's useful for
715 /// implementing objects and late binding.
716 class SFunction : public SExpr {
717 public:
719  : SExpr(COP_SFunction), VarDecl(Vd), Body(B) {
720  assert(Vd->Definition == nullptr);
722  Vd->Definition = this;
723  }
724 
725  SFunction(const SFunction &F, Variable *Vd, SExpr *B) // rewrite constructor
726  : SExpr(F), VarDecl(Vd), Body(B) {
727  assert(Vd->Definition == nullptr);
729  Vd->Definition = this;
730  }
731 
732  static bool classof(const SExpr *E) { return E->opcode() == COP_SFunction; }
733 
735  const Variable *variableDecl() const { return VarDecl; }
736 
737  SExpr *body() { return Body; }
738  const SExpr *body() const { return Body; }
739 
740  template <class V>
741  typename V::R_SExpr traverse(V &Vs, typename V::R_Ctx Ctx) {
742  // A self-variable points to the SFunction itself.
743  // A rewrite must introduce the variable with a null definition, and update
744  // it after 'this' has been rewritten.
745  Variable *Nvd = Vs.enterScope(*VarDecl, nullptr);
746  auto E1 = Vs.traverse(Body, Vs.declCtx(Ctx));
747  Vs.exitScope(*VarDecl);
748  // A rewrite operation will call SFun constructor to set Vvd->Definition.
749  return Vs.reduceSFunction(*this, Nvd, E1);
750  }
751 
752  template <class C>
753  typename C::CType compare(const SFunction* E, C& Cmp) const {
754  Cmp.enterScope(variableDecl(), E->variableDecl());
755  typename C::CType Ct = Cmp.compare(body(), E->body());
756  Cmp.leaveScope();
757  return Ct;
758  }
759 
760 private:
761  Variable *VarDecl;
762  SExpr* Body;
763 };
764 
765 /// A block of code -- e.g. the body of a function.
766 class Code : public SExpr {
767 public:
768  Code(SExpr *T, SExpr *B) : SExpr(COP_Code), ReturnType(T), Body(B) {}
769  Code(const Code &C, SExpr *T, SExpr *B) // rewrite constructor
770  : SExpr(C), ReturnType(T), Body(B) {}
771 
772  static bool classof(const SExpr *E) { return E->opcode() == COP_Code; }
773 
774  SExpr *returnType() { return ReturnType; }
775  const SExpr *returnType() const { return ReturnType; }
776 
777  SExpr *body() { return Body; }
778  const SExpr *body() const { return Body; }
779 
780  template <class V>
781  typename V::R_SExpr traverse(V &Vs, typename V::R_Ctx Ctx) {
782  auto Nt = Vs.traverse(ReturnType, Vs.typeCtx(Ctx));
783  auto Nb = Vs.traverse(Body, Vs.lazyCtx(Ctx));
784  return Vs.reduceCode(*this, Nt, Nb);
785  }
786 
787  template <class C>
788  typename C::CType compare(const Code* E, C& Cmp) const {
789  typename C::CType Ct = Cmp.compare(returnType(), E->returnType());
790  if (Cmp.notTrue(Ct))
791  return Ct;
792  return Cmp.compare(body(), E->body());
793  }
794 
795 private:
796  SExpr* ReturnType;
797  SExpr* Body;
798 };
799 
800 /// A typed, writable location in memory
801 class Field : public SExpr {
802 public:
803  Field(SExpr *R, SExpr *B) : SExpr(COP_Field), Range(R), Body(B) {}
804  Field(const Field &C, SExpr *R, SExpr *B) // rewrite constructor
805  : SExpr(C), Range(R), Body(B) {}
806 
807  static bool classof(const SExpr *E) { return E->opcode() == COP_Field; }
808 
809  SExpr *range() { return Range; }
810  const SExpr *range() const { return Range; }
811 
812  SExpr *body() { return Body; }
813  const SExpr *body() const { return Body; }
814 
815  template <class V>
816  typename V::R_SExpr traverse(V &Vs, typename V::R_Ctx Ctx) {
817  auto Nr = Vs.traverse(Range, Vs.typeCtx(Ctx));
818  auto Nb = Vs.traverse(Body, Vs.lazyCtx(Ctx));
819  return Vs.reduceField(*this, Nr, Nb);
820  }
821 
822  template <class C>
823  typename C::CType compare(const Field* E, C& Cmp) const {
824  typename C::CType Ct = Cmp.compare(range(), E->range());
825  if (Cmp.notTrue(Ct))
826  return Ct;
827  return Cmp.compare(body(), E->body());
828  }
829 
830 private:
831  SExpr* Range;
832  SExpr* Body;
833 };
834 
835 /// Apply an argument to a function.
836 /// Note that this does not actually call the function. Functions are curried,
837 /// so this returns a closure in which the first parameter has been applied.
838 /// Once all parameters have been applied, Call can be used to invoke the
839 /// function.
840 class Apply : public SExpr {
841 public:
842  Apply(SExpr *F, SExpr *A) : SExpr(COP_Apply), Fun(F), Arg(A) {}
843  Apply(const Apply &A, SExpr *F, SExpr *Ar) // rewrite constructor
844  : SExpr(A), Fun(F), Arg(Ar) {}
845 
846  static bool classof(const SExpr *E) { return E->opcode() == COP_Apply; }
847 
848  SExpr *fun() { return Fun; }
849  const SExpr *fun() const { return Fun; }
850 
851  SExpr *arg() { return Arg; }
852  const SExpr *arg() const { return Arg; }
853 
854  template <class V>
855  typename V::R_SExpr traverse(V &Vs, typename V::R_Ctx Ctx) {
856  auto Nf = Vs.traverse(Fun, Vs.subExprCtx(Ctx));
857  auto Na = Vs.traverse(Arg, Vs.subExprCtx(Ctx));
858  return Vs.reduceApply(*this, Nf, Na);
859  }
860 
861  template <class C>
862  typename C::CType compare(const Apply* E, C& Cmp) const {
863  typename C::CType Ct = Cmp.compare(fun(), E->fun());
864  if (Cmp.notTrue(Ct))
865  return Ct;
866  return Cmp.compare(arg(), E->arg());
867  }
868 
869 private:
870  SExpr* Fun;
871  SExpr* Arg;
872 };
873 
874 /// Apply a self-argument to a self-applicable function.
875 class SApply : public SExpr {
876 public:
877  SApply(SExpr *Sf, SExpr *A = nullptr) : SExpr(COP_SApply), Sfun(Sf), Arg(A) {}
878  SApply(SApply &A, SExpr *Sf, SExpr *Ar = nullptr) // rewrite constructor
879  : SExpr(A), Sfun(Sf), Arg(Ar) {}
880 
881  static bool classof(const SExpr *E) { return E->opcode() == COP_SApply; }
882 
883  SExpr *sfun() { return Sfun; }
884  const SExpr *sfun() const { return Sfun; }
885 
886  SExpr *arg() { return Arg ? Arg : Sfun; }
887  const SExpr *arg() const { return Arg ? Arg : Sfun; }
888 
889  bool isDelegation() const { return Arg != nullptr; }
890 
891  template <class V>
892  typename V::R_SExpr traverse(V &Vs, typename V::R_Ctx Ctx) {
893  auto Nf = Vs.traverse(Sfun, Vs.subExprCtx(Ctx));
894  typename V::R_SExpr Na = Arg ? Vs.traverse(Arg, Vs.subExprCtx(Ctx))
895  : nullptr;
896  return Vs.reduceSApply(*this, Nf, Na);
897  }
898 
899  template <class C>
900  typename C::CType compare(const SApply* E, C& Cmp) const {
901  typename C::CType Ct = Cmp.compare(sfun(), E->sfun());
902  if (Cmp.notTrue(Ct) || (!arg() && !E->arg()))
903  return Ct;
904  return Cmp.compare(arg(), E->arg());
905  }
906 
907 private:
908  SExpr* Sfun;
909  SExpr* Arg;
910 };
911 
912 /// Project a named slot from a C++ struct or class.
913 class Project : public SExpr {
914 public:
915  Project(SExpr *R, const ValueDecl *Cvd)
916  : SExpr(COP_Project), Rec(R), Cvdecl(Cvd) {
917  assert(Cvd && "ValueDecl must not be null");
918  }
919 
920  static bool classof(const SExpr *E) { return E->opcode() == COP_Project; }
921 
922  SExpr *record() { return Rec; }
923  const SExpr *record() const { return Rec; }
924 
925  const ValueDecl *clangDecl() const { return Cvdecl; }
926 
927  bool isArrow() const { return (Flags & 0x01) != 0; }
928 
929  void setArrow(bool b) {
930  if (b) Flags |= 0x01;
931  else Flags &= 0xFFFE;
932  }
933 
934  StringRef slotName() const {
935  if (Cvdecl->getDeclName().isIdentifier())
936  return Cvdecl->getName();
937  if (!SlotName) {
938  SlotName = "";
939  llvm::raw_string_ostream OS(*SlotName);
940  Cvdecl->printName(OS);
941  }
942  return *SlotName;
943  }
944 
945  template <class V>
946  typename V::R_SExpr traverse(V &Vs, typename V::R_Ctx Ctx) {
947  auto Nr = Vs.traverse(Rec, Vs.subExprCtx(Ctx));
948  return Vs.reduceProject(*this, Nr);
949  }
950 
951  template <class C>
952  typename C::CType compare(const Project* E, C& Cmp) const {
953  typename C::CType Ct = Cmp.compare(record(), E->record());
954  if (Cmp.notTrue(Ct))
955  return Ct;
956  return Cmp.comparePointers(Cvdecl, E->Cvdecl);
957  }
958 
959 private:
960  SExpr* Rec;
961  mutable llvm::Optional<std::string> SlotName;
962  const ValueDecl *Cvdecl;
963 };
964 
965 /// Call a function (after all arguments have been applied).
966 class Call : public SExpr {
967 public:
968  Call(SExpr *T, const CallExpr *Ce = nullptr)
969  : SExpr(COP_Call), Target(T), Cexpr(Ce) {}
970  Call(const Call &C, SExpr *T) : SExpr(C), Target(T), Cexpr(C.Cexpr) {}
971 
972  static bool classof(const SExpr *E) { return E->opcode() == COP_Call; }
973 
974  SExpr *target() { return Target; }
975  const SExpr *target() const { return Target; }
976 
977  const CallExpr *clangCallExpr() const { return Cexpr; }
978 
979  template <class V>
980  typename V::R_SExpr traverse(V &Vs, typename V::R_Ctx Ctx) {
981  auto Nt = Vs.traverse(Target, Vs.subExprCtx(Ctx));
982  return Vs.reduceCall(*this, Nt);
983  }
984 
985  template <class C>
986  typename C::CType compare(const Call* E, C& Cmp) const {
987  return Cmp.compare(target(), E->target());
988  }
989 
990 private:
991  SExpr* Target;
992  const CallExpr *Cexpr;
993 };
994 
995 /// Allocate memory for a new value on the heap or stack.
996 class Alloc : public SExpr {
997 public:
998  enum AllocKind {
1001  };
1002 
1003  Alloc(SExpr *D, AllocKind K) : SExpr(COP_Alloc), Dtype(D) { Flags = K; }
1004  Alloc(const Alloc &A, SExpr *Dt) : SExpr(A), Dtype(Dt) { Flags = A.kind(); }
1005 
1006  static bool classof(const SExpr *E) { return E->opcode() == COP_Call; }
1007 
1008  AllocKind kind() const { return static_cast<AllocKind>(Flags); }
1009 
1010  SExpr *dataType() { return Dtype; }
1011  const SExpr *dataType() const { return Dtype; }
1012 
1013  template <class V>
1014  typename V::R_SExpr traverse(V &Vs, typename V::R_Ctx Ctx) {
1015  auto Nd = Vs.traverse(Dtype, Vs.declCtx(Ctx));
1016  return Vs.reduceAlloc(*this, Nd);
1017  }
1018 
1019  template <class C>
1020  typename C::CType compare(const Alloc* E, C& Cmp) const {
1021  typename C::CType Ct = Cmp.compareIntegers(kind(), E->kind());
1022  if (Cmp.notTrue(Ct))
1023  return Ct;
1024  return Cmp.compare(dataType(), E->dataType());
1025  }
1026 
1027 private:
1028  SExpr* Dtype;
1029 };
1030 
1031 /// Load a value from memory.
1032 class Load : public SExpr {
1033 public:
1034  Load(SExpr *P) : SExpr(COP_Load), Ptr(P) {}
1035  Load(const Load &L, SExpr *P) : SExpr(L), Ptr(P) {}
1036 
1037  static bool classof(const SExpr *E) { return E->opcode() == COP_Load; }
1038 
1039  SExpr *pointer() { return Ptr; }
1040  const SExpr *pointer() const { return Ptr; }
1041 
1042  template <class V>
1043  typename V::R_SExpr traverse(V &Vs, typename V::R_Ctx Ctx) {
1044  auto Np = Vs.traverse(Ptr, Vs.subExprCtx(Ctx));
1045  return Vs.reduceLoad(*this, Np);
1046  }
1047 
1048  template <class C>
1049  typename C::CType compare(const Load* E, C& Cmp) const {
1050  return Cmp.compare(pointer(), E->pointer());
1051  }
1052 
1053 private:
1054  SExpr* Ptr;
1055 };
1056 
1057 /// Store a value to memory.
1058 /// The destination is a pointer to a field, the source is the value to store.
1059 class Store : public SExpr {
1060 public:
1061  Store(SExpr *P, SExpr *V) : SExpr(COP_Store), Dest(P), Source(V) {}
1062  Store(const Store &S, SExpr *P, SExpr *V) : SExpr(S), Dest(P), Source(V) {}
1063 
1064  static bool classof(const SExpr *E) { return E->opcode() == COP_Store; }
1065 
1066  SExpr *destination() { return Dest; } // Address to store to
1067  const SExpr *destination() const { return Dest; }
1068 
1069  SExpr *source() { return Source; } // Value to store
1070  const SExpr *source() const { return Source; }
1071 
1072  template <class V>
1073  typename V::R_SExpr traverse(V &Vs, typename V::R_Ctx Ctx) {
1074  auto Np = Vs.traverse(Dest, Vs.subExprCtx(Ctx));
1075  auto Nv = Vs.traverse(Source, Vs.subExprCtx(Ctx));
1076  return Vs.reduceStore(*this, Np, Nv);
1077  }
1078 
1079  template <class C>
1080  typename C::CType compare(const Store* E, C& Cmp) const {
1081  typename C::CType Ct = Cmp.compare(destination(), E->destination());
1082  if (Cmp.notTrue(Ct))
1083  return Ct;
1084  return Cmp.compare(source(), E->source());
1085  }
1086 
1087 private:
1088  SExpr* Dest;
1089  SExpr* Source;
1090 };
1091 
1092 /// If p is a reference to an array, then p[i] is a reference to the i'th
1093 /// element of the array.
1094 class ArrayIndex : public SExpr {
1095 public:
1096  ArrayIndex(SExpr *A, SExpr *N) : SExpr(COP_ArrayIndex), Array(A), Index(N) {}
1097  ArrayIndex(const ArrayIndex &E, SExpr *A, SExpr *N)
1098  : SExpr(E), Array(A), Index(N) {}
1099 
1100  static bool classof(const SExpr *E) { return E->opcode() == COP_ArrayIndex; }
1101 
1102  SExpr *array() { return Array; }
1103  const SExpr *array() const { return Array; }
1104 
1105  SExpr *index() { return Index; }
1106  const SExpr *index() const { return Index; }
1107 
1108  template <class V>
1109  typename V::R_SExpr traverse(V &Vs, typename V::R_Ctx Ctx) {
1110  auto Na = Vs.traverse(Array, Vs.subExprCtx(Ctx));
1111  auto Ni = Vs.traverse(Index, Vs.subExprCtx(Ctx));
1112  return Vs.reduceArrayIndex(*this, Na, Ni);
1113  }
1114 
1115  template <class C>
1116  typename C::CType compare(const ArrayIndex* E, C& Cmp) const {
1117  typename C::CType Ct = Cmp.compare(array(), E->array());
1118  if (Cmp.notTrue(Ct))
1119  return Ct;
1120  return Cmp.compare(index(), E->index());
1121  }
1122 
1123 private:
1124  SExpr* Array;
1125  SExpr* Index;
1126 };
1127 
1128 /// Pointer arithmetic, restricted to arrays only.
1129 /// If p is a reference to an array, then p + n, where n is an integer, is
1130 /// a reference to a subarray.
1131 class ArrayAdd : public SExpr {
1132 public:
1133  ArrayAdd(SExpr *A, SExpr *N) : SExpr(COP_ArrayAdd), Array(A), Index(N) {}
1134  ArrayAdd(const ArrayAdd &E, SExpr *A, SExpr *N)
1135  : SExpr(E), Array(A), Index(N) {}
1136 
1137  static bool classof(const SExpr *E) { return E->opcode() == COP_ArrayAdd; }
1138 
1139  SExpr *array() { return Array; }
1140  const SExpr *array() const { return Array; }
1141 
1142  SExpr *index() { return Index; }
1143  const SExpr *index() const { return Index; }
1144 
1145  template <class V>
1146  typename V::R_SExpr traverse(V &Vs, typename V::R_Ctx Ctx) {
1147  auto Na = Vs.traverse(Array, Vs.subExprCtx(Ctx));
1148  auto Ni = Vs.traverse(Index, Vs.subExprCtx(Ctx));
1149  return Vs.reduceArrayAdd(*this, Na, Ni);
1150  }
1151 
1152  template <class C>
1153  typename C::CType compare(const ArrayAdd* E, C& Cmp) const {
1154  typename C::CType Ct = Cmp.compare(array(), E->array());
1155  if (Cmp.notTrue(Ct))
1156  return Ct;
1157  return Cmp.compare(index(), E->index());
1158  }
1159 
1160 private:
1161  SExpr* Array;
1162  SExpr* Index;
1163 };
1164 
1165 /// Simple arithmetic unary operations, e.g. negate and not.
1166 /// These operations have no side-effects.
1167 class UnaryOp : public SExpr {
1168 public:
1169  UnaryOp(TIL_UnaryOpcode Op, SExpr *E) : SExpr(COP_UnaryOp), Expr0(E) {
1170  Flags = Op;
1171  }
1172 
1173  UnaryOp(const UnaryOp &U, SExpr *E) : SExpr(U), Expr0(E) { Flags = U.Flags; }
1174 
1175  static bool classof(const SExpr *E) { return E->opcode() == COP_UnaryOp; }
1176 
1178  return static_cast<TIL_UnaryOpcode>(Flags);
1179  }
1180 
1181  SExpr *expr() { return Expr0; }
1182  const SExpr *expr() const { return Expr0; }
1183 
1184  template <class V>
1185  typename V::R_SExpr traverse(V &Vs, typename V::R_Ctx Ctx) {
1186  auto Ne = Vs.traverse(Expr0, Vs.subExprCtx(Ctx));
1187  return Vs.reduceUnaryOp(*this, Ne);
1188  }
1189 
1190  template <class C>
1191  typename C::CType compare(const UnaryOp* E, C& Cmp) const {
1192  typename C::CType Ct =
1193  Cmp.compareIntegers(unaryOpcode(), E->unaryOpcode());
1194  if (Cmp.notTrue(Ct))
1195  return Ct;
1196  return Cmp.compare(expr(), E->expr());
1197  }
1198 
1199 private:
1200  SExpr* Expr0;
1201 };
1202 
1203 /// Simple arithmetic binary operations, e.g. +, -, etc.
1204 /// These operations have no side effects.
1205 class BinaryOp : public SExpr {
1206 public:
1208  : SExpr(COP_BinaryOp), Expr0(E0), Expr1(E1) {
1209  Flags = Op;
1210  }
1211 
1212  BinaryOp(const BinaryOp &B, SExpr *E0, SExpr *E1)
1213  : SExpr(B), Expr0(E0), Expr1(E1) {
1214  Flags = B.Flags;
1215  }
1216 
1217  static bool classof(const SExpr *E) { return E->opcode() == COP_BinaryOp; }
1218 
1220  return static_cast<TIL_BinaryOpcode>(Flags);
1221  }
1222 
1223  SExpr *expr0() { return Expr0; }
1224  const SExpr *expr0() const { return Expr0; }
1225 
1226  SExpr *expr1() { return Expr1; }
1227  const SExpr *expr1() const { return Expr1; }
1228 
1229  template <class V>
1230  typename V::R_SExpr traverse(V &Vs, typename V::R_Ctx Ctx) {
1231  auto Ne0 = Vs.traverse(Expr0, Vs.subExprCtx(Ctx));
1232  auto Ne1 = Vs.traverse(Expr1, Vs.subExprCtx(Ctx));
1233  return Vs.reduceBinaryOp(*this, Ne0, Ne1);
1234  }
1235 
1236  template <class C>
1237  typename C::CType compare(const BinaryOp* E, C& Cmp) const {
1238  typename C::CType Ct =
1239  Cmp.compareIntegers(binaryOpcode(), E->binaryOpcode());
1240  if (Cmp.notTrue(Ct))
1241  return Ct;
1242  Ct = Cmp.compare(expr0(), E->expr0());
1243  if (Cmp.notTrue(Ct))
1244  return Ct;
1245  return Cmp.compare(expr1(), E->expr1());
1246  }
1247 
1248 private:
1249  SExpr* Expr0;
1250  SExpr* Expr1;
1251 };
1252 
1253 /// Cast expressions.
1254 /// Cast expressions are essentially unary operations, but we treat them
1255 /// as a distinct AST node because they only change the type of the result.
1256 class Cast : public SExpr {
1257 public:
1258  Cast(TIL_CastOpcode Op, SExpr *E) : SExpr(COP_Cast), Expr0(E) { Flags = Op; }
1259  Cast(const Cast &C, SExpr *E) : SExpr(C), Expr0(E) { Flags = C.Flags; }
1260 
1261  static bool classof(const SExpr *E) { return E->opcode() == COP_Cast; }
1262 
1264  return static_cast<TIL_CastOpcode>(Flags);
1265  }
1266 
1267  SExpr *expr() { return Expr0; }
1268  const SExpr *expr() const { return Expr0; }
1269 
1270  template <class V>
1271  typename V::R_SExpr traverse(V &Vs, typename V::R_Ctx Ctx) {
1272  auto Ne = Vs.traverse(Expr0, Vs.subExprCtx(Ctx));
1273  return Vs.reduceCast(*this, Ne);
1274  }
1275 
1276  template <class C>
1277  typename C::CType compare(const Cast* E, C& Cmp) const {
1278  typename C::CType Ct =
1279  Cmp.compareIntegers(castOpcode(), E->castOpcode());
1280  if (Cmp.notTrue(Ct))
1281  return Ct;
1282  return Cmp.compare(expr(), E->expr());
1283  }
1284 
1285 private:
1286  SExpr* Expr0;
1287 };
1288 
1289 class SCFG;
1290 
1291 /// Phi Node, for code in SSA form.
1292 /// Each Phi node has an array of possible values that it can take,
1293 /// depending on where control flow comes from.
1294 class Phi : public SExpr {
1295 public:
1297 
1298  // In minimal SSA form, all Phi nodes are MultiVal.
1299  // During conversion to SSA, incomplete Phi nodes may be introduced, which
1300  // are later determined to be SingleVal, and are thus redundant.
1301  enum Status {
1302  PH_MultiVal = 0, // Phi node has multiple distinct values. (Normal)
1303  PH_SingleVal, // Phi node has one distinct value, and can be eliminated
1304  PH_Incomplete // Phi node is incomplete
1305  };
1306 
1307  Phi() : SExpr(COP_Phi) {}
1308  Phi(MemRegionRef A, unsigned Nvals) : SExpr(COP_Phi), Values(A, Nvals) {}
1309  Phi(const Phi &P, ValArray &&Vs) : SExpr(P), Values(std::move(Vs)) {}
1310 
1311  static bool classof(const SExpr *E) { return E->opcode() == COP_Phi; }
1312 
1313  const ValArray &values() const { return Values; }
1314  ValArray &values() { return Values; }
1315 
1316  Status status() const { return static_cast<Status>(Flags); }
1317  void setStatus(Status s) { Flags = s; }
1318 
1319  /// Return the clang declaration of the variable for this Phi node, if any.
1320  const ValueDecl *clangDecl() const { return Cvdecl; }
1321 
1322  /// Set the clang variable associated with this Phi node.
1323  void setClangDecl(const ValueDecl *Cvd) { Cvdecl = Cvd; }
1324 
1325  template <class V>
1326  typename V::R_SExpr traverse(V &Vs, typename V::R_Ctx Ctx) {
1327  typename V::template Container<typename V::R_SExpr>
1328  Nvs(Vs, Values.size());
1329 
1330  for (const auto *Val : Values)
1331  Nvs.push_back( Vs.traverse(Val, Vs.subExprCtx(Ctx)) );
1332  return Vs.reducePhi(*this, Nvs);
1333  }
1334 
1335  template <class C>
1336  typename C::CType compare(const Phi *E, C &Cmp) const {
1337  // TODO: implement CFG comparisons
1338  return Cmp.comparePointers(this, E);
1339  }
1340 
1341 private:
1342  ValArray Values;
1343  const ValueDecl* Cvdecl = nullptr;
1344 };
1345 
1346 /// Base class for basic block terminators: Branch, Goto, and Return.
1347 class Terminator : public SExpr {
1348 protected:
1350  Terminator(const SExpr &E) : SExpr(E) {}
1351 
1352 public:
1353  static bool classof(const SExpr *E) {
1354  return E->opcode() >= COP_Goto && E->opcode() <= COP_Return;
1355  }
1356 
1357  /// Return the list of basic blocks that this terminator can branch to.
1359 
1361  return const_cast<Terminator*>(this)->successors();
1362  }
1363 };
1364 
1365 /// Jump to another basic block.
1366 /// A goto instruction is essentially a tail-recursive call into another
1367 /// block. In addition to the block pointer, it specifies an index into the
1368 /// phi nodes of that block. The index can be used to retrieve the "arguments"
1369 /// of the call.
1370 class Goto : public Terminator {
1371 public:
1372  Goto(BasicBlock *B, unsigned I)
1373  : Terminator(COP_Goto), TargetBlock(B), Index(I) {}
1374  Goto(const Goto &G, BasicBlock *B, unsigned I)
1375  : Terminator(COP_Goto), TargetBlock(B), Index(I) {}
1376 
1377  static bool classof(const SExpr *E) { return E->opcode() == COP_Goto; }
1378 
1379  const BasicBlock *targetBlock() const { return TargetBlock; }
1380  BasicBlock *targetBlock() { return TargetBlock; }
1381 
1382  /// Returns the index into the
1383  unsigned index() const { return Index; }
1384 
1385  /// Return the list of basic blocks that this terminator can branch to.
1386  ArrayRef<BasicBlock *> successors() { return TargetBlock; }
1387 
1388  template <class V>
1389  typename V::R_SExpr traverse(V &Vs, typename V::R_Ctx Ctx) {
1390  BasicBlock *Ntb = Vs.reduceBasicBlockRef(TargetBlock);
1391  return Vs.reduceGoto(*this, Ntb);
1392  }
1393 
1394  template <class C>
1395  typename C::CType compare(const Goto *E, C &Cmp) const {
1396  // TODO: implement CFG comparisons
1397  return Cmp.comparePointers(this, E);
1398  }
1399 
1400 private:
1401  BasicBlock *TargetBlock;
1402  unsigned Index;
1403 };
1404 
1405 /// A conditional branch to two other blocks.
1406 /// Note that unlike Goto, Branch does not have an index. The target blocks
1407 /// must be child-blocks, and cannot have Phi nodes.
1408 class Branch : public Terminator {
1409 public:
1411  : Terminator(COP_Branch), Condition(C) {
1412  Branches[0] = T;
1413  Branches[1] = E;
1414  }
1415 
1416  Branch(const Branch &Br, SExpr *C, BasicBlock *T, BasicBlock *E)
1417  : Terminator(Br), Condition(C) {
1418  Branches[0] = T;
1419  Branches[1] = E;
1420  }
1421 
1422  static bool classof(const SExpr *E) { return E->opcode() == COP_Branch; }
1423 
1424  const SExpr *condition() const { return Condition; }
1425  SExpr *condition() { return Condition; }
1426 
1427  const BasicBlock *thenBlock() const { return Branches[0]; }
1428  BasicBlock *thenBlock() { return Branches[0]; }
1429 
1430  const BasicBlock *elseBlock() const { return Branches[1]; }
1431  BasicBlock *elseBlock() { return Branches[1]; }
1432 
1433  /// Return the list of basic blocks that this terminator can branch to.
1435  return llvm::makeArrayRef(Branches);
1436  }
1437 
1438  template <class V>
1439  typename V::R_SExpr traverse(V &Vs, typename V::R_Ctx Ctx) {
1440  auto Nc = Vs.traverse(Condition, Vs.subExprCtx(Ctx));
1441  BasicBlock *Ntb = Vs.reduceBasicBlockRef(Branches[0]);
1442  BasicBlock *Nte = Vs.reduceBasicBlockRef(Branches[1]);
1443  return Vs.reduceBranch(*this, Nc, Ntb, Nte);
1444  }
1445 
1446  template <class C>
1447  typename C::CType compare(const Branch *E, C &Cmp) const {
1448  // TODO: implement CFG comparisons
1449  return Cmp.comparePointers(this, E);
1450  }
1451 
1452 private:
1453  SExpr *Condition;
1454  BasicBlock *Branches[2];
1455 };
1456 
1457 /// Return from the enclosing function, passing the return value to the caller.
1458 /// Only the exit block should end with a return statement.
1459 class Return : public Terminator {
1460 public:
1461  Return(SExpr* Rval) : Terminator(COP_Return), Retval(Rval) {}
1462  Return(const Return &R, SExpr* Rval) : Terminator(R), Retval(Rval) {}
1463 
1464  static bool classof(const SExpr *E) { return E->opcode() == COP_Return; }
1465 
1466  /// Return an empty list.
1468 
1469  SExpr *returnValue() { return Retval; }
1470  const SExpr *returnValue() const { return Retval; }
1471 
1472  template <class V>
1473  typename V::R_SExpr traverse(V &Vs, typename V::R_Ctx Ctx) {
1474  auto Ne = Vs.traverse(Retval, Vs.subExprCtx(Ctx));
1475  return Vs.reduceReturn(*this, Ne);
1476  }
1477 
1478  template <class C>
1479  typename C::CType compare(const Return *E, C &Cmp) const {
1480  return Cmp.compare(Retval, E->Retval);
1481  }
1482 
1483 private:
1484  SExpr* Retval;
1485 };
1486 
1488  switch (opcode()) {
1489  case COP_Goto: return cast<Goto>(this)->successors();
1490  case COP_Branch: return cast<Branch>(this)->successors();
1491  case COP_Return: return cast<Return>(this)->successors();
1492  default:
1493  return None;
1494  }
1495 }
1496 
1497 /// A basic block is part of an SCFG. It can be treated as a function in
1498 /// continuation passing style. A block consists of a sequence of phi nodes,
1499 /// which are "arguments" to the function, followed by a sequence of
1500 /// instructions. It ends with a Terminator, which is a Branch or Goto to
1501 /// another basic block in the same SCFG.
1502 class BasicBlock : public SExpr {
1503 public:
1506 
1507  // TopologyNodes are used to overlay tree structures on top of the CFG,
1508  // such as dominator and postdominator trees. Each block is assigned an
1509  // ID in the tree according to a depth-first search. Tree traversals are
1510  // always up, towards the parents.
1511  struct TopologyNode {
1512  int NodeID = 0;
1513 
1514  // Includes this node, so must be > 1.
1515  int SizeOfSubTree = 0;
1516 
1517  // Pointer to parent.
1518  BasicBlock *Parent = nullptr;
1519 
1520  TopologyNode() = default;
1521 
1522  bool isParentOf(const TopologyNode& OtherNode) {
1523  return OtherNode.NodeID > NodeID &&
1524  OtherNode.NodeID < NodeID + SizeOfSubTree;
1525  }
1526 
1527  bool isParentOfOrEqual(const TopologyNode& OtherNode) {
1528  return OtherNode.NodeID >= NodeID &&
1529  OtherNode.NodeID < NodeID + SizeOfSubTree;
1530  }
1531  };
1532 
1534  : SExpr(COP_BasicBlock), Arena(A), BlockID(0), Visited(false) {}
1536  Terminator *T)
1537  : SExpr(COP_BasicBlock), Arena(A), BlockID(0), Visited(false),
1538  Args(std::move(As)), Instrs(std::move(Is)), TermInstr(T) {}
1539 
1540  static bool classof(const SExpr *E) { return E->opcode() == COP_BasicBlock; }
1541 
1542  /// Returns the block ID. Every block has a unique ID in the CFG.
1543  int blockID() const { return BlockID; }
1544 
1545  /// Returns the number of predecessors.
1546  size_t numPredecessors() const { return Predecessors.size(); }
1547  size_t numSuccessors() const { return successors().size(); }
1548 
1549  const SCFG* cfg() const { return CFGPtr; }
1550  SCFG* cfg() { return CFGPtr; }
1551 
1552  const BasicBlock *parent() const { return DominatorNode.Parent; }
1553  BasicBlock *parent() { return DominatorNode.Parent; }
1554 
1555  const InstrArray &arguments() const { return Args; }
1556  InstrArray &arguments() { return Args; }
1557 
1558  InstrArray &instructions() { return Instrs; }
1559  const InstrArray &instructions() const { return Instrs; }
1560 
1561  /// Returns a list of predecessors.
1562  /// The order of predecessors in the list is important; each phi node has
1563  /// exactly one argument for each precessor, in the same order.
1564  BlockArray &predecessors() { return Predecessors; }
1565  const BlockArray &predecessors() const { return Predecessors; }
1566 
1567  ArrayRef<BasicBlock*> successors() { return TermInstr->successors(); }
1568  ArrayRef<BasicBlock*> successors() const { return TermInstr->successors(); }
1569 
1570  const Terminator *terminator() const { return TermInstr; }
1571  Terminator *terminator() { return TermInstr; }
1572 
1573  void setTerminator(Terminator *E) { TermInstr = E; }
1574 
1575  bool Dominates(const BasicBlock &Other) {
1576  return DominatorNode.isParentOfOrEqual(Other.DominatorNode);
1577  }
1578 
1579  bool PostDominates(const BasicBlock &Other) {
1580  return PostDominatorNode.isParentOfOrEqual(Other.PostDominatorNode);
1581  }
1582 
1583  /// Add a new argument.
1584  void addArgument(Phi *V) {
1585  Args.reserveCheck(1, Arena);
1586  Args.push_back(V);
1587  }
1588 
1589  /// Add a new instruction.
1591  Instrs.reserveCheck(1, Arena);
1592  Instrs.push_back(V);
1593  }
1594 
1595  // Add a new predecessor, and return the phi-node index for it.
1596  // Will add an argument to all phi-nodes, initialized to nullptr.
1597  unsigned addPredecessor(BasicBlock *Pred);
1598 
1599  // Reserve space for Nargs arguments.
1600  void reserveArguments(unsigned Nargs) { Args.reserve(Nargs, Arena); }
1601 
1602  // Reserve space for Nins instructions.
1603  void reserveInstructions(unsigned Nins) { Instrs.reserve(Nins, Arena); }
1604 
1605  // Reserve space for NumPreds predecessors, including space in phi nodes.
1606  void reservePredecessors(unsigned NumPreds);
1607 
1608  /// Return the index of BB, or Predecessors.size if BB is not a predecessor.
1609  unsigned findPredecessorIndex(const BasicBlock *BB) const {
1610  auto I = llvm::find(Predecessors, BB);
1611  return std::distance(Predecessors.cbegin(), I);
1612  }
1613 
1614  template <class V>
1615  typename V::R_BasicBlock traverse(V &Vs, typename V::R_Ctx Ctx) {
1616  typename V::template Container<SExpr*> Nas(Vs, Args.size());
1617  typename V::template Container<SExpr*> Nis(Vs, Instrs.size());
1618 
1619  // Entering the basic block should do any scope initialization.
1620  Vs.enterBasicBlock(*this);
1621 
1622  for (const auto *E : Args) {
1623  auto Ne = Vs.traverse(E, Vs.subExprCtx(Ctx));
1624  Nas.push_back(Ne);
1625  }
1626  for (const auto *E : Instrs) {
1627  auto Ne = Vs.traverse(E, Vs.subExprCtx(Ctx));
1628  Nis.push_back(Ne);
1629  }
1630  auto Nt = Vs.traverse(TermInstr, Ctx);
1631 
1632  // Exiting the basic block should handle any scope cleanup.
1633  Vs.exitBasicBlock(*this);
1634 
1635  return Vs.reduceBasicBlock(*this, Nas, Nis, Nt);
1636  }
1637 
1638  template <class C>
1639  typename C::CType compare(const BasicBlock *E, C &Cmp) const {
1640  // TODO: implement CFG comparisons
1641  return Cmp.comparePointers(this, E);
1642  }
1643 
1644 private:
1645  friend class SCFG;
1646 
1647  // assign unique ids to all instructions
1648  unsigned renumberInstrs(unsigned id);
1649 
1650  unsigned topologicalSort(SimpleArray<BasicBlock *> &Blocks, unsigned ID);
1651  unsigned topologicalFinalSort(SimpleArray<BasicBlock *> &Blocks, unsigned ID);
1652  void computeDominator();
1653  void computePostDominator();
1654 
1655  // The arena used to allocate this block.
1656  MemRegionRef Arena;
1657 
1658  // The CFG that contains this block.
1659  SCFG *CFGPtr = nullptr;
1660 
1661  // Unique ID for this BB in the containing CFG. IDs are in topological order.
1662  unsigned BlockID : 31;
1663 
1664  // Bit to determine if a block has been visited during a traversal.
1665  bool Visited : 1;
1666 
1667  // Predecessor blocks in the CFG.
1668  BlockArray Predecessors;
1669 
1670  // Phi nodes. One argument per predecessor.
1671  InstrArray Args;
1672 
1673  // Instructions.
1674  InstrArray Instrs;
1675 
1676  // Terminating instruction.
1677  Terminator *TermInstr = nullptr;
1678 
1679  // The dominator tree.
1680  TopologyNode DominatorNode;
1681 
1682  // The post-dominator tree.
1683  TopologyNode PostDominatorNode;
1684 };
1685 
1686 /// An SCFG is a control-flow graph. It consists of a set of basic blocks,
1687 /// each of which terminates in a branch to another basic block. There is one
1688 /// entry point, and one exit point.
1689 class SCFG : public SExpr {
1690 public:
1694 
1695  SCFG(MemRegionRef A, unsigned Nblocks)
1696  : SExpr(COP_SCFG), Arena(A), Blocks(A, Nblocks) {
1697  Entry = new (A) BasicBlock(A);
1698  Exit = new (A) BasicBlock(A);
1699  auto *V = new (A) Phi();
1700  Exit->addArgument(V);
1701  Exit->setTerminator(new (A) Return(V));
1702  add(Entry);
1703  add(Exit);
1704  }
1705 
1706  SCFG(const SCFG &Cfg, BlockArray &&Ba) // steals memory from Ba
1707  : SExpr(COP_SCFG), Arena(Cfg.Arena), Blocks(std::move(Ba)) {
1708  // TODO: set entry and exit!
1709  }
1710 
1711  static bool classof(const SExpr *E) { return E->opcode() == COP_SCFG; }
1712 
1713  /// Return true if this CFG is valid.
1714  bool valid() const { return Entry && Exit && Blocks.size() > 0; }
1715 
1716  /// Return true if this CFG has been normalized.
1717  /// After normalization, blocks are in topological order, and block and
1718  /// instruction IDs have been assigned.
1719  bool normal() const { return Normal; }
1720 
1721  iterator begin() { return Blocks.begin(); }
1722  iterator end() { return Blocks.end(); }
1723 
1724  const_iterator begin() const { return cbegin(); }
1725  const_iterator end() const { return cend(); }
1726 
1727  const_iterator cbegin() const { return Blocks.cbegin(); }
1728  const_iterator cend() const { return Blocks.cend(); }
1729 
1730  const BasicBlock *entry() const { return Entry; }
1731  BasicBlock *entry() { return Entry; }
1732  const BasicBlock *exit() const { return Exit; }
1733  BasicBlock *exit() { return Exit; }
1734 
1735  /// Return the number of blocks in the CFG.
1736  /// Block::blockID() will return a number less than numBlocks();
1737  size_t numBlocks() const { return Blocks.size(); }
1738 
1739  /// Return the total number of instructions in the CFG.
1740  /// This is useful for building instruction side-tables;
1741  /// A call to SExpr::id() will return a number less than numInstructions().
1742  unsigned numInstructions() { return NumInstructions; }
1743 
1744  inline void add(BasicBlock *BB) {
1745  assert(BB->CFGPtr == nullptr);
1746  BB->CFGPtr = this;
1747  Blocks.reserveCheck(1, Arena);
1748  Blocks.push_back(BB);
1749  }
1750 
1751  void setEntry(BasicBlock *BB) { Entry = BB; }
1752  void setExit(BasicBlock *BB) { Exit = BB; }
1753 
1754  void computeNormalForm();
1755 
1756  template <class V>
1757  typename V::R_SExpr traverse(V &Vs, typename V::R_Ctx Ctx) {
1758  Vs.enterCFG(*this);
1759  typename V::template Container<BasicBlock *> Bbs(Vs, Blocks.size());
1760 
1761  for (const auto *B : Blocks) {
1762  Bbs.push_back( B->traverse(Vs, Vs.subExprCtx(Ctx)) );
1763  }
1764  Vs.exitCFG(*this);
1765  return Vs.reduceSCFG(*this, Bbs);
1766  }
1767 
1768  template <class C>
1769  typename C::CType compare(const SCFG *E, C &Cmp) const {
1770  // TODO: implement CFG comparisons
1771  return Cmp.comparePointers(this, E);
1772  }
1773 
1774 private:
1775  // assign unique ids to all instructions
1776  void renumberInstrs();
1777 
1778  MemRegionRef Arena;
1779  BlockArray Blocks;
1780  BasicBlock *Entry = nullptr;
1781  BasicBlock *Exit = nullptr;
1782  unsigned NumInstructions = 0;
1783  bool Normal = false;
1784 };
1785 
1786 /// An identifier, e.g. 'foo' or 'x'.
1787 /// This is a pseduo-term; it will be lowered to a variable or projection.
1788 class Identifier : public SExpr {
1789 public:
1790  Identifier(StringRef Id): SExpr(COP_Identifier), Name(Id) {}
1791  Identifier(const Identifier &) = default;
1792 
1793  static bool classof(const SExpr *E) { return E->opcode() == COP_Identifier; }
1794 
1795  StringRef name() const { return Name; }
1796 
1797  template <class V>
1798  typename V::R_SExpr traverse(V &Vs, typename V::R_Ctx Ctx) {
1799  return Vs.reduceIdentifier(*this);
1800  }
1801 
1802  template <class C>
1803  typename C::CType compare(const Identifier* E, C& Cmp) const {
1804  return Cmp.compareStrings(name(), E->name());
1805  }
1806 
1807 private:
1808  StringRef Name;
1809 };
1810 
1811 /// An if-then-else expression.
1812 /// This is a pseduo-term; it will be lowered to a branch in a CFG.
1813 class IfThenElse : public SExpr {
1814 public:
1816  : SExpr(COP_IfThenElse), Condition(C), ThenExpr(T), ElseExpr(E) {}
1817  IfThenElse(const IfThenElse &I, SExpr *C, SExpr *T, SExpr *E)
1818  : SExpr(I), Condition(C), ThenExpr(T), ElseExpr(E) {}
1819 
1820  static bool classof(const SExpr *E) { return E->opcode() == COP_IfThenElse; }
1821 
1822  SExpr *condition() { return Condition; } // Address to store to
1823  const SExpr *condition() const { return Condition; }
1824 
1825  SExpr *thenExpr() { return ThenExpr; } // Value to store
1826  const SExpr *thenExpr() const { return ThenExpr; }
1827 
1828  SExpr *elseExpr() { return ElseExpr; } // Value to store
1829  const SExpr *elseExpr() const { return ElseExpr; }
1830 
1831  template <class V>
1832  typename V::R_SExpr traverse(V &Vs, typename V::R_Ctx Ctx) {
1833  auto Nc = Vs.traverse(Condition, Vs.subExprCtx(Ctx));
1834  auto Nt = Vs.traverse(ThenExpr, Vs.subExprCtx(Ctx));
1835  auto Ne = Vs.traverse(ElseExpr, Vs.subExprCtx(Ctx));
1836  return Vs.reduceIfThenElse(*this, Nc, Nt, Ne);
1837  }
1838 
1839  template <class C>
1840  typename C::CType compare(const IfThenElse* E, C& Cmp) const {
1841  typename C::CType Ct = Cmp.compare(condition(), E->condition());
1842  if (Cmp.notTrue(Ct))
1843  return Ct;
1844  Ct = Cmp.compare(thenExpr(), E->thenExpr());
1845  if (Cmp.notTrue(Ct))
1846  return Ct;
1847  return Cmp.compare(elseExpr(), E->elseExpr());
1848  }
1849 
1850 private:
1851  SExpr* Condition;
1852  SExpr* ThenExpr;
1853  SExpr* ElseExpr;
1854 };
1855 
1856 /// A let-expression, e.g. let x=t; u.
1857 /// This is a pseduo-term; it will be lowered to instructions in a CFG.
1858 class Let : public SExpr {
1859 public:
1860  Let(Variable *Vd, SExpr *Bd) : SExpr(COP_Let), VarDecl(Vd), Body(Bd) {
1862  }
1863 
1864  Let(const Let &L, Variable *Vd, SExpr *Bd) : SExpr(L), VarDecl(Vd), Body(Bd) {
1866  }
1867 
1868  static bool classof(const SExpr *E) { return E->opcode() == COP_Let; }
1869 
1871  const Variable *variableDecl() const { return VarDecl; }
1872 
1873  SExpr *body() { return Body; }
1874  const SExpr *body() const { return Body; }
1875 
1876  template <class V>
1877  typename V::R_SExpr traverse(V &Vs, typename V::R_Ctx Ctx) {
1878  // This is a variable declaration, so traverse the definition.
1879  auto E0 = Vs.traverse(VarDecl->Definition, Vs.subExprCtx(Ctx));
1880  // Tell the rewriter to enter the scope of the let variable.
1881  Variable *Nvd = Vs.enterScope(*VarDecl, E0);
1882  auto E1 = Vs.traverse(Body, Ctx);
1883  Vs.exitScope(*VarDecl);
1884  return Vs.reduceLet(*this, Nvd, E1);
1885  }
1886 
1887  template <class C>
1888  typename C::CType compare(const Let* E, C& Cmp) const {
1889  typename C::CType Ct =
1890  Cmp.compare(VarDecl->definition(), E->VarDecl->definition());
1891  if (Cmp.notTrue(Ct))
1892  return Ct;
1893  Cmp.enterScope(variableDecl(), E->variableDecl());
1894  Ct = Cmp.compare(body(), E->body());
1895  Cmp.leaveScope();
1896  return Ct;
1897  }
1898 
1899 private:
1900  Variable *VarDecl;
1901  SExpr* Body;
1902 };
1903 
1904 const SExpr *getCanonicalVal(const SExpr *E);
1905 SExpr* simplifyToCanonicalVal(SExpr *E);
1907 
1908 } // namespace til
1909 } // namespace threadSafety
1910 
1911 } // namespace clang
1912 
1913 #endif // LLVM_CLANG_ANALYSIS_ANALYSES_THREADSAFETYTIL_H
clang::threadSafety::til::SCFG::setExit
void setExit(BasicBlock *BB)
Definition: ThreadSafetyTIL.h:1752
clang::threadSafety::til::Branch::successors
ArrayRef< BasicBlock * > successors()
Return the list of basic blocks that this terminator can branch to.
Definition: ThreadSafetyTIL.h:1434
clang::threadSafety::til::BasicBlock::terminator
const Terminator * terminator() const
Definition: ThreadSafetyTIL.h:1570
clang::threadSafety::til::BasicBlock::classof
static bool classof(const SExpr *E)
Definition: ThreadSafetyTIL.h:1540
clang::threadSafety::til::SExpr::SExpr
SExpr()=delete
clang::threadSafety::til::Alloc::dataType
const SExpr * dataType() const
Definition: ThreadSafetyTIL.h:1011
clang::threadSafety::til::BOP_LogicOr
@ BOP_LogicOr
Definition: ThreadSafetyTIL.h:109
clang::threadSafety::til::Store::traverse
V::R_SExpr traverse(V &Vs, typename V::R_Ctx Ctx)
Definition: ThreadSafetyTIL.h:1073
clang::threadSafety::til::ArrayIndex::array
SExpr * array()
Definition: ThreadSafetyTIL.h:1102
clang::threadSafety::til::Apply
Apply an argument to a function.
Definition: ThreadSafetyTIL.h:840
clang::threadSafety::til::Load::compare
C::CType compare(const Load *E, C &Cmp) const
Definition: ThreadSafetyTIL.h:1049
clang::threadSafety::til::BOP_Cmp
@ BOP_Cmp
Definition: ThreadSafetyTIL.h:107
clang::threadSafety::til::BOP_BitAnd
@ BOP_BitAnd
Definition: ThreadSafetyTIL.h:100
clang::threadSafety::til::BinaryOp::expr0
SExpr * expr0()
Definition: ThreadSafetyTIL.h:1223
clang::threadSafety::til::Goto
Jump to another basic block.
Definition: ThreadSafetyTIL.h:1370
clang::threadSafety::til::Variable::VariableKind
VariableKind
Definition: ThreadSafetyTIL.h:357
clang::threadSafety::til::Code::compare
C::CType compare(const Code *E, C &Cmp) const
Definition: ThreadSafetyTIL.h:788
clang::threadSafety::til::UnaryOp::UnaryOp
UnaryOp(const UnaryOp &U, SExpr *E)
Definition: ThreadSafetyTIL.h:1173
ThreadSafetyUtil.h
clang::threadSafety::til::Alloc::kind
AllocKind kind() const
Definition: ThreadSafetyTIL.h:1008
clang::threadSafety::til::BOP_Neq
@ BOP_Neq
Definition: ThreadSafetyTIL.h:104
clang::threadSafety::til::Branch::traverse
V::R_SExpr traverse(V &Vs, typename V::R_Ctx Ctx)
Definition: ThreadSafetyTIL.h:1439
clang::threadSafety::til::Future
Placeholder for an expression that has not yet been created.
Definition: ThreadSafetyTIL.h:435
clang::threadSafety::til::SCFG::numBlocks
size_t numBlocks() const
Return the number of blocks in the CFG.
Definition: ThreadSafetyTIL.h:1737
clang::threadSafety::til::UOP_BitNot
@ UOP_BitNot
Definition: ThreadSafetyTIL.h:87
clang::threadSafety::til::SCFG::traverse
V::R_SExpr traverse(V &Vs, typename V::R_Ctx Ctx)
Definition: ThreadSafetyTIL.h:1757
clang::threadSafety::til::BasicBlock::reservePredecessors
void reservePredecessors(unsigned NumPreds)
Definition: ThreadSafetyTIL.cpp:71
clang::threadSafety::til::IfThenElse::condition
SExpr * condition()
Definition: ThreadSafetyTIL.h:1822
clang::threadSafety::til::Phi::PH_MultiVal
@ PH_MultiVal
Definition: ThreadSafetyTIL.h:1302
clang::threadSafety::til::BinaryOp::BinaryOp
BinaryOp(const BinaryOp &B, SExpr *E0, SExpr *E1)
Definition: ThreadSafetyTIL.h:1212
clang::threadSafety::til::Call::target
SExpr * target()
Definition: ThreadSafetyTIL.h:974
clang::threadSafety::til::Let::body
const SExpr * body() const
Definition: ThreadSafetyTIL.h:1874
clang::threadSafety::til::ArrayAdd::ArrayAdd
ArrayAdd(SExpr *A, SExpr *N)
Definition: ThreadSafetyTIL.h:1133
clang::threadSafety::til::BinaryOp::compare
C::CType compare(const BinaryOp *E, C &Cmp) const
Definition: ThreadSafetyTIL.h:1237
clang::threadSafety::til::Function::traverse
V::R_SExpr traverse(V &Vs, typename V::R_Ctx Ctx)
Definition: ThreadSafetyTIL.h:686
clang::threadSafety::til::BOP_BitOr
@ BOP_BitOr
Definition: ThreadSafetyTIL.h:102
clang::threadSafety::til::Literal::Literal
Literal(ValueType VT)
Definition: ThreadSafetyTIL.h:533
clang::threadSafety::til::SApply::traverse
V::R_SExpr traverse(V &Vs, typename V::R_Ctx Ctx)
Definition: ThreadSafetyTIL.h:892
clang::threadSafety::til::SApply::sfun
SExpr * sfun()
Definition: ThreadSafetyTIL.h:883
clang::threadSafety::til::Let::classof
static bool classof(const SExpr *E)
Definition: ThreadSafetyTIL.h:1868
clang::threadSafety::til::LiteralT::LiteralT
LiteralT(T Dat)
Definition: ThreadSafetyTIL.h:567
clang::threadSafety::til::Branch
A conditional branch to two other blocks.
Definition: ThreadSafetyTIL.h:1408
clang::threadSafety::til::Undefined::compare
C::CType compare(const Undefined *E, C &Cmp) const
Definition: ThreadSafetyTIL.h:500
clang::threadSafety::til::Load
Load a value from memory.
Definition: ThreadSafetyTIL.h:1032
clang::threadSafety::til::Project::clangDecl
const ValueDecl * clangDecl() const
Definition: ThreadSafetyTIL.h:925
clang::threadSafety::til::LiteralPtr::traverse
V::R_SExpr traverse(V &Vs, typename V::R_Ctx Ctx)
Definition: ThreadSafetyTIL.h:647
clang::threadSafety::til::BOP_BitXor
@ BOP_BitXor
Definition: ThreadSafetyTIL.h:101
clang::threadSafety::til::SExpr::block
BasicBlock * block() const
Returns the block, if this is an instruction in a basic block, otherwise returns null.
Definition: ThreadSafetyTIL.h:315
clang::threadSafety::til::SCFG::setEntry
void setEntry(BasicBlock *BB)
Definition: ThreadSafetyTIL.h:1751
clang::threadSafety::til::Field::range
const SExpr * range() const
Definition: ThreadSafetyTIL.h:810
clang::threadSafety::til::Code::returnType
SExpr * returnType()
Definition: ThreadSafetyTIL.h:774
clang::threadSafety::til::Identifier
An identifier, e.g.
Definition: ThreadSafetyTIL.h:1788
clang::threadSafety::til::Alloc::traverse
V::R_SExpr traverse(V &Vs, typename V::R_Ctx Ctx)
Definition: ThreadSafetyTIL.h:1014
clang::threadSafety::til::UnaryOp
Simple arithmetic unary operations, e.g.
Definition: ThreadSafetyTIL.h:1167
clang::threadSafety::til::Cast
Cast expressions.
Definition: ThreadSafetyTIL.h:1256
clang::threadSafety::til::IfThenElse::traverse
V::R_SExpr traverse(V &Vs, typename V::R_Ctx Ctx)
Definition: ThreadSafetyTIL.h:1832
clang::threadSafety::til::Apply::fun
const SExpr * fun() const
Definition: ThreadSafetyTIL.h:849
clang::threadSafety::til::Return::returnValue
SExpr * returnValue()
Definition: ThreadSafetyTIL.h:1469
clang::threadSafety::til::BOP_Max
const TIL_BinaryOpcode BOP_Max
Definition: ThreadSafetyTIL.h:137
clang::threadSafety::til::Branch::elseBlock
const BasicBlock * elseBlock() const
Definition: ThreadSafetyTIL.h:1430
clang::threadSafety::til::Function::variableDecl
const Variable * variableDecl() const
Definition: ThreadSafetyTIL.h:680
clang::threadSafety::til::SCFG::exit
BasicBlock * exit()
Definition: ThreadSafetyTIL.h:1733
clang::threadSafety::til::Branch::thenBlock
BasicBlock * thenBlock()
Definition: ThreadSafetyTIL.h:1428
clang::threadSafety::til::Literal::as
LiteralT< T > & as()
Definition: ThreadSafetyTIL.h:546
clang::threadSafety::til::SExpr::SExprID
unsigned SExprID
Definition: ThreadSafetyTIL.h:327
clang::threadSafety::til::Variable::clangDecl
const ValueDecl * clangDecl() const
Return the clang declaration for this variable, if any.
Definition: ThreadSafetyTIL.h:393
clang::threadSafety::til::Code::returnType
const SExpr * returnType() const
Definition: ThreadSafetyTIL.h:775
clang::threadSafety::til::Apply::Apply
Apply(const Apply &A, SExpr *F, SExpr *Ar)
Definition: ThreadSafetyTIL.h:843
clang::threadSafety::til::BasicBlock::arguments
const InstrArray & arguments() const
Definition: ThreadSafetyTIL.h:1555
clang::threadSafety::til::Alloc::classof
static bool classof(const SExpr *E)
Definition: ThreadSafetyTIL.h:1006
clang::threadSafety::til::Wildcard
Placeholder for a wildcard that matches any other expression.
Definition: ThreadSafetyTIL.h:509
clang::threadSafety::til::Phi::ValArray
SimpleArray< SExpr * > ValArray
Definition: ThreadSafetyTIL.h:1296
clang::threadSafety::til::LiteralPtr::setClangDecl
void setClangDecl(const ValueDecl *VD)
Definition: ThreadSafetyTIL.h:644
clang::threadSafety::til::ValueType::Signed
bool Signed
Definition: ThreadSafetyTIL.h:184
clang::threadSafety::til::Undefined::classof
static bool classof(const SExpr *E)
Definition: ThreadSafetyTIL.h:492
clang::threadSafety::til::Undefined::Undefined
Undefined(const Undefined &U)
Definition: ThreadSafetyTIL.h:490
clang::threadSafety::til::SimpleArray< BasicBlock * >::const_iterator
const BasicBlock * * const_iterator
Definition: ThreadSafetyUtil.h:131
clang::threadSafety::til::Phi::clangDecl
const ValueDecl * clangDecl() const
Return the clang declaration of the variable for this Phi node, if any.
Definition: ThreadSafetyTIL.h:1320
clang::threadSafety::til::Variable::Variable
Variable(const Variable &Vd, SExpr *D)
Definition: ThreadSafetyTIL.h:379
clang::threadSafety::til::SCFG::begin
iterator begin()
Definition: ThreadSafetyTIL.h:1721
clang::threadSafety::til::LiteralPtr::clangDecl
const ValueDecl * clangDecl() const
Definition: ThreadSafetyTIL.h:643
clang::threadSafety::til::Future::~Future
virtual ~Future()=delete
clang::threadSafety::til::Identifier::classof
static bool classof(const SExpr *E)
Definition: ThreadSafetyTIL.h:1793
clang::threadSafety::til::IfThenElse::compare
C::CType compare(const IfThenElse *E, C &Cmp) const
Definition: ThreadSafetyTIL.h:1840
clang::threadSafety::til::SCFG::computeNormalForm
void computeNormalForm()
Definition: ThreadSafetyTIL.cpp:290
clang::threadSafety::til::SCFG::SCFG
SCFG(MemRegionRef A, unsigned Nblocks)
Definition: ThreadSafetyTIL.h:1695
clang::threadSafety::til::Phi::Status
Status
Definition: ThreadSafetyTIL.h:1301
clang::threadSafety::til::SCFG::begin
const_iterator begin() const
Definition: ThreadSafetyTIL.h:1724
clang::threadSafety::til::SFunction::SFunction
SFunction(const SFunction &F, Variable *Vd, SExpr *B)
Definition: ThreadSafetyTIL.h:725
clang::threadSafety::til::Future::compute
virtual SExpr * compute()
Definition: ThreadSafetyTIL.h:449
clang::threadSafety::til::SimpleArray::cend
const_iterator cend() const
Definition: ThreadSafetyUtil.h:165
clang::threadSafety::til::Alloc::Alloc
Alloc(SExpr *D, AllocKind K)
Definition: ThreadSafetyTIL.h:1003
clang::threadSafety::til::ValueType::BT_Bool
@ BT_Bool
Definition: ThreadSafetyTIL.h:156
clang::threadSafety::til::BasicBlock::TopologyNode::SizeOfSubTree
int SizeOfSubTree
Definition: ThreadSafetyTIL.h:1515
clang::threadSafety::til::Field::Field
Field(const Field &C, SExpr *R, SExpr *B)
Definition: ThreadSafetyTIL.h:804
clang::threadSafety::til::Function::Function
Function(const Function &F, Variable *Vd, SExpr *Bd)
Definition: ThreadSafetyTIL.h:672
clang::threadSafety::til::Variable::VK_Let
@ VK_Let
Let-variable.
Definition: ThreadSafetyTIL.h:359
clang::threadSafety::til::Project::compare
C::CType compare(const Project *E, C &Cmp) const
Definition: ThreadSafetyTIL.h:952
clang::threadSafety::til::Code::Code
Code(SExpr *T, SExpr *B)
Definition: ThreadSafetyTIL.h:768
clang::threadSafety::til::ArrayIndex::index
const SExpr * index() const
Definition: ThreadSafetyTIL.h:1106
llvm::Optional< std::string >
clang::threadSafety::til::CAST_none
@ CAST_none
Definition: ThreadSafetyTIL.h:114
clang::threadSafety::til::Future::maybeGetResult
SExpr * maybeGetResult() const
Definition: ThreadSafetyTIL.h:452
clang::threadSafety::til::SExpr::opcode
TIL_Opcode opcode() const
Definition: ThreadSafetyTIL.h:281
clang::threadSafety::til::UnaryOp::expr
SExpr * expr()
Definition: ThreadSafetyTIL.h:1181
clang::threadSafety::til::BOP_Div
@ BOP_Div
Definition: ThreadSafetyTIL.h:96
clang::threadSafety::til::Field::body
const SExpr * body() const
Definition: ThreadSafetyTIL.h:813
clang::threadSafety::til::Branch::thenBlock
const BasicBlock * thenBlock() const
Definition: ThreadSafetyTIL.h:1427
clang::threadSafety::til::Apply::fun
SExpr * fun()
Definition: ThreadSafetyTIL.h:848
clang::threadSafety::til::BOP_Eq
@ BOP_Eq
Definition: ThreadSafetyTIL.h:103
clang::threadSafety::til::BOP_Sub
@ BOP_Sub
Definition: ThreadSafetyTIL.h:94
clang::threadSafety::til::SimpleArray::push_back
void push_back(const T &Elem)
Definition: ThreadSafetyUtil.h:178
clang::threadSafety::til::Branch::Branch
Branch(const Branch &Br, SExpr *C, BasicBlock *T, BasicBlock *E)
Definition: ThreadSafetyTIL.h:1416
clang::threadSafety::til::Variable::definition
SExpr * definition()
Return the definition of the variable.
Definition: ThreadSafetyTIL.h:398
clang::threadSafety::til::Field
A typed, writable location in memory.
Definition: ThreadSafetyTIL.h:801
clang::threadSafety::til::CAST_Max
const TIL_CastOpcode CAST_Max
Definition: ThreadSafetyTIL.h:139
clang::threadSafety::til::TIL_BinaryOpcode
TIL_BinaryOpcode
Opcode for binary arithmetic operations.
Definition: ThreadSafetyTIL.h:92
clang::threadSafety::til::Field::Field
Field(SExpr *R, SExpr *B)
Definition: ThreadSafetyTIL.h:803
clang::threadSafety::til::SimpleArray::end
iterator end()
Definition: ThreadSafetyUtil.h:159
clang::threadSafety::til::BasicBlock::findPredecessorIndex
unsigned findPredecessorIndex(const BasicBlock *BB) const
Return the index of BB, or Predecessors.size if BB is not a predecessor.
Definition: ThreadSafetyTIL.h:1609
clang::threadSafety::til::Future::compare
C::CType compare(const Future *E, C &Cmp) const
Definition: ThreadSafetyTIL.h:473
clang::threadSafety::til::BasicBlock::blockID
int blockID() const
Returns the block ID. Every block has a unique ID in the CFG.
Definition: ThreadSafetyTIL.h:1543
clang::threadSafety::til::Branch::classof
static bool classof(const SExpr *E)
Definition: ThreadSafetyTIL.h:1422
clang::threadSafety::til::BasicBlock::TopologyNode
Definition: ThreadSafetyTIL.h:1511
clang::threadSafety::til::ValueType::BaseType
BaseType
Definition: ThreadSafetyTIL.h:154
clang::threadSafety::til::LiteralT::LiteralT
LiteralT(const LiteralT< T > &L)
Definition: ThreadSafetyTIL.h:568
b
__device__ __2f16 b
Definition: __clang_hip_libdevice_declares.h:319
clang::threadSafety::til::BasicBlock::addArgument
void addArgument(Phi *V)
Add a new argument.
Definition: ThreadSafetyTIL.h:1584
clang::threadSafety::til::Cast::traverse
V::R_SExpr traverse(V &Vs, typename V::R_Ctx Ctx)
Definition: ThreadSafetyTIL.h:1271
clang::threadSafety::til::Alloc::AK_Heap
@ AK_Heap
Definition: ThreadSafetyTIL.h:1000
clang::threadSafety::til::Project
Project a named slot from a C++ struct or class.
Definition: ThreadSafetyTIL.h:913
clang::threadSafety::til::Function::compare
C::CType compare(const Function *E, C &Cmp) const
Definition: ThreadSafetyTIL.h:697
clang::threadSafety::til::Project::isArrow
bool isArrow() const
Definition: ThreadSafetyTIL.h:927
clang::threadSafety::til::SimpleArray::begin
iterator begin()
Definition: ThreadSafetyUtil.h:158
clang::threadSafety::til::BOP_Rem
@ BOP_Rem
Definition: ThreadSafetyTIL.h:97
clang::threadSafety::til::Apply::classof
static bool classof(const SExpr *E)
Definition: ThreadSafetyTIL.h:846
clang::threadSafety::til::Call::Call
Call(SExpr *T, const CallExpr *Ce=nullptr)
Definition: ThreadSafetyTIL.h:968
clang::threadSafety::til::Phi::setStatus
void setStatus(Status s)
Definition: ThreadSafetyTIL.h:1317
Decl.h
clang::threadSafety::til::BinaryOp::classof
static bool classof(const SExpr *E)
Definition: ThreadSafetyTIL.h:1217
clang::threadSafety::til::BasicBlock::parent
const BasicBlock * parent() const
Definition: ThreadSafetyTIL.h:1552
clang::threadSafety::til::ValueType::BT_String
@ BT_String
Definition: ThreadSafetyTIL.h:159
clang::threadSafety::til::CAST_Min
const TIL_CastOpcode CAST_Min
Definition: ThreadSafetyTIL.h:138
clang::threadSafety::til::Code::body
SExpr * body()
Definition: ThreadSafetyTIL.h:777
clang::threadSafety::til::ArrayIndex::index
SExpr * index()
Definition: ThreadSafetyTIL.h:1105
clang::threadSafety::til::UnaryOp::unaryOpcode
TIL_UnaryOpcode unaryOpcode() const
Definition: ThreadSafetyTIL.h:1177
clang::threadSafety::til::UOP_LogicNot
@ UOP_LogicNot
Definition: ThreadSafetyTIL.h:88
clang::threadSafety::til::Wildcard::traverse
V::R_SExpr traverse(V &Vs, typename V::R_Ctx Ctx)
Definition: ThreadSafetyTIL.h:516
clang::threadSafety::til::SimpleArray::reserveCheck
void reserveCheck(size_t N, MemRegionRef A)
Definition: ThreadSafetyUtil.h:123
clang::threadSafety::til::Literal::traverse
V::R_SExpr traverse(V &Vs, typename V::R_Ctx Ctx)
Definition: ThreadSafetyTIL.h:578
clang::threadSafety::til::Future::FS_pending
@ FS_pending
Definition: ThreadSafetyTIL.h:438
size_t
__SIZE_TYPE__ size_t
The unsigned integer type of the result of the sizeof operator.
Definition: opencl-c-base.h:118
clang::threadSafety::til::Call
Call a function (after all arguments have been applied).
Definition: ThreadSafetyTIL.h:966
clang::dataflow::Literal
uint32_t Literal
Literals are represented as positive integers.
Definition: WatchedLiteralsSolver.cpp:55
U
clang::threadSafety::til::BasicBlock::instructions
InstrArray & instructions()
Definition: ThreadSafetyTIL.h:1558
clang::threadSafety::til::Phi::setClangDecl
void setClangDecl(const ValueDecl *Cvd)
Set the clang variable associated with this Phi node.
Definition: ThreadSafetyTIL.h:1323
clang::threadSafety::til::Let::body
SExpr * body()
Definition: ThreadSafetyTIL.h:1873
clang::threadSafety::til::Future::FutureStatus
FutureStatus
Definition: ThreadSafetyTIL.h:437
clang::threadSafety::til::Let::variableDecl
const Variable * variableDecl() const
Definition: ThreadSafetyTIL.h:1871
clang::threadSafety::til::Phi::Phi
Phi(const Phi &P, ValArray &&Vs)
Definition: ThreadSafetyTIL.h:1309
clang::threadSafety::til::SApply::SApply
SApply(SExpr *Sf, SExpr *A=nullptr)
Definition: ThreadSafetyTIL.h:877
clang::threadSafety::til::TIL_UnaryOpcode
TIL_UnaryOpcode
Opcode for unary arithmetic operations.
Definition: ThreadSafetyTIL.h:85
clang::threadSafety::til::UOP_Min
const TIL_UnaryOpcode UOP_Min
Definition: ThreadSafetyTIL.h:134
V
#define V(N, I)
Definition: ASTContext.h:3235
clang::threadSafety::til::Apply::traverse
V::R_SExpr traverse(V &Vs, typename V::R_Ctx Ctx)
Definition: ThreadSafetyTIL.h:855
clang::threadSafety::til::Return::compare
C::CType compare(const Return *E, C &Cmp) const
Definition: ThreadSafetyTIL.h:1479
clang::threadSafety::til::ArrayAdd::compare
C::CType compare(const ArrayAdd *E, C &Cmp) const
Definition: ThreadSafetyTIL.h:1153
clang::threadSafety::til::Project::record
const SExpr * record() const
Definition: ThreadSafetyTIL.h:923
clang::threadSafety::til::Cast::Cast
Cast(TIL_CastOpcode Op, SExpr *E)
Definition: ThreadSafetyTIL.h:1258
clang::threadSafety::til::BasicBlock::reserveInstructions
void reserveInstructions(unsigned Nins)
Definition: ThreadSafetyTIL.h:1603
clang::threadSafety::til::Identifier::compare
C::CType compare(const Identifier *E, C &Cmp) const
Definition: ThreadSafetyTIL.h:1803
clang::threadSafety::til::ValueType::BT_Pointer
@ BT_Pointer
Definition: ThreadSafetyTIL.h:160
clang::threadSafety::til::BasicBlock::setTerminator
void setTerminator(Terminator *E)
Definition: ThreadSafetyTIL.h:1573
clang::threadSafety::til::BOP_Shl
@ BOP_Shl
Definition: ThreadSafetyTIL.h:98
clang::threadSafety::til::SApply::SApply
SApply(SApply &A, SExpr *Sf, SExpr *Ar=nullptr)
Definition: ThreadSafetyTIL.h:878
clang::threadSafety::til::Branch::condition
SExpr * condition()
Definition: ThreadSafetyTIL.h:1425
clang::threadSafety::til::BasicBlock::instructions
const InstrArray & instructions() const
Definition: ThreadSafetyTIL.h:1559
Id
int Id
Definition: ASTDiff.cpp:189
clang::threadSafety::til::Variable::kind
VariableKind kind() const
Return the kind of variable (let, function param, or self)
Definition: ThreadSafetyTIL.h:387
clang::threadSafety::til::ValueType::BT_Void
@ BT_Void
Definition: ThreadSafetyTIL.h:155
clang::threadSafety::til::ValueType::Size
SizeType Size
Definition: ThreadSafetyTIL.h:183
clang::threadSafety::til::SCFG::valid
bool valid() const
Return true if this CFG is valid.
Definition: ThreadSafetyTIL.h:1714
clang::threadSafety::til::Alloc
Allocate memory for a new value on the heap or stack.
Definition: ThreadSafetyTIL.h:996
clang::threadSafety::til::BasicBlock::arguments
InstrArray & arguments()
Definition: ThreadSafetyTIL.h:1556
clang::threadSafety::til::BasicBlock::predecessors
BlockArray & predecessors()
Returns a list of predecessors.
Definition: ThreadSafetyTIL.h:1564
clang::threadSafety::til::Apply::arg
SExpr * arg()
Definition: ThreadSafetyTIL.h:851
clang::threadSafety::til::Goto::traverse
V::R_SExpr traverse(V &Vs, typename V::R_Ctx Ctx)
Definition: ThreadSafetyTIL.h:1389
clang::threadSafety::til::ArrayAdd::array
const SExpr * array() const
Definition: ThreadSafetyTIL.h:1140
clang::threadSafety::til::SCFG::BlockArray
SimpleArray< BasicBlock * > BlockArray
Definition: ThreadSafetyTIL.h:1691
clang::threadSafety::til::Store::destination
const SExpr * destination() const
Definition: ThreadSafetyTIL.h:1067
clang::threadSafety::til::Project::traverse
V::R_SExpr traverse(V &Vs, typename V::R_Ctx Ctx)
Definition: ThreadSafetyTIL.h:946
clang::threadSafety::til::Load::Load
Load(SExpr *P)
Definition: ThreadSafetyTIL.h:1034
clang::threadSafety::til::UnaryOp::expr
const SExpr * expr() const
Definition: ThreadSafetyTIL.h:1182
clang::threadSafety::til::CAST_toFloat
@ CAST_toFloat
Definition: ThreadSafetyTIL.h:123
clang::threadSafety::til::Phi::traverse
V::R_SExpr traverse(V &Vs, typename V::R_Ctx Ctx)
Definition: ThreadSafetyTIL.h:1326
clang::threadSafety::til::ValueType::ST_128
@ ST_128
Definition: ThreadSafetyTIL.h:171
clang::threadSafety::til::LiteralPtr::LiteralPtr
LiteralPtr(const ValueDecl *D)
Definition: ThreadSafetyTIL.h:637
clang::threadSafety::til::ValueType::BT_Float
@ BT_Float
Definition: ThreadSafetyTIL.h:158
clang::threadSafety::til::Branch::elseBlock
BasicBlock * elseBlock()
Definition: ThreadSafetyTIL.h:1431
clang::threadSafety::til::UOP_Max
const TIL_UnaryOpcode UOP_Max
Definition: ThreadSafetyTIL.h:135
clang::threadSafety::til::BOP_Leq
@ BOP_Leq
Definition: ThreadSafetyTIL.h:106
clang::api_notes::BlockID
BlockID
The various types of blocks that can occur within a API notes file.
Definition: APINotesFormat.h:38
clang::threadSafety::til::Phi::Phi
Phi()
Definition: ThreadSafetyTIL.h:1307
clang::threadSafety::til::Alloc::Alloc
Alloc(const Alloc &A, SExpr *Dt)
Definition: ThreadSafetyTIL.h:1004
clang::threadSafety::til::ThreadSafetyTIL::isTrivial
bool isTrivial(const SExpr *E)
Definition: ThreadSafetyTIL.h:334
clang::threadSafety::til::SCFG::add
void add(BasicBlock *BB)
Definition: ThreadSafetyTIL.h:1744
clang::threadSafety::til::LiteralT
Definition: ThreadSafetyTIL.h:526
clang::threadSafety::til::Cast::castOpcode
TIL_CastOpcode castOpcode() const
Definition: ThreadSafetyTIL.h:1263
clang::threadSafety::til::BasicBlock::parent
BasicBlock * parent()
Definition: ThreadSafetyTIL.h:1553
clang::VarDecl
Represents a variable declaration or definition.
Definition: Decl.h:906
clang::threadSafety::til::Code
A block of code – e.g. the body of a function.
Definition: ThreadSafetyTIL.h:766
clang::threadSafety::til::IfThenElse::elseExpr
SExpr * elseExpr()
Definition: ThreadSafetyTIL.h:1828
clang::threadSafety::til::ArrayIndex::array
const SExpr * array() const
Definition: ThreadSafetyTIL.h:1103
clang::threadSafety::til::Variable::setName
void setName(StringRef S)
Definition: ThreadSafetyTIL.h:401
clang::threadSafety::til::Let
A let-expression, e.g.
Definition: ThreadSafetyTIL.h:1858
clang::threadSafety::til::SExpr::Reserved
unsigned char Reserved
Definition: ThreadSafetyTIL.h:325
clang::threadSafety::til::Phi
Phi Node, for code in SSA form.
Definition: ThreadSafetyTIL.h:1294
clang::threadSafety::til::CAST_truncNum
@ CAST_truncNum
Definition: ThreadSafetyTIL.h:120
clang::threadSafety::til::Let::Let
Let(Variable *Vd, SExpr *Bd)
Definition: ThreadSafetyTIL.h:1860
clang::threadSafety::til::Phi::PH_Incomplete
@ PH_Incomplete
Definition: ThreadSafetyTIL.h:1304
clang::threadSafety::til::Goto::Goto
Goto(BasicBlock *B, unsigned I)
Definition: ThreadSafetyTIL.h:1372
clang::threadSafety::til::SimpleArray::cbegin
const_iterator cbegin() const
Definition: ThreadSafetyUtil.h:164
clang::threadSafety::til::getBinaryOpcodeString
StringRef getBinaryOpcodeString(TIL_BinaryOpcode Op)
Return the name of a binary opcode.
Definition: ThreadSafetyTIL.cpp:28
clang::threadSafety::til::Wildcard::Wildcard
Wildcard()
Definition: ThreadSafetyTIL.h:511
clang::threadSafety::til::Cast::expr
const SExpr * expr() const
Definition: ThreadSafetyTIL.h:1268
clang::threadSafety::til::Undefined
Placeholder for expressions that cannot be represented in the TIL.
Definition: ThreadSafetyTIL.h:487
clang::threadSafety::til::Phi::values
const ValArray & values() const
Definition: ThreadSafetyTIL.h:1313
clang::threadSafety::til::SExpr::SExpr
SExpr(TIL_Opcode Op)
Definition: ThreadSafetyTIL.h:321
clang::threadSafety::til::BOP_Shr
@ BOP_Shr
Definition: ThreadSafetyTIL.h:99
clang::threadSafety::til::Project::setArrow
void setArrow(bool b)
Definition: ThreadSafetyTIL.h:929
clang::threadSafety::til::SimpleArray::reserve
void reserve(size_t Ncp, MemRegionRef A)
Definition: ThreadSafetyUtil.h:113
clang::threadSafety::til::BasicBlock::addInstruction
void addInstruction(SExpr *V)
Add a new instruction.
Definition: ThreadSafetyTIL.h:1590
clang::threadSafety::til::Return::Return
Return(const Return &R, SExpr *Rval)
Definition: ThreadSafetyTIL.h:1462
Base
clang::threadSafety::til::Literal::compare
C::CType compare(const Literal *E, C &Cmp) const
Definition: ThreadSafetyTIL.h:553
clang::threadSafety::til::Store::source
SExpr * source()
Definition: ThreadSafetyTIL.h:1069
clang::threadSafety::til::Variable::Variable
Variable(StringRef s, SExpr *D=nullptr)
Definition: ThreadSafetyTIL.h:368
clang::threadSafety::til::SExpr::Opcode
const TIL_Opcode Opcode
Definition: ThreadSafetyTIL.h:324
clang::threadSafety::til::IfThenElse::IfThenElse
IfThenElse(const IfThenElse &I, SExpr *C, SExpr *T, SExpr *E)
Definition: ThreadSafetyTIL.h:1817
clang::threadSafety::til::BasicBlock::TopologyNode::isParentOfOrEqual
bool isParentOfOrEqual(const TopologyNode &OtherNode)
Definition: ThreadSafetyTIL.h:1527
clang::threadSafety::til::Variable::definition
const SExpr * definition() const
Definition: ThreadSafetyTIL.h:399
clang::threadSafety::til::BasicBlock::PostDominates
bool PostDominates(const BasicBlock &Other)
Definition: ThreadSafetyTIL.h:1579
clang::threadSafety::til::Wildcard::classof
static bool classof(const SExpr *E)
Definition: ThreadSafetyTIL.h:514
clang::threadSafety::til::SCFG::cbegin
const_iterator cbegin() const
Definition: ThreadSafetyTIL.h:1727
clang::threadSafety::til::Apply::arg
const SExpr * arg() const
Definition: ThreadSafetyTIL.h:852
clang::threadSafety::til::BasicBlock::successors
ArrayRef< BasicBlock * > successors() const
Definition: ThreadSafetyTIL.h:1568
clang::threadSafety::til::Goto::classof
static bool classof(const SExpr *E)
Definition: ThreadSafetyTIL.h:1377
getName
static std::string getName(const CallEvent &Call)
Definition: ReturnValueChecker.cpp:61
clang::threadSafety::til::Code::traverse
V::R_SExpr traverse(V &Vs, typename V::R_Ctx Ctx)
Definition: ThreadSafetyTIL.h:781
clang::threadSafety::til::Phi::compare
C::CType compare(const Phi *E, C &Cmp) const
Definition: ThreadSafetyTIL.h:1336
clang::threadSafety::til::Store::compare
C::CType compare(const Store *E, C &Cmp) const
Definition: ThreadSafetyTIL.h:1080
clang::threadSafety::til::SApply::classof
static bool classof(const SExpr *E)
Definition: ThreadSafetyTIL.h:881
clang::threadSafety::til::BinaryOp::expr1
const SExpr * expr1() const
Definition: ThreadSafetyTIL.h:1227
clang::threadSafety::til::SExpr::Flags
unsigned short Flags
Definition: ThreadSafetyTIL.h:326
clang::threadSafety::til::UnaryOp::UnaryOp
UnaryOp(TIL_UnaryOpcode Op, SExpr *E)
Definition: ThreadSafetyTIL.h:1169
clang::threadSafety::til::IfThenElse::elseExpr
const SExpr * elseExpr() const
Definition: ThreadSafetyTIL.h:1829
clang::threadSafety::til::Literal::clangExpr
const Expr * clangExpr() const
Definition: ThreadSafetyTIL.h:539
clang::threadSafety::til::Variable::traverse
V::R_SExpr traverse(V &Vs, typename V::R_Ctx Ctx)
Definition: ThreadSafetyTIL.h:407
clang::threadSafety::til::Literal::valueType
ValueType valueType() const
Definition: ThreadSafetyTIL.h:541
clang::threadSafety::til::simplifyToCanonicalVal
SExpr * simplifyToCanonicalVal(SExpr *E)
Definition: ThreadSafetyTIL.cpp:104
clang::threadSafety::til::Goto::successors
ArrayRef< BasicBlock * > successors()
Return the list of basic blocks that this terminator can branch to.
Definition: ThreadSafetyTIL.h:1386
clang::threadSafety::til::Branch::Branch
Branch(SExpr *C, BasicBlock *T, BasicBlock *E)
Definition: ThreadSafetyTIL.h:1410
clang::threadSafety::til::ValueType::BT_ValueRef
@ BT_ValueRef
Definition: ThreadSafetyTIL.h:161
clang::threadSafety::til::ArrayIndex
If p is a reference to an array, then p[i] is a reference to the i'th element of the array.
Definition: ThreadSafetyTIL.h:1094
clang::threadSafety::til::SApply::arg
const SExpr * arg() const
Definition: ThreadSafetyTIL.h:887
clang::threadSafety::til::BasicBlock::numSuccessors
size_t numSuccessors() const
Definition: ThreadSafetyTIL.h:1547
clang::threadSafety::til::IfThenElse::thenExpr
const SExpr * thenExpr() const
Definition: ThreadSafetyTIL.h:1826
clang::threadSafety::til::Store::destination
SExpr * destination()
Definition: ThreadSafetyTIL.h:1066
clang::threadSafety::til::Literal
Definition: ThreadSafetyTIL.h:529
clang::threadSafety::til::COP_Max
const TIL_Opcode COP_Max
Definition: ThreadSafetyTIL.h:133
clang::threadSafety::til::Load::pointer
SExpr * pointer()
Definition: ThreadSafetyTIL.h:1039
clang::threadSafety::til::BasicBlock::TopologyNode::TopologyNode
TopologyNode()=default
clang::threadSafety::til::SimpleArray< SExpr * >
clang::threadSafety::til::Project::slotName
StringRef slotName() const
Definition: ThreadSafetyTIL.h:934
clang::threadSafety::til::UnaryOp::traverse
V::R_SExpr traverse(V &Vs, typename V::R_Ctx Ctx)
Definition: ThreadSafetyTIL.h:1185
clang::threadSafety::til::SApply
Apply a self-argument to a self-applicable function.
Definition: ThreadSafetyTIL.h:875
clang::threadSafety::til::Apply::compare
C::CType compare(const Apply *E, C &Cmp) const
Definition: ThreadSafetyTIL.h:862
clang::threadSafety::til::TIL_CastOpcode
TIL_CastOpcode
Opcode for cast operations.
Definition: ThreadSafetyTIL.h:113
clang::threadSafety::til::Project::classof
static bool classof(const SExpr *E)
Definition: ThreadSafetyTIL.h:920
clang::threadSafety::til::ArrayAdd::index
const SExpr * index() const
Definition: ThreadSafetyTIL.h:1143
clang::threadSafety::til::Variable::Variable
Variable(SExpr *D, const ValueDecl *Cvd=nullptr)
Definition: ThreadSafetyTIL.h:373
clang::threadSafety::til::Cast::Cast
Cast(const Cast &C, SExpr *E)
Definition: ThreadSafetyTIL.h:1259
clang::threadSafety::til::ValueType::Base
BaseType Base
Definition: ThreadSafetyTIL.h:182
clang::threadSafety::til::Terminator::successors
ArrayRef< BasicBlock * > successors() const
Definition: ThreadSafetyTIL.h:1360
P
StringRef P
Definition: ASTMatchersInternal.cpp:563
clang::threadSafety::til::Phi::Phi
Phi(MemRegionRef A, unsigned Nvals)
Definition: ThreadSafetyTIL.h:1308
clang::threadSafety::til::Apply::Apply
Apply(SExpr *F, SExpr *A)
Definition: ThreadSafetyTIL.h:842
clang::threadSafety::til::BasicBlock::Dominates
bool Dominates(const BasicBlock &Other)
Definition: ThreadSafetyTIL.h:1575
clang::threadSafety::til::LiteralPtr::compare
C::CType compare(const LiteralPtr *E, C &Cmp) const
Definition: ThreadSafetyTIL.h:652
clang::threadSafety::til::Undefined::traverse
V::R_SExpr traverse(V &Vs, typename V::R_Ctx Ctx)
Definition: ThreadSafetyTIL.h:495
clang::threadSafety::til::SFunction::variableDecl
Variable * variableDecl()
Definition: ThreadSafetyTIL.h:734
clang::threadSafety::til::ValueType::BT_Int
@ BT_Int
Definition: ThreadSafetyTIL.h:157
clang::threadSafety::til::SimpleArray< BasicBlock * >::iterator
BasicBlock * * iterator
Definition: ThreadSafetyUtil.h:130
clang::threadSafety::til::Return::classof
static bool classof(const SExpr *E)
Definition: ThreadSafetyTIL.h:1464
clang::threadSafety::til::UOP_Minus
@ UOP_Minus
Definition: ThreadSafetyTIL.h:86
false
#define false
Definition: stdbool.h:22
clang::threadSafety::til::Function::variableDecl
Variable * variableDecl()
Definition: ThreadSafetyTIL.h:679
clang::threadSafety::til::Variable::name
StringRef name() const
Return the name of the variable, if any.
Definition: ThreadSafetyTIL.h:390
clang::threadSafety::til::Call::classof
static bool classof(const SExpr *E)
Definition: ThreadSafetyTIL.h:972
clang::threadSafety::til::BasicBlock::numPredecessors
size_t numPredecessors() const
Returns the number of predecessors.
Definition: ThreadSafetyTIL.h:1546
clang::threadSafety::til::BasicBlock::terminator
Terminator * terminator()
Definition: ThreadSafetyTIL.h:1571
clang::ValueDecl
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:701
clang::threadSafety::til::Store::Store
Store(const Store &S, SExpr *P, SExpr *V)
Definition: ThreadSafetyTIL.h:1062
clang::threadSafety::til::ValueType::getValueType
static ValueType getValueType()
clang::threadSafety::til::Branch::condition
const SExpr * condition() const
Definition: ThreadSafetyTIL.h:1424
clang::threadSafety::til::Code::body
const SExpr * body() const
Definition: ThreadSafetyTIL.h:778
clang::threadSafety::til::BinaryOp
Simple arithmetic binary operations, e.g.
Definition: ThreadSafetyTIL.h:1205
clang::threadSafety::til::SCFG::classof
static bool classof(const SExpr *E)
Definition: ThreadSafetyTIL.h:1711
clang::threadSafety::til::UnaryOp::compare
C::CType compare(const UnaryOp *E, C &Cmp) const
Definition: ThreadSafetyTIL.h:1191
clang::threadSafety::til::Code::Code
Code(const Code &C, SExpr *T, SExpr *B)
Definition: ThreadSafetyTIL.h:769
clang::threadSafety::til::Let::Let
Let(const Let &L, Variable *Vd, SExpr *Bd)
Definition: ThreadSafetyTIL.h:1864
clang::threadSafety::til::Terminator::classof
static bool classof(const SExpr *E)
Definition: ThreadSafetyTIL.h:1353
clang::DeclarationName::isIdentifier
bool isIdentifier() const
Predicate functions for querying what type of name this is.
Definition: DeclarationName.h:384
clang::threadSafety::til::ArrayAdd
Pointer arithmetic, restricted to arrays only.
Definition: ThreadSafetyTIL.h:1131
clang::threadSafety::til::Return::successors
ArrayRef< BasicBlock * > successors()
Return an empty list.
Definition: ThreadSafetyTIL.h:1467
clang::threadSafety::til::Call::target
const SExpr * target() const
Definition: ThreadSafetyTIL.h:975
llvm::ArrayRef
Definition: LLVM.h:34
clang::threadSafety::til::BasicBlock::TopologyNode::NodeID
int NodeID
Definition: ThreadSafetyTIL.h:1512
clang::threadSafety::til::Return::Return
Return(SExpr *Rval)
Definition: ThreadSafetyTIL.h:1461
clang::threadSafety::til::BOP_Add
@ BOP_Add
Definition: ThreadSafetyTIL.h:93
clang::threadSafety::til::ArrayIndex::ArrayIndex
ArrayIndex(SExpr *A, SExpr *N)
Definition: ThreadSafetyTIL.h:1096
clang::threadSafety::til::IfThenElse::thenExpr
SExpr * thenExpr()
Definition: ThreadSafetyTIL.h:1825
clang::threadSafety::til::Phi::status
Status status() const
Definition: ThreadSafetyTIL.h:1316
clang::threadSafety::til::Goto::compare
C::CType compare(const Goto *E, C &Cmp) const
Definition: ThreadSafetyTIL.h:1395
clang::threadSafety::til::ArrayIndex::traverse
V::R_SExpr traverse(V &Vs, typename V::R_Ctx Ctx)
Definition: ThreadSafetyTIL.h:1109
clang::threadSafety::til::ValueType
ValueTypes are data types that can actually be held in registers.
Definition: ThreadSafetyTIL.h:153
LLVM.h
clang::threadSafety::til::ValueType::getSizeType
static SizeType getSizeType(unsigned nbytes)
Definition: ThreadSafetyTIL.h:190
clang::threadSafety::til::Let::traverse
V::R_SExpr traverse(V &Vs, typename V::R_Ctx Ctx)
Definition: ThreadSafetyTIL.h:1877
clang::threadSafety::til::ValueType::ST_1
@ ST_1
Definition: ThreadSafetyTIL.h:166
clang::threadSafety::til::Function::body
const SExpr * body() const
Definition: ThreadSafetyTIL.h:683
clang::threadSafety::til::SApply::isDelegation
bool isDelegation() const
Definition: ThreadSafetyTIL.h:889
clang::threadSafety::til::Identifier::traverse
V::R_SExpr traverse(V &Vs, typename V::R_Ctx Ctx)
Definition: ThreadSafetyTIL.h:1798
clang::threadSafety::til::Variable
A named variable, e.g.
Definition: ThreadSafetyTIL.h:355
clang::threadSafety::til::Function::Function
Function(Variable *Vd, SExpr *Bd)
Definition: ThreadSafetyTIL.h:667
clang::threadSafety::til::BasicBlock::compare
C::CType compare(const BasicBlock *E, C &Cmp) const
Definition: ThreadSafetyTIL.h:1639
clang::threadSafety::til::Field::classof
static bool classof(const SExpr *E)
Definition: ThreadSafetyTIL.h:807
clang::threadSafety::til::Load::traverse
V::R_SExpr traverse(V &Vs, typename V::R_Ctx Ctx)
Definition: ThreadSafetyTIL.h:1043
clang::threadSafety::til::Goto::index
unsigned index() const
Returns the index into the.
Definition: ThreadSafetyTIL.h:1383
clang::threadSafety::til::Wildcard::compare
C::CType compare(const Wildcard *E, C &Cmp) const
Definition: ThreadSafetyTIL.h:521
clang::threadSafety::til::Field::compare
C::CType compare(const Field *E, C &Cmp) const
Definition: ThreadSafetyTIL.h:823
clang::threadSafety::til::BasicBlock::TopologyNode::isParentOf
bool isParentOf(const TopologyNode &OtherNode)
Definition: ThreadSafetyTIL.h:1522
clang::threadSafety::til::Terminator::successors
ArrayRef< BasicBlock * > successors()
Return the list of basic blocks that this terminator can branch to.
Definition: ThreadSafetyTIL.h:1487
clang::threadSafety::til::BasicBlock::BasicBlock
BasicBlock(BasicBlock &B, MemRegionRef A, InstrArray &&As, InstrArray &&Is, Terminator *T)
Definition: ThreadSafetyTIL.h:1535
clang::threadSafety::til::Phi::PH_SingleVal
@ PH_SingleVal
Definition: ThreadSafetyTIL.h:1303
clang::threadSafety::til::BasicBlock::cfg
SCFG * cfg()
Definition: ThreadSafetyTIL.h:1550
clang::threadSafety::til::Call::traverse
V::R_SExpr traverse(V &Vs, typename V::R_Ctx Ctx)
Definition: ThreadSafetyTIL.h:980
clang::ast_matchers::GtestCmp::Ne
@ Ne
clang::threadSafety::til::Field::range
SExpr * range()
Definition: ThreadSafetyTIL.h:809
clang::threadSafety::til::Undefined::Undefined
Undefined(const Stmt *S=nullptr)
Definition: ThreadSafetyTIL.h:489
clang::threadSafety::til::Variable::setDefinition
void setDefinition(SExpr *E)
Definition: ThreadSafetyTIL.h:403
clang::threadSafety::til::Variable::setClangDecl
void setClangDecl(const ValueDecl *VD)
Definition: ThreadSafetyTIL.h:404
clang::threadSafety::til::Return::returnValue
const SExpr * returnValue() const
Definition: ThreadSafetyTIL.h:1470
clang::threadSafety::til::Load::pointer
const SExpr * pointer() const
Definition: ThreadSafetyTIL.h:1040
clang::threadSafety::til::SCFG::compare
C::CType compare(const SCFG *E, C &Cmp) const
Definition: ThreadSafetyTIL.h:1769
clang::threadSafety::til::CAST_objToPtr
@ CAST_objToPtr
Definition: ThreadSafetyTIL.h:129
clang::threadSafety::til::Variable::compare
C::CType compare(const Variable *E, C &Cmp) const
Definition: ThreadSafetyTIL.h:413
clang::threadSafety::til::Variable::classof
static bool classof(const SExpr *E)
Definition: ThreadSafetyTIL.h:384
clang::threadSafety::til::ValueType::ST_16
@ ST_16
Definition: ThreadSafetyTIL.h:168
clang::threadSafety::til::SCFG::cend
const_iterator cend() const
Definition: ThreadSafetyTIL.h:1728
clang::threadSafety::til::ArrayAdd::index
SExpr * index()
Definition: ThreadSafetyTIL.h:1142
clang::threadSafety::til::BasicBlock::TopologyNode::Parent
BasicBlock * Parent
Definition: ThreadSafetyTIL.h:1518
clang::threadSafety::til::Project::Project
Project(SExpr *R, const ValueDecl *Cvd)
Definition: ThreadSafetyTIL.h:915
clang::threadSafety::til::Variable::VK_SFun
@ VK_SFun
SFunction (self) parameter.
Definition: ThreadSafetyTIL.h:365
clang::threadSafety::til::Call::compare
C::CType compare(const Call *E, C &Cmp) const
Definition: ThreadSafetyTIL.h:986
clang::threadSafety::til::SCFG::end
iterator end()
Definition: ThreadSafetyTIL.h:1722
clang::threadSafety::til::ArrayAdd::array
SExpr * array()
Definition: ThreadSafetyTIL.h:1139
clang::threadSafety::til::Goto::Goto
Goto(const Goto &G, BasicBlock *B, unsigned I)
Definition: ThreadSafetyTIL.h:1374
clang::threadSafety::til::LiteralT::value
T value() const
Definition: ThreadSafetyTIL.h:570
clang::threadSafety::til::IfThenElse::classof
static bool classof(const SExpr *E)
Definition: ThreadSafetyTIL.h:1820
clang::threadSafety::til::ValueType::ST_32
@ ST_32
Definition: ThreadSafetyTIL.h:169
std
Definition: Format.h:4477
clang::threadSafety::til::Literal::classof
static bool classof(const SExpr *E)
Definition: ThreadSafetyTIL.h:536
clang::threadSafety::til::Literal::Literal
Literal(const Expr *C)
Definition: ThreadSafetyTIL.h:531
clang::threadSafety::til::MemRegionRef
Definition: ThreadSafetyUtil.h:38
clang::threadSafety::til::Code::classof
static bool classof(const SExpr *E)
Definition: ThreadSafetyTIL.h:772
clang::threadSafety::til::Variable::VK_Fun
@ VK_Fun
Function parameter.
Definition: ThreadSafetyTIL.h:362
clang::threadSafety::til::SFunction::SFunction
SFunction(Variable *Vd, SExpr *B)
Definition: ThreadSafetyTIL.h:718
clang::threadSafety::til::Future::classof
static bool classof(const SExpr *E)
Definition: ThreadSafetyTIL.h:446
clang::threadSafety::til::Terminator::Terminator
Terminator(TIL_Opcode Op)
Definition: ThreadSafetyTIL.h:1349
clang::Builtin::ID
ID
Definition: Builtins.h:52
clang::threadSafety::til::BasicBlock
A basic block is part of an SCFG.
Definition: ThreadSafetyTIL.h:1502
clang::threadSafety::til::SApply::arg
SExpr * arg()
Definition: ThreadSafetyTIL.h:886
clang
Definition: CalledOnceCheck.h:17
clang::threadSafety::til::simplifyIncompleteArg
void simplifyIncompleteArg(til::Phi *Ph)
Definition: ThreadSafetyTIL.cpp:133
clang::threadSafety::til::BOP_Min
const TIL_BinaryOpcode BOP_Min
Definition: ThreadSafetyTIL.h:136
clang::threadSafety::til::Store::source
const SExpr * source() const
Definition: ThreadSafetyTIL.h:1070
clang::threadSafety::til::ValueType::SizeType
SizeType
Definition: ThreadSafetyTIL.h:164
clang::threadSafety::til::BOP_Lt
@ BOP_Lt
Definition: ThreadSafetyTIL.h:105
distance
float __ovld __cnfn distance(float, float)
Returns the distance between p0 and p1.
clang::threadSafety::til::Function
A function – a.k.a.
Definition: ThreadSafetyTIL.h:665
clang::Stmt
Stmt - This represents one statement.
Definition: Stmt.h:71
clang::threadSafety::til::getUnaryOpcodeString
StringRef getUnaryOpcodeString(TIL_UnaryOpcode Op)
Return the name of a unary opcode.
Definition: ThreadSafetyTIL.cpp:19
clang::threadSafety::til::ValueType::ST_0
@ ST_0
Definition: ThreadSafetyTIL.h:165
clang::threadSafety::til::Let::compare
C::CType compare(const Let *E, C &Cmp) const
Definition: ThreadSafetyTIL.h:1888
clang::threadSafety::til::LiteralT::value
T & value()
Definition: ThreadSafetyTIL.h:571
clang::threadSafety::til::BasicBlock::reserveArguments
void reserveArguments(unsigned Nargs)
Definition: ThreadSafetyTIL.h:1600
clang::threadSafety::til::TIL_Opcode
TIL_Opcode
Enum for the different distinct classes of SExpr.
Definition: ThreadSafetyTIL.h:78
clang::threadSafety::til::Cast::compare
C::CType compare(const Cast *E, C &Cmp) const
Definition: ThreadSafetyTIL.h:1277
clang::threadSafety::til::SExpr::SExpr
SExpr(const SExpr &E)
Definition: ThreadSafetyTIL.h:322
clang::threadSafety::til::BinaryOp::expr0
const SExpr * expr0() const
Definition: ThreadSafetyTIL.h:1224
clang::threadSafety::til::Alloc::dataType
SExpr * dataType()
Definition: ThreadSafetyTIL.h:1010
clang::threadSafety::til::BasicBlock::cfg
const SCFG * cfg() const
Definition: ThreadSafetyTIL.h:1549
clang::threadSafety::til::Future::traverse
V::R_SExpr traverse(V &Vs, typename V::R_Ctx Ctx)
Definition: ThreadSafetyTIL.h:467
clang::threadSafety::til::SCFG::numInstructions
unsigned numInstructions()
Return the total number of instructions in the CFG.
Definition: ThreadSafetyTIL.h:1742
clang::threadSafety::til::UnaryOp::classof
static bool classof(const SExpr *E)
Definition: ThreadSafetyTIL.h:1175
clang::threadSafety::til::Alloc::AK_Stack
@ AK_Stack
Definition: ThreadSafetyTIL.h:999
clang::threadSafety::til::ValueType::ST_64
@ ST_64
Definition: ThreadSafetyTIL.h:170
clang::threadSafety::til::Call::Call
Call(const Call &C, SExpr *T)
Definition: ThreadSafetyTIL.h:970
clang::threadSafety::til::Goto::targetBlock
const BasicBlock * targetBlock() const
Definition: ThreadSafetyTIL.h:1379
clang::threadSafety::til::SCFG::entry
BasicBlock * entry()
Definition: ThreadSafetyTIL.h:1731
clang::threadSafety::til::COP_Min
const TIL_Opcode COP_Min
Definition: ThreadSafetyTIL.h:132
clang::threadSafety::til::Let::variableDecl
Variable * variableDecl()
Definition: ThreadSafetyTIL.h:1870
clang::NamedDecl::getDeclName
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Definition: Decl.h:313
s
__device__ __2f16 float bool s
Definition: __clang_hip_libdevice_declares.h:320
clang::threadSafety::til::ArrayAdd::traverse
V::R_SExpr traverse(V &Vs, typename V::R_Ctx Ctx)
Definition: ThreadSafetyTIL.h:1146
clang::threadSafety::til::SFunction::traverse
V::R_SExpr traverse(V &Vs, typename V::R_Ctx Ctx)
Definition: ThreadSafetyTIL.h:741
clang::threadSafety::til::Store
Store a value to memory.
Definition: ThreadSafetyTIL.h:1059
clang::threadSafety::til::ValueType::ST_8
@ ST_8
Definition: ThreadSafetyTIL.h:167
clang::threadSafety::til::Store::classof
static bool classof(const SExpr *E)
Definition: ThreadSafetyTIL.h:1064
clang::threadSafety::til::SExpr::id
unsigned id() const
Returns the instruction ID for this expression.
Definition: ThreadSafetyTIL.h:311
clang::threadSafety::til::IfThenElse::condition
const SExpr * condition() const
Definition: ThreadSafetyTIL.h:1823
clang::threadSafety::til::SCFG::entry
const BasicBlock * entry() const
Definition: ThreadSafetyTIL.h:1730
clang::threadSafety::til::SFunction::body
SExpr * body()
Definition: ThreadSafetyTIL.h:737
clang::VarDecl::Definition
@ Definition
This declaration is definitely a definition.
Definition: Decl.h:1248
clang::threadSafety::til::BOP_Mul
@ BOP_Mul
Definition: ThreadSafetyTIL.h:95
clang::NamedDecl::printName
virtual void printName(raw_ostream &OS, const PrintingPolicy &Policy) const
Pretty-print the unqualified name of this declaration.
Definition: Decl.cpp:1618
clang::threadSafety::til::Return::traverse
V::R_SExpr traverse(V &Vs, typename V::R_Ctx Ctx)
Definition: ThreadSafetyTIL.h:1473
clang::threadSafety::til::ArrayIndex::classof
static bool classof(const SExpr *E)
Definition: ThreadSafetyTIL.h:1100
clang::threadSafety::til::BasicBlock::addPredecessor
unsigned addPredecessor(BasicBlock *Pred)
Definition: ThreadSafetyTIL.cpp:58
clang::threadSafety::til::Field::body
SExpr * body()
Definition: ThreadSafetyTIL.h:812
clang::threadSafety::til::ArrayAdd::classof
static bool classof(const SExpr *E)
Definition: ThreadSafetyTIL.h:1137
clang::threadSafety::til::ValueType::VectSize
unsigned char VectSize
Definition: ThreadSafetyTIL.h:187
clang::threadSafety::til::BasicBlock::predecessors
const BlockArray & predecessors() const
Definition: ThreadSafetyTIL.h:1565
clang::threadSafety::til::Return
Return from the enclosing function, passing the return value to the caller.
Definition: ThreadSafetyTIL.h:1459
clang::threadSafety::til::Terminator
Base class for basic block terminators: Branch, Goto, and Return.
Definition: ThreadSafetyTIL.h:1347
clang::threadSafety::til::Alloc::AllocKind
AllocKind
Definition: ThreadSafetyTIL.h:998
clang::threadSafety::til::SCFG::end
const_iterator end() const
Definition: ThreadSafetyTIL.h:1725
clang::threadSafety::til::SCFG::exit
const BasicBlock * exit() const
Definition: ThreadSafetyTIL.h:1732
clang::threadSafety::til::Load::Load
Load(const Load &L, SExpr *P)
Definition: ThreadSafetyTIL.h:1035
clang::threadSafety::til::Cast::classof
static bool classof(const SExpr *E)
Definition: ThreadSafetyTIL.h:1261
clang::threadSafety::til::Field::traverse
V::R_SExpr traverse(V &Vs, typename V::R_Ctx Ctx)
Definition: ThreadSafetyTIL.h:816
clang::threadSafety::til::ArrayIndex::ArrayIndex
ArrayIndex(const ArrayIndex &E, SExpr *A, SExpr *N)
Definition: ThreadSafetyTIL.h:1097
clang::threadSafety::til::Alloc::compare
C::CType compare(const Alloc *E, C &Cmp) const
Definition: ThreadSafetyTIL.h:1020
clang::threadSafety::til::BinaryOp::binaryOpcode
TIL_BinaryOpcode binaryOpcode() const
Definition: ThreadSafetyTIL.h:1219
clang::threadSafety::til::ArrayAdd::ArrayAdd
ArrayAdd(const ArrayAdd &E, SExpr *A, SExpr *N)
Definition: ThreadSafetyTIL.h:1134
clang::threadSafety::til::BOP_LogicAnd
@ BOP_LogicAnd
Definition: ThreadSafetyTIL.h:108
clang::threadSafety::til::BasicBlock::successors
ArrayRef< BasicBlock * > successors()
Definition: ThreadSafetyTIL.h:1567
clang::threadSafety::til::SimpleArray::size
size_t size() const
Definition: ThreadSafetyUtil.h:135
clang::threadSafety::til::SExpr::Block
BasicBlock * Block
Definition: ThreadSafetyTIL.h:328
clang::Expr
This represents one expression.
Definition: Expr.h:109
clang::threadSafety::til::BasicBlock::traverse
V::R_BasicBlock traverse(V &Vs, typename V::R_Ctx Ctx)
Definition: ThreadSafetyTIL.h:1615
clang::threadSafety::til::Store::Store
Store(SExpr *P, SExpr *V)
Definition: ThreadSafetyTIL.h:1061
clang::threadSafety::til::SCFG::normal
bool normal() const
Return true if this CFG has been normalized.
Definition: ThreadSafetyTIL.h:1719
clang::threadSafety::til::SFunction::body
const SExpr * body() const
Definition: ThreadSafetyTIL.h:738
clang::threadSafety::til::SCFG
An SCFG is a control-flow graph.
Definition: ThreadSafetyTIL.h:1689
clang::threadSafety::til::Identifier::Identifier
Identifier(StringRef Id)
Definition: ThreadSafetyTIL.h:1790
clang::threadSafety::til::Literal::as
const LiteralT< T > & as() const
Definition: ThreadSafetyTIL.h:543
clang::threadSafety::til::Phi::classof
static bool classof(const SExpr *E)
Definition: ThreadSafetyTIL.h:1311
clang::threadSafety::til::getCanonicalVal
const SExpr * getCanonicalVal(const SExpr *E)
Definition: ThreadSafetyTIL.cpp:82
clang::threadSafety::til::SFunction
A self-applicable function.
Definition: ThreadSafetyTIL.h:716
clang::threadSafety::til::Load::classof
static bool classof(const SExpr *E)
Definition: ThreadSafetyTIL.h:1037
clang::threadSafety::til::CAST_extendNum
@ CAST_extendNum
Definition: ThreadSafetyTIL.h:117
clang::threadSafety::til::ValueType::ValueType
ValueType(BaseType B, SizeType Sz, bool S, unsigned char VS)
Definition: ThreadSafetyTIL.h:174
clang::threadSafety::til::Identifier::name
StringRef name() const
Definition: ThreadSafetyTIL.h:1795
clang::threadSafety::til::BinaryOp::BinaryOp
BinaryOp(TIL_BinaryOpcode Op, SExpr *E0, SExpr *E1)
Definition: ThreadSafetyTIL.h:1207
clang::threadSafety::til::SFunction::classof
static bool classof(const SExpr *E)
Definition: ThreadSafetyTIL.h:732
clang::threadSafety::til::SFunction::variableDecl
const Variable * variableDecl() const
Definition: ThreadSafetyTIL.h:735
clang::threadSafety::til::Function::body
SExpr * body()
Definition: ThreadSafetyTIL.h:682
clang::threadSafety::til::LiteralPtr
A Literal pointer to an object allocated in memory.
Definition: ThreadSafetyTIL.h:635
clang::threadSafety::til::Goto::targetBlock
BasicBlock * targetBlock()
Definition: ThreadSafetyTIL.h:1380
clang::threadSafety::til::Future::Future
Future()
Definition: ThreadSafetyTIL.h:443
clang::threadSafety::til::SFunction::compare
C::CType compare(const SFunction *E, C &Cmp) const
Definition: ThreadSafetyTIL.h:753
clang::threadSafety::til::Function::classof
static bool classof(const SExpr *E)
Definition: ThreadSafetyTIL.h:677
clang::threadSafety::til::BinaryOp::expr1
SExpr * expr1()
Definition: ThreadSafetyTIL.h:1226
clang::threadSafety::til::IfThenElse::IfThenElse
IfThenElse(SExpr *C, SExpr *T, SExpr *E)
Definition: ThreadSafetyTIL.h:1815
clang::threadSafety::til::IfThenElse
An if-then-else expression.
Definition: ThreadSafetyTIL.h:1813
clang::CallExpr
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition: Expr.h:2810
clang::threadSafety::til::Future::FS_evaluating
@ FS_evaluating
Definition: ThreadSafetyTIL.h:439
clang::threadSafety::til::SExpr::setID
void setID(BasicBlock *B, unsigned id)
Set the basic block and instruction ID for this expression.
Definition: ThreadSafetyTIL.h:318
clang::threadSafety::til::BinaryOp::traverse
V::R_SExpr traverse(V &Vs, typename V::R_Ctx Ctx)
Definition: ThreadSafetyTIL.h:1230
clang::threadSafety::til::Phi::values
ValArray & values()
Definition: ThreadSafetyTIL.h:1314
clang::threadSafety::til::Future::result
SExpr * result()
Definition: ThreadSafetyTIL.h:455
clang::threadSafety::til::SCFG::SCFG
SCFG(const SCFG &Cfg, BlockArray &&Ba)
Definition: ThreadSafetyTIL.h:1706
clang::threadSafety::til::Call::clangCallExpr
const CallExpr * clangCallExpr() const
Definition: ThreadSafetyTIL.h:977
clang::threadSafety::til::LiteralPtr::classof
static bool classof(const SExpr *E)
Definition: ThreadSafetyTIL.h:640
clang::threadSafety::til::Project::record
SExpr * record()
Definition: ThreadSafetyTIL.h:922
clang::threadSafety::til::BasicBlock::BasicBlock
BasicBlock(MemRegionRef A)
Definition: ThreadSafetyTIL.h:1533
clang::threadSafety::til::Terminator::Terminator
Terminator(const SExpr &E)
Definition: ThreadSafetyTIL.h:1350
clang::threadSafety::til::ArrayIndex::compare
C::CType compare(const ArrayIndex *E, C &Cmp) const
Definition: ThreadSafetyTIL.h:1116
clang::threadSafety::til::SApply::sfun
const SExpr * sfun() const
Definition: ThreadSafetyTIL.h:884
clang::threadSafety::til::CAST_toInt
@ CAST_toInt
Definition: ThreadSafetyTIL.h:126
clang::threadSafety::til::Future::FS_done
@ FS_done
Definition: ThreadSafetyTIL.h:440
clang::threadSafety::til::Branch::compare
C::CType compare(const Branch *E, C &Cmp) const
Definition: ThreadSafetyTIL.h:1447
clang::threadSafety::til::Variable::setKind
void setKind(VariableKind K)
Definition: ThreadSafetyTIL.h:402
clang::threadSafety::til::Cast::expr
SExpr * expr()
Definition: ThreadSafetyTIL.h:1267
clang::threadSafety::til::SExpr
Base class for AST nodes in the typed intermediate language.
Definition: ThreadSafetyTIL.h:277
clang::threadSafety::til::SApply::compare
C::CType compare(const SApply *E, C &Cmp) const
Definition: ThreadSafetyTIL.h:900
clang::NamedDecl::getName
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition: Decl.h:274