[OpenMP][OMPIRBuilder] Mirgrate getName from clang to OMPIRBuilder
This change moves the getName function from clang and moves the separator class members from CGOpenMPRuntime into OMPIRBuilder. Also enusre all the getters in the config class are const. Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D137725
This commit is contained in:
parent
4f17734175
commit
2aa338f68e
|
@ -1057,14 +1057,11 @@ static FieldDecl *addFieldToRecordDecl(ASTContext &C, DeclContext *DC,
|
||||||
return Field;
|
return Field;
|
||||||
}
|
}
|
||||||
|
|
||||||
CGOpenMPRuntime::CGOpenMPRuntime(CodeGenModule &CGM, StringRef FirstSeparator,
|
CGOpenMPRuntime::CGOpenMPRuntime(CodeGenModule &CGM)
|
||||||
StringRef Separator)
|
: CGM(CGM), OMPBuilder(CGM.getModule()), OffloadEntriesInfoManager() {
|
||||||
: CGM(CGM), FirstSeparator(FirstSeparator), Separator(Separator),
|
|
||||||
OMPBuilder(CGM.getModule()), OffloadEntriesInfoManager() {
|
|
||||||
KmpCriticalNameTy = llvm::ArrayType::get(CGM.Int32Ty, /*NumElements*/ 8);
|
KmpCriticalNameTy = llvm::ArrayType::get(CGM.Int32Ty, /*NumElements*/ 8);
|
||||||
llvm::OpenMPIRBuilderConfig Config(CGM.getLangOpts().OpenMPIsDevice, false,
|
llvm::OpenMPIRBuilderConfig Config(CGM.getLangOpts().OpenMPIsDevice, false,
|
||||||
hasRequiresUnifiedSharedMemory());
|
hasRequiresUnifiedSharedMemory());
|
||||||
|
|
||||||
// Initialize Types used in OpenMPIRBuilder from OMPKinds.def
|
// Initialize Types used in OpenMPIRBuilder from OMPKinds.def
|
||||||
OMPBuilder.initialize();
|
OMPBuilder.initialize();
|
||||||
OMPBuilder.setConfig(Config);
|
OMPBuilder.setConfig(Config);
|
||||||
|
@ -1088,14 +1085,7 @@ void CGOpenMPRuntime::clear() {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string CGOpenMPRuntime::getName(ArrayRef<StringRef> Parts) const {
|
std::string CGOpenMPRuntime::getName(ArrayRef<StringRef> Parts) const {
|
||||||
SmallString<128> Buffer;
|
return OMPBuilder.createPlatformSpecificName(Parts);
|
||||||
llvm::raw_svector_ostream OS(Buffer);
|
|
||||||
StringRef Sep = FirstSeparator;
|
|
||||||
for (StringRef Part : Parts) {
|
|
||||||
OS << Sep << Part;
|
|
||||||
Sep = Separator;
|
|
||||||
}
|
|
||||||
return std::string(OS.str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static llvm::Function *
|
static llvm::Function *
|
||||||
|
|
|
@ -306,15 +306,10 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
CodeGenModule &CGM;
|
CodeGenModule &CGM;
|
||||||
StringRef FirstSeparator, Separator;
|
|
||||||
|
|
||||||
/// An OpenMP-IR-Builder instance.
|
/// An OpenMP-IR-Builder instance.
|
||||||
llvm::OpenMPIRBuilder OMPBuilder;
|
llvm::OpenMPIRBuilder OMPBuilder;
|
||||||
|
|
||||||
/// Constructor allowing to redefine the name separator for the variables.
|
|
||||||
explicit CGOpenMPRuntime(CodeGenModule &CGM, StringRef FirstSeparator,
|
|
||||||
StringRef Separator);
|
|
||||||
|
|
||||||
/// Helper to emit outlined function for 'target' directive.
|
/// Helper to emit outlined function for 'target' directive.
|
||||||
/// \param D Directive to emit.
|
/// \param D Directive to emit.
|
||||||
/// \param ParentName Name of the function that encloses the target region.
|
/// \param ParentName Name of the function that encloses the target region.
|
||||||
|
@ -691,8 +686,7 @@ protected:
|
||||||
Address DependenciesArray);
|
Address DependenciesArray);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit CGOpenMPRuntime(CodeGenModule &CGM)
|
explicit CGOpenMPRuntime(CodeGenModule &CGM);
|
||||||
: CGOpenMPRuntime(CGM, ".", ".") {}
|
|
||||||
virtual ~CGOpenMPRuntime() {}
|
virtual ~CGOpenMPRuntime() {}
|
||||||
virtual void clear();
|
virtual void clear();
|
||||||
|
|
||||||
|
|
|
@ -889,7 +889,7 @@ unsigned CGOpenMPRuntimeGPU::getDefaultLocationReserved2Flags() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
CGOpenMPRuntimeGPU::CGOpenMPRuntimeGPU(CodeGenModule &CGM)
|
CGOpenMPRuntimeGPU::CGOpenMPRuntimeGPU(CodeGenModule &CGM)
|
||||||
: CGOpenMPRuntime(CGM, "_", "$") {
|
: CGOpenMPRuntime(CGM) {
|
||||||
llvm::OpenMPIRBuilderConfig Config(CGM.getLangOpts().OpenMPIsDevice, true,
|
llvm::OpenMPIRBuilderConfig Config(CGM.getLangOpts().OpenMPIsDevice, true,
|
||||||
hasRequiresUnifiedSharedMemory());
|
hasRequiresUnifiedSharedMemory());
|
||||||
OMPBuilder.setConfig(Config);
|
OMPBuilder.setConfig(Config);
|
||||||
|
|
|
@ -92,34 +92,61 @@ public:
|
||||||
/// directive is present or not.
|
/// directive is present or not.
|
||||||
Optional<bool> HasRequiresUnifiedSharedMemory;
|
Optional<bool> HasRequiresUnifiedSharedMemory;
|
||||||
|
|
||||||
|
/// First separator used between the initial two parts of a name.
|
||||||
|
Optional<StringRef> FirstSeparator;
|
||||||
|
/// Separator used between all of the rest consecutive parts of s name
|
||||||
|
Optional<StringRef> Separator;
|
||||||
|
|
||||||
OpenMPIRBuilderConfig() {}
|
OpenMPIRBuilderConfig() {}
|
||||||
OpenMPIRBuilderConfig(bool IsEmbedded, bool IsTargetCodegen,
|
OpenMPIRBuilderConfig(bool IsEmbedded, bool IsTargetCodegen,
|
||||||
bool HasRequiresUnifiedSharedMemory)
|
bool HasRequiresUnifiedSharedMemory)
|
||||||
: IsEmbedded(IsEmbedded), IsTargetCodegen(IsTargetCodegen),
|
: IsEmbedded(IsEmbedded), IsTargetCodegen(IsTargetCodegen),
|
||||||
HasRequiresUnifiedSharedMemory(HasRequiresUnifiedSharedMemory) {}
|
HasRequiresUnifiedSharedMemory(HasRequiresUnifiedSharedMemory) {}
|
||||||
|
|
||||||
// Convenience getter functions that assert if the value is not present.
|
// Getters functions that assert if the required values are not present.
|
||||||
bool isEmbedded() {
|
bool isEmbedded() const {
|
||||||
assert(IsEmbedded.has_value() && "IsEmbedded is not set");
|
assert(IsEmbedded.has_value() && "IsEmbedded is not set");
|
||||||
return IsEmbedded.value();
|
return IsEmbedded.value();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isTargetCodegen() {
|
bool isTargetCodegen() const {
|
||||||
assert(IsTargetCodegen.has_value() && "IsTargetCodegen is not set");
|
assert(IsTargetCodegen.has_value() && "IsTargetCodegen is not set");
|
||||||
return IsTargetCodegen.value();
|
return IsTargetCodegen.value();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool hasRequiresUnifiedSharedMemory() {
|
bool hasRequiresUnifiedSharedMemory() const {
|
||||||
assert(HasRequiresUnifiedSharedMemory.has_value() &&
|
assert(HasRequiresUnifiedSharedMemory.has_value() &&
|
||||||
"HasUnifiedSharedMemory is not set");
|
"HasUnifiedSharedMemory is not set");
|
||||||
return HasRequiresUnifiedSharedMemory.value();
|
return HasRequiresUnifiedSharedMemory.value();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns the FirstSeparator if set, otherwise use the default
|
||||||
|
// separator depending on isTargetCodegen
|
||||||
|
StringRef firstSeparator() const {
|
||||||
|
if (FirstSeparator.has_value())
|
||||||
|
return FirstSeparator.value();
|
||||||
|
if (isTargetCodegen())
|
||||||
|
return "_";
|
||||||
|
return ".";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Returns the Separator if set, otherwise use the default
|
||||||
|
// separator depending on isTargetCodegen
|
||||||
|
StringRef separator() const {
|
||||||
|
if (Separator.has_value())
|
||||||
|
return Separator.value();
|
||||||
|
if (isTargetCodegen())
|
||||||
|
return "$";
|
||||||
|
return ".";
|
||||||
|
}
|
||||||
|
|
||||||
void setIsEmbedded(bool Value) { IsEmbedded = Value; }
|
void setIsEmbedded(bool Value) { IsEmbedded = Value; }
|
||||||
void setIsTargetCodegen(bool Value) { IsTargetCodegen = Value; }
|
void setIsTargetCodegen(bool Value) { IsTargetCodegen = Value; }
|
||||||
void setHasRequiresUnifiedSharedMemory(bool Value) {
|
void setHasRequiresUnifiedSharedMemory(bool Value) {
|
||||||
HasRequiresUnifiedSharedMemory = Value;
|
HasRequiresUnifiedSharedMemory = Value;
|
||||||
}
|
}
|
||||||
|
void setFirstSeparator(StringRef FS) { FirstSeparator = FS; }
|
||||||
|
void setSeparator(StringRef S) { Separator = S; }
|
||||||
};
|
};
|
||||||
|
|
||||||
/// An interface to create LLVM-IR for OpenMP directives.
|
/// An interface to create LLVM-IR for OpenMP directives.
|
||||||
|
@ -150,6 +177,16 @@ public:
|
||||||
/// Type used throughout for insertion points.
|
/// Type used throughout for insertion points.
|
||||||
using InsertPointTy = IRBuilder<>::InsertPoint;
|
using InsertPointTy = IRBuilder<>::InsertPoint;
|
||||||
|
|
||||||
|
/// Get the create a name using the platform specific separators.
|
||||||
|
/// \param Parts parts of the final name that needs separation
|
||||||
|
/// The created name has a first separator between the first and second part
|
||||||
|
/// and a second separator between all other parts.
|
||||||
|
/// E.g. with FirstSeparator "$" and Separator "." and
|
||||||
|
/// parts: "p1", "p2", "p3", "p4"
|
||||||
|
/// The resulting name is "p1$p2.p3.p4"
|
||||||
|
/// The separators are retrieved from the OpenMPIRBuilderConfig.
|
||||||
|
std::string createPlatformSpecificName(ArrayRef<StringRef> Parts) const;
|
||||||
|
|
||||||
/// Callback type for variable finalization (think destructors).
|
/// Callback type for variable finalization (think destructors).
|
||||||
///
|
///
|
||||||
/// \param CodeGenIP is the insertion point at which the finalization code
|
/// \param CodeGenIP is the insertion point at which the finalization code
|
||||||
|
|
|
@ -3963,6 +3963,12 @@ std::string OpenMPIRBuilder::getNameWithSeparators(ArrayRef<StringRef> Parts,
|
||||||
return OS.str().str();
|
return OS.str().str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string
|
||||||
|
OpenMPIRBuilder::createPlatformSpecificName(ArrayRef<StringRef> Parts) const {
|
||||||
|
return OpenMPIRBuilder::getNameWithSeparators(Parts, Config.firstSeparator(),
|
||||||
|
Config.separator());
|
||||||
|
}
|
||||||
|
|
||||||
GlobalVariable *
|
GlobalVariable *
|
||||||
OpenMPIRBuilder::getOrCreateInternalVariable(Type *Ty, const StringRef &Name,
|
OpenMPIRBuilder::getOrCreateInternalVariable(Type *Ty, const StringRef &Name,
|
||||||
unsigned AddressSpace) {
|
unsigned AddressSpace) {
|
||||||
|
|
Loading…
Reference in New Issue