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.

llvm-svn: 84020
This commit is contained in:
Dale Johannesen 2009-10-13 20:46:56 +00:00
parent 41e170eb54
commit fd04c74bc0
10 changed files with 65 additions and 15 deletions

View File

@ -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.
///

View File

@ -529,6 +529,7 @@ lltok::Kind LLLexer::LexIdentifier() {
KEYWORD(module);
KEYWORD(asm);
KEYWORD(sideeffect);
KEYWORD(msasm);
KEYWORD(gc);
KEYWORD(ccc);

View File

@ -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;

View File

@ -62,6 +62,7 @@ namespace lltok {
kw_module,
kw_asm,
kw_sideeffect,
kw_msasm,
kw_gc,
kw_dbg,
kw_c,

View File

@ -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;
}
}

View File

@ -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();

View File

@ -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 << "\", \"";

View File

@ -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) ....--*/

View File

@ -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!");

View File

@ -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
}