21 AsmFlavor gnuAsmFlavor =
24 : AsmFlavor::x86_intel;
26 return isa<MSAsmStmt>(&
s) ? AsmFlavor::x86_intel : gnuAsmFlavor;
30 std::string &constraints,
bool &hasUnwindClobber,
31 bool &readOnly,
bool readNone) {
33 hasUnwindClobber =
false;
37 for (
unsigned i = 0, e =
s.getNumClobbers(); i != e; i++) {
38 std::string clobber =
s.getClobber(i);
39 if (clobber ==
"memory") {
40 readOnly = readNone =
false;
41 }
else if (clobber ==
"unwind") {
42 hasUnwindClobber =
true;
44 }
else if (clobber !=
"cc") {
49 diag::warn_stack_clash_protection_inline_asm);
52 if (isa<MSAsmStmt>(&
s)) {
53 if (clobber ==
"eax" || clobber ==
"edx") {
54 if (constraints.find(
"=&A") != std::string::npos)
56 std::string::size_type position1 =
57 constraints.find(
"={" + clobber +
"}");
58 if (position1 != std::string::npos) {
59 constraints.insert(position1 + 1,
"&");
62 std::string::size_type position2 = constraints.find(
"=A");
63 if (position2 != std::string::npos) {
64 constraints.insert(position2 + 1,
"&");
69 if (!constraints.empty())
73 constraints += clobber;
79 if (!machineClobbers.empty()) {
80 if (!constraints.empty())
82 constraints += machineClobbers;
88 std::string asmString =
s.generateAsmString(
getContext());
90 bool isGCCAsmGoto =
false;
92 std::string constraints;
93 std::vector<mlir::Value> outArgs;
94 std::vector<mlir::Value> inArgs;
95 std::vector<mlir::Value> inOutArgs;
103 bool readOnly =
true, readNone =
true;
105 if (
s.getNumInputs() != 0 ||
s.getNumOutputs() != 0) {
111 bool hasUnwindClobber =
false;
112 collectClobbers(*
this,
s, constraints, hasUnwindClobber, readOnly, readNone);
114 std::array<mlir::ValueRange, 3> operands = {outArgs, inArgs, inOutArgs};
116 mlir::Type resultType;
118 bool hasSideEffect =
s.isVolatile() ||
s.getNumOutputs() == 0;
120 cir::InlineAsmOp ia = builder.create<cir::InlineAsmOp>(
121 getLoc(
s.getAsmLoc()), resultType, operands, asmString, constraints,
126 }
else if (hasUnwindClobber) {
133 ia.setOperandAttrsAttr(builder.getArrayAttr(operandAttrs));
135 return mlir::success();
static AsmFlavor inferFlavor(const CIRGenModule &cgm, const AsmStmt &s)
static void collectClobbers(const CIRGenFunction &cgf, const AsmStmt &s, std::string &constraints, bool &hasUnwindClobber, bool &readOnly, bool readNone)
__device__ __2f16 float __ockl_bool s
AsmStmt is the base class for GCCAsmStmt and MSAsmStmt.
const TargetInfo & getTarget() const
mlir::Location getLoc(clang::SourceLocation srcLoc)
Helpers to convert Clang's SourceLocation to a MLIR Location.
mlir::LogicalResult emitAsmStmt(const clang::AsmStmt &s)
CIRGenModule & getCIRGenModule()
clang::ASTContext & getContext() const
This class organizes the cross-function state that is used while generating CIR code.
DiagnosticBuilder errorNYI(SourceLocation, llvm::StringRef)
Helpers to emit "not yet implemented" error diagnostics.
clang::DiagnosticsEngine & getDiags() const
const clang::CodeGenOptions & getCodeGenOpts() const
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
StringRef getNormalizedGCCRegisterName(StringRef Name, bool ReturnCanonical=false) const
Returns the "normalized" GCC register name.
virtual std::string_view getClobbers() const =0
Returns a string of target-specific clobbers, in LLVM format.
virtual bool isSPRegName(StringRef) const
The JSON file list parser is used to communicate input to InstallAPI.
static bool asmMemoryEffects()
static bool asmOutputOperands()
static bool asmInputOperands()
static bool asmUnwindClobber()