|
31 | 31 | #include "clang/CIR/Dialect/IR/CIRDialect.h" |
32 | 32 | #include "clang/CIR/MissingFeatures.h" |
33 | 33 | #include "clang/CIR/TypeEvaluationKind.h" |
| 34 | +#include "llvm/ADT/ScopedHashTable.h" |
34 | 35 |
|
35 | 36 | namespace { |
36 | 37 | class ScalarExprEmitter; |
@@ -103,6 +104,14 @@ class CIRGenFunction : public CIRGenTypeCache { |
103 | 104 | /// Sanitizers enabled for this function. |
104 | 105 | clang::SanitizerSet sanOpts; |
105 | 106 |
|
| 107 | + /// The symbol table maps a variable name to a value in the current scope. |
| 108 | + /// Entering a function creates a new scope, and the function arguments are |
| 109 | + /// added to the mapping. When the processing of a function is terminated, |
| 110 | + /// the scope is destroyed and the mappings created in this scope are |
| 111 | + /// dropped. |
| 112 | + using SymTableTy = llvm::ScopedHashTable<const clang::Decl *, mlir::Value>; |
| 113 | + SymTableTy symbolTable; |
| 114 | + |
106 | 115 | /// Whether or not a Microsoft-style asm block has been processed within |
107 | 116 | /// this fuction. These can potentially set the return value. |
108 | 117 | bool sawAsmBlock = false; |
@@ -325,6 +334,9 @@ class CIRGenFunction : public CIRGenTypeCache { |
325 | 334 | ~SourceLocRAIIObject() { restore(); } |
326 | 335 | }; |
327 | 336 |
|
| 337 | + using SymTableScopeTy = |
| 338 | + llvm::ScopedHashTableScope<const clang::Decl *, mlir::Value>; |
| 339 | + |
328 | 340 | /// Hold counters for incrementally naming temporaries |
329 | 341 | unsigned counterRefTmp = 0; |
330 | 342 | unsigned counterAggTmp = 0; |
@@ -499,7 +511,11 @@ class CIRGenFunction : public CIRGenTypeCache { |
499 | 511 | void setAddrOfLocalVar(const clang::VarDecl *vd, Address addr) { |
500 | 512 | assert(!localDeclMap.count(vd) && "Decl already exists in LocalDeclMap!"); |
501 | 513 | localDeclMap.insert({vd, addr}); |
502 | | - // TODO: Add symbol table support |
| 514 | + |
| 515 | + // Add to the symbol table if not there already. |
| 516 | + if (symbolTable.count(vd)) |
| 517 | + return; |
| 518 | + symbolTable.insert(vd, addr.getPointer()); |
503 | 519 | } |
504 | 520 |
|
505 | 521 | bool shouldNullCheckClassCastValue(const CastExpr *ce); |
|
0 commit comments