diff options
author | Dale Johannesen <dalej@apple.com> | 2009-10-13 20:46:56 +0000 |
---|---|---|
committer | Dale Johannesen <dalej@apple.com> | 2009-10-13 20:46:56 +0000 |
commit | 4360298d2bf3c1ba8595a415cfa235df0bc76335 (patch) | |
tree | d8ccc1e4677e43ef3420c6a3a18007298a866a3e | |
parent | 9578c7aad61935364b28677f19e330b621016148 (diff) | |
download | external_llvm-4360298d2bf3c1ba8595a415cfa235df0bc76335.zip external_llvm-4360298d2bf3c1ba8595a415cfa235df0bc76335.tar.gz external_llvm-4360298d2bf3c1ba8595a415cfa235df0bc76335.tar.bz2 |
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.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@84020 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/llvm/InlineAsm.h | 8 | ||||
-rw-r--r-- | lib/AsmParser/LLLexer.cpp | 1 | ||||
-rw-r--r-- | lib/AsmParser/LLParser.cpp | 9 | ||||
-rw-r--r-- | lib/AsmParser/LLToken.h | 1 | ||||
-rw-r--r-- | lib/Bitcode/Reader/BitcodeReader.cpp | 5 | ||||
-rw-r--r-- | lib/Bitcode/Writer/BitcodeWriter.cpp | 3 | ||||
-rw-r--r-- | lib/VMCore/AsmWriter.cpp | 2 | ||||
-rw-r--r-- | lib/VMCore/Core.cpp | 5 | ||||
-rw-r--r-- | lib/VMCore/InlineAsm.cpp | 10 | ||||
-rw-r--r-- | test/Assembler/msasm.ll | 36 |
10 files changed, 65 insertions, 15 deletions
diff --git a/include/llvm/InlineAsm.h b/include/llvm/InlineAsm.h index e0d992b..bc55031 100644 --- a/include/llvm/InlineAsm.h +++ b/include/llvm/InlineAsm.h @@ -31,18 +31,22 @@ class InlineAsm : public Value { 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. /// diff --git a/lib/AsmParser/LLLexer.cpp b/lib/AsmParser/LLLexer.cpp index 16e0bd7..0e9f1a0 100644 --- a/lib/AsmParser/LLLexer.cpp +++ b/lib/AsmParser/LLLexer.cpp @@ -529,6 +529,7 @@ lltok::Kind LLLexer::LexIdentifier() { KEYWORD(module); KEYWORD(asm); KEYWORD(sideeffect); + KEYWORD(msasm); KEYWORD(gc); KEYWORD(ccc); diff --git a/lib/AsmParser/LLParser.cpp b/lib/AsmParser/LLParser.cpp index a1186ac..09bc5f7 100644 --- a/lib/AsmParser/LLParser.cpp +++ b/lib/AsmParser/LLParser.cpp @@ -1959,16 +1959,17 @@ bool LLParser::ParseValID(ValID &ID) { 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 @@ bool LLParser::ConvertValIDToValue(const Type *Ty, ValID &ID, Value *&V, 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; diff --git a/lib/AsmParser/LLToken.h b/lib/AsmParser/LLToken.h index bfcb58e..b3c59ee 100644 --- a/lib/AsmParser/LLToken.h +++ b/lib/AsmParser/LLToken.h @@ -62,6 +62,7 @@ namespace lltok { kw_module, kw_asm, kw_sideeffect, + kw_msasm, kw_gc, kw_dbg, kw_c, diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp index 50b99ae..4eb12c6 100644 --- a/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/lib/Bitcode/Reader/BitcodeReader.cpp @@ -1164,7 +1164,8 @@ bool BitcodeReader::ParseConstants() { 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 @@ bool BitcodeReader::ParseConstants() { 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; } } diff --git a/lib/Bitcode/Writer/BitcodeWriter.cpp b/lib/Bitcode/Writer/BitcodeWriter.cpp index 2c45b34..12a1f5e 100644 --- a/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -679,7 +679,8 @@ static void WriteConstants(unsigned FirstVal, unsigned LastVal, } 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(); diff --git a/lib/VMCore/AsmWriter.cpp b/lib/VMCore/AsmWriter.cpp index 3e628ae..b5ae81b 100644 --- a/lib/VMCore/AsmWriter.cpp +++ b/lib/VMCore/AsmWriter.cpp @@ -1206,6 +1206,8 @@ static void WriteAsOperandInternal(raw_ostream &Out, const Value *V, Out << "asm "; if (IA->hasSideEffects()) Out << "sideeffect "; + if (IA->isMsAsm()) + Out << "msasm "; Out << '"'; PrintEscapedString(IA->getAsmString(), Out); Out << "\", \""; diff --git a/lib/VMCore/Core.cpp b/lib/VMCore/Core.cpp index 47a8e1b..bff3087 100644 --- a/lib/VMCore/Core.cpp +++ b/lib/VMCore/Core.cpp @@ -884,9 +884,10 @@ LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant, } 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) ....--*/ diff --git a/lib/VMCore/InlineAsm.cpp b/lib/VMCore/InlineAsm.cpp index fbd6b90..0520dfa 100644 --- a/lib/VMCore/InlineAsm.cpp +++ b/lib/VMCore/InlineAsm.cpp @@ -27,17 +27,19 @@ InlineAsm::~InlineAsm() { // 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!"); diff --git a/test/Assembler/msasm.ll b/test/Assembler/msasm.ll new file mode 100644 index 0000000..5e32963 --- /dev/null +++ b/test/Assembler/msasm.ll @@ -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 +} |