Skip to content

Commit

Permalink
[NFC] Remove unnecessary changes from the trunk
Browse files Browse the repository at this point in the history
  • Loading branch information
skatrak committed Jan 16, 2025
1 parent e469284 commit f7e8f10
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 126 deletions.
1 change: 1 addition & 0 deletions flang/lib/Lower/OpenMP/DataSharingProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,7 @@ void DataSharingProcessor::doPrivatize(const semantics::Symbol *sym,
clauseOps->privateSyms.push_back(mlir::SymbolRefAttr::get(privatizerOp));
clauseOps->privateVars.push_back(hsb.getAddr());
}

symToPrivatizer[sym] = privatizerOp;
}

Expand Down
1 change: 0 additions & 1 deletion flang/lib/Lower/OpenMP/DataSharingProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ class DataSharingProcessor {
bool useDelayedPrivatization;
bool callsInitClone = false;
lower::SymMap &symTable;

OMPConstructSymbolVisitor visitor;
bool privatizationDone = false;

Expand Down
132 changes: 63 additions & 69 deletions flang/lib/Lower/OpenMP/OpenMP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1102,7 +1102,6 @@ static void createBodyOfOp(mlir::Operation &op, const OpWithBodyGenInfo &info,
firOpBuilder.createBlock(&op.getRegion(0));
return {};
}();

// Mark the earliest insertion point.
mlir::Operation *marker = insertMarker(firOpBuilder);

Expand Down Expand Up @@ -1858,7 +1857,6 @@ static mlir::omp::LoopNestOp genLoopNestOp(
std::pair<mlir::omp::BlockArgOpenMPOpInterface, const EntryBlockArgs &>>
wrapperArgs,
llvm::omp::Directive directive, DataSharingProcessor &dsp) {

auto ivCallback = [&](mlir::Operation *op) {
genLoopVars(op, converter, loc, iv, wrapperArgs);
return llvm::SmallVector<const semantics::Symbol *>(iv);
Expand All @@ -1867,15 +1865,13 @@ static mlir::omp::LoopNestOp genLoopNestOp(
auto *nestedEval =
getCollapsedLoopEval(eval, getCollapseValue(item->clauses));

auto loopNestOp = genOpWithBody<mlir::omp::LoopNestOp>(
return genOpWithBody<mlir::omp::LoopNestOp>(
OpWithBodyGenInfo(converter, symTable, semaCtx, loc, *nestedEval,
directive)
.setClauses(&item->clauses)
.setDataSharingProcessor(&dsp)
.setGenRegionEntryCb(ivCallback),
queue, item, clauseOps);

return loopNestOp;
}

static void genLoopOp(lower::AbstractConverter &converter,
Expand Down Expand Up @@ -2202,76 +2198,77 @@ genTargetOp(lower::AbstractConverter &converter, lower::SymMap &symTable,
if (!converter.getSymbolAddress(sym))
return;

if (llvm::is_contained(mapSyms, &sym))
return;

if (const auto *details =
sym.template detailsIf<semantics::HostAssocDetails>())
converter.copySymbolBinding(details->symbol(), sym);
std::stringstream name;
fir::ExtendedValue dataExv = converter.getSymbolExtendedValue(sym);
name << sym.name().ToString();

lower::AddrAndBoundsInfo info = getDataOperandBaseAddr(
converter, firOpBuilder, sym, converter.getCurrentLocation());
llvm::SmallVector<mlir::Value> bounds =
lower::genImplicitBoundsOps<mlir::omp::MapBoundsOp,
mlir::omp::MapBoundsType>(
firOpBuilder, info, dataExv,
semantics::IsAssumedSizeArray(sym.GetUltimate()),
converter.getCurrentLocation());

llvm::omp::OpenMPOffloadMappingFlags mapFlag =
llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_IMPLICIT;
mlir::omp::VariableCaptureKind captureKind =
mlir::omp::VariableCaptureKind::ByRef;

mlir::Value baseOp = info.rawInput;
mlir::Type eleType = baseOp.getType();
if (auto refType = mlir::dyn_cast<fir::ReferenceType>(baseOp.getType()))
eleType = refType.getElementType();

// If a variable is specified in declare target link and if device
// type is not specified as `nohost`, it needs to be mapped tofrom
mlir::ModuleOp mod = firOpBuilder.getModule();
mlir::Operation *op = mod.lookupSymbol(converter.mangleName(sym));
auto declareTargetOp =
llvm::dyn_cast_if_present<mlir::omp::DeclareTargetInterface>(op);
if (declareTargetOp && declareTargetOp.isDeclareTarget()) {
if (declareTargetOp.getDeclareTargetCaptureClause() ==
mlir::omp::DeclareTargetCaptureClause::link &&
declareTargetOp.getDeclareTargetDeviceType() !=
mlir::omp::DeclareTargetDeviceType::nohost) {
if (!llvm::is_contained(mapSyms, &sym)) {
if (const auto *details =
sym.template detailsIf<semantics::HostAssocDetails>())
converter.copySymbolBinding(details->symbol(), sym);
std::stringstream name;
fir::ExtendedValue dataExv = converter.getSymbolExtendedValue(sym);
name << sym.name().ToString();

lower::AddrAndBoundsInfo info = getDataOperandBaseAddr(
converter, firOpBuilder, sym, converter.getCurrentLocation());
llvm::SmallVector<mlir::Value> bounds =
lower::genImplicitBoundsOps<mlir::omp::MapBoundsOp,
mlir::omp::MapBoundsType>(
firOpBuilder, info, dataExv,
semantics::IsAssumedSizeArray(sym.GetUltimate()),
converter.getCurrentLocation());

llvm::omp::OpenMPOffloadMappingFlags mapFlag =
llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_IMPLICIT;
mlir::omp::VariableCaptureKind captureKind =
mlir::omp::VariableCaptureKind::ByRef;

mlir::Value baseOp = info.rawInput;
mlir::Type eleType = baseOp.getType();
if (auto refType = mlir::dyn_cast<fir::ReferenceType>(baseOp.getType()))
eleType = refType.getElementType();

// If a variable is specified in declare target link and if device
// type is not specified as `nohost`, it needs to be mapped tofrom
mlir::ModuleOp mod = firOpBuilder.getModule();
mlir::Operation *op = mod.lookupSymbol(converter.mangleName(sym));
auto declareTargetOp =
llvm::dyn_cast_if_present<mlir::omp::DeclareTargetInterface>(op);
if (declareTargetOp && declareTargetOp.isDeclareTarget()) {
if (declareTargetOp.getDeclareTargetCaptureClause() ==
mlir::omp::DeclareTargetCaptureClause::link &&
declareTargetOp.getDeclareTargetDeviceType() !=
mlir::omp::DeclareTargetDeviceType::nohost) {
mapFlag |= llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_TO;
mapFlag |= llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_FROM;
}
} else if (fir::isa_trivial(eleType) || fir::isa_char(eleType)) {
captureKind = mlir::omp::VariableCaptureKind::ByCopy;
} else if (!fir::isa_builtin_cptr_type(eleType)) {
mapFlag |= llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_TO;
mapFlag |= llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_FROM;
}
} else if (fir::isa_trivial(eleType) || fir::isa_char(eleType)) {
captureKind = mlir::omp::VariableCaptureKind::ByCopy;
} else if (!fir::isa_builtin_cptr_type(eleType)) {
mapFlag |= llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_TO;
mapFlag |= llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_FROM;
auto location =
mlir::NameLoc::get(mlir::StringAttr::get(firOpBuilder.getContext(),
sym.name().ToString()),
baseOp.getLoc());
mlir::Value mapOp = createMapInfoOp(
firOpBuilder, location, baseOp, /*varPtrPtr=*/mlir::Value{},
name.str(), bounds, /*members=*/{},
/*membersIndex=*/mlir::ArrayAttr{},
static_cast<
std::underlying_type_t<llvm::omp::OpenMPOffloadMappingFlags>>(
mapFlag),
captureKind, baseOp.getType());

clauseOps.mapVars.push_back(mapOp);
mapSyms.push_back(&sym);
}
auto location = mlir::NameLoc::get(
mlir::StringAttr::get(firOpBuilder.getContext(), sym.name().ToString()),
baseOp.getLoc());
mlir::Value mapOp = createMapInfoOp(
firOpBuilder, location, baseOp, /*varPtrPtr=*/mlir::Value{}, name.str(),
bounds, /*members=*/{},
/*membersIndex=*/mlir::ArrayAttr{},
static_cast<
std::underlying_type_t<llvm::omp::OpenMPOffloadMappingFlags>>(
mapFlag),
captureKind, baseOp.getType());

clauseOps.mapVars.push_back(mapOp);
mapSyms.push_back(&sym);
};
lower::pft::visitAllSymbols(eval, captureImplicitMap);

auto targetOp = firOpBuilder.create<mlir::omp::TargetOp>(loc, clauseOps);

llvm::SmallVector<mlir::Value> mapBaseValues;
extractMappedBaseValues(clauseOps.mapVars, mapBaseValues);

EntryBlockArgs args;
args.hostEvalVars = clauseOps.hostEvalVars;
// TODO: Add in_reduction syms and vars.
Expand Down Expand Up @@ -2471,14 +2468,12 @@ genTeamsOp(lower::AbstractConverter &converter, lower::SymMap &symTable,
return llvm::to_vector(args.getSyms());
};

auto teamsOp = genOpWithBody<mlir::omp::TeamsOp>(
return genOpWithBody<mlir::omp::TeamsOp>(
OpWithBodyGenInfo(converter, symTable, semaCtx, loc, eval,
llvm::omp::Directive::OMPD_teams)
.setClauses(&item->clauses)
.setGenRegionEntryCb(genRegionEntryCB),
queue, item, clauseOps);

return teamsOp;
}

//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -2528,6 +2523,7 @@ static void genStandaloneDo(lower::AbstractConverter &converter,
const ConstructQueue &queue,
ConstructQueue::const_iterator item) {
lower::StatementContext stmtCtx;

mlir::omp::WsloopOperands wsloopClauseOps;
llvm::SmallVector<const semantics::Symbol *> wsloopReductionSyms;
genWsloopClauses(converter, semaCtx, stmtCtx, item->clauses, loc,
Expand Down Expand Up @@ -3449,7 +3445,6 @@ static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
ConstructQueue queue{
buildConstructQueue(converter.getFirOpBuilder().getModule(), semaCtx,
eval, source, directive, clauses)};

genOMPDispatch(converter, symTable, semaCtx, eval, currentLocation, queue,
queue.begin());
}
Expand All @@ -3475,7 +3470,6 @@ static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
std::get<parser::OmpSectionBlocks>(sectionsConstruct.t);
clauses.append(makeClauses(
std::get<parser::OmpClauseList>(endSectionsDirective.t), semaCtx));

mlir::Location currentLocation = converter.getCurrentLocation();

llvm::omp::Directive directive =
Expand Down
1 change: 1 addition & 0 deletions llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -2904,6 +2904,7 @@ class OpenMPIRBuilder {
Function *OutlinedFunction,
StringRef EntryFnName,
StringRef EntryFnIDName);

/// Type of BodyGen to use for region codegen
///
/// Priv: If device pointer privatization is required, emit the body of the
Expand Down
42 changes: 2 additions & 40 deletions llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ static const omp::GV &getGridValue(const Triple &T, Function *Kernel) {
if (T.isAMDGPU()) {
StringRef Features =
Kernel->getFnAttribute("target-features").getValueAsString();

if (Features.count("+wavefrontsize64"))
return omp::getAMDGPUGridValues<64>();
return omp::getAMDGPUGridValues<32>();
Expand Down Expand Up @@ -1248,6 +1247,7 @@ static void targetParallelCallback(
CallInst *CI = cast<CallInst>(OutlinedFn.user_back());
assert(CI && "Expected call instruction to outlined function");
CI->getParent()->setName("omp_parallel");

Builder.SetInsertPoint(CI);
Type *PtrTy = OMPIRBuilder->VoidPtr;
Value *NullPtrValue = Constant::getNullValue(PtrTy);
Expand Down Expand Up @@ -4371,7 +4371,6 @@ OpenMPIRBuilder::applyStaticChunkedWorkshareLoop(DebugLoc DL,
IsLastChunk, CountUntilOrigTripCount, ChunkRange, "omp_chunk.tripcount");
Value *BackcastedChunkTC =
Builder.CreateTrunc(ChunkTripCount, IVTy, "omp_chunk.tripcount.trunc");

CLI->setTripCount(BackcastedChunkTC);

// Update all uses of the induction variable except the one in the condition
Expand Down Expand Up @@ -6838,44 +6837,6 @@ FunctionCallee OpenMPIRBuilder::createDispatchDeinitFunction() {
return getOrCreateRuntimeFunction(M, omp::OMPRTL___kmpc_dispatch_deinit);
}

static void emitUsed(StringRef Name, std::vector<llvm::WeakTrackingVH> &List,
Type *Int8PtrTy, Module &M) {
if (List.empty())
return;

// Convert List to what ConstantArray needs.
SmallVector<Constant *, 8> UsedArray;
UsedArray.resize(List.size());
for (unsigned i = 0, e = List.size(); i != e; ++i) {
UsedArray[i] = ConstantExpr::getPointerBitCastOrAddrSpaceCast(
cast<Constant>(&*List[i]), Int8PtrTy);
}

if (UsedArray.empty())
return;
ArrayType *ATy = ArrayType::get(Int8PtrTy, UsedArray.size());

auto *GV =
new GlobalVariable(M, ATy, false, llvm::GlobalValue::AppendingLinkage,
llvm::ConstantArray::get(ATy, UsedArray), Name);

GV->setSection("llvm.metadata");
}

static void
emitExecutionMode(OpenMPIRBuilder &OMPBuilder, IRBuilderBase &Builder,
StringRef FunctionName, omp::OMPTgtExecModeFlags ExecFlags,
std::vector<llvm::WeakTrackingVH> &LLVMCompilerUsed) {
auto Int8Ty = Type::getInt8Ty(Builder.getContext());
auto *GVMode =
new llvm::GlobalVariable(OMPBuilder.M, Int8Ty, /*isConstant=*/true,
llvm::GlobalValue::WeakAnyLinkage,
llvm::ConstantInt::get(Int8Ty, ExecFlags),
Twine(FunctionName, "_exec_mode"));
GVMode->setVisibility(llvm::GlobalVariable::ProtectedVisibility);
LLVMCompilerUsed.emplace_back(GVMode);
}

static Value *removeASCastIfPresent(Value *V) {
if (Operator::getOpcode(V) == Instruction::AddrSpaceCast)
return cast<Operator>(V)->getOperand(0);
Expand Down Expand Up @@ -7580,6 +7541,7 @@ emitTargetCall(OpenMPIRBuilder &OMPBuilder, IRBuilderBase &Builder,
Result, Clause)
: Clause;
};

// If a multi-dimensional THREAD_LIMIT is set, it is the OMPX_BARE case, so
// the NUM_THREADS clause is overriden by THREAD_LIMIT.
SmallVector<Value *, 3> NumThreadsC;
Expand Down
1 change: 0 additions & 1 deletion mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2388,7 +2388,6 @@ LogicalResult DistributeOp::verifyRegions() {
if (!isComposite())
return emitError()
<< "'omp.composite' attribute missing from composite wrapper";

// Check for the allowed leaf constructs that may appear in a composite
// construct directly after DISTRIBUTE.
if (isa<WsloopOp>(nested)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3557,6 +3557,7 @@ static llvm::omp::OpenMPOffloadMappingFlags mapParentWithMembers(
// runtime information on the dynamically allocated data).
auto parentClause =
llvm::cast<omp::MapInfoOp>(mapData.MapClause[mapDataIndex]);

llvm::Value *lowAddr, *highAddr;
if (!parentClause.getPartialMap()) {
lowAddr = builder.CreatePointerCast(mapData.Pointers[mapDataIndex],
Expand Down Expand Up @@ -4141,7 +4142,6 @@ convertOmpTargetData(Operation *op, llvm::IRBuilderBase &builder,
// If device info is available then region has already been generated
if (info.DevicePtrInfoMap.empty()) {
builder.restoreIP(codeGenIP);

// For device pass, if use_device_ptr(addr) mappings were present,
// we need to link them here before codegen.
if (ompBuilder->Config.IsTargetDevice.value_or(false)) {
Expand Down Expand Up @@ -4973,7 +4973,6 @@ convertOmpTarget(Operation &opInst, llvm::IRBuilderBase &builder,
return exitBlock.takeError();

builder.SetInsertPoint(*exitBlock);

if (!privateCleanupRegions.empty()) {
if (failed(inlineOmpRegionCleanup(
privateCleanupRegions, llvmPrivateVars, moduleTranslation,
Expand Down Expand Up @@ -5215,6 +5214,7 @@ static bool isTargetDeviceOp(Operation *op) {
static LogicalResult
convertHostOrTargetOperation(Operation *op, llvm::IRBuilderBase &builder,
LLVM::ModuleTranslation &moduleTranslation) {

llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder();

return llvm::TypeSwitch<Operation *, LogicalResult>(op)
Expand Down Expand Up @@ -5340,19 +5340,6 @@ convertHostOrTargetOperation(Operation *op, llvm::IRBuilderBase &builder,
});
}

template <typename FirstOpType, typename... RestOpTypes>
bool matchOpNest(Operation *op, FirstOpType &firstOp, RestOpTypes &...restOps) {
if ((firstOp = mlir::dyn_cast<FirstOpType>(op))) {
if constexpr (sizeof...(RestOpTypes) == 0) {
return true;
} else {
Block &innerBlock = getContainedBlock(firstOp);
return matchOpScanNest(innerBlock, restOps...);
}
}
return false;
}

static LogicalResult
convertTargetDeviceOp(Operation *op, llvm::IRBuilderBase &builder,
LLVM::ModuleTranslation &moduleTranslation) {
Expand Down

0 comments on commit f7e8f10

Please sign in to comment.