1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-01-31 20:51:52 +01:00

[ms-inline asm] Enumerate the InlineAsm dialects and rename the nsdialect to

inteldialect.

llvm-svn: 163231
This commit is contained in:
Chad Rosier 2012-09-05 19:00:49 +00:00
parent 4e03b89c79
commit 542e938cf4
11 changed files with 38 additions and 30 deletions

View File

@ -2894,19 +2894,18 @@ call void asm sideeffect "eieio", ""()
call void asm alignstack "eieio", ""() call void asm alignstack "eieio", ""()
</pre> </pre>
<p>Inline asms also support using non-standard assembly dialects. The standard <p>Inline asms also support using non-standard assembly dialects. The assumed
dialect is ATT, which is assumed when the '<tt>nsdialect</tt>' keyword is not dialect is ATT. When the '<tt>inteldialect</tt>' keyword is present, the
present. When the '<tt>nsdialect</tt>' keyword is present, the dialect is inline asm is using the Intel dialect. Currently, ATT and Intel are the
assumed to be Intel. Currently, ATT and Intel are the only supported only supported dialects. An example is:</p>
dialects. An example is:</p>
<pre class="doc_code"> <pre class="doc_code">
call void asm nsdialect "eieio", ""() call void asm inteldialect "eieio", ""()
</pre> </pre>
<p>If multiple keywords appear the '<tt>sideeffect</tt>' keyword must come <p>If multiple keywords appear the '<tt>sideeffect</tt>' keyword must come
first, the '<tt>alignstack</tt>' keyword second and the first, the '<tt>alignstack</tt>' keyword second and the
'<tt>nsdialect</tt>' keyword last.</p> '<tt>inteldialect</tt>' keyword last.</p>
<!-- <!--
<p>TODO: The format of the asm and constraints string still need to be <p>TODO: The format of the asm and constraints string still need to be

View File

@ -168,7 +168,7 @@ namespace bitc {
CST_CODE_BLOCKADDRESS = 21, // CST_CODE_BLOCKADDRESS [fnty, fnval, bb#] CST_CODE_BLOCKADDRESS = 21, // CST_CODE_BLOCKADDRESS [fnty, fnval, bb#]
CST_CODE_DATA = 22, // DATA: [n x elements] CST_CODE_DATA = 22, // DATA: [n x elements]
CST_CODE_INLINEASM = 23 // INLINEASM: [sideeffect|alignstack| CST_CODE_INLINEASM = 23 // INLINEASM: [sideeffect|alignstack|
// nsdialect,asmstr,conststr] // asmdialect,asmstr,conststr]
}; };
/// CastOpcodes - These are values used in the bitcode files to encode which /// CastOpcodes - These are values used in the bitcode files to encode which

View File

@ -33,6 +33,13 @@ template<class ConstantClass, class TypeClass, class ValType>
struct ConstantCreator; struct ConstantCreator;
class InlineAsm : public Value { class InlineAsm : public Value {
public:
enum AsmDialect {
AD_ATT,
AD_Intel
};
private:
friend struct ConstantCreator<InlineAsm, PointerType, InlineAsmKeyType>; friend struct ConstantCreator<InlineAsm, PointerType, InlineAsmKeyType>;
friend class ConstantUniqueMap<InlineAsmKeyType, const InlineAsmKeyType&, friend class ConstantUniqueMap<InlineAsmKeyType, const InlineAsmKeyType&,
PointerType, InlineAsm, false>; PointerType, InlineAsm, false>;
@ -43,12 +50,11 @@ class InlineAsm : public Value {
std::string AsmString, Constraints; std::string AsmString, Constraints;
bool HasSideEffects; bool HasSideEffects;
bool IsAlignStack; bool IsAlignStack;
/// AsmDialect - 0 is AT&T (default) and 1 is the Intel dialect. AsmDialect Dialect;
unsigned AsmDialect;
InlineAsm(PointerType *Ty, const std::string &AsmString, InlineAsm(PointerType *Ty, const std::string &AsmString,
const std::string &Constraints, bool hasSideEffects, const std::string &Constraints, bool hasSideEffects,
bool isAlignStack, unsigned asmDialect); bool isAlignStack, AsmDialect asmDialect);
virtual ~InlineAsm(); virtual ~InlineAsm();
/// When the ConstantUniqueMap merges two types and makes two InlineAsms /// When the ConstantUniqueMap merges two types and makes two InlineAsms
@ -60,11 +66,12 @@ public:
/// ///
static InlineAsm *get(FunctionType *Ty, StringRef AsmString, static InlineAsm *get(FunctionType *Ty, StringRef AsmString,
StringRef Constraints, bool hasSideEffects, StringRef Constraints, bool hasSideEffects,
bool isAlignStack = false, unsigned asmDialect = 0); bool isAlignStack = false,
AsmDialect asmDialect = AD_ATT);
bool hasSideEffects() const { return HasSideEffects; } bool hasSideEffects() const { return HasSideEffects; }
bool isAlignStack() const { return IsAlignStack; } bool isAlignStack() const { return IsAlignStack; }
unsigned getDialect() const { return AsmDialect; } AsmDialect getDialect() const { return Dialect; }
/// getType - InlineAsm's are always pointers. /// getType - InlineAsm's are always pointers.
/// ///

View File

@ -510,7 +510,7 @@ lltok::Kind LLLexer::LexIdentifier() {
KEYWORD(asm); KEYWORD(asm);
KEYWORD(sideeffect); KEYWORD(sideeffect);
KEYWORD(alignstack); KEYWORD(alignstack);
KEYWORD(nsdialect); KEYWORD(inteldialect);
KEYWORD(gc); KEYWORD(gc);
KEYWORD(ccc); KEYWORD(ccc);

View File

@ -2069,18 +2069,18 @@ bool LLParser::ParseValID(ValID &ID, PerFunctionState *PFS) {
case lltok::kw_asm: { case lltok::kw_asm: {
// ValID ::= 'asm' SideEffect? AlignStack? STRINGCONSTANT ',' STRINGCONSTANT // ValID ::= 'asm' SideEffect? AlignStack? STRINGCONSTANT ',' STRINGCONSTANT
bool HasSideEffect, AlignStack, NSDialect; bool HasSideEffect, AlignStack, AsmDialect;
Lex.Lex(); Lex.Lex();
if (ParseOptionalToken(lltok::kw_sideeffect, HasSideEffect) || if (ParseOptionalToken(lltok::kw_sideeffect, HasSideEffect) ||
ParseOptionalToken(lltok::kw_alignstack, AlignStack) || ParseOptionalToken(lltok::kw_alignstack, AlignStack) ||
ParseOptionalToken(lltok::kw_nsdialect, NSDialect) || ParseOptionalToken(lltok::kw_inteldialect, AsmDialect) ||
ParseStringConstant(ID.StrVal) || ParseStringConstant(ID.StrVal) ||
ParseToken(lltok::comma, "expected comma in inline asm expression") || ParseToken(lltok::comma, "expected comma in inline asm expression") ||
ParseToken(lltok::StringConstant, "expected constraint string")) ParseToken(lltok::StringConstant, "expected constraint string"))
return true; return true;
ID.StrVal2 = Lex.getStrVal(); ID.StrVal2 = Lex.getStrVal();
ID.UIntVal = unsigned(HasSideEffect) | (unsigned(AlignStack)<<1) | ID.UIntVal = unsigned(HasSideEffect) | (unsigned(AlignStack)<<1) |
(unsigned(NSDialect)<<2); (unsigned(AsmDialect)<<2);
ID.Kind = ValID::t_InlineAsm; ID.Kind = ValID::t_InlineAsm;
return false; return false;
} }
@ -2498,7 +2498,7 @@ bool LLParser::ConvertValIDToValue(Type *Ty, ValID &ID, Value *&V,
if (!FTy || !InlineAsm::Verify(FTy, ID.StrVal2)) if (!FTy || !InlineAsm::Verify(FTy, ID.StrVal2))
return Error(ID.Loc, "invalid type for inline asm constraint string"); return Error(ID.Loc, "invalid type for inline asm constraint string");
V = InlineAsm::get(FTy, ID.StrVal, ID.StrVal2, ID.UIntVal&1, V = InlineAsm::get(FTy, ID.StrVal, ID.StrVal2, ID.UIntVal&1,
(ID.UIntVal>>1)&1, (ID.UIntVal>>2)&1); (ID.UIntVal>>1)&1, (InlineAsm::AsmDialect(ID.UIntVal>>2)));
return false; return false;
} }
case ValID::t_MDNode: case ValID::t_MDNode:

View File

@ -72,7 +72,7 @@ namespace lltok {
kw_asm, kw_asm,
kw_sideeffect, kw_sideeffect,
kw_alignstack, kw_alignstack,
kw_nsdialect, kw_inteldialect,
kw_gc, kw_gc,
kw_c, kw_c,

View File

@ -1245,7 +1245,7 @@ bool BitcodeReader::ParseConstants() {
V = ConstantExpr::getICmp(Record[3], Op0, Op1); V = ConstantExpr::getICmp(Record[3], Op0, Op1);
break; break;
} }
// This maintains backward compatibility, pre-'nsdialect'. // This maintains backward compatibility, pre-asm dialect keywords.
// FIXME: Remove with the 4.0 release. // FIXME: Remove with the 4.0 release.
case bitc::CST_CODE_INLINEASM_OLD: { case bitc::CST_CODE_INLINEASM_OLD: {
if (Record.size() < 2) return Error("Invalid INLINEASM record"); if (Record.size() < 2) return Error("Invalid INLINEASM record");
@ -1268,7 +1268,8 @@ bool BitcodeReader::ParseConstants() {
AsmStr, ConstrStr, HasSideEffects, IsAlignStack); AsmStr, ConstrStr, HasSideEffects, IsAlignStack);
break; break;
} }
// This version adds support for the 'nsdialect' keyword. // This version adds support for the asm dialect keywords (e.g.,
// inteldialect).
case bitc::CST_CODE_INLINEASM: { case bitc::CST_CODE_INLINEASM: {
if (Record.size() < 2) return Error("Invalid INLINEASM record"); if (Record.size() < 2) return Error("Invalid INLINEASM record");
std::string AsmStr, ConstrStr; std::string AsmStr, ConstrStr;
@ -1289,7 +1290,7 @@ bool BitcodeReader::ParseConstants() {
PointerType *PTy = cast<PointerType>(CurTy); PointerType *PTy = cast<PointerType>(CurTy);
V = InlineAsm::get(cast<FunctionType>(PTy->getElementType()), V = InlineAsm::get(cast<FunctionType>(PTy->getElementType()),
AsmStr, ConstrStr, HasSideEffects, IsAlignStack, AsmStr, ConstrStr, HasSideEffects, IsAlignStack,
AsmDialect); InlineAsm::AsmDialect(AsmDialect));
break; break;
} }
case bitc::CST_CODE_BLOCKADDRESS:{ case bitc::CST_CODE_BLOCKADDRESS:{

View File

@ -1029,8 +1029,9 @@ static void WriteAsOperandInternal(raw_ostream &Out, const Value *V,
Out << "sideeffect "; Out << "sideeffect ";
if (IA->isAlignStack()) if (IA->isAlignStack())
Out << "alignstack "; Out << "alignstack ";
if (IA->getDialect() != 0) // We don't emit the AD_ATT dialect as it's the assumed default.
Out << "nsdialect "; if (IA->getDialect() == InlineAsm::AD_Intel)
Out << "inteldialect ";
Out << '"'; Out << '"';
PrintEscapedString(IA->getAsmString(), Out); PrintEscapedString(IA->getAsmString(), Out);
Out << "\", \""; Out << "\", \"";

View File

@ -352,7 +352,7 @@ struct ExprMapKeyType {
struct InlineAsmKeyType { struct InlineAsmKeyType {
InlineAsmKeyType(StringRef AsmString, InlineAsmKeyType(StringRef AsmString,
StringRef Constraints, bool hasSideEffects, StringRef Constraints, bool hasSideEffects,
bool isAlignStack, unsigned asmDialect) bool isAlignStack, InlineAsm::AsmDialect asmDialect)
: asm_string(AsmString), constraints(Constraints), : asm_string(AsmString), constraints(Constraints),
has_side_effects(hasSideEffects), is_align_stack(isAlignStack), has_side_effects(hasSideEffects), is_align_stack(isAlignStack),
asm_dialect(asmDialect) {} asm_dialect(asmDialect) {}
@ -360,7 +360,7 @@ struct InlineAsmKeyType {
std::string constraints; std::string constraints;
bool has_side_effects; bool has_side_effects;
bool is_align_stack; bool is_align_stack;
unsigned asm_dialect; InlineAsm::AsmDialect asm_dialect;
bool operator==(const InlineAsmKeyType& that) const { bool operator==(const InlineAsmKeyType& that) const {
return this->asm_string == that.asm_string && return this->asm_string == that.asm_string &&
this->constraints == that.constraints && this->constraints == that.constraints &&

View File

@ -1056,7 +1056,7 @@ LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty, const char *AsmString,
const char *Constraints, const char *Constraints,
LLVMBool HasSideEffects, LLVMBool HasSideEffects,
LLVMBool IsAlignStack, LLVMBool IsAlignStack,
unsigned AsmDialect) { InlineAsm::AsmDialect AsmDialect) {
return wrap(InlineAsm::get(dyn_cast<FunctionType>(unwrap(Ty)), AsmString, return wrap(InlineAsm::get(dyn_cast<FunctionType>(unwrap(Ty)), AsmString,
Constraints, HasSideEffects, IsAlignStack, Constraints, HasSideEffects, IsAlignStack,
AsmDialect)); AsmDialect));

View File

@ -27,7 +27,7 @@ InlineAsm::~InlineAsm() {
InlineAsm *InlineAsm::get(FunctionType *Ty, StringRef AsmString, InlineAsm *InlineAsm::get(FunctionType *Ty, StringRef AsmString,
StringRef Constraints, bool hasSideEffects, StringRef Constraints, bool hasSideEffects,
bool isAlignStack, unsigned asmDialect) { bool isAlignStack, AsmDialect asmDialect) {
InlineAsmKeyType Key(AsmString, Constraints, hasSideEffects, isAlignStack, InlineAsmKeyType Key(AsmString, Constraints, hasSideEffects, isAlignStack,
asmDialect); asmDialect);
LLVMContextImpl *pImpl = Ty->getContext().pImpl; LLVMContextImpl *pImpl = Ty->getContext().pImpl;
@ -36,11 +36,11 @@ InlineAsm *InlineAsm::get(FunctionType *Ty, StringRef AsmString,
InlineAsm::InlineAsm(PointerType *Ty, const std::string &asmString, InlineAsm::InlineAsm(PointerType *Ty, const std::string &asmString,
const std::string &constraints, bool hasSideEffects, const std::string &constraints, bool hasSideEffects,
bool isAlignStack, unsigned asmDialect) bool isAlignStack, AsmDialect asmDialect)
: Value(Ty, Value::InlineAsmVal), : Value(Ty, Value::InlineAsmVal),
AsmString(asmString), Constraints(constraints), AsmString(asmString), Constraints(constraints),
HasSideEffects(hasSideEffects), IsAlignStack(isAlignStack), HasSideEffects(hasSideEffects), IsAlignStack(isAlignStack),
AsmDialect(asmDialect) { Dialect(asmDialect) {
// Do various checks on the constraint string and type. // Do various checks on the constraint string and type.
assert(Verify(getFunctionType(), constraints) && assert(Verify(getFunctionType(), constraints) &&