mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-11-23 13:50:11 +00:00
Update some uses of getAttr()
to be explicit about Inherent vs Discardable (NFC)
This commit is contained in:
parent
0a8d17e79b
commit
830b9b072d
@ -736,10 +736,10 @@ For example, we can write
|
||||
def GetOwner: NativeCodeCall<"$0.getOwner()">;
|
||||
|
||||
def CopyAttrFoo: NativeCodeCallVoid<
|
||||
"$1->setAttr($_builder.getStringAttr(\"foo\"), $0->getAttr(\"foo\"))">;
|
||||
"$1->setAttr($_builder.getStringAttr(\"foo\"), $0->getInherentAttr(\"foo\"))">;
|
||||
|
||||
def CopyAttrBar: NativeCodeCallVoid<
|
||||
"$1->setAttr($_builder.getStringAttr(\"bar\"), $0->getAttr(\"bar\"))">;
|
||||
"$1->setAttr($_builder.getStringAttr(\"bar\"), $0->getInherentAttr(\"bar\"))">;
|
||||
|
||||
|
||||
def : Pattern<
|
||||
|
@ -42,8 +42,8 @@ DebugTranslation::DebugTranslation(Operation *module, llvm::Module &llvmModule)
|
||||
llvmModule.addModuleFlag(llvm::Module::Warning, debugVersionKey,
|
||||
llvm::DEBUG_METADATA_VERSION);
|
||||
|
||||
if (auto targetTripleAttr =
|
||||
module->getAttr(LLVM::LLVMDialect::getTargetTripleAttrName())) {
|
||||
if (auto targetTripleAttr = module->getDiscardableAttr(
|
||||
LLVM::LLVMDialect::getTargetTripleAttrName())) {
|
||||
auto targetTriple =
|
||||
llvm::Triple(cast<StringAttr>(targetTripleAttr).getValue());
|
||||
if (targetTriple.isKnownWindowsMSVCEnvironment()) {
|
||||
|
@ -1327,7 +1327,7 @@ prepareLLVMModule(Operation *m, llvm::LLVMContext &llvmContext,
|
||||
m->getContext()->getOrLoadDialect<LLVM::LLVMDialect>();
|
||||
auto llvmModule = std::make_unique<llvm::Module>(name, llvmContext);
|
||||
if (auto dataLayoutAttr =
|
||||
m->getAttr(LLVM::LLVMDialect::getDataLayoutAttrName())) {
|
||||
m->getDiscardableAttr(LLVM::LLVMDialect::getDataLayoutAttrName())) {
|
||||
llvmModule->setDataLayout(cast<StringAttr>(dataLayoutAttr).getValue());
|
||||
} else {
|
||||
FailureOr<llvm::DataLayout> llvmDataLayout(llvm::DataLayout(""));
|
||||
@ -1347,7 +1347,7 @@ prepareLLVMModule(Operation *m, llvm::LLVMContext &llvmContext,
|
||||
llvmModule->setDataLayout(*llvmDataLayout);
|
||||
}
|
||||
if (auto targetTripleAttr =
|
||||
m->getAttr(LLVM::LLVMDialect::getTargetTripleAttrName()))
|
||||
m->getDiscardableAttr(LLVM::LLVMDialect::getTargetTripleAttrName()))
|
||||
llvmModule->setTargetTriple(cast<StringAttr>(targetTripleAttr).getValue());
|
||||
|
||||
// Inject declarations for `malloc` and `free` functions that can be used in
|
||||
|
@ -61,12 +61,12 @@ void printModRefResult(ModRefResult result, Operation *op, Value location) {
|
||||
|
||||
void TestAliasAnalysisBase::runAliasAnalysisOnOperation(
|
||||
Operation *op, AliasAnalysis &aliasAnalysis) {
|
||||
llvm::errs() << "Testing : " << op->getAttr("sym_name") << "\n";
|
||||
llvm::errs() << "Testing : " << *op->getInherentAttr("sym_name") << "\n";
|
||||
|
||||
// Collect all of the values to check for aliasing behavior.
|
||||
SmallVector<Value, 32> valsToCheck;
|
||||
op->walk([&](Operation *op) {
|
||||
if (!op->getAttr("test.ptr"))
|
||||
if (!op->getDiscardableAttr("test.ptr"))
|
||||
return;
|
||||
valsToCheck.append(op->result_begin(), op->result_end());
|
||||
for (Region ®ion : op->getRegions())
|
||||
@ -82,12 +82,12 @@ void TestAliasAnalysisBase::runAliasAnalysisOnOperation(
|
||||
|
||||
void TestAliasAnalysisModRefBase::runAliasAnalysisOnOperation(
|
||||
Operation *op, AliasAnalysis &aliasAnalysis) {
|
||||
llvm::errs() << "Testing : " << op->getAttr("sym_name") << "\n";
|
||||
llvm::errs() << "Testing : " << *op->getInherentAttr("sym_name") << "\n";
|
||||
|
||||
// Collect all of the values to check for aliasing behavior.
|
||||
SmallVector<Value, 32> valsToCheck;
|
||||
op->walk([&](Operation *op) {
|
||||
if (!op->getAttr("test.ptr"))
|
||||
if (!op->getDiscardableAttr("test.ptr"))
|
||||
return;
|
||||
valsToCheck.append(op->result_begin(), op->result_end());
|
||||
for (Region ®ion : op->getRegions())
|
||||
@ -98,7 +98,7 @@ void TestAliasAnalysisModRefBase::runAliasAnalysisOnOperation(
|
||||
// Check for aliasing behavior between each of the values.
|
||||
for (auto &it : valsToCheck) {
|
||||
op->walk([&](Operation *op) {
|
||||
if (!op->getAttr("test.ptr"))
|
||||
if (!op->getDiscardableAttr("test.ptr"))
|
||||
return;
|
||||
printModRefResult(aliasAnalysis.getModRef(op, it), op, it);
|
||||
});
|
||||
|
@ -27,8 +27,8 @@ struct TestCallGraphPass
|
||||
return "Print the contents of a constructed callgraph.";
|
||||
}
|
||||
void runOnOperation() override {
|
||||
llvm::errs() << "Testing : " << getOperation()->getAttr("test.name")
|
||||
<< "\n";
|
||||
llvm::errs() << "Testing : "
|
||||
<< getOperation()->getDiscardableAttr("test.name") << "\n";
|
||||
getAnalysis<CallGraph>().print(llvm::errs());
|
||||
}
|
||||
};
|
||||
|
@ -211,9 +211,10 @@ void VectorizerTestPass::testComposeMaps(llvm::raw_ostream &outs) {
|
||||
maps.reserve(matches.size());
|
||||
for (auto m : llvm::reverse(matches)) {
|
||||
auto *opInst = m.getMatchedOperation();
|
||||
auto map = cast<AffineMapAttr>(
|
||||
opInst->getAttr(VectorizerTestPass::kTestAffineMapAttrName))
|
||||
.getValue();
|
||||
auto map =
|
||||
cast<AffineMapAttr>(opInst->getDiscardableAttr(
|
||||
VectorizerTestPass::kTestAffineMapAttrName))
|
||||
.getValue();
|
||||
maps.push_back(map);
|
||||
}
|
||||
if (maps.empty())
|
||||
|
@ -32,7 +32,7 @@ struct TestDataLayoutQuery
|
||||
|
||||
func.walk([&](test::DataLayoutQueryOp op) {
|
||||
// Skip the ops with already processed in a deeper call.
|
||||
if (op->getAttr("size"))
|
||||
if (op->getDiscardableAttr("size"))
|
||||
return;
|
||||
|
||||
const DataLayout &layout = layouts.getAbove(op);
|
||||
|
@ -212,7 +212,7 @@ void ConvertToTargetEnv::runOnOperation() {
|
||||
func::FuncOp fn = getOperation();
|
||||
|
||||
auto targetEnv = dyn_cast_or_null<spirv::TargetEnvAttr>(
|
||||
fn.getOperation()->getAttr(spirv::getTargetEnvAttrName()));
|
||||
fn.getOperation()->getDiscardableAttr(spirv::getTargetEnvAttrName()));
|
||||
if (!targetEnv) {
|
||||
fn.emitError("missing 'spirv.target_env' attribute");
|
||||
return signalPassFailure();
|
||||
|
@ -53,7 +53,8 @@ void TestSpirvEntryPointABIPass::runOnOperation() {
|
||||
MLIRContext *context = &getContext();
|
||||
StringRef attrName = spirv::getEntryPointABIAttrName();
|
||||
for (gpu::GPUFuncOp gpuFunc : gpuModule.getOps<gpu::GPUFuncOp>()) {
|
||||
if (!gpu::GPUDialect::isKernel(gpuFunc) || gpuFunc->getAttr(attrName))
|
||||
if (!gpu::GPUDialect::isKernel(gpuFunc) ||
|
||||
gpuFunc->getDiscardableAttr(attrName))
|
||||
continue;
|
||||
SmallVector<int32_t, 3> workgroupSizeVec(workgroupSize.begin(),
|
||||
workgroupSize.end());
|
||||
|
@ -57,7 +57,7 @@ void ReportShapeFnPass::runOnOperation() {
|
||||
|
||||
// Lookup shape function library.
|
||||
SmallVector<shape::FunctionLibraryOp, 4> libraries;
|
||||
auto attr = module->getAttr("shape.lib");
|
||||
auto attr = module->getDiscardableAttr("shape.lib");
|
||||
if (attr) {
|
||||
auto lookup = [&](Attribute attr) {
|
||||
return cast<shape::FunctionLibraryOp>(
|
||||
|
@ -37,6 +37,7 @@
|
||||
#include "llvm/ADT/StringExtras.h"
|
||||
#include "llvm/ADT/StringSwitch.h"
|
||||
#include "llvm/Support/Base64.h"
|
||||
#include "llvm/Support/Casting.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <numeric>
|
||||
@ -528,9 +529,9 @@ LogicalResult TestOpWithVariadicResultsAndFolder::fold(
|
||||
}
|
||||
|
||||
OpFoldResult TestOpInPlaceFold::fold(FoldAdaptor adaptor) {
|
||||
if (adaptor.getOp() && !(*this)->getAttr("attr")) {
|
||||
if (adaptor.getOp() && !getProperties().attr) {
|
||||
// The folder adds "attr" if not present.
|
||||
(*this)->setAttr("attr", adaptor.getOp());
|
||||
getProperties().attr = dyn_cast_or_null<IntegerAttr>(adaptor.getOp());
|
||||
return getResult();
|
||||
}
|
||||
return {};
|
||||
|
@ -551,12 +551,12 @@ struct TestRegionRewriteBlockMovement : public ConversionPattern {
|
||||
// Inline this region into the parent region.
|
||||
auto &parentRegion = *op->getParentRegion();
|
||||
auto &opRegion = op->getRegion(0);
|
||||
if (op->getAttr("legalizer.should_clone"))
|
||||
if (op->getDiscardableAttr("legalizer.should_clone"))
|
||||
rewriter.cloneRegionBefore(opRegion, parentRegion, parentRegion.end());
|
||||
else
|
||||
rewriter.inlineRegionBefore(opRegion, parentRegion, parentRegion.end());
|
||||
|
||||
if (op->getAttr("legalizer.erase_old_blocks")) {
|
||||
if (op->getDiscardableAttr("legalizer.erase_old_blocks")) {
|
||||
while (!opRegion.empty())
|
||||
rewriter.eraseBlock(&opRegion.front());
|
||||
}
|
||||
|
@ -55,7 +55,9 @@ public:
|
||||
return DiagnosedSilenceableFailure::success();
|
||||
}
|
||||
|
||||
Attribute getMessage() { return getOperation()->getAttr("message"); }
|
||||
Attribute getMessage() {
|
||||
return getOperation()->getDiscardableAttr("message");
|
||||
}
|
||||
|
||||
static ParseResult parse(OpAsmParser &parser, OperationState &state) {
|
||||
StringAttr message;
|
||||
|
@ -681,7 +681,8 @@ struct TestCreateVectorBroadcast
|
||||
auto targetShape =
|
||||
cast<VectorType>(op->getResult(0).getType()).getShape();
|
||||
auto arrayAttr =
|
||||
cast<DenseI64ArrayAttr>(op->getAttr("broadcast_dims")).asArrayRef();
|
||||
cast<DenseI64ArrayAttr>(op->getDiscardableAttr("broadcast_dims"))
|
||||
.asArrayRef();
|
||||
llvm::SetVector<int64_t> broadcastedDims;
|
||||
broadcastedDims.insert(arrayAttr.begin(), arrayAttr.end());
|
||||
OpBuilder b(op);
|
||||
|
@ -59,7 +59,7 @@ struct SymbolUsesPass
|
||||
symbolUse.getUser()->getParentOp(), symbolUse.getSymbolRef())) {
|
||||
symbolUse.getUser()->emitRemark()
|
||||
<< "found use of symbol : " << symbolUse.getSymbolRef() << " : "
|
||||
<< symbol->getAttr(SymbolTable::getSymbolAttrName());
|
||||
<< *symbol->getInherentAttr(SymbolTable::getSymbolAttrName());
|
||||
}
|
||||
}
|
||||
symbol->emitRemark() << "symbol has " << llvm::size(*symbolUses) << " uses";
|
||||
|
@ -42,7 +42,8 @@ struct TestTopologicalSortAnalysisPass
|
||||
// If the root has an "ordered" attribute, we fill the selectedOps
|
||||
// vector in a certain order.
|
||||
int64_t pos =
|
||||
cast<IntegerAttr>(selected->getAttr("selected")).getInt();
|
||||
cast<IntegerAttr>(selected->getDiscardableAttr("selected"))
|
||||
.getInt();
|
||||
if (pos >= static_cast<int64_t>(selectedOps.size()))
|
||||
selectedOps.append(pos + 1 - selectedOps.size(), nullptr);
|
||||
selectedOps[pos] = selected;
|
||||
|
@ -878,7 +878,8 @@ void PatternEmitter::emitAttributeMatch(DagNode tree, StringRef opName,
|
||||
} else if (attr.isOptional()) {
|
||||
// For a missing attribute that is optional according to definition, we
|
||||
// should just capture a mlir::Attribute() to signal the missing state.
|
||||
// That is precisely what getAttr() returns on missing attributes.
|
||||
// That is precisely what getDiscardableAttr() returns on missing
|
||||
// attributes.
|
||||
} else {
|
||||
emitMatchCheck(opName, tgfmt("tblgen_attr", &fmtCtx),
|
||||
formatv("\"expected op '{0}' to have attribute '{1}' "
|
||||
|
@ -63,7 +63,7 @@ TEST(Bytecode, MultiModuleWithResource) {
|
||||
|
||||
// Try to see if we have a valid resource in the parsed module.
|
||||
auto checkResourceAttribute = [&](Operation *op) {
|
||||
Attribute attr = roundTripModule->getAttr("bytecode.test");
|
||||
Attribute attr = roundTripModule->getDiscardableAttr("bytecode.test");
|
||||
ASSERT_TRUE(attr);
|
||||
auto denseResourceAttr = dyn_cast<DenseI32ResourceElementsAttr>(attr);
|
||||
ASSERT_TRUE(denseResourceAttr);
|
||||
|
@ -285,7 +285,7 @@ TEST(OperandStorageTest, PopulateDefaultAttrs) {
|
||||
// Verify default attributes populated post op creation.
|
||||
Operation *op = b.create<test::OpAttrMatch1>(b.getUnknownLoc(), req1, nullptr,
|
||||
nullptr, req2);
|
||||
auto opt = op->getAttr("default_valued_attr");
|
||||
auto opt = op->getInherentAttr("default_valued_attr");
|
||||
EXPECT_NE(opt, nullptr) << *op;
|
||||
|
||||
op->destroy();
|
||||
|
@ -76,12 +76,13 @@ TEST(PassManagerTest, OpSpecificAnalysis) {
|
||||
|
||||
// Verify that each function got annotated with expected attributes.
|
||||
for (func::FuncOp func : module->getOps<func::FuncOp>()) {
|
||||
ASSERT_TRUE(isa<BoolAttr>(func->getAttr("isFunc")));
|
||||
EXPECT_TRUE(cast<BoolAttr>(func->getAttr("isFunc")).getValue());
|
||||
ASSERT_TRUE(isa<BoolAttr>(func->getDiscardableAttr("isFunc")));
|
||||
EXPECT_TRUE(cast<BoolAttr>(func->getDiscardableAttr("isFunc")).getValue());
|
||||
|
||||
bool isSecret = func.getName() == "secret";
|
||||
ASSERT_TRUE(isa<BoolAttr>(func->getAttr("isSecret")));
|
||||
EXPECT_EQ(cast<BoolAttr>(func->getAttr("isSecret")).getValue(), isSecret);
|
||||
ASSERT_TRUE(isa<BoolAttr>(func->getDiscardableAttr("isSecret")));
|
||||
EXPECT_EQ(cast<BoolAttr>(func->getDiscardableAttr("isSecret")).getValue(),
|
||||
isSecret);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user