Skip to content

Commit

Permalink
Merged master:519b019a0a6 into amd-gfx:f8e6c611a2d
Browse files Browse the repository at this point in the history
Local branch amd-gfx f8e6c61 Merged master:8472ae1773a into amd-gfx:036904c0a38
Remote branch master 519b019 Verify MemorySSA after all updates.
  • Loading branch information
Sw authored and Sw committed Jun 12, 2020
2 parents f8e6c61 + 519b019 commit 7e2b6a2
Show file tree
Hide file tree
Showing 64 changed files with 1,559 additions and 1,358 deletions.
160 changes: 80 additions & 80 deletions llvm/lib/Target/X86/X86FastISel.cpp

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions llvm/lib/Transforms/Utils/LoopUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -622,11 +622,11 @@ void llvm::deleteDeadLoop(Loop *L, DominatorTree *DT, ScalarEvolution *SE,
if (MSSA) {
MSSAU->applyUpdates({{DominatorTree::Delete, Preheader, L->getHeader()}},
*DT);
if (VerifyMemorySSA)
MSSA->verifyMemorySSA();
SmallSetVector<BasicBlock *, 8> DeadBlockSet(L->block_begin(),
L->block_end());
MSSAU->removeBlocks(DeadBlockSet);
if (VerifyMemorySSA)
MSSA->verifyMemorySSA();
}
}

Expand Down
23 changes: 23 additions & 0 deletions llvm/test/Analysis/MemorySSA/pr46275.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
; RUN: opt -S -memoryssa -loop-deletion -loop-simplifycfg -verify-memoryssa < %s | FileCheck %s
; REQUIRES: asserts

; CHECK-LABEL: @foo()
define void @foo() {
entry:
br i1 false, label %for.body.lr.ph, label %for.end

for.body.lr.ph: ; preds = %entry
br label %for.body

for.body: ; preds = %for.body, %for.body.lr.ph
call void @foo()
call void @foo()
br i1 false, label %for.body, label %for.cond.for.end_crit_edge

for.cond.for.end_crit_edge: ; preds = %for.body
unreachable

for.end: ; preds = %entry
ret void
}

56 changes: 31 additions & 25 deletions mlir/cmake/modules/AddMLIR.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -125,38 +125,44 @@ function(add_mlir_library name)

if(TARGET ${name})
target_link_libraries(${name} INTERFACE ${LLVM_COMMON_LIBS})

if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
set(export_to_mlirtargets)
if (${name} IN_LIST LLVM_DISTRIBUTION_COMPONENTS OR
"mlir-libraries" IN_LIST LLVM_DISTRIBUTION_COMPONENTS OR
NOT LLVM_DISTRIBUTION_COMPONENTS)
set(export_to_mlirtargets EXPORT MLIRTargets)
set_property(GLOBAL PROPERTY MLIR_HAS_EXPORTS True)
endif()

install(TARGETS ${name}
COMPONENT ${name}
${export_to_mlirtargets}
LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}
RUNTIME DESTINATION bin)

if (NOT LLVM_ENABLE_IDE)
add_llvm_install_targets(install-${name}
DEPENDS ${name}
COMPONENT ${name})
endif()
set_property(GLOBAL APPEND PROPERTY MLIR_ALL_LIBS ${name})
endif()
set_property(GLOBAL APPEND PROPERTY MLIR_EXPORTS ${name})
add_mlir_library_install(${name})
else()
# Add empty "phony" target
add_custom_target(${name})
endif()
set_target_properties(${name} PROPERTIES FOLDER "MLIR libraries")
endfunction(add_mlir_library)

# Adds an MLIR library target for installation.
# This is usually done as part of add_mlir_library but is broken out for cases
# where non-standard library builds can be installed.
function(add_mlir_library_install name)
if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
set(export_to_mlirtargets)
if (${name} IN_LIST LLVM_DISTRIBUTION_COMPONENTS OR
"mlir-libraries" IN_LIST LLVM_DISTRIBUTION_COMPONENTS OR
NOT LLVM_DISTRIBUTION_COMPONENTS)
set(export_to_mlirtargets EXPORT MLIRTargets)
set_property(GLOBAL PROPERTY MLIR_HAS_EXPORTS True)
endif()

install(TARGETS ${name}
COMPONENT ${name}
${export_to_mlirtargets}
LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}
RUNTIME DESTINATION bin)

if (NOT LLVM_ENABLE_IDE)
add_llvm_install_targets(install-${name}
DEPENDS ${name}
COMPONENT ${name})
endif()
set_property(GLOBAL APPEND PROPERTY MLIR_ALL_LIBS ${name})
endif()
set_property(GLOBAL APPEND PROPERTY MLIR_EXPORTS ${name})
endfunction()

# Declare the library associated with a dialect.
function(add_mlir_dialect_library name)
set_property(GLOBAL APPEND PROPERTY MLIR_DIALECT_LIBS ${name})
Expand Down
51 changes: 37 additions & 14 deletions mlir/include/mlir/Dialect/SPIRV/SPIRVTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "mlir/IR/TypeSupport.h"
#include "mlir/IR/Types.h"

#include <bits/stdint-uintn.h>
#include <tuple>

// Forward declare enum classes related to op availability. Their definitions
Expand Down Expand Up @@ -276,22 +277,40 @@ class StructType : public Type::TypeBase<StructType, CompositeType,
public:
using Base::Base;

// Layout information used for members in a struct in SPIR-V
//
// TODO(ravishankarm) : For now this only supports the offset type, so uses
// uint64_t value to represent the offset, with
// std::numeric_limit<uint64_t>::max indicating no offset. Change this to
// something that can hold all the information needed for different member
// types
using LayoutInfo = uint64_t;
// Type for specifying the offset of the struct members
using OffsetInfo = uint32_t;

// Type for specifying the decoration(s) on struct members
struct MemberDecorationInfo {
uint32_t memberIndex : 31;
uint32_t hasValue : 1;
Decoration decoration;
uint32_t decorationValue;

MemberDecorationInfo(uint32_t index, uint32_t hasValue,
Decoration decoration, uint32_t decorationValue)
: memberIndex(index), hasValue(hasValue), decoration(decoration),
decorationValue(decorationValue) {}

bool operator==(const MemberDecorationInfo &other) const {
return (this->memberIndex == other.memberIndex) &&
(this->decoration == other.decoration) &&
(this->decorationValue == other.decorationValue);
}

using MemberDecorationInfo = std::pair<uint32_t, spirv::Decoration>;
bool operator<(const MemberDecorationInfo &other) const {
return this->memberIndex < other.memberIndex ||
(this->memberIndex == other.memberIndex &&
static_cast<uint32_t>(this->decoration) <
static_cast<uint32_t>(other.decoration));
}
};

static bool kindof(unsigned kind) { return kind == TypeKind::Struct; }

/// Construct a StructType with at least one member.
static StructType get(ArrayRef<Type> memberTypes,
ArrayRef<LayoutInfo> layoutInfo = {},
ArrayRef<OffsetInfo> offsetInfo = {},
ArrayRef<MemberDecorationInfo> memberDecorations = {});

/// Construct a struct with no members.
Expand Down Expand Up @@ -323,9 +342,9 @@ class StructType : public Type::TypeBase<StructType, CompositeType,

ElementTypeRange getElementTypes() const;

bool hasLayout() const;
bool hasOffset() const;

uint64_t getOffset(unsigned) const;
uint64_t getMemberOffset(unsigned) const;

// Returns in `allMemberDecorations` the spirv::Decorations (apart from
// Offset) associated with all members of the StructType.
Expand All @@ -334,15 +353,19 @@ class StructType : public Type::TypeBase<StructType, CompositeType,

// Returns in `memberDecorations` all the spirv::Decorations (apart from
// Offset) associated with the `i`-th member of the StructType.
void getMemberDecorations(
unsigned i, SmallVectorImpl<spirv::Decoration> &memberDecorations) const;
void getMemberDecorations(unsigned i,
SmallVectorImpl<StructType::MemberDecorationInfo>
&memberDecorations) const;

void getExtensions(SPIRVType::ExtensionArrayRefVector &extensions,
Optional<spirv::StorageClass> storage = llvm::None);
void getCapabilities(SPIRVType::CapabilityArrayRefVector &capabilities,
Optional<spirv::StorageClass> storage = llvm::None);
};

llvm::hash_code
hash_value(const StructType::MemberDecorationInfo &memberDecorationInfo);

// SPIR-V cooperative matrix type
class CooperativeMatrixNVType
: public Type::TypeBase<CooperativeMatrixNVType, CompositeType,
Expand Down
9 changes: 5 additions & 4 deletions mlir/lib/Dialect/SPIRV/LayoutUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ VulkanLayoutUtils::decorateType(spirv::StructType structType,
}

SmallVector<Type, 4> memberTypes;
SmallVector<Size, 4> layoutInfo;
SmallVector<spirv::StructType::OffsetInfo, 4> offsetInfo;
SmallVector<spirv::StructType::MemberDecorationInfo, 4> memberDecorations;

Size structMemberOffset = 0;
Expand All @@ -46,7 +46,8 @@ VulkanLayoutUtils::decorateType(spirv::StructType structType,
decorateType(structType.getElementType(i), memberSize, memberAlignment);
structMemberOffset = llvm::alignTo(structMemberOffset, memberAlignment);
memberTypes.push_back(memberType);
layoutInfo.push_back(structMemberOffset);
offsetInfo.push_back(
static_cast<spirv::StructType::OffsetInfo>(structMemberOffset));
// If the member's size is the max value, it must be the last member and it
// must be a runtime array.
assert(memberSize != std::numeric_limits<Size>().max() ||
Expand All @@ -66,7 +67,7 @@ VulkanLayoutUtils::decorateType(spirv::StructType structType,
size = llvm::alignTo(structMemberOffset, maxMemberAlignment);
alignment = maxMemberAlignment;
structType.getMemberDecorations(memberDecorations);
return spirv::StructType::get(memberTypes, layoutInfo, memberDecorations);
return spirv::StructType::get(memberTypes, offsetInfo, memberDecorations);
}

Type VulkanLayoutUtils::decorateType(Type type, VulkanLayoutUtils::Size &size,
Expand Down Expand Up @@ -168,7 +169,7 @@ bool VulkanLayoutUtils::isLegalType(Type type) {
case spirv::StorageClass::StorageBuffer:
case spirv::StorageClass::PushConstant:
case spirv::StorageClass::PhysicalStorageBuffer:
return structType.hasLayout() || !structType.getNumElements();
return structType.hasOffset() || !structType.getNumElements();
default:
return true;
}
Expand Down
70 changes: 44 additions & 26 deletions mlir/lib/Dialect/SPIRV/SPIRVDialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -535,30 +535,31 @@ static Type parseImageType(SPIRVDialect const &dialect,
static ParseResult parseStructMemberDecorations(
SPIRVDialect const &dialect, DialectAsmParser &parser,
ArrayRef<Type> memberTypes,
SmallVectorImpl<StructType::LayoutInfo> &layoutInfo,
SmallVectorImpl<StructType::OffsetInfo> &offsetInfo,
SmallVectorImpl<StructType::MemberDecorationInfo> &memberDecorationInfo) {

// Check if the first element is offset.
llvm::SMLoc layoutLoc = parser.getCurrentLocation();
StructType::LayoutInfo layout = 0;
OptionalParseResult layoutParseResult = parser.parseOptionalInteger(layout);
if (layoutParseResult.hasValue()) {
if (failed(*layoutParseResult))
llvm::SMLoc offsetLoc = parser.getCurrentLocation();
StructType::OffsetInfo offset = 0;
OptionalParseResult offsetParseResult = parser.parseOptionalInteger(offset);
if (offsetParseResult.hasValue()) {
if (failed(*offsetParseResult))
return failure();

if (layoutInfo.size() != memberTypes.size() - 1) {
return parser.emitError(
layoutLoc, "layout specification must be given for all members");
if (offsetInfo.size() != memberTypes.size() - 1) {
return parser.emitError(offsetLoc,
"offset specification must be given for "
"all members");
}
layoutInfo.push_back(layout);
offsetInfo.push_back(offset);
}

// Check for no spirv::Decorations.
if (succeeded(parser.parseOptionalRSquare()))
return success();

// If there was a layout, make sure to parse the comma.
if (layoutParseResult.hasValue() && parser.parseComma())
// If there was an offset, make sure to parse the comma.
if (offsetParseResult.hasValue() && parser.parseComma())
return failure();

// Check for spirv::Decorations.
Expand All @@ -567,9 +568,23 @@ static ParseResult parseStructMemberDecorations(
if (!memberDecoration)
return failure();

memberDecorationInfo.emplace_back(
static_cast<uint32_t>(memberTypes.size() - 1),
memberDecoration.getValue());
// Parse member decoration value if it exists.
if (succeeded(parser.parseOptionalEqual())) {
auto memberDecorationValue =
parseAndVerifyInteger<uint32_t>(dialect, parser);

if (!memberDecorationValue)
return failure();

memberDecorationInfo.emplace_back(
static_cast<uint32_t>(memberTypes.size() - 1), 1,
memberDecoration.getValue(), memberDecorationValue.getValue());
} else {
memberDecorationInfo.emplace_back(
static_cast<uint32_t>(memberTypes.size() - 1), 0,
memberDecoration.getValue(), 0);
}

} while (succeeded(parser.parseOptionalComma()));

return parser.parseRSquare();
Expand All @@ -587,7 +602,7 @@ static Type parseStructType(SPIRVDialect const &dialect,
return StructType::getEmpty(dialect.getContext());

SmallVector<Type, 4> memberTypes;
SmallVector<StructType::LayoutInfo, 4> layoutInfo;
SmallVector<StructType::OffsetInfo, 4> offsetInfo;
SmallVector<StructType::MemberDecorationInfo, 4> memberDecorationInfo;

do {
Expand All @@ -597,21 +612,21 @@ static Type parseStructType(SPIRVDialect const &dialect,
memberTypes.push_back(memberType);

if (succeeded(parser.parseOptionalLSquare())) {
if (parseStructMemberDecorations(dialect, parser, memberTypes, layoutInfo,
if (parseStructMemberDecorations(dialect, parser, memberTypes, offsetInfo,
memberDecorationInfo)) {
return Type();
}
}
} while (succeeded(parser.parseOptionalComma()));

if (!layoutInfo.empty() && memberTypes.size() != layoutInfo.size()) {
if (!offsetInfo.empty() && memberTypes.size() != offsetInfo.size()) {
parser.emitError(parser.getNameLoc(),
"layout specification must be given for all members");
"offset specification must be given for all members");
return Type();
}
if (parser.parseGreater())
return Type();
return StructType::get(memberTypes, layoutInfo, memberDecorationInfo);
return StructType::get(memberTypes, offsetInfo, memberDecorationInfo);
}

// spirv-type ::= array-type
Expand Down Expand Up @@ -679,17 +694,20 @@ static void print(StructType type, DialectAsmPrinter &os) {
os << "struct<";
auto printMember = [&](unsigned i) {
os << type.getElementType(i);
SmallVector<spirv::Decoration, 0> decorations;
SmallVector<spirv::StructType::MemberDecorationInfo, 0> decorations;
type.getMemberDecorations(i, decorations);
if (type.hasLayout() || !decorations.empty()) {
if (type.hasOffset() || !decorations.empty()) {
os << " [";
if (type.hasLayout()) {
os << type.getOffset(i);
if (type.hasOffset()) {
os << type.getMemberOffset(i);
if (!decorations.empty())
os << ", ";
}
auto eachFn = [&os](spirv::Decoration decoration) {
os << stringifyDecoration(decoration);
auto eachFn = [&os](spirv::StructType::MemberDecorationInfo decoration) {
os << stringifyDecoration(decoration.decoration);
if (decoration.hasValue) {
os << "=" << decoration.decorationValue;
}
};
llvm::interleaveComma(decorations, os, eachFn);
os << "]";
Expand Down
Loading

0 comments on commit 7e2b6a2

Please sign in to comment.