Skip to content

Commit 8bfb688

Browse files
authored
Merge branch 'main' into nfc_cgi_getName
2 parents 5c367b7 + 556ff19 commit 8bfb688

File tree

124 files changed

+17033
-13228
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

124 files changed

+17033
-13228
lines changed

compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,15 @@ void NORETURN CheckFailed(const char *file, int, const char *cond, u64, u64) {
125125
} // namespace __sanitizer
126126
#endif
127127

128+
#define INTERFACE extern "C" __attribute__((visibility("default")))
129+
128130
#define HANDLER_RECOVER(name, kind) \
129-
SANITIZER_INTERFACE_WEAK_DEF(void, __ubsan_handle_##name##_minimal) { \
131+
INTERFACE void __ubsan_handle_##name##_minimal() { \
130132
__ubsan_report_error(kind, GET_CALLER_PC(), nullptr); \
131133
}
132134

133135
#define HANDLER_NORECOVER(name, kind) \
134-
SANITIZER_INTERFACE_WEAK_DEF(void, __ubsan_handle_##name##_minimal_abort) { \
136+
INTERFACE void __ubsan_handle_##name##_minimal_abort() { \
135137
uintptr_t caller = GET_CALLER_PC(); \
136138
__ubsan_report_error_fatal(kind, caller, nullptr); \
137139
abort_with_message(kind, caller, nullptr); \
@@ -142,14 +144,13 @@ void NORETURN CheckFailed(const char *file, int, const char *cond, u64, u64) {
142144
HANDLER_NORECOVER(name, kind)
143145

144146
#define HANDLER_RECOVER_PTR(name, kind) \
145-
SANITIZER_INTERFACE_WEAK_DEF(void, __ubsan_handle_##name##_minimal, \
146-
const uintptr_t address) { \
147+
INTERFACE void __ubsan_handle_##name##_minimal(const uintptr_t address) { \
147148
__ubsan_report_error(kind, GET_CALLER_PC(), &address); \
148149
}
149150

150151
#define HANDLER_NORECOVER_PTR(name, kind) \
151-
SANITIZER_INTERFACE_WEAK_DEF(void, __ubsan_handle_##name##_minimal_abort, \
152-
const uintptr_t address) { \
152+
INTERFACE void __ubsan_handle_##name##_minimal_abort( \
153+
const uintptr_t address) { \
153154
uintptr_t caller = GET_CALLER_PC(); \
154155
__ubsan_report_error_fatal(kind, caller, &address); \
155156
abort_with_message(kind, caller, &address); \

flang/include/flang/Lower/AbstractConverter.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,21 @@ class AbstractConverter {
108108
/// added or replaced at the inner-most level of the local symbol map.
109109
virtual void bindSymbol(SymbolRef sym, const fir::ExtendedValue &exval) = 0;
110110

111+
/// Binds the symbol's physical storage to a storage descriptor,
112+
/// which is the base address of the storage and the offset
113+
/// within the storage, where the symbol begins.
114+
/// The symbol binding will be added or replaced at the innermost level
115+
/// of the local symbol map.
116+
virtual void
117+
bindSymbolStorage(SymbolRef sym,
118+
Fortran::lower::SymMap::StorageDesc storage) = 0;
119+
120+
/// Returns the storage descriptor previously bound to this symbol.
121+
/// If there is no bound storage, the descriptor will contain
122+
/// nullptr base address.
123+
virtual Fortran::lower::SymMap::StorageDesc
124+
getSymbolStorage(SymbolRef sym) = 0;
125+
111126
/// Override lowering of expression with pre-lowered values.
112127
/// Associate mlir::Value to evaluate::Expr. All subsequent call to
113128
/// genExprXXX() will replace any occurrence of an overridden

flang/include/flang/Lower/ConvertVariable.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,14 @@ void defineCommonBlocks(
9292
/// The COMMON block is a global structure. \p commonValue is the base address
9393
/// of the COMMON block. As the offset from the symbol \p sym, generate the
9494
/// COMMON block member value (commonValue + offset) for the symbol.
95+
/// \p commonSize specifies the syze of the COMMON block in bytes.
96+
/// The size is used to represent a COMMON block reference as
97+
/// a !fir.ref<!fir.array<SIZExi8>>.
9598
mlir::Value genCommonBlockMember(AbstractConverter &converter,
9699
mlir::Location loc,
97100
const Fortran::semantics::Symbol &sym,
98-
mlir::Value commonValue);
101+
mlir::Value commonValue,
102+
std::size_t commonSize);
99103

100104
/// Lower a symbol attributes given an optional storage \p and add it to the
101105
/// provided symbol map. If \preAlloc is not provided, a temporary storage will

flang/include/flang/Lower/SymbolMap.h

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,22 @@ struct SymbolBox : public fir::details::matcher<SymbolBox> {
146146
class SymMap {
147147
public:
148148
using AcDoVar = llvm::StringRef;
149+
/// Descriptor of a symbol's storage consists of the base address
150+
/// of the storage and the offset within that storage.
151+
using StorageDesc = std::pair<mlir::Value, std::uint64_t>;
149152

150153
SymMap() { pushScope(); }
151154
SymMap(const SymMap &) = delete;
152155

153-
void pushScope() { symbolMapStack.emplace_back(); }
156+
void pushScope() {
157+
symbolMapStack.emplace_back();
158+
storageMapStack.emplace_back();
159+
}
154160
void popScope() {
155161
symbolMapStack.pop_back();
156162
assert(symbolMapStack.size() >= 1);
163+
storageMapStack.pop_back();
164+
assert(storageMapStack.size() >= 1);
157165
}
158166

159167
/// Add an extended value to the symbol table.
@@ -287,6 +295,8 @@ class SymMap {
287295
symbolMapStack.emplace_back();
288296
assert(symbolMapStack.size() == 1);
289297
impliedDoStack.clear();
298+
storageMapStack.clear();
299+
storageMapStack.emplace_back();
290300
}
291301

292302
friend llvm::raw_ostream &operator<<(llvm::raw_ostream &os,
@@ -315,6 +325,16 @@ class SymMap {
315325
return std::nullopt;
316326
}
317327

328+
/// Register the symbol's storage at the innermost level
329+
/// of the symbol table. If the storage is already registered,
330+
/// it will be replaced.
331+
void registerStorage(semantics::SymbolRef sym, StorageDesc storage);
332+
/// Lookup the symbol's storage at the innermost level of the symbol table.
333+
StorageDesc lookupStorage(semantics::SymbolRef sym);
334+
StorageDesc lookupStorage(const semantics::Symbol *sym) {
335+
return lookupStorage(*sym);
336+
}
337+
318338
private:
319339
/// Bind `box` to `symRef` in the symbol map.
320340
void makeSym(semantics::SymbolRef symRef, const SymbolBox &box,
@@ -332,6 +352,10 @@ class SymMap {
332352
// Implied DO induction variables are not represented as Se::Symbol in
333353
// Ev::Expr. Keep the variable markers in their own stack.
334354
llvm::SmallVector<std::pair<AcDoVar, mlir::Value>> impliedDoStack;
355+
356+
// A stack of maps between the symbols and their storage descriptors.
357+
llvm::SmallVector<llvm::DenseMap<const semantics::Symbol *, StorageDesc>>
358+
storageMapStack;
335359
};
336360

337361
/// RAII wrapper for SymMap.

flang/include/flang/Optimizer/Analysis/TBAAForest.h

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ struct TBAATree {
4646

4747
mlir::LLVM::TBAATypeDescriptorAttr getRoot() const { return parent; }
4848

49+
/// For the given name, get or create a subtree in the current
50+
/// subtree. For example, this is used for creating subtrees
51+
/// inside the "global data" subtree for the COMMON block variables
52+
/// belonging to the same COMMON block.
53+
SubtreeState &getOrCreateNamedSubtree(mlir::StringAttr name);
54+
4955
private:
5056
SubtreeState(mlir::MLIRContext *ctx, std::string name,
5157
mlir::LLVM::TBAANodeAttr grandParent)
@@ -57,6 +63,9 @@ struct TBAATree {
5763
const std::string parentId;
5864
mlir::MLIRContext *const context;
5965
mlir::LLVM::TBAATypeDescriptorAttr parent;
66+
// A map of named sub-trees, e.g. sub-trees of the COMMON blocks
67+
// placed under the "global data" root.
68+
llvm::DenseMap<mlir::StringAttr, SubtreeState> namedSubtrees;
6069
};
6170

6271
/// A subtree for POINTER/TARGET variables data.
@@ -131,22 +140,29 @@ class TBAAForrest {
131140
// responsibility to provide unique name for the scope.
132141
// If the scope string is empty, returns the TBAA tree for the
133142
// "root" scope of the given function.
134-
inline const TBAATree &getFuncTreeWithScope(mlir::func::FuncOp func,
135-
llvm::StringRef scope) {
143+
inline TBAATree &getMutableFuncTreeWithScope(mlir::func::FuncOp func,
144+
llvm::StringRef scope) {
136145
mlir::StringAttr name = func.getSymNameAttr();
137146
if (!scope.empty())
138147
name = mlir::StringAttr::get(name.getContext(),
139148
llvm::Twine(name) + " - " + scope);
140149
return getFuncTree(name);
141150
}
142151

152+
inline const TBAATree &getFuncTreeWithScope(mlir::func::FuncOp func,
153+
llvm::StringRef scope) {
154+
return getMutableFuncTreeWithScope(func, scope);
155+
}
156+
143157
private:
144-
const TBAATree &getFuncTree(mlir::StringAttr symName) {
158+
TBAATree &getFuncTree(mlir::StringAttr symName) {
145159
if (!separatePerFunction)
146160
symName = mlir::StringAttr::get(symName.getContext(), "");
147161
if (!trees.contains(symName))
148162
trees.insert({symName, TBAATree::buildTree(symName)});
149-
return trees.at(symName);
163+
auto it = trees.find(symName);
164+
assert(it != trees.end());
165+
return it->second;
150166
}
151167

152168
// Should each function use a different tree?

flang/include/flang/Optimizer/Builder/FIRBuilder.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,12 @@ class FirOpBuilder : public mlir::OpBuilder, public mlir::OpBuilder::Listener {
365365
// Linkage helpers (inline). The default linkage is external.
366366
//===--------------------------------------------------------------------===//
367367

368-
mlir::StringAttr createCommonLinkage() { return getStringAttr("common"); }
368+
static mlir::StringAttr createCommonLinkage(mlir::MLIRContext *context) {
369+
return mlir::StringAttr::get(context, "common");
370+
}
371+
mlir::StringAttr createCommonLinkage() {
372+
return createCommonLinkage(getContext());
373+
}
369374

370375
mlir::StringAttr createInternalLinkage() { return getStringAttr("internal"); }
371376

flang/include/flang/Optimizer/Builder/HLFIRTools.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,8 @@ fir::FortranVariableOpInterface
224224
genDeclare(mlir::Location loc, fir::FirOpBuilder &builder,
225225
const fir::ExtendedValue &exv, llvm::StringRef name,
226226
fir::FortranVariableFlagsAttr flags,
227-
mlir::Value dummyScope = nullptr,
227+
mlir::Value dummyScope = nullptr, mlir::Value storage = nullptr,
228+
std::uint64_t storageOffset = 0,
228229
cuf::DataAttributeAttr dataAttr = {});
229230

230231
/// Generate an hlfir.associate to build a variable from an expression value.

flang/include/flang/Optimizer/Dialect/FIRType.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,7 @@ std::optional<std::pair<uint64_t, unsigned short>>
551551
getTypeSizeAndAlignment(mlir::Location loc, mlir::Type ty,
552552
const mlir::DataLayout &dl,
553553
const fir::KindMapping &kindMap);
554+
554555
} // namespace fir
555556

556557
#endif // FORTRAN_OPTIMIZER_DIALECT_FIRTYPE_H

flang/include/flang/Optimizer/HLFIR/HLFIROps.td

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,12 @@ def hlfir_DeclareOp
109109
attr-dict `:` functional-type(operands, results)
110110
}];
111111

112-
let builders = [
113-
OpBuilder<(ins "mlir::Value":$memref, "llvm::StringRef":$uniq_name,
114-
CArg<"mlir::Value", "{}">:$shape, CArg<"mlir::ValueRange", "{}">:$typeparams,
112+
let builders = [OpBuilder<(ins "mlir::Value":$memref,
113+
"llvm::StringRef":$uniq_name, CArg<"mlir::Value", "{}">:$shape,
114+
CArg<"mlir::ValueRange", "{}">:$typeparams,
115115
CArg<"mlir::Value", "{}">:$dummy_scope,
116+
CArg<"mlir::Value", "{}">:$storage,
117+
CArg<"std::uint64_t", "0">:$storage_offset,
116118
CArg<"fir::FortranVariableFlagsAttr", "{}">:$fortran_attrs,
117119
CArg<"cuf::DataAttributeAttr", "{}">:$data_attr)>];
118120

flang/include/flang/Optimizer/Transforms/Passes.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,8 @@ def AddAliasTags : Pass<"fir-add-alias-tags", "mlir::ModuleOp"> {
326326
theory, each operation could be considered in prallel, so long as there
327327
aren't races adding new tags to the mlir context.
328328
}];
329-
let dependentDialects = [ "fir::FIROpsDialect" ];
329+
// The pass inserts TBAA attributes from LLVM dialect.
330+
let dependentDialects = ["mlir::LLVM::LLVMDialect"];
330331
}
331332

332333
def SimplifyRegionLite : Pass<"simplify-region-lite", "mlir::ModuleOp"> {

0 commit comments

Comments
 (0)