Skip to content

Commit 943ba68

Browse files
committed
Variable renaming only (Alias -> Clone)
1 parent 8d5d2e1 commit 943ba68

File tree

1 file changed

+56
-57
lines changed

1 file changed

+56
-57
lines changed

libclc/utils/libclc-remangler/LibclcRemangler.cpp

Lines changed: 56 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,28 @@
1111
// `unsigned long`, and `char` to appear as if they use `long long`,
1212
// `unsigned long long`, and `signed char`, as is consistent with the primitive
1313
// types defined by OpenCL C. Following a remangling, the original function
14-
// mangling will be made an alias to either the remangled function or a function
15-
// with a suitable function if any exists. In some cases an alias of the
16-
// remangled function is created for functions where multiple parameters have
17-
// been replaced, and the replaced values are aliases.
14+
// mangling will be built as a clone of either the remangled function or a
15+
// function with a suitable function if any exists. In some cases a clone of
16+
// the remangled function is created for functions where multiple parameters
17+
// have been replaced, and the replaced values are aliases.
1818
//
19-
// Original Alias Example:
19+
// Original Clone Example:
2020
// If libclc defined a function `f(long)` the mangled name would be
2121
// `_Z1fl`. The remangler would rename this function to `_Z1fx`
22-
// (`f(long long)`.) If the target uses 64-bit `long`, `_Z1fl` is made
23-
// an alias to the old function now under the name `_Z1fx`, whereas if
24-
// the target uses 32-bit `long`, `_Z1fl` is made an alias to `_Z1fi`
22+
// (`f(long long)`.) If the target uses 64-bit `long`, `_Z1fl` is
23+
// cloned from the old function now under the name `_Z1fx`, whereas if
24+
// the target uses 32-bit `long`, `_Z1fl` is cloned from `_Z1fi`
2525
// (`f(int)`) if such a function exists.
2626
//
27-
// Remangled Alias Example:
27+
// Remangled Clone Example:
2828
// In cases where the remangled name squashes valid versions of a
29-
// function an alias is created. `f(long, char, signed char)` would be
29+
// function a clone is created. `f(long, char, signed char)` would be
3030
// mangled to
3131
// `_Z1flca`. The remangler would rename this function to `_Z1fyaa`
3232
// (`f(long long, signed char, signed char)`). If the target uses a
33-
// signed char then a valid alias `_Z1fyca`,
33+
// signed char then a valid clone `_Z1fyca`,
3434
// (`f(long long, char, signed char)`), is not defined. The remangler
35-
// creates an alias of the renamed function,`_Z1fyaa` , to this
35+
// creates a clone of the renamed function,`_Z1fyaa` , to this
3636
// permutation, `_Z1fyca`.
3737
//
3838
//===----------------------------------------------------------------------===//
@@ -480,19 +480,19 @@ class Remangler {
480480

481481
class TargetTypeReplacements {
482482
SmallDenseMap<const char *, const char *> ParameterTypeReplacements;
483-
SmallDenseMap<const char *, const char *> AliasTypeReplacements;
484-
SmallDenseMap<const char *, const char *> RemangledAliasTypeReplacements;
483+
SmallDenseMap<const char *, const char *> CloneTypeReplacements;
484+
SmallDenseMap<const char *, const char *> RemangledCloneTypeReplacements;
485485

486486
void CreateRemangledTypeReplacements() {
487487
// RemangleTypes which are not aliases or not the exact same alias type
488488
for (auto &TypeReplacementPair : ParameterTypeReplacements)
489-
if (AliasTypeReplacements.find(TypeReplacementPair.getFirst()) ==
490-
AliasTypeReplacements.end())
491-
RemangledAliasTypeReplacements[TypeReplacementPair.getFirst()] =
489+
if (CloneTypeReplacements.find(TypeReplacementPair.getFirst()) ==
490+
CloneTypeReplacements.end())
491+
RemangledCloneTypeReplacements[TypeReplacementPair.getFirst()] =
492492
TypeReplacementPair.getSecond();
493-
else if (AliasTypeReplacements[TypeReplacementPair.getFirst()] !=
493+
else if (CloneTypeReplacements[TypeReplacementPair.getFirst()] !=
494494
TypeReplacementPair.getSecond())
495-
RemangledAliasTypeReplacements[TypeReplacementPair.getFirst()] =
495+
RemangledCloneTypeReplacements[TypeReplacementPair.getFirst()] =
496496
TypeReplacementPair.getSecond();
497497
}
498498

@@ -505,22 +505,22 @@ class TargetTypeReplacements {
505505
// Replace char with signed char
506506
ParameterTypeReplacements["char"] = "signed char";
507507

508-
// Make replaced long functions aliases to either integer or long long
508+
// Make replaced long functions clones of either integer or long long
509509
// variant
510510
if (LongWidth == SupportedLongWidth::L32) {
511-
AliasTypeReplacements["long"] = "int";
512-
AliasTypeReplacements["unsigned long"] = "unsigned int";
511+
CloneTypeReplacements["long"] = "int";
512+
CloneTypeReplacements["unsigned long"] = "unsigned int";
513513
} else {
514-
AliasTypeReplacements["long"] = "long long";
515-
AliasTypeReplacements["unsigned long"] = "unsigned long long";
514+
CloneTypeReplacements["long"] = "long long";
515+
CloneTypeReplacements["unsigned long"] = "unsigned long long";
516516
}
517517

518-
// Make replaced char functions aliases to either integer or long long
518+
// Make replaced char functions clones of either integer or long long
519519
// variant
520520
if (CharSignedness == Signedness::Signed) {
521-
AliasTypeReplacements["char"] = "signed char";
521+
CloneTypeReplacements["char"] = "signed char";
522522
} else {
523-
AliasTypeReplacements["char"] = "unsigned char";
523+
CloneTypeReplacements["char"] = "unsigned char";
524524
}
525525

526526
CreateRemangledTypeReplacements();
@@ -530,21 +530,21 @@ class TargetTypeReplacements {
530530
return ParameterTypeReplacements;
531531
}
532532

533-
SmallDenseMap<const char *, const char *> getAliasTypeReplacements() {
534-
return AliasTypeReplacements;
533+
SmallDenseMap<const char *, const char *> getCloneTypeReplacements() {
534+
return CloneTypeReplacements;
535535
}
536536

537537
SmallDenseMap<const char *, const char *>
538-
getRemangledAliasTypeReplacements() {
539-
return RemangledAliasTypeReplacements;
538+
getRemangledCloneTypeReplacements() {
539+
return RemangledCloneTypeReplacements;
540540
}
541541
};
542542

543-
bool createAliasFromMap(
543+
bool createCloneFromMap(
544544
Module *M, std::string originalName,
545545
const itanium_demangle::Node *functionTree,
546546
SmallDenseMap<const char *, const char *> TypeReplacements,
547-
bool AliaseeTypeReplacement = false) {
547+
bool CloneeTypeReplacement = false) {
548548
Remangler ATR{functionTree, TypeReplacements};
549549
std::string RemangledName = ATR.remangle();
550550

@@ -555,42 +555,41 @@ bool createAliasFromMap(
555555
if (RemangledName == originalName)
556556
return true;
557557

558-
StringRef AliasName, AliaseeName;
559-
if (AliaseeTypeReplacement) {
560-
AliasName = originalName;
561-
AliaseeName = RemangledName;
558+
StringRef CloneName, CloneeName;
559+
if (CloneeTypeReplacement) {
560+
CloneName = originalName;
561+
CloneeName = RemangledName;
562562
} else {
563-
AliasName = RemangledName;
564-
AliaseeName = originalName;
563+
CloneName = RemangledName;
564+
CloneeName = originalName;
565565
}
566566

567-
Function *Aliasee = M->getFunction(AliaseeName);
568-
if (Aliasee) {
569-
// TODO - rename 'alias*' to 'clone*'
567+
Function *Clonee = M->getFunction(CloneeName);
568+
if (Clonee) {
570569
ValueToValueMapTy Dummy;
571-
Function *NewF = CloneFunction(Aliasee, Dummy);
572-
NewF->setName(std::string(AliasName));
570+
Function *NewF = CloneFunction(Clonee, Dummy);
571+
NewF->setName(std::string(CloneName));
573572
} else if (Verbose) {
574-
std::cout << "Could not create copy " << AliasName.data() << " : missing "
575-
<< AliaseeName.data() << std::endl;
573+
std::cout << "Could not create copy " << CloneName.data() << " : missing "
574+
<< CloneeName.data() << std::endl;
576575
}
577576

578577
return true;
579578
}
580579

581-
bool createAliases(Module *M, std::string originalMangledName,
580+
bool createClones(Module *M, std::string originalMangledName,
582581
std::string remangledName,
583582
const itanium_demangle::Node *functionTree,
584583
TargetTypeReplacements replacements) {
585-
// create alias of original function
586-
if (!createAliasFromMap(M, originalMangledName, functionTree,
587-
replacements.getAliasTypeReplacements(),
588-
/* AliaseeTypeReplacement= */ true))
584+
// create clone of original function
585+
if (!createCloneFromMap(M, originalMangledName, functionTree,
586+
replacements.getCloneTypeReplacements(),
587+
/* CloneeTypeReplacement= */ true))
589588
return false;
590589

591-
// create alias from remangled function
592-
if (!createAliasFromMap(M, remangledName, functionTree,
593-
replacements.getRemangledAliasTypeReplacements()))
590+
// create clone of remangled function
591+
if (!createCloneFromMap(M, remangledName, functionTree,
592+
replacements.getRemangledCloneTypeReplacements()))
594593
return false;
595594

596595
return true;
@@ -626,9 +625,9 @@ bool remangleFunction(Function &func, Module *M,
626625
}
627626
func.setName(RemangledName);
628627

629-
// Make an alias to a suitable function using the old name if there is a
630-
// type-mapping and the corresponding aliasee function exists.
631-
if (!createAliases(M, MangledName, RemangledName, FunctionTree,
628+
// Make a clone of a suitable function using the old name if there is a
629+
// type-mapping and the corresponding clonee function exists.
630+
if (!createClones(M, MangledName, RemangledName, FunctionTree,
632631
replacements))
633632
return false;
634633
}

0 commit comments

Comments
 (0)