[cfe-dev] [CLANG][X86][inline-asm]Clang support for inline assembly MS style

Haroush, Matan via cfe-dev cfe-dev at lists.llvm.org
Mon Dec 12 10:47:52 PST 2016


I do believe this will be the easiest place to implement this feature.

I’ve noticed I can pass the parser to the buildMSAsmString and use the Parser::getActions() member method as a way to access the Sema::lookupInlineAsmIdentifier. However I am still not sure I fully understand how to properly create its parameters and safely use the lookup result (of type ExprResult).

Would appreciate any suggestions or leads on what is the best approach to lookup the identifiers (in order to determine if they are enum constants).
Thanks,
Matan Haroush

From: Reid Kleckner [mailto:rnk at google.com]
Sent: Wednesday, December 07, 2016 19:03
To: Haroush, Matan <matan.haroush at intel.com>
Cc: cfe-dev at lists.llvm.org
Subject: Re: [cfe-dev] [CLANG][X86][inline-asm]Clang support for inline assembly MS style

We should probably rewrite enums in the frontend into integer constants. I guess the fix would live in buildMSAsmString.

2016-12-05 7:38 GMT-08:00 Haroush, Matan via cfe-dev <cfe-dev at lists.llvm.org<mailto:cfe-dev at lists.llvm.org>>:

Hey
I’m working on adding support for inline asm to LLVM.org.
I am trying to determine what is the best place to insert code to enable use of enumerated constants
when using Microsoft style inline asm in a similar fashion to the way macros are used.

EXAMPLE:
########################################################################################################
C code:

int test_inline_asm_enum() {
    enum { A = 12, B};                        // can also be declared globally
                __asm mov ax, A
    return B;
}

Generated LLVM IR:

define i32 @test_inline_asm_enum() #0 {
entry:
call void asm sideeffect inteldialect                                                                          \
"mov ax, qword ptr A",   "~{dirflag},~{fpsr},~{flags}"() #1, !srcloc !1
ret i32 13
}

COMPILE LINE:

Clang -cc1 -fasm-blocks -O0 -emit-llvm <codefile.c> -o -

* without –emit-llvm flag the compiler will crash as it tries to handles A like a variable.
** note the absence of an allocation of A before the function call, this is because enums are
not emitted to IR but treated as integer constants.

########################################################################################################

After some investigation I narrowed the scope to two locations in clang which are reasonable candidates:

1.       buildMsAsmString – where macros are handled

2.       asmParser/X86 AsmParser which handles the assembly semantics and emits the IR.


My main issue though is to determine if the token/identifier belongs to an EnumConstDecl/Expr.
I’ve noticed the code in this area uses a lookup method which is called via parser->semaCallback.
However I don’t really understand yet how to create an instance of such a handler in order to lookup
previously declared labels(particularly EnumConstantDecls).

I was hoping that someone may have some insight to share regarding the problem or on lookup usage in general.
Please let me know if you need any clarifications and feel free to contact me via mail.
Thanks,

Matan Haroush


---------------------------------------------------------------------
Intel Israel (74) Limited

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.

_______________________________________________
cfe-dev mailing list
cfe-dev at lists.llvm.org<mailto:cfe-dev at lists.llvm.org>
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

---------------------------------------------------------------------
Intel Israel (74) Limited

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20161212/bce423cb/attachment.html>


More information about the cfe-dev mailing list