mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-05 14:34:55 +00:00
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
This commit is contained in:
parent
9578c7aad6
commit
4360298d2b
@ -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.
|
||||
///
|
||||
|
@ -529,6 +529,7 @@ lltok::Kind LLLexer::LexIdentifier() {
|
||||
KEYWORD(module);
|
||||
KEYWORD(asm);
|
||||
KEYWORD(sideeffect);
|
||||
KEYWORD(msasm);
|
||||
KEYWORD(gc);
|
||||
|
||||
KEYWORD(ccc);
|
||||
|
@ -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;
|
||||
|
@ -62,6 +62,7 @@ namespace lltok {
|
||||
kw_module,
|
||||
kw_asm,
|
||||
kw_sideeffect,
|
||||
kw_msasm,
|
||||
kw_gc,
|
||||
kw_dbg,
|
||||
kw_c,
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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 << "\", \"";
|
||||
|
@ -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) ....--*/
|
||||
|
@ -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!");
|
||||
|
36
test/Assembler/msasm.ll
Normal file
36
test/Assembler/msasm.ll
Normal 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
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user