[PATCH] D121072: [X86][Experiment] Mangle global variable for inline assembly
Phoebe Wang via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sun Mar 6 06:11:44 PST 2022
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]);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D121072.413296.patch
Type: text/x-patch
Size: 1074 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220306/96d2f561/attachment-0001.bin>
More information about the cfe-commits
mailing list