[llvm-commits] [llvm] r84020 - in /llvm/trunk: include/llvm/InlineAsm.h lib/AsmParser/LLLexer.cpp lib/AsmParser/LLParser.cpp lib/AsmParser/LLToken.h lib/Bitcode/Reader/BitcodeReader.cpp lib/Bitcode/Writer/BitcodeWriter.cpp lib/VMCore/AsmWriter.cpp lib/VMCore/Core.cpp lib/VMCore/InlineAsm.cpp test/Assembler/msasm.ll

Chris Lattner clattner at apple.com
Tue Oct 13 18:11:40 PDT 2009


On Oct 13, 2009, at 1:46 PM, Dale Johannesen wrote:

> Author: johannes
> Date: Tue Oct 13 15:46:56 2009
> New Revision: 84020
>
> URL: http://llvm.org/viewvc/llvm-project?rev=84020&view=rev
> Log:
> Add an "msasm" flag to inline asm as suggested in PR 5125.
> A little ugliness is accepted to keep the binary file format
> compatible.  No functional change yet.

Hi Dale,

In general I think that this is a great approach.  One concern I have  
is that "is ms asm" doesn't tell me what the flag does.  Would it be  
possible to name this something like "might be call" or something that  
more accurately conveys the semantic effect of this?  I'd much prefer  
LangRef to have a concrete description of what it does (like volatile)  
instead of saying "originally from an asm block" which doesn't  
communicate what it does or when someone would want to set it.

-Chris

>
>
> Added:
>    llvm/trunk/test/Assembler/msasm.ll
> Modified:
>    llvm/trunk/include/llvm/InlineAsm.h
>    llvm/trunk/lib/AsmParser/LLLexer.cpp
>    llvm/trunk/lib/AsmParser/LLParser.cpp
>    llvm/trunk/lib/AsmParser/LLToken.h
>    llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
>    llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp
>    llvm/trunk/lib/VMCore/AsmWriter.cpp
>    llvm/trunk/lib/VMCore/Core.cpp
>    llvm/trunk/lib/VMCore/InlineAsm.cpp
>
> Modified: llvm/trunk/include/llvm/InlineAsm.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/InlineAsm.h?rev=84020&r1=84019&r2=84020&view=diff
>
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- llvm/trunk/include/llvm/InlineAsm.h (original)
> +++ llvm/trunk/include/llvm/InlineAsm.h Tue Oct 13 15:46:56 2009
> @@ -31,18 +31,22 @@
>
>   std::string AsmString, Constraints;
>   bool HasSideEffects;
> +  bool IsMsAsm;
>
>   InlineAsm(const FunctionType *Ty, const StringRef &AsmString,
> -            const StringRef &Constraints, bool hasSideEffects);
> +            const StringRef &Constraints, bool hasSideEffects,
> +            bool isMsAsm = false);
>   virtual ~InlineAsm();
> public:
>
>   /// InlineAsm::get - Return the the specified uniqued inline asm  
> string.
>   ///
>   static InlineAsm *get(const FunctionType *Ty, const StringRef  
> &AsmString,
> -                        const StringRef &Constraints, bool  
> hasSideEffects);
> +                        const StringRef &Constraints, bool  
> hasSideEffects,
> +                        bool isMsAsm = false);
>
>   bool hasSideEffects() const { return HasSideEffects; }
> +  bool isMsAsm() const { return IsMsAsm; }
>
>   /// getType - InlineAsm's are always pointers.
>   ///
>
> Modified: llvm/trunk/lib/AsmParser/LLLexer.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLLexer.cpp?rev=84020&r1=84019&r2=84020&view=diff
>
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- llvm/trunk/lib/AsmParser/LLLexer.cpp (original)
> +++ llvm/trunk/lib/AsmParser/LLLexer.cpp Tue Oct 13 15:46:56 2009
> @@ -529,6 +529,7 @@
>   KEYWORD(module);
>   KEYWORD(asm);
>   KEYWORD(sideeffect);
> +  KEYWORD(msasm);
>   KEYWORD(gc);
>
>   KEYWORD(ccc);
>
> Modified: llvm/trunk/lib/AsmParser/LLParser.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLParser.cpp?rev=84020&r1=84019&r2=84020&view=diff
>
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- llvm/trunk/lib/AsmParser/LLParser.cpp (original)
> +++ llvm/trunk/lib/AsmParser/LLParser.cpp Tue Oct 13 15:46:56 2009
> @@ -1959,16 +1959,17 @@
>     return false;
>
>   case lltok::kw_asm: {
> -    // ValID ::= 'asm' SideEffect? STRINGCONSTANT ',' STRINGCONSTANT
> -    bool HasSideEffect;
> +    // ValID ::= 'asm' SideEffect? MsAsm? STRINGCONSTANT ','  
> STRINGCONSTANT
> +    bool HasSideEffect, MsAsm;
>     Lex.Lex();
>     if (ParseOptionalToken(lltok::kw_sideeffect, HasSideEffect) ||
> +        ParseOptionalToken(lltok::kw_msasm, MsAsm) ||
>         ParseStringConstant(ID.StrVal) ||
>         ParseToken(lltok::comma, "expected comma in inline asm  
> expression") ||
>         ParseToken(lltok::StringConstant, "expected constraint  
> string"))
>       return true;
>     ID.StrVal2 = Lex.getStrVal();
> -    ID.UIntVal = HasSideEffect;
> +    ID.UIntVal = HasSideEffect | ((unsigned)MsAsm<<1);
>     ID.Kind = ValID::t_InlineAsm;
>     return false;
>   }
> @@ -2368,7 +2369,7 @@
>       PTy ? dyn_cast<FunctionType>(PTy->getElementType()) : 0;
>     if (!FTy || !InlineAsm::Verify(FTy, ID.StrVal2))
>       return Error(ID.Loc, "invalid type for inline asm constraint  
> string");
> -    V = InlineAsm::get(FTy, ID.StrVal, ID.StrVal2, ID.UIntVal);
> +    V = InlineAsm::get(FTy, ID.StrVal, ID.StrVal2, ID.UIntVal&1,  
> ID.UIntVal>>1);
>     return false;
>   } else if (ID.Kind == ValID::t_Metadata) {
>     V = ID.MetadataVal;
>
> Modified: llvm/trunk/lib/AsmParser/LLToken.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLToken.h?rev=84020&r1=84019&r2=84020&view=diff
>
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- llvm/trunk/lib/AsmParser/LLToken.h (original)
> +++ llvm/trunk/lib/AsmParser/LLToken.h Tue Oct 13 15:46:56 2009
> @@ -62,6 +62,7 @@
>     kw_module,
>     kw_asm,
>     kw_sideeffect,
> +    kw_msasm,
>     kw_gc,
>     kw_dbg,
>     kw_c,
>
> Modified: llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp?rev=84020&r1=84019&r2=84020&view=diff
>
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp (original)
> +++ llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp Tue Oct 13  
> 15:46:56 2009
> @@ -1164,7 +1164,8 @@
>     case bitc::CST_CODE_INLINEASM: {
>       if (Record.size() < 2) return Error("Invalid INLINEASM record");
>       std::string AsmStr, ConstrStr;
> -      bool HasSideEffects = Record[0];
> +      bool HasSideEffects = Record[0] & 1;
> +      bool IsMsAsm = Record[0] >> 1;
>       unsigned AsmStrSize = Record[1];
>       if (2+AsmStrSize >= Record.size())
>         return Error("Invalid INLINEASM record");
> @@ -1178,7 +1179,7 @@
>         ConstrStr += (char)Record[3+AsmStrSize+i];
>       const PointerType *PTy = cast<PointerType>(CurTy);
>       V = InlineAsm::get(cast<FunctionType>(PTy->getElementType()),
> -                         AsmStr, ConstrStr, HasSideEffects);
> +                         AsmStr, ConstrStr, HasSideEffects, IsMsAsm);
>       break;
>     }
>     }
>
> Modified: llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp?rev=84020&r1=84019&r2=84020&view=diff
>
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp (original)
> +++ llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp Tue Oct 13  
> 15:46:56 2009
> @@ -679,7 +679,8 @@
>     }
>
>     if (const InlineAsm *IA = dyn_cast<InlineAsm>(V)) {
> -      Record.push_back(unsigned(IA->hasSideEffects()));
> +      Record.push_back(unsigned(IA->hasSideEffects()) |
> +                       unsigned(IA->isMsAsm()) << 1);
>
>       // Add the asm string.
>       const std::string &AsmStr = IA->getAsmString();
>
> Modified: llvm/trunk/lib/VMCore/AsmWriter.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/AsmWriter.cpp?rev=84020&r1=84019&r2=84020&view=diff
>
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- llvm/trunk/lib/VMCore/AsmWriter.cpp (original)
> +++ llvm/trunk/lib/VMCore/AsmWriter.cpp Tue Oct 13 15:46:56 2009
> @@ -1206,6 +1206,8 @@
>     Out << "asm ";
>     if (IA->hasSideEffects())
>       Out << "sideeffect ";
> +    if (IA->isMsAsm())
> +      Out << "msasm ";
>     Out << '"';
>     PrintEscapedString(IA->getAsmString(), Out);
>     Out << "\", \"";
>
> Modified: llvm/trunk/lib/VMCore/Core.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Core.cpp?rev=84020&r1=84019&r2=84020&view=diff
>
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- llvm/trunk/lib/VMCore/Core.cpp (original)
> +++ llvm/trunk/lib/VMCore/Core.cpp Tue Oct 13 15:46:56 2009
> @@ -884,9 +884,10 @@
> }
>
> LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty, const char *AsmString,
> -                                const char *Constraints, int  
> HasSideEffects) {
> +                                const char *Constraints, int  
> HasSideEffects,
> +                                int IsMsAsm) {
>   return wrap(InlineAsm::get(dyn_cast<FunctionType>(unwrap(Ty)),  
> AsmString,
> -                             Constraints, HasSideEffects));
> +                             Constraints, HasSideEffects, IsMsAsm));
> }
>
> /*--.. Operations on global variables, functions, and aliases  
> (globals) ....--*/
>
> Modified: llvm/trunk/lib/VMCore/InlineAsm.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/InlineAsm.cpp?rev=84020&r1=84019&r2=84020&view=diff
>
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- llvm/trunk/lib/VMCore/InlineAsm.cpp (original)
> +++ llvm/trunk/lib/VMCore/InlineAsm.cpp Tue Oct 13 15:46:56 2009
> @@ -27,17 +27,19 @@
> // case when the type gets refined.
>
> InlineAsm *InlineAsm::get(const FunctionType *Ty, const StringRef  
> &AsmString,
> -                          const StringRef &Constraints, bool  
> hasSideEffects) {
> +                          const StringRef &Constraints, bool  
> hasSideEffects,
> +                          bool isMsAsm) {
>   // FIXME: memoize!
> -  return new InlineAsm(Ty, AsmString, Constraints, hasSideEffects);
> +  return new InlineAsm(Ty, AsmString, Constraints, hasSideEffects,  
> isMsAsm);
> }
>
> InlineAsm::InlineAsm(const FunctionType *Ty, const StringRef  
> &asmString,
> -                     const StringRef &constraints, bool  
> hasSideEffects)
> +                     const StringRef &constraints, bool  
> hasSideEffects,
> +                     bool isMsAsm)
>   : Value(PointerType::getUnqual(Ty),
>           Value::InlineAsmVal),
>     AsmString(asmString),
> -    Constraints(constraints), HasSideEffects(hasSideEffects) {
> +    Constraints(constraints), HasSideEffects(hasSideEffects),  
> IsMsAsm(isMsAsm) {
>
>   // Do various checks on the constraint string and type.
>   assert(Verify(Ty, constraints) && "Function type not legal for  
> constraints!");
>
> Added: llvm/trunk/test/Assembler/msasm.ll
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/msasm.ll?rev=84020&view=auto
>
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- llvm/trunk/test/Assembler/msasm.ll (added)
> +++ llvm/trunk/test/Assembler/msasm.ll Tue Oct 13 15:46:56 2009
> @@ -0,0 +1,36 @@
> +; RUN: llvm-as < %s | llvm-dis | FileCheck %s
> +target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32- 
> i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64- 
> f80:128:128"
> +target triple = "i386-apple-darwin10.0"
> +
> +define void @test1() nounwind {
> +; CHECK: test1
> +; CHECK: sideeffect
> +; CHECK-NOT: msasm
> +	tail call void asm sideeffect "mov",  
> "~{dirflag},~{fpsr},~{flags}"() nounwind
> +	ret void
> +; CHECK: ret
> +}
> +define void @test2() nounwind {
> +; CHECK: test2
> +; CHECK: sideeffect
> +; CHECK: msasm
> +	tail call void asm sideeffect msasm "mov",  
> "~{dirflag},~{fpsr},~{flags}"() nounwind
> +	ret void
> +; CHECK: ret
> +}
> +define void @test3() nounwind {
> +; CHECK: test3
> +; CHECK-NOT: sideeffect
> +; CHECK: msasm
> +	tail call void asm msasm "mov", "~{dirflag},~{fpsr},~{flags}"()  
> nounwind
> +	ret void
> +; CHECK: ret
> +}
> +define void @test4() nounwind {
> +; CHECK: test4
> +; CHECK-NOT: sideeffect
> +; CHECK-NOT: msasm
> +	tail call void asm  "mov", "~{dirflag},~{fpsr},~{flags}"() nounwind
> +	ret void
> +; CHECK: ret
> +}
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits




More information about the llvm-commits mailing list