================
@@ -0,0 +1,384 @@
+//===-- InlineAsmPrepare - Prepare inline asm for code generation 
---------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This pass prepares inline assembly for code generation with the fast 
register
+// allocator---e.g., by converting "rm" (register-or-memory) constraints to "m"
+// (memory-only) constraints, simplifying register allocation by forcing
+// operands to memory locations, avoiding the complexity of handling dual
+// register/memory options. The other register allocators are equipped to
+// handle folding registers all ready.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/CodeGen/InlineAsmPrepare.h"
+#include "llvm/CodeGen/Passes.h"
+#include "llvm/IR/DerivedTypes.h"
+#include "llvm/IR/Function.h"
+#include "llvm/IR/IRBuilder.h"
+#include "llvm/IR/InlineAsm.h"
+#include "llvm/IR/Instructions.h"
+#include "llvm/IR/Module.h"
+#include "llvm/InitializePasses.h"
+#include "llvm/Pass.h"
+#include <sstream>
+
+using namespace llvm;
+
+#define DEBUG_TYPE "inline-asm-prepare"
+
+namespace {
+
+class InlineAsmPrepare : public FunctionPass {
+  InlineAsmPrepare(InlineAsmPrepare &) = delete;
+
+public:
+  InlineAsmPrepare() : FunctionPass(ID) {}
+
+  void getAnalysisUsage(AnalysisUsage &AU) const override {
+    AU.setPreservesCFG();
+  }
+  bool runOnFunction(Function &F) override;
+
+  static char ID;
+};
+
+char InlineAsmPrepare::ID = 0;
+
+} // end anonymous namespace
+
+INITIALIZE_PASS(InlineAsmPrepare, DEBUG_TYPE,
+                "Prepare inline asm insts for fast register allocation", false,
+                false)
+FunctionPass *llvm::createInlineAsmPass() { return new InlineAsmPrepare(); }
+
+/// Find all inline assembly calls in the given function.
+static SmallVector<CallBase *, 4> findInlineAsms(Function &F) {
+  SmallVector<CallBase *, 4> InlineAsms;
+
+  for (BasicBlock &BB : F)
+    for (Instruction &I : BB)
+      if (CallBase *CB = dyn_cast<CallBase>(&I); CB && CB->isInlineAsm())
+        InlineAsms.push_back(CB);
+
+  return InlineAsms;
+}
+
+static bool isRegMemConstraint(StringRef Constraint) {
+  return Constraint.size() == 2 && (Constraint == "rm" || Constraint == "mr");
+}
+
+/// Convert instances of the "rm" constraints into "m".
+static std::pair<std::string, bool>
+convertConstraintsToMemory(StringRef ConstraintStr) {
+  auto I = ConstraintStr.begin(), E = ConstraintStr.end();
+  std::ostringstream Out;
----------------
nikic wrote:

Use raw_string_ostream.

https://github.com/llvm/llvm-project/pull/92040
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to