ConstantSDNode *constantNode = dyn_cast(node); if (constantNode != nullptr) { int value = constantNode->getZExtValue(); // do something with the constant value }
ConstantSDNode *constantNode = dyn_castThis example is similar to the first one, but for constants that have a bitwidth of 64 (i.e., they are 64-bit integers). We use getAPIntValue to get the value as an APInt (which is a class that can represent integers of any bitwidth), and then use getSExtValue to get the value as a signed 64-bit integer. Package library: LLVM(node); if (constantNode != nullptr && constantNode->getAPIntValue().getBitWidth() == 64) { int64_t value = constantNode->getSExtValue(); // do something with the constant value }