Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
No local reverts carried

---------

Signed-off-by: Simon Camphausen <[email protected]>
Co-authored-by: Simon Camphausen <[email protected]>
Co-authored-by: Marius Brehler <[email protected]>
  • Loading branch information
3 people authored Aug 22, 2024
1 parent e6d7bb2 commit 6ca0613
Show file tree
Hide file tree
Showing 20 changed files with 715 additions and 541 deletions.
4 changes: 2 additions & 2 deletions compiler/src/iree/compiler/Codegen/Utils/GPUUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -558,8 +558,8 @@ Value emitGPUGroupReduction(Location loc, OpBuilder &builder, Value input,
if (auto gpuReduceKind = combiningKindToAllReduce(kind)) {
// Simple case -- emit `gpu.subgroup_reduce` directly.
Value laneVal = builder.create<vector::ReductionOp>(loc, kind, input);
return builder.create<gpu::SubgroupReduceOp>(loc, laneVal,
*gpuReduceKind);
return builder.create<gpu::SubgroupReduceOp>(loc, laneVal, *gpuReduceKind,
/*uniform=*/false);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ namespace mlir::iree_compiler::IREE::Util {

namespace {

static std::optional<Value> buildUnrealizedConversionCastOp(OpBuilder &builder,
Type toType,
ValueRange inputs,
Location loc) {
return builder.create<UnrealizedConversionCastOp>(loc, toType, inputs)
.getResult(0);
}

class TestConversionPass : public TestConversionBase<TestConversionPass> {
public:
TestConversionPass() = default;
Expand Down Expand Up @@ -50,6 +58,8 @@ class TestConversionPass : public TestConversionBase<TestConversionPass> {
});
}

typeConverter.addTargetMaterialization(buildUnrealizedConversionCastOp);

RewritePatternSet patterns(&getContext());
populateUtilConversionPatterns(context, conversionTarget, typeConverter,
patterns);
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -38,40 +38,62 @@ std::string mapPreprocessorDirective(PreprocessorDirective directive) {
case PreprocessorDirective::PRAGMA:
return "#pragma";
default:
llvm_unreachable("unsupported unary operator");
llvm_unreachable("unsupported preprocessor directive");
return "XXX";
}
}
} // namespace

Value allocateVariable(OpBuilder builder, Location location, Type type,
Attribute initializer) {
return builder
.create<emitc::VariableOp>(
/*location=*/location,
/*resultType=*/type,
/*value=*/initializer)
.getResult();
TypedValue<emitc::LValueType> allocateVariable(OpBuilder builder,
Location location, Type type,
Attribute initializer) {
Value result = builder
.create<emitc::VariableOp>(
/*location=*/location,
/*resultType=*/emitc::LValueType::get(type),
/*value=*/initializer)
.getResult();
return cast<TypedValue<emitc::LValueType>>(result);
}

Value allocateVariable(OpBuilder builder, Location location, Type type,
std::optional<StringRef> initializer) {
TypedValue<emitc::LValueType>
allocateVariable(OpBuilder builder, Location location, Type type,
std::optional<StringRef> initializer) {
auto ctx = builder.getContext();
return allocateVariable(
builder, location, type,
emitc::OpaqueAttr::get(ctx, initializer.value_or("")));
}

Value addressOf(OpBuilder builder, Location location, Value operand) {
TypedValue<emitc::LValueType> asLValue(OpBuilder builder, Location loc,
Value value) {
auto var = allocateVariable(builder, loc, value.getType());
builder.create<emitc::AssignOp>(loc, var, value);
return var;
}

Value asRValue(OpBuilder builder, Location loc,
TypedValue<emitc::LValueType> value) {
return builder.create<emitc::LoadOp>(loc, value.getType().getValueType(),
value);
}

TypedValue<emitc::PointerType>
addressOf(OpBuilder builder, Location location,
TypedValue<emitc::LValueType> operand) {
auto ctx = builder.getContext();

return builder
.create<emitc::ApplyOp>(
/*location=*/location,
/*result=*/emitc::PointerType::get(operand.getType()),
/*applicableOperator=*/StringAttr::get(ctx, "&"),
/*operand=*/operand)
.getResult();
auto result =
builder
.create<emitc::ApplyOp>(
/*location=*/location,
/*result=*/
emitc::PointerType::get(operand.getType().getValueType()),
/*applicableOperator=*/StringAttr::get(ctx, "&"),
/*operand=*/operand)
.getResult();

return cast<TypedValue<emitc::PointerType>>(result);
}

Value contentsOf(OpBuilder builder, Location location, Value operand) {
Expand Down Expand Up @@ -136,7 +158,7 @@ void memset(OpBuilder builder, Location location, Value dest, int ch,
}

Value arrayElement(OpBuilder builder, Location location, Type type,
size_t index, Value operand) {
size_t index, TypedValue<emitc::PointerType> operand) {
auto ctx = builder.getContext();
return builder
.create<emitc::CallOpaqueOp>(
Expand All @@ -151,7 +173,8 @@ Value arrayElement(OpBuilder builder, Location location, Type type,
}

Value arrayElementAddress(OpBuilder builder, Location location, Type type,
IntegerAttr index, Value operand) {
IntegerAttr index,
TypedValue<emitc::PointerType> operand) {
auto ctx = builder.getContext();
return builder
.create<emitc::CallOpaqueOp>(
Expand All @@ -165,7 +188,7 @@ Value arrayElementAddress(OpBuilder builder, Location location, Type type,
}

Value arrayElementAddress(OpBuilder builder, Location location, Type type,
Value index, Value operand) {
Value index, TypedValue<emitc::PointerType> operand) {
auto ctx = builder.getContext();
return builder
.create<emitc::CallOpaqueOp>(
Expand All @@ -180,8 +203,9 @@ Value arrayElementAddress(OpBuilder builder, Location location, Type type,
.getResult(0);
}

void arrayElementAssign(OpBuilder builder, Location location, Value array,
size_t index, Value value) {
void arrayElementAssign(OpBuilder builder, Location location,
TypedValue<emitc::PointerType> array, size_t index,
Value value) {
auto ctx = builder.getContext();
builder.create<emitc::CallOpaqueOp>(
/*location=*/location,
Expand Down Expand Up @@ -210,50 +234,52 @@ void structDefinition(OpBuilder builder, Location location,
}

Value structMember(OpBuilder builder, Location location, Type type,
StringRef memberName, Value operand) {
Value var = allocateVariable(builder, location, type);
Value member =
builder.create<emitc::MemberOp>(location, type, memberName, operand);
builder.create<emitc::AssignOp>(location, var, member);
return var;
StringRef memberName,
TypedValue<emitc::LValueType> operand) {
TypedValue<emitc::LValueType> member = builder.create<emitc::MemberOp>(
location, emitc::LValueType::get(type), memberName, operand);
return builder.create<emitc::LoadOp>(location, type, member).getResult();
}

Value structMemberAddress(OpBuilder builder, Location location,
emitc::PointerType type, StringRef memberName,
Value operand) {
Value member = builder.create<emitc::MemberOp>(location, type.getPointee(),
memberName, operand);
return addressOf(builder, location, member);
TypedValue<emitc::PointerType>
structMemberAddress(OpBuilder builder, Location location,
emitc::PointerType type, StringRef memberName,
TypedValue<emitc::LValueType> operand) {
auto member = builder.create<emitc::MemberOp>(location, type.getPointee(),
memberName, operand);
return addressOf(builder, location, member.getResult());
}

void structMemberAssign(OpBuilder builder, Location location,
StringRef memberName, Value operand, Value data) {
Value member = builder.create<emitc::MemberOp>(location, data.getType(),
memberName, operand);
StringRef memberName,
TypedValue<emitc::LValueType> operand, Value data) {
Value member = builder.create<emitc::MemberOp>(
location, emitc::LValueType::get(data.getType()), memberName, operand);
builder.create<emitc::AssignOp>(location, member, data);
}

Value structPtrMember(OpBuilder builder, Location location, Type type,
StringRef memberName, Value operand) {
Value var = allocateVariable(builder, location, type);
Value member =
builder.create<emitc::MemberOfPtrOp>(location, type, memberName, operand);
builder.create<emitc::AssignOp>(location, var, member);
return var;
StringRef memberName,
TypedValue<emitc::LValueType> operand) {
TypedValue<emitc::LValueType> member = builder.create<emitc::MemberOfPtrOp>(
location, emitc::LValueType::get(type), memberName, operand);
return builder.create<emitc::LoadOp>(location, type, member).getResult();
}

Value structPtrMemberAddress(OpBuilder builder, Location location,
emitc::PointerType type, StringRef memberName,
Value operand) {
Value member = builder.create<emitc::MemberOfPtrOp>(
location, type.getPointee(), memberName, operand);
return addressOf(builder, location, member);
TypedValue<emitc::PointerType>
structPtrMemberAddress(OpBuilder builder, Location location,
emitc::PointerType type, StringRef memberName,
TypedValue<emitc::LValueType> operand) {
auto member = builder.create<emitc::MemberOfPtrOp>(
location, emitc::LValueType::get(type.getPointee()), memberName, operand);
return addressOf(builder, location, member.getResult());
}

void structPtrMemberAssign(OpBuilder builder, Location location,
StringRef memberName, Value operand, Value data) {
Value member = builder.create<emitc::MemberOfPtrOp>(location, data.getType(),
memberName, operand);
StringRef memberName,
TypedValue<emitc::LValueType> operand, Value data) {
Value member = builder.create<emitc::MemberOfPtrOp>(
location, emitc::LValueType::get(data.getType()), memberName, operand);
builder.create<emitc::AssignOp>(location, member, data);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,25 @@ enum PreprocessorDirective {
PRAGMA
};

Value allocateVariable(OpBuilder builder, Location location, Type type,
Attribute initializer);

Value allocateVariable(OpBuilder builder, Location location, Type type,
std::optional<StringRef> initializer = std::nullopt);

Value addressOf(OpBuilder builder, Location location, Value operand);
TypedValue<emitc::LValueType> allocateVariable(OpBuilder builder,
Location location, Type type,
Attribute initializer);

TypedValue<emitc::LValueType>
allocateVariable(OpBuilder builder, Location location, Type type,
std::optional<StringRef> initializer = std::nullopt);

/// Convert a value to an EmitC LValue by allocating a new variable and
/// assigning the operand to it. Note that the variable declaration and
/// assignment are split into two separate statements, so that padding bytes for
/// struct values are not copied.
TypedValue<emitc::LValueType> asLValue(OpBuilder builder, Location loc,
Value value);
Value asRValue(OpBuilder builder, Location loc,
TypedValue<emitc::LValueType> value);

TypedValue<emitc::PointerType> addressOf(OpBuilder builder, Location location,
TypedValue<emitc::LValueType> operand);

Value contentsOf(OpBuilder builder, Location location, Value operand);

Expand All @@ -66,42 +78,46 @@ void memset(OpBuilder builder, Location location, Value dest, int ch,
Value count);

Value arrayElement(OpBuilder builder, Location location, Type type,
size_t index, Value operand);
size_t index, TypedValue<emitc::PointerType> operand);

Value arrayElementAddress(OpBuilder builder, Location location, Type type,
IntegerAttr index, Value operand);
IntegerAttr index,
TypedValue<emitc::PointerType> operand);

Value arrayElementAddress(OpBuilder builder, Location location, Type type,
Value index, Value operand);
Value index, TypedValue<emitc::PointerType> operand);

void arrayElementAssign(OpBuilder builder, Location location, Value array,
size_t index, Value value);
void arrayElementAssign(OpBuilder builder, Location location,
TypedValue<emitc::PointerType> array, size_t index,
Value value);

void structDefinition(OpBuilder builder, Location location,
StringRef structName, ArrayRef<StructField> fields);

Value structMember(OpBuilder builder, Location location, Type type,
StringRef memberName, Value operand);
StringRef memberName, TypedValue<emitc::LValueType> operand);

Value structMemberAddress(OpBuilder builder, Location location,
emitc::PointerType type, StringRef memberName,
Value operand);

void structMemberAssign(OpBuilder builder, Location location,
StringRef memberName, Value operand, Value data);
TypedValue<emitc::PointerType>
structMemberAddress(OpBuilder builder, Location location,
emitc::PointerType type, StringRef memberName,
TypedValue<emitc::LValueType> operand);

void structMemberAssign(OpBuilder builder, Location location,
StringRef memberName, Value operand, StringRef data);
StringRef memberName,
TypedValue<emitc::LValueType> operand, Value data);

Value structPtrMember(OpBuilder builder, Location location, Type type,
StringRef memberName, Value operand);
StringRef memberName,
TypedValue<emitc::LValueType> operand);

Value structPtrMemberAddress(OpBuilder builder, Location location,
emitc::PointerType type, StringRef memberName,
Value operand);
TypedValue<emitc::PointerType>
structPtrMemberAddress(OpBuilder builder, Location location,
emitc::PointerType type, StringRef memberName,
TypedValue<emitc::LValueType> operand);

void structPtrMemberAssign(OpBuilder builder, Location location,
StringRef memberName, Value operand, Value data);
StringRef memberName,
TypedValue<emitc::LValueType> operand, Value data);

Value ireeMakeCstringView(OpBuilder builder, Location location,
std::string str);
Expand Down
Loading

0 comments on commit 6ca0613

Please sign in to comment.