llvm.org GIT mirror llvm / 12e7467
[LLVM-C] Use Length-Providing Value Name Getters and Setters Summary: - Provide LLVMGetValueName2 and LLVMSetValueName2 that return and take the length of the provided C string respectively - Deprecate LLVMGetValueName and LLVMSetValueName Reviewers: whitequark, deadalnix Reviewed By: whitequark Subscribers: llvm-commits, harlanhaskins Differential Revision: https://reviews.llvm.org/D46890 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@332810 91177308-0d34-0410-b5e6-96231b3b80d8 Robert Widmann 1 year, 4 months ago
3 changed file(s) with 37 addition(s) and 12 deletion(s). Raw diff Collapse all Expand all
14951495 *
14961496 * @see llvm::Value::getName()
14971497 */
1498 const char *LLVMGetValueName(LLVMValueRef Val);
1498 const char *LLVMGetValueName2(LLVMValueRef Val, size_t *Length);
14991499
15001500 /**
15011501 * Set the string name of a value.
15021502 *
15031503 * @see llvm::Value::setName()
15041504 */
1505 void LLVMSetValueName(LLVMValueRef Val, const char *Name);
1505 void LLVMSetValueName2(LLVMValueRef Val, const char *Name, size_t NameLen);
15061506
15071507 /**
15081508 * Dump a representation of a value to stderr.
15531553
15541554 LLVMValueRef LLVMIsAMDNode(LLVMValueRef Val);
15551555 LLVMValueRef LLVMIsAMDString(LLVMValueRef Val);
1556
1557 /** Deprecated: Use LLVMGetValueName2 instead. */
1558 const char *LLVMGetValueName(LLVMValueRef Val);
1559 /** Deprecated: Use LLVMSetValueName2 instead. */
1560 void LLVMSetValueName(LLVMValueRef Val, const char *Name);
15561561
15571562 /**
15581563 * @}
793793 default:
794794 return LLVMInstructionValueKind;
795795 }
796 }
797
798 const char *LLVMGetValueName2(LLVMValueRef Val, size_t *Length) {
799 auto *V = unwrap(Val);
800 *Length = V->getName().size();
801 return V->getName().data();
802 }
803
804 void LLVMSetValueName2(LLVMValueRef Val, const char *Name, size_t NameLen) {
805 unwrap(Val)->setName(StringRef(Name, NameLen));
796806 }
797807
798808 const char *LLVMGetValueName(LLVMValueRef Val) {
173173 LLVMValueRef SrcNext = nullptr;
174174 LLVMValueRef DstNext = nullptr;
175175 while (true) {
176 const char *Name = LLVMGetValueName(SrcCur);
177 LLVMSetValueName(DstCur, Name);
176 size_t NameLen;
177 const char *Name = LLVMGetValueName2(SrcCur, &NameLen);
178 LLVMSetValueName2(DstCur, Name, NameLen);
178179
179180 VMap[SrcCur] = DstCur;
180181
231232
232233 // Maybe it is a symbol
233234 if (LLVMIsAGlobalValue(Cst)) {
234 const char *Name = LLVMGetValueName(Cst);
235 size_t NameLen;
236 const char *Name = LLVMGetValueName2(Cst, &NameLen);
235237
236238 // Try function
237239 if (LLVMIsAFunction(Cst)) {
401403 if (!LLVMIsAInstruction(Src))
402404 report_fatal_error("Expected an instruction");
403405
404 const char *Name = LLVMGetValueName(Src);
406 size_t NameLen;
407 const char *Name = LLVMGetValueName2(Src, &NameLen);
405408
406409 // Check if this is something we already computed.
407410 {
733736 report_fatal_error("Basic block is not a basic block");
734737
735738 const char *Name = LLVMGetBasicBlockName(Src);
736 const char *VName = LLVMGetValueName(V);
739 size_t NameLen;
740 const char *VName = LLVMGetValueName2(V, &NameLen);
737741 if (Name != VName)
738742 report_fatal_error("Basic block name mismatch");
739743
829833 }
830834
831835 while (true) {
832 const char *Name = LLVMGetValueName(Cur);
836 size_t NameLen;
837 const char *Name = LLVMGetValueName2(Cur, &NameLen);
833838 if (LLVMGetNamedGlobal(M, Name))
834839 report_fatal_error("GlobalVariable already cloned");
835840 LLVMAddGlobal(M, LLVMGetElementType(TypeCloner(M).Clone(Cur)), Name);
862867 Cur = Begin;
863868 Next = nullptr;
864869 while (true) {
865 const char *Name = LLVMGetValueName(Cur);
870 size_t NameLen;
871 const char *Name = LLVMGetValueName2(Cur, &NameLen);
866872 if (LLVMGetNamedFunction(M, Name))
867873 report_fatal_error("Function already cloned");
868874 auto Ty = LLVMGetElementType(TypeCloner(M).Clone(Cur));
908914 }
909915
910916 while (true) {
911 const char *Name = LLVMGetValueName(Cur);
917 size_t NameLen;
918 const char *Name = LLVMGetValueName2(Cur, &NameLen);
912919 LLVMValueRef G = LLVMGetNamedGlobal(M, Name);
913920 if (!G)
914921 report_fatal_error("GlobalVariable must have been declared already");
951958 Cur = Begin;
952959 Next = nullptr;
953960 while (true) {
954 const char *Name = LLVMGetValueName(Cur);
961 size_t NameLen;
962 const char *Name = LLVMGetValueName2(Cur, &NameLen);
955963 LLVMValueRef Fun = LLVMGetNamedFunction(M, Name);
956964 if (!Fun)
957965 report_fatal_error("Function must have been declared already");
958966
959967 if (LLVMHasPersonalityFn(Cur)) {
960 const char *FName = LLVMGetValueName(LLVMGetPersonalityFn(Cur));
968 size_t FNameLen;
969 const char *FName = LLVMGetValueName2(LLVMGetPersonalityFn(Cur),
970 &FNameLen);
961971 LLVMValueRef P = LLVMGetNamedFunction(M, FName);
962972 if (!P)
963973 report_fatal_error("Could not find personality function");