Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions clang/include/clang/CIR/Dialect/IR/CIRAttrs.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#ifndef LLVM_CLANG_CIR_DIALECT_IR_CIRATTRS_H
#define LLVM_CLANG_CIR_DIALECT_IR_CIRATTRS_H

#include "clang/CIR/Dialect/IR/CIROpsEnums.h"
#include "clang/CIR/Dialect/IR/CIRTypes.h"

#include "mlir/IR/Attributes.h"
Expand Down
42 changes: 42 additions & 0 deletions clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
Original file line number Diff line number Diff line change
Expand Up @@ -276,4 +276,46 @@ def ConstPtrAttr : CIR_Attr<"ConstPtr", "ptr", [TypedAttrInterface]> {
}];
}

//===----------------------------------------------------------------------===//
// VisibilityAttr
//===----------------------------------------------------------------------===//

def CIR_VisibilityKind : I32EnumAttr<"VisibilityKind", "C/C++ visibility", [
I32EnumAttrCase<"Default", 1, "default">,
I32EnumAttrCase<"Hidden", 2, "hidden">,
I32EnumAttrCase<"Protected", 3, "protected">
]> {
let genSpecializedAttr = 0;
let cppNamespace = "::cir";
}

def CIR_VisibilityAttr : CIR_Attr<"Visibility", "visibility"> {
let summary = "Visibility attribute";
let description = [{
Visibility attributes.
}];
let parameters = (ins "VisibilityKind":$value);

let assemblyFormat = [{
$value
}];

let builders = [
AttrBuilder<(ins CArg<"VisibilityKind", "cir::VisibilityKind::Default">:$value), [{
return $_get($_ctxt, value);
}]>
];

let skipDefaultBuilders = 1;

// Make DefaultValuedAttr accept VisibilityKind as default value ($0).
let constBuilderCall = "cir::VisibilityAttr::get($_builder.getContext(), $0)";

let extraClassDeclaration = [{
bool isDefault() const { return getValue() == VisibilityKind::Default; };
bool isHidden() const { return getValue() == VisibilityKind::Hidden; };
bool isProtected() const { return getValue() == VisibilityKind::Protected; };
}];
}

#endif // LLVM_CLANG_CIR_DIALECT_IR_CIRATTRS_TD
17 changes: 16 additions & 1 deletion clang/include/clang/CIR/Dialect/IR/CIROps.td
Original file line number Diff line number Diff line change
Expand Up @@ -1634,7 +1634,8 @@ def GlobalLinkageKind : I32EnumAttr<
// properties of a global variable will be added over time as more of ClangIR
// is upstreamed.

def GlobalOp : CIR_Op<"global"> {
def GlobalOp : CIR_Op<"global",
[DeclareOpInterfaceMethods<CIRGlobalValueInterface>]> {
let summary = "Declare or define a global variable";
let description = [{
The `cir.global` operation declares or defines a named global variable.
Expand All @@ -1643,17 +1644,31 @@ def GlobalOp : CIR_Op<"global"> {
described by the type of the variable.

The `linkage` tracks C/C++ linkage types, currently very similar to LLVM's.
Symbol visibility in `sym_visibility` is defined in terms of MLIR's visibility
and verified to be in accordance to `linkage`.
}];

// Note that both sym_name and sym_visibility are tied to Symbol trait.
// TODO: sym_visibility can possibly be represented by implementing the
// necessary Symbol's interface in terms of linkage instead.
let arguments = (ins SymbolNameAttr:$sym_name,
DefaultValuedAttr<
CIR_VisibilityAttr,
"VisibilityKind::Default"
>:$global_visibility,
OptionalAttr<StrAttr>:$sym_visibility,
TypeAttr:$sym_type,
Arg<GlobalLinkageKind, "linkage type">:$linkage,
OptionalAttr<AnyAttr>:$initial_value,
UnitAttr:$comdat,
UnitAttr:$dsolocal,
OptionalAttr<I64Attr>:$alignment);

let assemblyFormat = [{
($sym_visibility^)?
(`` $global_visibility^)?
$linkage
(`comdat` $comdat^)?
(`dsolocal` $dsolocal^)?
$sym_name
custom<GlobalOpTypeAndInitialValue>($sym_type, $initial_value)
Expand Down
4 changes: 2 additions & 2 deletions clang/include/clang/CIR/Dialect/IR/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ mlir_tablegen(CIROpsDialect.cpp.inc -gen-dialect-defs)
add_public_tablegen_target(MLIRCIROpsIncGen)
add_dependencies(mlir-headers MLIRCIROpsIncGen)

mlir_tablegen(CIROpsAttributes.h.inc -gen-attrdef-decls)
mlir_tablegen(CIROpsAttributes.cpp.inc -gen-attrdef-defs)
mlir_tablegen(CIROpsEnums.h.inc -gen-enum-decls)
mlir_tablegen(CIROpsEnums.cpp.inc -gen-enum-defs)
mlir_tablegen(CIROpsAttributes.h.inc -gen-attrdef-decls)
mlir_tablegen(CIROpsAttributes.cpp.inc -gen-attrdef-defs)
add_public_tablegen_target(MLIRCIREnumsGen)

set(LLVM_TARGET_DEFINITIONS CIRTypeConstraints.td)
Expand Down
6 changes: 2 additions & 4 deletions clang/include/clang/CIR/MissingFeatures.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ struct MissingFeatures {
static bool cgfSymbolTable() { return false; }

// Unhandled global/linkage information.
static bool opGlobalDSOLocal() { return false; }
static bool opGlobalThreadLocal() { return false; }
static bool opGlobalConstant() { return false; }
static bool opGlobalWeakRef() { return false; }
Expand All @@ -41,11 +40,11 @@ struct MissingFeatures {
static bool opGlobalVisibility() { return false; }
static bool opGlobalDLLImportExport() { return false; }
static bool opGlobalPartition() { return false; }
static bool opGlobalCIRGlobalValueInterface() { return false; }

static bool supportIFuncAttr() { return false; }
static bool supportVisibility() { return false; }
static bool supportComdat() { return false; }
static bool hiddenVisibility() { return false; }
static bool protectedVisibility() { return false; }

// Load/store attributes
static bool opLoadStoreThreadLocal() { return false; }
Expand Down Expand Up @@ -188,7 +187,6 @@ struct MissingFeatures {
static bool updateCompletedType() { return false; }
static bool targetSpecificCXXABI() { return false; }
static bool moduleNameHash() { return false; }
static bool setDSOLocal() { return false; }
static bool constantFoldSwitchStatement() { return false; }
static bool cudaSupport() { return false; }
static bool maybeHandleStaticInExternC() { return false; }
Expand Down
Loading
Loading