Skip to content

Commit 521cc4a

Browse files
Clean up a little bit
1 parent 423fe88 commit 521cc4a

File tree

1 file changed

+18
-51
lines changed

1 file changed

+18
-51
lines changed

mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp

Lines changed: 18 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
#include <optional>
4242
#include <utility>
4343

44-
#define DEBUG_TYPE "openmp-to-llvm-ir-translation"
4544
using namespace mlir;
4645

4746
namespace {
@@ -3322,6 +3321,14 @@ static bool privatizerNeedsMap(omp::PrivateClauseOp &privatizer) {
33223321
Value blockArg0 = allocRegion.getArgument(0);
33233322
return !blockArg0.use_empty();
33243323
}
3324+
3325+
// Return the llvm::Value * corresponding to the privateVar that
3326+
// is being privatized. It isn't always as simple as looking up
3327+
// moduleTranslation with privateVar. For instance, in case of
3328+
// an allocatable, the descriptor for the allocatable is privatized.
3329+
// This descriptor is mapped using an MapInfoOp. So, this function
3330+
// will return a pointer to the llvm::Value corresponding to the
3331+
// block argument for the mapped descriptor.
33253332
static llvm::Value *
33263333
findHostAssociatedValue(Value privateVar, omp::TargetOp targetOp,
33273334
llvm::DenseMap<Value, int> &mappedPrivateVars,
@@ -3336,17 +3343,8 @@ findHostAssociatedValue(Value privateVar, omp::TargetOp targetOp,
33363343
"A block argument corresponding to a mapped var should have "
33373344
"!llvm.ptr type");
33383345

3339-
LLVM_DEBUG(llvm::dbgs() << "privVarType = ");
3340-
LLVM_DEBUG(privVarType.dump());
3341-
LLVM_DEBUG(llvm::dbgs() << "\n");
3342-
LLVM_DEBUG(llvm::dbgs() << "blockArgType = ");
3343-
LLVM_DEBUG(blockArg.getType().dump());
3344-
LLVM_DEBUG(llvm::dbgs() << "\n");
3345-
33463346
if (privVarType == blockArg.getType()) {
33473347
llvm::Value *v = moduleTranslation.lookupValue(blockArg);
3348-
LLVM_DEBUG(llvm::dbgs() << "Host Associated Value : ");
3349-
LLVM_DEBUG(v->dump());
33503348
return v;
33513349
}
33523350

@@ -3358,13 +3356,9 @@ findHostAssociatedValue(Value privateVar, omp::TargetOp targetOp,
33583356
llvm::Value *load =
33593357
builder.CreateLoad(moduleTranslation.convertType(privVarType),
33603358
moduleTranslation.lookupValue(blockArg));
3361-
LLVM_DEBUG(llvm::dbgs() << "Host Associated Value : ");
3362-
LLVM_DEBUG(load->dump());
33633359
return load;
33643360
}
33653361
}
3366-
LLVM_DEBUG(llvm::dbgs() << "Host Associated Value : ");
3367-
LLVM_DEBUG(moduleTranslation.lookupValue(privateVar)->dump());
33683362
return moduleTranslation.lookupValue(privateVar);
33693363
}
33703364
static LogicalResult
@@ -3415,54 +3409,36 @@ convertOmpTarget(Operation &opInst, llvm::IRBuilderBase &builder,
34153409
OperandRange privateVars = targetOp.getPrivateVars();
34163410
std::optional<ArrayAttr> privateSyms = targetOp.getPrivateSyms();
34173411
auto reverseIt = mapVars.rbegin();
3418-
LLVM_DEBUG(llvm::dbgs() << "****Private Vars*******\n");
34193412
for (auto [privVar, privSym] :
34203413
llvm::reverse(llvm::zip_equal(privateVars, *privateSyms))) {
3421-
LLVM_DEBUG(llvm::dbgs() << "-- {\n");
3422-
LLVM_DEBUG(privVar.dump());
3423-
LLVM_DEBUG(llvm::dbgs() << "Type:-> ");
3424-
LLVM_DEBUG(privVar.getType().dump());
34253414
SymbolRefAttr privatizerName = llvm::cast<SymbolRefAttr>(privSym);
3426-
LLVM_DEBUG(llvm::dbgs() << "Privatizer: " << privatizerName << "\n}");
3427-
34283415
omp::PrivateClauseOp privatizer =
3429-
SymbolTable::lookupNearestSymbolFrom<omp::PrivateClauseOp>(
3430-
targetOp, privatizerName);
3431-
if (!privatizerNeedsMap(privatizer)) {
3432-
LLVM_DEBUG(llvm::dbgs() << " - DOES NOT need map\n");
3416+
findPrivatizer(targetOp, privatizerName);
3417+
if (!privatizerNeedsMap(privatizer))
34333418
continue;
3434-
}
3435-
LLVM_DEBUG(llvm::dbgs() << " - NEEDS map");
3436-
LLVM_DEBUG(llvm::dbgs() << " -> Mapped Arg : -> ");
3437-
LLVM_DEBUG((*reverseIt).dump());
3438-
LLVM_DEBUG(llvm::dbgs() << " -> Block Arg: -> ");
3439-
LLVM_DEBUG(targetOp.getRegion().getArgument(lastMapBlockArgsIdx).dump());
3440-
LLVM_DEBUG(llvm::dbgs() << "\n");
34413419

34423420
// The MapInfoOp defining the map var isn't really needed later.
3443-
// We'll do some sanity checks on it right now.
3421+
// So, we don't store it in any datastructure. Instead, we just
3422+
// do some sanity checks on it right now.
34443423
omp::MapInfoOp mapInfoOp =
34453424
llvm::cast<omp::MapInfoOp>((*reverseIt).getDefiningOp());
34463425
Type varType = mapInfoOp.getVarType();
3447-
LLVM_DEBUG(llvm::dbgs() << "mapInfoOp.getVarType() = ");
3448-
LLVM_DEBUG(varType.dump());
3449-
LLVM_DEBUG(llvm::dbgs() << "\n");
34503426

3427+
// Check #1: Check that the type of the private variable matches
3428+
// the type of the variable being mapped.
34513429
if (!isa<LLVM::LLVMPointerType>(privVar.getType()))
34523430
assert(
34533431
varType == privVar.getType() &&
34543432
"Type of private var doesn't match the type of the mapped value");
3433+
3434+
// Ok, only 1 sanity check for now.
3435+
// Record the index of the block argument corresponding to this
3436+
// mapvar.
34553437
mappedPrivateVars.insert({privVar, lastMapBlockArgsIdx});
34563438
lastMapBlockArgsIdx--;
34573439
reverseIt++;
34583440
}
34593441
}
3460-
for (auto [privVar, blockArgIdx] : mappedPrivateVars) {
3461-
LLVM_DEBUG(llvm::dbgs() << "*****Private->MappedVars****\n");
3462-
LLVM_DEBUG(privVar.dump());
3463-
LLVM_DEBUG(llvm::dbgs() << "->\n");
3464-
LLVM_DEBUG(targetRegion.getArgument(blockArgIdx).dump());
3465-
}
34663442
LogicalResult bodyGenStatus = success();
34673443
using InsertPointTy = llvm::OpenMPIRBuilder::InsertPointTy;
34683444
auto bodyCB = [&](InsertPointTy allocaIP,
@@ -3488,17 +3464,8 @@ convertOmpTarget(Operation &opInst, llvm::IRBuilderBase &builder,
34883464
auto mapInfoOp = cast<omp::MapInfoOp>(mapOp.getDefiningOp());
34893465
llvm::Value *mapOpValue =
34903466
moduleTranslation.lookupValue(mapInfoOp.getVarPtr());
3491-
LLVM_DEBUG(llvm::dbgs()
3492-
<< "ModuleTranslation Mapping Table for mapVars\n");
3493-
LLVM_DEBUG(arg.dump());
3494-
LLVM_DEBUG(llvm::dbgs() << "---->"; mapOpValue->dump());
3495-
LLVM_DEBUG(llvm::dbgs() << "\n");
34963467
moduleTranslation.mapValue(arg, mapOpValue);
34973468
}
3498-
LLVM_DEBUG(llvm::dbgs() << "LLVM Module before privatization\n");
3499-
LLVM_DEBUG(llvm::dbgs() << "------------------------------------\n");
3500-
LLVM_DEBUG(builder.GetInsertBlock()->getParent()->getParent()->dump());
3501-
LLVM_DEBUG(llvm::dbgs() << "------------------------------------\n");
35023469
// Do privatization after moduleTranslation has already recorded
35033470
// mapped values.
35043471
SmallVector<llvm::Value *> llvmPrivateVars;

0 commit comments

Comments
 (0)