return ListTy.get();
}
-bool RecTy::baseClassOf(const RecTy *RHS) const{
+bool RecTy::baseClassOf(const RecTy *RHS) const {
assert (RHS && "NULL pointer");
return Kind == RHS->getRecTyKind();
}
return BitInit::get(Val != 0);
}
-Init *BitRecTy::convertValue(TypedInit *VI) {
- RecTy *Ty = VI->getType();
+Init *BitRecTy::convertValue(TypedInit *TI) {
+ RecTy *Ty = TI->getType();
if (isa<BitRecTy>(Ty))
- return VI; // Accept variable if it is already of bit type!
+ return TI; // Accept variable if it is already of bit type!
if (auto *BitsTy = dyn_cast<BitsRecTy>(Ty))
// Accept only bits<1> expression.
- return BitsTy->getNumBits() == 1 ? VI : nullptr;
+ return BitsTy->getNumBits() == 1 ? TI : nullptr;
// Ternary !if can be converted to bit, but only if both sides are
// convertible to a bit.
- if (TernOpInit *TOI = dyn_cast<TernOpInit>(VI)) {
+ if (TernOpInit *TOI = dyn_cast<TernOpInit>(TI)) {
if (TOI->getOpcode() != TernOpInit::TernaryOp::IF)
return nullptr;
if (!TOI->getMHS()->convertInitializerTo(BitRecTy::get()) ||
return BitsInit::get(NewBits);
}
-Init *BitsRecTy::convertValue(BitInit *UI) {
+Init *BitsRecTy::convertValue(BitInit *BI) {
if (Size != 1) return nullptr; // Can only convert single bit.
- return BitsInit::get(UI);
+ return BitsInit::get(BI);
}
/// canFitInBitfield - Return true if the number of bits is large enough to hold
return nullptr;
}
-Init *BitsRecTy::convertValue(TypedInit *VI) {
- if (Size == 1 && isa<BitRecTy>(VI->getType()))
- return BitsInit::get(VI);
+Init *BitsRecTy::convertValue(TypedInit *TI) {
+ if (Size == 1 && isa<BitRecTy>(TI->getType()))
+ return BitsInit::get(TI);
- if (VI->getType()->typeIsConvertibleTo(this)) {
+ if (TI->getType()->typeIsConvertibleTo(this)) {
SmallVector<Init *, 16> NewBits(Size);
for (unsigned i = 0; i != Size; ++i)
- NewBits[i] = VarBitInit::get(VI, i);
+ NewBits[i] = VarBitInit::get(TI, i);
return BitsInit::get(NewBits);
}
Init *IntRecTy::convertValue(BitsInit *BI) {
int64_t Result = 0;
for (unsigned i = 0, e = BI->getNumBits(); i != e; ++i)
- if (BitInit *Bit = dyn_cast<BitInit>(BI->getBit(i))) {
- Result |= Bit->getValue() << i;
- } else {
+ if (BitInit *Bit = dyn_cast<BitInit>(BI->getBit(i)))
+ Result |= static_cast<int64_t>(Bit->getValue()) << i;
+ else
return nullptr;
- }
return IntInit::get(Result);
}
return kind==BitRecTyKind || kind==BitsRecTyKind || kind==IntRecTyKind;
}
-Init *StringRecTy::convertValue(UnOpInit *BO) {
- if (BO->getOpcode() == UnOpInit::CAST) {
- Init *L = BO->getOperand()->convertInitializerTo(this);
+Init *StringRecTy::convertValue(UnOpInit *UO) {
+ if (UO->getOpcode() == UnOpInit::CAST) {
+ Init *L = UO->getOperand()->convertInitializerTo(this);
if (!L) return nullptr;
- if (L != BO->getOperand())
+ if (L != UO->getOperand())
return UnOpInit::get(UnOpInit::CAST, L, StringRecTy::get());
- return BO;
+ return UO;
}
- return convertValue((TypedInit*)BO);
+ return convertValue((TypedInit*)UO);
}
Init *StringRecTy::convertValue(BinOpInit *BO) {
return nullptr;
}
-Init *DagRecTy::convertValue(UnOpInit *BO) {
- if (BO->getOpcode() == UnOpInit::CAST) {
- Init *L = BO->getOperand()->convertInitializerTo(this);
+Init *DagRecTy::convertValue(UnOpInit *UO) {
+ if (UO->getOpcode() == UnOpInit::CAST) {
+ Init *L = UO->getOperand()->convertInitializerTo(this);
if (!L) return nullptr;
- if (L != BO->getOperand())
- return UnOpInit::get(UnOpInit::CAST, L, new DagRecTy);
- return BO;
+ if (L != UO->getOperand())
+ return UnOpInit::get(UnOpInit::CAST, L, DagRecTy::get());
+ return UO;
}
return nullptr;
}
Init *R = BO->getRHS()->convertInitializerTo(this);
if (!L || !R) return nullptr;
if (L != BO->getLHS() || R != BO->getRHS())
- return BinOpInit::get(BinOpInit::CONCAT, L, R, new DagRecTy);
+ return BinOpInit::get(BinOpInit::CONCAT, L, R, DagRecTy::get());
return BO;
}
return nullptr;
ProfileBitsInit(FoldingSetNodeID &ID, ArrayRef<Init *> Range) {
ID.AddInteger(Range.size());
- for (ArrayRef<Init *>::iterator i = Range.begin(),
- iend = Range.end();
- i != iend;
- ++i)
- ID.AddPointer(*i);
+ for (Init *I : Range)
+ ID.AddPointer(I);
}
BitsInit *BitsInit::get(ArrayRef<Init *> Range) {
ID.AddInteger(Range.size());
ID.AddPointer(EltTy);
- for (ArrayRef<Init *>::iterator i = Range.begin(),
- iend = Range.end();
- i != iend;
- ++i)
- ID.AddPointer(*i);
+ for (Init *I : Range)
+ ID.AddPointer(I);
}
ListInit *ListInit::get(ArrayRef<Init *> Range, RecTy *EltTy) {
Init *TemplateArgName = QualifyName(*CurRec, CurMultiClass, Name,
":");
-
+
if (CurRec->isTemplateArg(TemplateArgName)) {
const RecordVal *RV = CurRec->getValue(TemplateArgName);
assert(RV && "Template arg doesn't exist??");
}
if (CurMultiClass) {
- Init *MCName = QualifyName(CurMultiClass->Rec, CurMultiClass, Name, "::");
+ Init *MCName = QualifyName(CurMultiClass->Rec, CurMultiClass, Name,
+ "::");
if (CurMultiClass->Rec.isTemplateArg(MCName)) {
const RecordVal *RV = CurMultiClass->Rec.getValue(MCName);
}
case HEAD: {
if (ListInit *LHSl = dyn_cast<ListInit>(LHS)) {
- assert(LHSl->getSize() != 0 && "Empty list in car");
+ assert(!LHSl->empty() && "Empty list in head");
return LHSl->getElement(0);
}
break;
}
case TAIL: {
if (ListInit *LHSl = dyn_cast<ListInit>(LHS)) {
- assert(LHSl->getSize() != 0 && "Empty list in cdr");
+ assert(!LHSl->empty() && "Empty list in tail");
// Note the +1. We can't just pass the result of getValues()
// directly.
- ArrayRef<Init *>::iterator begin = LHSl->getValues().begin()+1;
- ArrayRef<Init *>::iterator end = LHSl->getValues().end();
- ListInit *Result =
- ListInit::get(ArrayRef<Init *>(begin, end - begin),
- LHSl->getType());
- return Result;
+ return ListInit::get(LHSl->getValues().slice(1), LHSl->getType());
}
break;
}
case EMPTY: {
- if (ListInit *LHSl = dyn_cast<ListInit>(LHS)) {
- if (LHSl->getSize() == 0) {
- return IntInit::get(1);
- } else {
- return IntInit::get(0);
- }
- }
- if (StringInit *LHSs = dyn_cast<StringInit>(LHS)) {
- if (LHSs->getValue().empty()) {
- return IntInit::get(1);
- } else {
- return IntInit::get(0);
- }
- }
+ if (ListInit *LHSl = dyn_cast<ListInit>(LHS))
+ return IntInit::get(LHSl->empty());
+ if (StringInit *LHSs = dyn_cast<StringInit>(LHS))
+ return IntInit::get(LHSs->getValue().empty());
break;
}
Args.insert(Args.end(), LHSs->begin(), LHSs->end());
Args.insert(Args.end(), RHSs->begin(), RHSs->end());
return ListInit::get(
- Args, static_cast<ListRecTy *>(LHSs->getType())->getElementType());
+ Args, cast<ListRecTy>(LHSs->getType())->getElementType());
}
break;
}
return Result + "(" + LHS->getAsString() + ", " + RHS->getAsString() + ")";
}
-TernOpInit *TernOpInit::get(TernaryOp opc, Init *lhs,
- Init *mhs, Init *rhs,
- RecTy *Type) {
+TernOpInit *TernOpInit::get(TernaryOp opc, Init *lhs, Init *mhs, Init *rhs,
+ RecTy *Type) {
typedef std::pair<
std::pair<
std::pair<std::pair<unsigned, RecTy *>, Init *>,
static Init *EvaluateOperation(OpInit *RHSo, Init *LHS, Init *Arg,
RecTy *Type, Record *CurRec,
MultiClass *CurMultiClass) {
- std::vector<Init *> NewOperands;
-
- TypedInit *TArg = dyn_cast<TypedInit>(Arg);
-
// If this is a dag, recurse
- if (TArg && TArg->getType()->getAsString() == "dag") {
- Init *Result = ForeachHelper(LHS, Arg, RHSo, Type,
- CurRec, CurMultiClass);
- return Result;
- }
+ if (auto *TArg = dyn_cast<TypedInit>(Arg))
+ if (TArg->getType()->getAsString() == "dag")
+ return ForeachHelper(LHS, Arg, RHSo, Type, CurRec, CurMultiClass);
+ std::vector<Init *> NewOperands;
for (int i = 0; i < RHSo->getNumOperands(); ++i) {
- OpInit *RHSoo = dyn_cast<OpInit>(RHSo->getOperand(i));
-
- if (RHSoo) {
- Init *Result = EvaluateOperation(RHSoo, LHS, Arg,
- Type, CurRec, CurMultiClass);
- if (Result) {
+ if (auto *RHSoo = dyn_cast<OpInit>(RHSo->getOperand(i))) {
+ if (Init *Result = EvaluateOperation(RHSoo, LHS, Arg,
+ Type, CurRec, CurMultiClass))
NewOperands.push_back(Result);
- } else {
+ else
NewOperands.push_back(Arg);
- }
} else if (LHS->getAsString() == RHSo->getOperand(i)->getAsString()) {
NewOperands.push_back(Arg);
} else {
OpInit *RHSo = dyn_cast<OpInit>(RHS);
- if (!RHSo) {
+ if (!RHSo)
PrintFatalError(CurRec->getLoc(), "!foreach requires an operator\n");
- }
TypedInit *LHSt = dyn_cast<TypedInit>(LHS);
Init *Val = MHSd->getOperator();
Init *Result = EvaluateOperation(RHSo, LHS, Val,
Type, CurRec, CurMultiClass);
- if (Result) {
+ if (Result)
Val = Result;
- }
std::vector<std::pair<Init *, std::string> > args;
for (unsigned int i = 0; i < MHSd->getNumArgs(); ++i) {
// Process args
Init *Result = EvaluateOperation(RHSo, LHS, Arg, Type,
CurRec, CurMultiClass);
- if (Result) {
+ if (Result)
Arg = Result;
- }
// TODO: Process arg names
args.push_back(std::make_pair(Arg, ArgName));
std::vector<Init *> NewOperands;
std::vector<Init *> NewList(MHSl->begin(), MHSl->end());
- for (std::vector<Init *>::iterator li = NewList.begin(),
- liend = NewList.end();
- li != liend;
- ++li) {
- Init *Item = *li;
+ for (Init *&Item : NewList) {
NewOperands.clear();
for(int i = 0; i < RHSo->getNumOperands(); ++i) {
// First, replace the foreach variable with the list item
- if (LHS->getAsString() == RHSo->getOperand(i)->getAsString()) {
+ if (LHS->getAsString() == RHSo->getOperand(i)->getAsString())
NewOperands.push_back(Item);
- } else {
+ else
NewOperands.push_back(RHSo->getOperand(i));
- }
}
// Now run the operator and use its result as the new list item
const OpInit *NewOp = RHSo->clone(NewOperands);
Init *NewItem = NewOp->Fold(CurRec, CurMultiClass);
if (NewItem != NewOp)
- *li = NewItem;
+ Item = NewItem;
}
return ListInit::get(NewList, MHSl->getType());
}
VarInit *RHSv = dyn_cast<VarInit>(RHS);
StringInit *RHSs = dyn_cast<StringInit>(RHS);
- if ((LHSd && MHSd && RHSd)
- || (LHSv && MHSv && RHSv)
- || (LHSs && MHSs && RHSs)) {
- if (RHSd) {
- Record *Val = RHSd->getDef();
- if (LHSd->getAsString() == RHSd->getAsString()) {
- Val = MHSd->getDef();
- }
- return DefInit::get(Val);
- }
- if (RHSv) {
- std::string Val = RHSv->getName();
- if (LHSv->getAsString() == RHSv->getAsString()) {
- Val = MHSv->getName();
- }
- return VarInit::get(Val, getType());
+ if (LHSd && MHSd && RHSd) {
+ Record *Val = RHSd->getDef();
+ if (LHSd->getAsString() == RHSd->getAsString())
+ Val = MHSd->getDef();
+ return DefInit::get(Val);
+ }
+ if (LHSv && MHSv && RHSv) {
+ std::string Val = RHSv->getName();
+ if (LHSv->getAsString() == RHSv->getAsString())
+ Val = MHSv->getName();
+ return VarInit::get(Val, getType());
+ }
+ if (LHSs && MHSs && RHSs) {
+ std::string Val = RHSs->getValue();
+
+ std::string::size_type found;
+ std::string::size_type idx = 0;
+ while (true) {
+ found = Val.find(LHSs->getValue(), idx);
+ if (found == std::string::npos)
+ break;
+ Val.replace(found, LHSs->getValue().size(), MHSs->getValue());
+ idx = found + MHSs->getValue().size();
}
- if (RHSs) {
- std::string Val = RHSs->getValue();
-
- std::string::size_type found;
- std::string::size_type idx = 0;
- do {
- found = Val.find(LHSs->getValue(), idx);
- if (found != std::string::npos) {
- Val.replace(found, LHSs->getValue().size(), MHSs->getValue());
- }
- idx = found + MHSs->getValue().size();
- } while (found != std::string::npos);
- return StringInit::get(Val);
- }
+ return StringInit::get(Val);
}
break;
}
case FOREACH: {
- Init *Result = ForeachHelper(LHS, MHS, RHS, getType(),
- CurRec, CurMultiClass);
- if (Result) {
+ if (Init *Result = ForeachHelper(LHS, MHS, RHS, getType(),
+ CurRec, CurMultiClass))
return Result;
- }
break;
}
if (Init *I = LHS->convertInitializerTo(IntRecTy::get()))
LHSi = dyn_cast<IntInit>(I);
if (LHSi) {
- if (LHSi->getValue()) {
+ if (LHSi->getValue())
return MHS;
- } else {
- return RHS;
- }
+ return RHS;
}
break;
}
Init *mhs = MHS->resolveReferences(R, RV);
return (TernOpInit::get(getOpcode(), lhs, mhs,
RHS, getType()))->Fold(&R, nullptr);
- } else {
- Init *rhs = RHS->resolveReferences(R, RV);
- return (TernOpInit::get(getOpcode(), lhs, MHS,
- rhs, getType()))->Fold(&R, nullptr);
}
+ Init *rhs = RHS->resolveReferences(R, RV);
+ return (TernOpInit::get(getOpcode(), lhs, MHS,
+ rhs, getType()))->Fold(&R, nullptr);
}
}
case SUBST: Result = "!subst"; break;
case FOREACH: Result = "!foreach"; break;
case IF: Result = "!if"; break;
- }
- return Result + "(" + LHS->getAsString() + ", " + MHS->getAsString() + ", "
- + RHS->getAsString() + ")";
+ }
+ return Result + "(" + LHS->getAsString() + ", " + MHS->getAsString() + ", " +
+ RHS->getAsString() + ")";
}
RecTy *TypedInit::getFieldType(const std::string &FieldName) const {
RecordVal *RV = R.getValue(getNameInit());
assert(RV && "Reference to a non-existent variable?");
ListInit *LI = dyn_cast<ListInit>(RV->getValue());
- if (!LI) {
- TypedInit *VI = cast<TypedInit>(RV->getValue());
- return VarListElementInit::get(VI, Elt);
- }
+ if (!LI)
+ return VarListElementInit::get(cast<TypedInit>(RV->getValue()), Elt);
if (Elt >= LI->getSize())
return nullptr; // Out of range reference.
assert(TheInit != this && "Infinite loop detected!");
if (Init *I = TheInit->getFieldInit(R, RV, FieldName))
return I;
- else
- return nullptr;
+ return nullptr;
}
return nullptr;
}
}
std::string VarBitInit::getAsString() const {
- return TI->getAsString() + "{" + utostr(Bit) + "}";
+ return TI->getAsString() + "{" + utostr(Bit) + "}";
}
Init *VarBitInit::resolveReferences(Record &R, const RecordVal *RV) const {
Init *VarListElementInit:: resolveListElementReference(Record &R,
const RecordVal *RV,
unsigned Elt) const {
- Init *Result = TI->resolveListElementReference(R, RV, Element);
-
- if (Result) {
+ if (Init *Result = TI->resolveListElementReference(R, RV, Element)) {
if (TypedInit *TInit = dyn_cast<TypedInit>(Result)) {
Init *Result2 = TInit->resolveListElementReference(R, RV, Elt);
if (Result2) return Result2;
}
return Result;
}
-
+
return nullptr;
}
Init *FieldInit::resolveReferences(Record &R, const RecordVal *RV) const {
Init *NewRec = RV ? Rec->resolveReferences(R, RV) : Rec;
- Init *BitsVal = NewRec->getFieldInit(R, RV, FieldName);
- if (BitsVal) {
+ if (Init *BitsVal = NewRec->getFieldInit(R, RV, FieldName)) {
Init *BVR = BitsVal->resolveReferences(R, RV);
return BVR->isComplete() ? BVR : const_cast<FieldInit *>(this);
}
- if (NewRec != Rec) {
+ if (NewRec != Rec)
return FieldInit::get(NewRec, FieldName);
- }
return const_cast<FieldInit *>(this);
}
DagInit *
DagInit::get(Init *V, const std::string &VN,
const std::vector<std::pair<Init*, std::string> > &args) {
- typedef std::pair<Init*, std::string> PairType;
-
std::vector<Init *> Args;
std::vector<std::string> Names;
- for (std::vector<PairType>::const_iterator i = args.begin(),
- iend = args.end();
- i != iend;
- ++i) {
- Args.push_back(i->first);
- Names.push_back(i->second);
+ for (const auto &Arg : args) {
+ Args.push_back(Arg.first);
+ Names.push_back(Arg.second);
}
return DagInit::get(V, VN, Args, Names);
continue;
if (Init *V = Values[i].getValue())
if (Values[i].setValue(V->resolveReferences(*this, RV)))
- PrintFatalError(getLoc(), "Invalid value is found when setting '"
- + Values[i].getNameInitAsString()
- + "' after resolving references"
- + (RV ? " against '" + RV->getNameInitAsString()
- + "' of ("
- + RV->getValue()->getAsUnquotedString() + ")"
- : "")
- + "\n");
+ PrintFatalError(getLoc(), "Invalid value is found when setting '" +
+ Values[i].getNameInitAsString() +
+ "' after resolving references" +
+ (RV ? " against '" + RV->getNameInitAsString() +
+ "' of (" + RV->getValue()->getAsUnquotedString() +
+ ")"
+ : "") + "\n");
}
Init *OldName = getNameInit();
Init *NewName = Name->resolveReferences(*this, RV);
ListInit *List = getValueAsListInit(FieldName);
std::vector<Record*> Defs;
for (unsigned i = 0; i < List->getSize(); i++) {
- if (DefInit *DI = dyn_cast<DefInit>(List->getElement(i))) {
+ if (DefInit *DI = dyn_cast<DefInit>(List->getElement(i)))
Defs.push_back(DI->getDef());
- } else {
+ else
PrintFatalError(getLoc(), "Record `" + getName() + "', field `" +
FieldName + "' list is not entirely DefInit!");
- }
}
return Defs;
}
ListInit *List = getValueAsListInit(FieldName);
std::vector<int64_t> Ints;
for (unsigned i = 0; i < List->getSize(); i++) {
- if (IntInit *II = dyn_cast<IntInit>(List->getElement(i))) {
+ if (IntInit *II = dyn_cast<IntInit>(List->getElement(i)))
Ints.push_back(II->getValue());
- } else {
+ else
PrintFatalError(getLoc(), "Record `" + getName() + "', field `" +
FieldName + "' does not have a list of ints initializer!");
- }
}
return Ints;
}
ListInit *List = getValueAsListInit(FieldName);
std::vector<std::string> Strings;
for (unsigned i = 0; i < List->getSize(); i++) {
- if (StringInit *II = dyn_cast<StringInit>(List->getElement(i))) {
+ if (StringInit *II = dyn_cast<StringInit>(List->getElement(i)))
Strings.push_back(II->getValue());
- } else {
+ else
PrintFatalError(getLoc(), "Record `" + getName() + "', field `" +
FieldName + "' does not have a list of strings initializer!");
- }
}
return Strings;
}
Rec.dump();
errs() << "Defs:\n";
- for (RecordVector::const_iterator r = DefPrototypes.begin(),
- rend = DefPrototypes.end();
- r != rend;
- ++r) {
- (*r)->dump();
- }
+ for (const auto &Proto : DefPrototypes)
+ Proto->dump();
}
raw_ostream &llvm::operator<<(raw_ostream &OS, const RecordKeeper &RK) {
OS << "------------- Classes -----------------\n";
- const auto &Classes = RK.getClasses();
- for (const auto &C : Classes)
+ for (const auto &C : RK.getClasses())
OS << "class " << *C.second;
OS << "------------- Defs -----------------\n";
- const auto &Defs = RK.getDefs();
- for (const auto &D : Defs)
+ for (const auto &D : RK.getDefs())
OS << "def " << *D.second;
return OS;
}