Skip to content

Commit 623e067

Browse files
authored
Merge branch 'main' into cuf_drcp
2 parents 005c64b + db5f7dc commit 623e067

40 files changed

+639
-393
lines changed

clang/include/clang/CIR/MissingFeatures.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ struct MissingFeatures {
2727
// Address space related
2828
static bool addressSpace() { return false; }
2929

30-
// CIRGenFunction implementation details
31-
static bool cgfSymbolTable() { return false; }
32-
3330
// Unhandled global/linkage information.
3431
static bool opGlobalThreadLocal() { return false; }
3532
static bool opGlobalConstant() { return false; }

clang/lib/CIR/CodeGen/CIRGenExpr.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,12 @@ LValue CIRGenFunction::emitDeclRefLValue(const DeclRefExpr *e) {
591591
? emitLoadOfReferenceLValue(addr, getLoc(e->getSourceRange()),
592592
vd->getType(), AlignmentSource::Decl)
593593
: makeAddrLValue(addr, ty, AlignmentSource::Decl);
594+
595+
// Statics are defined as globals, so they are not include in the function's
596+
// symbol table.
597+
assert((vd->isStaticLocal() || symbolTable.count(vd)) &&
598+
"non-static locals should be already mapped");
599+
594600
return lv;
595601
}
596602

clang/lib/CIR/CodeGen/CIRGenFunction.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ void CIRGenFunction::declare(mlir::Value addrVal, const Decl *var, QualType ty,
215215
mlir::Location loc, CharUnits alignment,
216216
bool isParam) {
217217
assert(isa<NamedDecl>(var) && "Needs a named decl");
218-
assert(!cir::MissingFeatures::cgfSymbolTable());
218+
assert(!symbolTable.count(var) && "not supposed to be available just yet");
219219

220220
auto allocaOp = addrVal.getDefiningOp<cir::AllocaOp>();
221221
assert(allocaOp && "expected cir::AllocaOp");
@@ -224,6 +224,8 @@ void CIRGenFunction::declare(mlir::Value addrVal, const Decl *var, QualType ty,
224224
allocaOp.setInitAttr(mlir::UnitAttr::get(&getMLIRContext()));
225225
if (ty->isReferenceType() || ty.isConstQualified())
226226
allocaOp.setConstantAttr(mlir::UnitAttr::get(&getMLIRContext()));
227+
228+
symbolTable.insert(var, allocaOp);
227229
}
228230

229231
void CIRGenFunction::LexicalScope::cleanup() {
@@ -485,6 +487,9 @@ void CIRGenFunction::finishFunction(SourceLocation endLoc) {
485487
}
486488

487489
mlir::LogicalResult CIRGenFunction::emitFunctionBody(const clang::Stmt *body) {
490+
// We start with function level scope for variables.
491+
SymTableScopeTy varScope(symbolTable);
492+
488493
auto result = mlir::LogicalResult::success();
489494
if (const CompoundStmt *block = dyn_cast<CompoundStmt>(body))
490495
emitCompoundStmtWithoutScope(*block);
@@ -531,6 +536,8 @@ cir::FuncOp CIRGenFunction::generateCode(clang::GlobalDecl gd, cir::FuncOp fn,
531536
FunctionArgList args;
532537
QualType retTy = buildFunctionArgList(gd, args);
533538

539+
// Create a scope in the symbol table to hold variable declarations.
540+
SymTableScopeTy varScope(symbolTable);
534541
{
535542
LexicalScope lexScope(*this, fusedLoc, entryBB);
536543

clang/lib/CIR/CodeGen/CIRGenFunction.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "clang/CIR/Dialect/IR/CIRDialect.h"
3232
#include "clang/CIR/MissingFeatures.h"
3333
#include "clang/CIR/TypeEvaluationKind.h"
34+
#include "llvm/ADT/ScopedHashTable.h"
3435

3536
namespace {
3637
class ScalarExprEmitter;
@@ -103,6 +104,14 @@ class CIRGenFunction : public CIRGenTypeCache {
103104
/// Sanitizers enabled for this function.
104105
clang::SanitizerSet sanOpts;
105106

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+
106115
/// Whether or not a Microsoft-style asm block has been processed within
107116
/// this fuction. These can potentially set the return value.
108117
bool sawAsmBlock = false;
@@ -325,6 +334,9 @@ class CIRGenFunction : public CIRGenTypeCache {
325334
~SourceLocRAIIObject() { restore(); }
326335
};
327336

337+
using SymTableScopeTy =
338+
llvm::ScopedHashTableScope<const clang::Decl *, mlir::Value>;
339+
328340
/// Hold counters for incrementally naming temporaries
329341
unsigned counterRefTmp = 0;
330342
unsigned counterAggTmp = 0;
@@ -499,7 +511,11 @@ class CIRGenFunction : public CIRGenTypeCache {
499511
void setAddrOfLocalVar(const clang::VarDecl *vd, Address addr) {
500512
assert(!localDeclMap.count(vd) && "Decl already exists in LocalDeclMap!");
501513
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());
503519
}
504520

505521
bool shouldNullCheckClassCastValue(const CastExpr *ce);

clang/lib/CIR/CodeGen/CIRGenStmt.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ void CIRGenFunction::emitCompoundStmtWithoutScope(const CompoundStmt &s) {
3333
}
3434

3535
void CIRGenFunction::emitCompoundStmt(const CompoundStmt &s) {
36+
// Add local scope to track new declared variables.
37+
SymTableScopeTy varScope(symbolTable);
3638
mlir::Location scopeLoc = getLoc(s.getSourceRange());
3739
mlir::OpBuilder::InsertPoint scopeInsPt;
3840
builder.create<cir::ScopeOp>(

clang/test/Sema/attr-cfi-salt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 -fsyntax-only -fsanitize=kcfi -verify %s
1+
// RUN: %clang_cc1 -std=c11 -fsyntax-only -fsanitize=kcfi -verify %s
22
// RUN: %clang_cc1 -std=c89 -DKNR -fsyntax-only -fsanitize=kcfi -verify %s
33

44
#define __cfi_salt(S) __attribute__((cfi_salt(S)))

flang/module/cudadevice.f90

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -653,29 +653,29 @@ attributes(device) real(8) function sinpi(x) bind(c,name='__nv_sinpi')
653653
end function
654654
end interface
655655

656-
interface __double2ull_rn
657-
attributes(device) integer(8) function __double2ull_rn(r) bind(c)
656+
interface __double2ull_rd
657+
attributes(device) integer(8) function __double2ull_rd(r) bind(c, name='__nv_double2ull_rd')
658658
!dir$ ignore_tkr (d) r
659659
double precision, value :: r
660660
end function
661661
end interface
662662

663-
interface __double2ull_rz
664-
attributes(device) integer(8) function __double2ull_rz(r) bind(c)
663+
interface __double2ull_rn
664+
attributes(device) integer(8) function __double2ull_rn(r) bind(c, name='__nv_double2ull_rn')
665665
!dir$ ignore_tkr (d) r
666666
double precision, value :: r
667667
end function
668668
end interface
669669

670670
interface __double2ull_ru
671-
attributes(device) integer(8) function __double2ull_ru(r) bind(c)
671+
attributes(device) integer(8) function __double2ull_ru(r) bind(c, name='__nv_double2ull_ru')
672672
!dir$ ignore_tkr (d) r
673673
double precision, value :: r
674674
end function
675675
end interface
676676

677-
interface __double2ull_rd
678-
attributes(device) integer(8) function __double2ull_rd(r) bind(c)
677+
interface __double2ull_rz
678+
attributes(device) integer(8) function __double2ull_rz(r) bind(c, name='__nv_double2ull_rz')
679679
!dir$ ignore_tkr (d) r
680680
double precision, value :: r
681681
end function

flang/test/Lower/CUDA/cuda-libdevice.cuf

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ end subroutine
116116
! CHECK: %{{.*}} = fir.call @__nv_double2ll_ru(%{{.*}}) proc_attrs<bind_c> fastmath<contract> : (f64) -> i64
117117
! CHECK: %{{.*}} = fir.call @__nv_double2ll_rz(%{{.*}}) proc_attrs<bind_c> fastmath<contract> : (f64) -> i64
118118

119+
119120
attributes(global) subroutine test_drcp_rX()
120121
double precision :: res
121122
double precision :: r
@@ -130,3 +131,19 @@ end subroutine
130131
! CHECK: %{{.*}} = fir.call @__nv_drcp_rn(%{{.*}}) proc_attrs<bind_c> fastmath<contract> : (f64) -> f64
131132
! CHECK: %{{.*}} = fir.call @__nv_drcp_ru(%{{.*}}) proc_attrs<bind_c> fastmath<contract> : (f64) -> f64
132133
! CHECK: %{{.*}} = fir.call @__nv_drcp_rz(%{{.*}}) proc_attrs<bind_c> fastmath<contract> : (f64) -> f64
134+
135+
attributes(global) subroutine test_double2ull_rX()
136+
integer(8) :: res
137+
double precision :: r
138+
res = __double2ull_rd(r)
139+
res = __double2ull_rn(r)
140+
res = __double2ull_ru(r)
141+
res = __double2ull_rz(r)
142+
end subroutine
143+
144+
! CHECK-LABEL: _QPtest_double2ull_rx
145+
! CHECK: %{{.*}} = fir.call @__nv_double2ull_rd(%{{.*}}) proc_attrs<bind_c> fastmath<contract> : (f64) -> i64
146+
! CHECK: %{{.*}} = fir.call @__nv_double2ull_rn(%{{.*}}) proc_attrs<bind_c> fastmath<contract> : (f64) -> i64
147+
! CHECK: %{{.*}} = fir.call @__nv_double2ull_ru(%{{.*}}) proc_attrs<bind_c> fastmath<contract> : (f64) -> i64
148+
! CHECK: %{{.*}} = fir.call @__nv_double2ull_rz(%{{.*}}) proc_attrs<bind_c> fastmath<contract> : (f64) -> i64
149+

llvm/include/llvm/CGData/CodeGenData.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,9 @@ enum CGDataVersion {
285285
// Version 3 adds the total size of the Names in the stable function map so
286286
// we can skip reading them into the memory for non-assertion builds.
287287
Version3 = 3,
288+
// Version 4 adjusts the structure of stable function merging map for
289+
// efficient lazy loading support.
290+
Version4 = 4,
288291
CurrentVersion = CG_DATA_INDEX_VERSION
289292
};
290293
const uint64_t Version = CGDataVersion::CurrentVersion;

llvm/include/llvm/CGData/CodeGenData.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,4 @@ CG_DATA_SECT_ENTRY(CG_merge, CG_DATA_QUOTE(CG_DATA_MERGE_COMMON),
4949
#endif
5050

5151
/* Indexed codegen data format version (start from 1). */
52-
#define CG_DATA_INDEX_VERSION 3
52+
#define CG_DATA_INDEX_VERSION 4

0 commit comments

Comments
 (0)