pengfei created this revision. Herald added a project: All. pengfei requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
This is an experiment inspired by @efriedma 's suggestion on D120887 <https://reviews.llvm.org/D120887>. It seems a more concise way to solve Xiang's problem. There're some lit failures which I didn't care for now. I can fix them if we think this is a good approch. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D121072 Files: clang/lib/CodeGen/CGStmt.cpp Index: clang/lib/CodeGen/CGStmt.cpp =================================================================== --- clang/lib/CodeGen/CGStmt.cpp +++ clang/lib/CodeGen/CGStmt.cpp @@ -31,6 +31,7 @@ #include "llvm/IR/InlineAsm.h" #include "llvm/IR/Intrinsics.h" #include "llvm/IR/MDBuilder.h" +#include "llvm/IR/Mangler.h" #include "llvm/Support/SaveAndRestore.h" using namespace clang; @@ -2544,6 +2545,19 @@ Constraints += InputConstraint; } + // Replace global value to its name. + if (isa<MSAsmStmt>(&S)) { + for (int I = 0, E = Args.size(); I != E; ++I) { + if (auto *GV = dyn_cast<llvm::GlobalValue>(Args[I])) { + llvm::Mangler M; + SmallString<256> MangleName; + M.getNameWithPrefix(MangleName, GV, /*CannotUsePrivateLabel=*/true); + AsmString.replace(AsmString.find("$" + std::to_string(I)), 2, + MangleName.c_str()); + } + } + } + // Append the "input" part of inout constraints. for (unsigned i = 0, e = InOutArgs.size(); i != e; i++) { ArgTypes.push_back(InOutArgTypes[i]);
Index: clang/lib/CodeGen/CGStmt.cpp =================================================================== --- clang/lib/CodeGen/CGStmt.cpp +++ clang/lib/CodeGen/CGStmt.cpp @@ -31,6 +31,7 @@ #include "llvm/IR/InlineAsm.h" #include "llvm/IR/Intrinsics.h" #include "llvm/IR/MDBuilder.h" +#include "llvm/IR/Mangler.h" #include "llvm/Support/SaveAndRestore.h" using namespace clang; @@ -2544,6 +2545,19 @@ Constraints += InputConstraint; } + // Replace global value to its name. + if (isa<MSAsmStmt>(&S)) { + for (int I = 0, E = Args.size(); I != E; ++I) { + if (auto *GV = dyn_cast<llvm::GlobalValue>(Args[I])) { + llvm::Mangler M; + SmallString<256> MangleName; + M.getNameWithPrefix(MangleName, GV, /*CannotUsePrivateLabel=*/true); + AsmString.replace(AsmString.find("$" + std::to_string(I)), 2, + MangleName.c_str()); + } + } + } + // Append the "input" part of inout constraints. for (unsigned i = 0, e = InOutArgs.size(); i != e; i++) { ArgTypes.push_back(InOutArgTypes[i]);
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits